ValueLexicon

ValueLexicon is a class that maps distinct values to sequentially numbered integer identifiers. It automatically eliminates duplicates and uses a compact representation. See also SequenceLexicon.

Each distinct value is mapped to a 32-bit integer. The space used for each value is approximately 7 bytes plus the space needed for the value itself. For example, int64 values would need approximately 15 bytes each. Note also that values are referred to using 32-bit ids rather than 64-bit pointers.

This class has the same thread-safety properties as "string": const methods are thread safe, and non-const methods are not thread safe.

Example usage:

ValueLexicon<string> lexicon; uint32 cat_id = lexicon.Add("cat"); EXPECT_EQ(cat_id, lexicon.Add("cat")); EXPECT_EQ("cat", lexicon.value(cat_id));

Constructors

this
this()
Undocumented in source.
this
this(ValueLexicon!T x)
Undocumented in source.

Members

Functions

add
uint add(T value)

Add the given value to the lexicon if it is not already present, and return its integer id. Ids are assigned sequentially starting from zero.

clear
void clear()

Clears all data from the lexicon.

size
uint size()

Return the number of values in the lexicon.

value
const(T) value(uint id)

Return the value with the given id.

Meta