dasmig-core 1.2.0
Shared random engine, distributions and data tiers for the dasmig generator libraries
Loading...
Searching...
No Matches
dasmig::core::unique_rule Class Reference

Makes a batch unique by a key (an email, a username, ...). More...

#include <batch.hpp>

Public Member Functions

std::size_t max_attempts () const noexcept
 Attempts per item, including the first.
 
std::type_index type () const noexcept
 The item type the rule was made for.
 
std::string key_of (const void *item) const
 The key of an item.
 

Static Public Member Functions

template<typename T , typename Key >
static unique_rule by (Key key, std::size_t max_attempts=100)
 Unique by key.
 

Detailed Description

Makes a batch unique by a key (an email, a username, ...).

Items are generated, then checked in index order; an item whose key was already produced earlier in the same call is generated again with the next attempt seed (see attempt_seed()) until it is new or the attempts run out. The outcome is the same for any thread count. Uniqueness holds within one call: two batches that are concatenated are not checked against each other.

Definition at line 79 of file batch.hpp.

Member Function Documentation

◆ by()

template<typename T , typename Key >
static unique_rule dasmig::core::unique_rule::by ( Key  key,
std::size_t  max_attempts = 100 
)
inlinestatic

Unique by key.

Template Parameters
TThe item type the batch produces.
KeyCallable taking const T& and returning something convertible to std::string.
Parameters
keyExtracts the key.
max_attemptsAttempts per item, including the first (at least 1).
Returns
The rule.

Definition at line 90 of file batch.hpp.

◆ key_of()

std::string dasmig::core::unique_rule::key_of ( const void *  item) const
inline

The key of an item.

Parameters
itemPointer to an item of the rule's type.
Returns
The key.

Definition at line 111 of file batch.hpp.

◆ max_attempts()

std::size_t dasmig::core::unique_rule::max_attempts ( ) const
inlinenoexcept

Attempts per item, including the first.

Returns
The limit.

Definition at line 102 of file batch.hpp.

◆ type()

std::type_index dasmig::core::unique_rule::type ( ) const
inlinenoexcept

The item type the rule was made for.

Returns
Its type index.

Definition at line 106 of file batch.hpp.


The documentation for this class was generated from the following file: