nctref/examples/MapSOaLDhS.nct
2025-09-19 19:08:22 +03:00

32 lines
722 B
Plaintext

/*
* SOaLDhS: Statically-allocated, Open-addressing, Linear probing, Dynamic hash, sentinels
*/
record KVPair[K, V] {
K key;
V value;
}
record MapSOaLDhS[K, V, S; capacity, sentinel] {
S(K*) hash;
KVPair[capacity] data;
}
MapSOaLDhS_add: [K, V, S; capacity, sentinel]u1(MapSOaLDhS[K, V, S; capacity, sentinel]* this, K* key, V* value) -> {
S index = ((*this).hash)(value);
index = index & (capacity - 1);
loop {
KVPair[K, V]* pair = &((*this).data[index]);
if(((*pair).key == *key) || ((*pair).value == sentinel)) {
(*pair).key = *key;
(*pair).value = *value;
}
index = index + 1;
}
return 1;
};
@instantiate MapSOaLDhS_add[ugpr, ugpr, ugpr; 128, 0];
MapSOaLDhS[ugpr, ugpr, ugpr; 128, 0] map;