Make HashTable work complex types as key
- Add toHash() function for String - The key type shouldn't match exact for a lookup. The key type and lookup key type should be comparable. - Move elements when inserting if passed by value.
This commit is contained in:
@@ -31,6 +31,7 @@ import std.algorithm.mutation : bringToFront, copy;
|
||||
import std.algorithm.searching;
|
||||
import tanya.algorithm.comparison;
|
||||
import tanya.algorithm.mutation;
|
||||
import tanya.hash.lookup;
|
||||
import tanya.memory;
|
||||
import tanya.meta.trait;
|
||||
import tanya.meta.transform;
|
||||
@@ -1614,6 +1615,16 @@ struct String
|
||||
assert(s == "Казнить, нельзя помиловать.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the hash value for the string.
|
||||
*
|
||||
* Returns: Hash value for the string.
|
||||
*/
|
||||
size_t toHash() const @nogc nothrow pure @safe
|
||||
{
|
||||
return hash(get);
|
||||
}
|
||||
|
||||
mixin DefaultAllocator;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user