@@ -38,6 +38,7 @@ struct StringMap(T)
3838 import mir.utility: _expect;
3939 import core.lifetime : move;
4040 import mir.conv: emplaceRef;
41+ import mir.algebraic: Algebraic;
4142
4243 // /
4344 static struct KeyValue
@@ -49,6 +50,7 @@ struct StringMap(T)
4950 }
5051
5152 // / `hashOf` Implementation. Doesn't depend on order
53+ static if (is (T == Algebraic! Union, Union) && is (Union == union ))
5254 size_t toHash () scope @trusted const nothrow pure @nogc
5355 {
5456 if (implementation is null )
@@ -64,6 +66,22 @@ struct StringMap(T)
6466 }
6567 return hash;
6668 }
69+ else
70+ size_t toHash () scope @trusted const nothrow // pure @nogc
71+ {
72+ if (implementation is null )
73+ return 0 ;
74+ size_t hash;
75+ foreach (i, index; implementation.indices)
76+ {
77+ hash = hashOf(implementation._keys[index], hash);
78+ static if (__traits(hasMember, T, " toHash" ))
79+ hash = hashOf(implementation._values[index].toHash, hash);
80+ else
81+ hash = hashOf(implementation._values[index], hash);
82+ }
83+ return hash;
84+ }
6785
6886 // / `==` implementation. Doesn't depend on order
6987 // current implementation is workaround for linking bugs when used in self referencing algebraic types
0 commit comments