From 7569420fe0d9c242ab48c76c400a23a46e6b26bf Mon Sep 17 00:00:00 2001 From: Mid <> Date: Fri, 19 Sep 2025 19:08:22 +0300 Subject: [PATCH] MapSOaLDhS --- examples/MapSOaLDhS.nct | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/MapSOaLDhS.nct diff --git a/examples/MapSOaLDhS.nct b/examples/MapSOaLDhS.nct new file mode 100644 index 0000000..f42af7f --- /dev/null +++ b/examples/MapSOaLDhS.nct @@ -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;