MapSOaLDhS
This commit is contained in:
parent
fb6fd76d0b
commit
7569420fe0
31
examples/MapSOaLDhS.nct
Normal file
31
examples/MapSOaLDhS.nct
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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;
|
Loading…
Reference in New Issue
Block a user