IDGenerators

IDGenerators provides several classes that generate unique identifyers which are designed to fullfill specific requirements. The classes may also be used as a Functor, but be aware that parallelism is generally not supported.

GUIDGenerator

The GUIDGenerator class generates Globally Unique IDentifyers, it is not thread-safe.

value_type
The type of the generated GUIDs.
GUIDGenerator()
Constructor.
value_type generate()
Generates one GUID.
value_type operator()()
Generates one GUID.
std::size_t count() const
Returns the number of generated values.

KeyGenerator

The class template <typename T = std::size_t> KeyGenerator generates keys for binary-tree-based structures such as STL's map. It is not thread-safe.

Generally, binary trees have logarithmic time for certain operations, based on the assumption that the tree is balanced. Inserting items in sorted order in a tree results in a maximally un-balanced tree, i.e. a structure resembling a linked list rather than a tree. As a result, operations that usually run in logarithmic time require linear time. The KeyGenerator is designed to generate values that should result in a balanced tree when inserted sequentially.

Note that a KeyGenerator will typically always produce the same sequence, a reset() function allows a reset to the initial state.

value_type
The generated key-types, alias for template parameter "T".
template <typename T = std::size_t>
KeyGenerator()
Constructor.
value_type generate()
Generates one key.
value_type operator()()
Generates one key.
void reset()
Reset to initial state.
std::size_t count() const
Returns the number of generated values.

IncGenerator

The class template <typename T = std::size_t> IncGenerator generates incremental values: 0, 1, 2, .... It is not thread-safe.

Note that an IncGenerator will typically always produce the same sequence, a reset() function allows a reset to the initial state.

value_type
The generated index-types, alias for template parameter "T".
template <typename T = std::size_t>
IncGenerator()
Constructor.
value_type generate()
Generates one index.
value_type operator()()
Generates one index.
void reset()
Reset to initial state.
std::size_t count() const
Returns the number of generated values.

Example

To explain the purpose of the KeyGenerator consider the following piece of code:
#include <map>
#include <cvmlcpp/math/Euclid>
#include <cvmlcpp/base/IDGenerators>

std::map<std::size_t, dPoint3D> doubleMap;

KeyGenerator<std::size_t> kGen;

for (std::size_t i = 0; i < N; ++i)
{
	dPoint3D d;

	// Option A
	doubleMap.insert(std::pair<std::size_t, double>(i, d));

	// Option B
	doubleMap.insert(std::pair<std::size_t, double>(kGen(), d));
}

In this code, using kGen() requires a bit more processing, but will result in a better balanced tree.