From 8c4754b5634062ecc612b6810d9126f771fdf1b9 Mon Sep 17 00:00:00 2001 From: Mid <> Date: Wed, 15 Oct 2025 14:11:41 +0300 Subject: [PATCH] Joe expansion --- examples/MapDQCaLDhS.nct | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/examples/MapDQCaLDhS.nct b/examples/MapDQCaLDhS.nct index 5675067..69e16a9 100644 --- a/examples/MapDQCaLDhS.nct +++ b/examples/MapDQCaLDhS.nct @@ -46,8 +46,28 @@ MapDQCOaLDhS_try_add: [K, V, S]u1(MapDQCOaLDhS[K, V, S]* this, K* key, V* value) }; MapDQCOaLDhS_expand: [K, V, S]u1(MapDQCOaLDhS[K, V, S]* this) -> { - /* Unimplemented. */ - return 0; + S capacity = this.capacity; + KVPair[K, V][?]* old_data = this.data; + u8[?]* old_occupied = this.occupied; + + S new_capacity = capacity * 2; + this.capacity = new_capacity; + this.data = calloc(new_capacity, @sizeof KVPair[K, V]); + this.occupied = calloc(new_capacity, @sizeof((*this.occupied)[0])); + + S i = 0; + loop { + if(i == capacity) { + break; + } + if((*old_occupied)[i] != 0) { + KVPair[K, V]* pair = &((*old_data)[i]); + MapDQCOaLDhS_try_add[K, V, S](this, &pair.key, &pair.value); + } + i = i + 1; + } + + return 1; }; MapDQCOaLDhS_add: [K, V, S]u1(MapDQCOaLDhS[K, V, S]* this, K* key, V* value) -> {