From bb1745a05d96af1c433eff74ce912d9830b90cbe Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Thu, 21 Nov 2024 00:46:27 +0100 Subject: [PATCH] use map::HashMap instead of map::Map and use clz() to find a free spot --- src/cache.c3 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cache.c3 b/src/cache.c3 index 2123194..2b1b5f2 100644 --- a/src/cache.c3 +++ b/src/cache.c3 @@ -18,7 +18,7 @@ import std::collections::bitset; import std::collections::map; def BitArr = bitset::BitSet() @private; -def IdTable = map::Map() @private; +def IdTable = map::HashMap() @private; def IdTableEntry = map::Entry() @private; const usz CACHE_NCYCLES = (usz)(SIZE * 2.0/3.0); @@ -44,7 +44,7 @@ macro Cache.cycle(&cache) @private { fn void! Cache.init(&cache) { - cache.table = map::new()(SIZE); + cache.table.new_init(capacity: SIZE); // FIXME: this shit is SLOW foreach (idx, bit : cache.used) { cache.used[idx] = false; } foreach (idx, bit : cache.present) { cache.present[idx] = false; } @@ -83,10 +83,10 @@ fn Value*! Cache.search(&cache, Key id) /* If there is no free space left then just return the first position */ fn usz Cache.get_free_spot(&cache) @private { - // FIXME: This shit is SLOW, especially when clz() exists - foreach (idx, bit: cache.present) { - if (bit == false) { - return idx; + const BITS = $typeof(cache.present.data[0]).sizeof*8; + foreach (idx, d: cache.present.data) { + if (d.clz() != BITS) { + return idx*BITS + BITS-d.clz(); } } return 0;