Map template with a fixed set of keys, specified in the class' constructor.
If an item is added whose key is not in the fixed set, an exception is
thrown.
Such a map can be faster than a standard hash map, as the fixed set of
possible keys means that a fast binary search can be used to find the index
of the corresponding value. This of course only holds true when the time
taken to generate a hash from a key would be slower than the time taken to
do a binary search over the key. In the case of char[] keys, tests have
shown that for keys of 5 characters or longer, the FixedKeyMap starts to be
faster than the StandardKeyHashingMap, and that in the case of long keys
(100 characters) it is an order of magnitude faster.
Usage example:
importocean.util.container.FixedKeyMap;
// Create map instanceautomap = newFixedKeyMap!(char[], char[])("first", "second", "third");
// Add and check an entrymap["first"] = "hello";
assert(map["first"] == "hello");
// Example of adding an entry which will be rejectedtry
{
map["fifth"] = "should fail";
}
catch ( map.FixedKeyMapExceptione )
{
// expected
}
// Example of checking if a key is in the map (this does not throw an// exception if the key is not found)autonine = "ninth"inmap;
Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
Alternatively, this file may be distributed under the terms of the Tango
3-Clause BSD License (see LICENSE_BSD.txt for details).
Map template with a fixed set of keys.
Map template with a fixed set of keys, specified in the class' constructor. If an item is added whose key is not in the fixed set, an exception is thrown.
Such a map can be faster than a standard hash map, as the fixed set of possible keys means that a fast binary search can be used to find the index of the corresponding value. This of course only holds true when the time taken to generate a hash from a key would be slower than the time taken to do a binary search over the key. In the case of char[] keys, tests have shown that for keys of 5 characters or longer, the FixedKeyMap starts to be faster than the StandardKeyHashingMap, and that in the case of long keys (100 characters) it is an order of magnitude faster.
Usage example: