Associative array to get a unique key for.
Optional minimum key value; defaults to 1.
Optional maximum key value; defaults to K.max, where K is the key type of the passed associative array.
Optional value to assign to the key; defaults to V.init, where V is the value type of the passed associative array.
A unique key for the passed associative array. There will exist an array entry for the key, with the value value.
string[int] aa; immutable key = aa.uniqueKey; assert(key > 0); assert(key in aa); assert(aa[key] == string.init);
import std.conv : to; { string[int] aa; immutable key = aa.uniqueKey; assert(key in aa); } { long[long] aa; immutable key = aa.uniqueKey; assert(key in aa); } { shared bool[int] aa; immutable key = aa.uniqueKey; assert(key in aa); } { int[int] aa; immutable key = aa.uniqueKey(5, 6, 42); assert(key == 5); assert((aa[5] == 42), aa[5].to!string); }
Returns a unique key for the passed associative array. Reserves the key by assigning it a value.
Note: This function will end up in an endless loop if a narrow range of indexes is supplied and the associative array already contains values for all of them.