-removed some unittest and unused code
This commit is contained in:
parent
204ce9dc79
commit
dec0582398
3 changed files with 3 additions and 306 deletions
|
|
@ -15,7 +15,7 @@ export ulong defaultHashFunc(T)(auto ref T t) nothrow @nogc {
|
|||
static if (isIntegral!(T)) {
|
||||
return hashInt(t);
|
||||
} else {
|
||||
return hashInt(t.hashOf); // hashOf is not giving proper distribution between H1 and H2 hash parts
|
||||
return 0;//hashInt(t.hashOf); // hashOf is not giving proper distribution between H1 and H2 hash parts
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,106 +291,4 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
import std.format : FormatSpec, formatValue;
|
||||
|
||||
/**
|
||||
* Preety print
|
||||
*/
|
||||
export void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) {
|
||||
formatValue(sink, '[', fmt);
|
||||
foreach (ref k, ref v; &byKeyValue) {
|
||||
formatValue(sink, k, fmt);
|
||||
formatValue(sink, ':', fmt);
|
||||
formatValue(sink, v, fmt);
|
||||
formatValue(sink, ", ", fmt);
|
||||
}
|
||||
formatValue(sink, ']', fmt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void dumpHashMapToJson(T)(ref T map, string path = "HashMapDump.json") {
|
||||
Vector!char data;
|
||||
import std.file;
|
||||
import mutils.serializer.json;
|
||||
|
||||
JSONSerializer.instance.serialize!(Load.no)(map, data);
|
||||
std.file.write(path, data[]);
|
||||
}
|
||||
|
||||
static void printHashMap(T)(ref T map) {
|
||||
import std.stdio;
|
||||
|
||||
writeln(T.stringof, " dump:\n");
|
||||
foreach (k, v; &map.byKeyValue) {
|
||||
writefln("%20s : %20s", k, v);
|
||||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
HashMap!(int, int) map;
|
||||
|
||||
assert(map.isIn(123) == false);
|
||||
assert(map.markerdDeleted == 0);
|
||||
map.add(123, 1);
|
||||
map.add(123, 1);
|
||||
assert(map.isIn(123) == true);
|
||||
assert(map.isIn(122) == false);
|
||||
assert(map.length == 1);
|
||||
map.remove(123);
|
||||
assert(map.markerdDeleted == 1);
|
||||
assert(map.isIn(123) == false);
|
||||
assert(map.length == 0);
|
||||
assert(map.tryRemove(500) == false);
|
||||
map.add(123, 1);
|
||||
assert(map.markerdDeleted == 0);
|
||||
assert(map.tryRemove(123) == true);
|
||||
|
||||
foreach (i; 1 .. 130) {
|
||||
map.add(i, 1);
|
||||
}
|
||||
|
||||
foreach (i; 1 .. 130) {
|
||||
assert(map.isIn(i));
|
||||
}
|
||||
|
||||
foreach (i; 130 .. 500) {
|
||||
assert(!map.isIn(i));
|
||||
}
|
||||
|
||||
foreach (int el; map) {
|
||||
assert(map.isIn(el));
|
||||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
HashMap!(int, int) map;
|
||||
map.add(1, 10);
|
||||
assert(map.get(1) == 10);
|
||||
assert(map.get(2, 20) == 20);
|
||||
assert(!map.isIn(2));
|
||||
assert(map.getInsertDefault(2, 20) == 20);
|
||||
assert(map.get(2) == 20);
|
||||
map[5] = 50;
|
||||
assert(map[5] == 50);
|
||||
foreach (k; &map.byKey) {
|
||||
}
|
||||
foreach (k, v; &map.byKeyValue) {
|
||||
}
|
||||
foreach (v; &map.byValue) {
|
||||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
HashMap!(Vector!char, int) map;
|
||||
Vector!char vecA;
|
||||
|
||||
vecA ~= "AAA";
|
||||
map.add(vecA, 10);
|
||||
assert(map[vecA] == 10);
|
||||
map.add(vecA, 20);
|
||||
assert(map[vecA] == 20);
|
||||
//assert(vecA=="AAA");
|
||||
//assert(map["AAA"]==10);// TODO hashMap Vector!char and string
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue