The OpenD Programming Language

MirStringTable

Fast string table used to get key's id. The keys should be first sorted by length and then lexicographically.

Constructors

this
this(const(immutable(C)[])[] sortedKeys)

The keys should be first sorted by length and then lexicographically.

Members

Functions

get
bool get(C[] key, uint index)
opIndex
uint opIndex(C[] key)

Variables

sortedKeys
const(immutable(C)[])[] sortedKeys;

Keys sorted by length and then lexicographically.

Parameters

U

an unsigned type that can hold an index of sorted keys. U.max must be less then length of the table.

C

character type

Examples

static immutable sortedKeys = ["", "a", "b", "aab", "abb", "aaaaa"];
static immutable table = MirStringTable!ubyte(sortedKeys); // CTFE
static assert (table[""] == 0);
static assert (table["a"] == 1);
static assert (table["b"] == 2);
static assert (table["abb"] == 4);
assert (table["aaaaa"] == 5);
import mir.utility: simpleSort;
auto keys = ["aaaaa", "abb", "", "b", "a", "aab"];
// sorts keys by length and then lexicographically.
keys.simpleSort!smallerStringFirst;
assert(keys == ["", "a", "b", "aab", "abb", "aaaaa"]);

Meta