Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib2/core/hashtable.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ let .length(h: Hashtable<k,v>): USize = (
# Reallocates the hashtable with a new capacity, rehashing all existing entries.
# Used internally when the hashtable needs to grow.
let .realloc(h: Hashtable<k,v>, target-capacity: USize): Hashtable<k,v> = (
let new-data = mk-sparse-owned-data(type((HashtableRowExists,k,v)), target-capacity);
let new-data = Hashtable(mk-sparse-owned-data(type((HashtableRowExists,k,v)), target-capacity));
let old-i = 0_sz;
while old-i < h.data.capacity {
let old-kv = h.data[old-i];
if is(old-kv.first,HashtableRowFilled)
then new-data[old-i] = h.data[old-i];
then new-data.bind-direct(old-kv.second, old-kv.third);
old-i = old-i + 1;
};
Hashtable(new-data)
new-data
);

# new allocations = 1 if realloc is necessary
Expand Down
6 changes: 6 additions & 0 deletions tests/promises/hashtable/comparison.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ assert( safe-alloc-block-count == 0 );
assert( {"1":"2"}.lookup("1","3") == "2" );
assert( {"1":"2"}.lookup("2","3") == "3" );
assert( safe-alloc-block-count == 0 );

assert( {"1":"2"}["1"] == {"1":"2","2":"3","3":"4","4":"5","5":"6","6":"7","7":"8","8":"9","9":"10","10":"11","11":"12","12":"13","13":"14","14":"15","15":"16","16":"17","17":"18",
"18":"19","19":"20","20":"21","21":"22","22":"23"}["1"] );
assert( {"1":"2","2":"3","3":"4","4":"5","5":"6","6":"7","7":"8","8":"9","9":"10","10":"11","11":"12","12":"13","13":"14","14":"15","15":"16","16":"17","17":"18",
"18":"19","19":"20","20":"21","21":"22","22":"23","23":"24","24":"25","25":"26","26":"27","27":"28","28":"29","29":"30","30":"31","31":"32","32":"33"}["11"] == Some("12") );
assert( safe-alloc-block-count == 0 );
16 changes: 16 additions & 0 deletions tests/promises/hashtable/realloc.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import lib/std/minimal.lsts;

let table = mk-hashtable(type(String), type(U64));

let ti = 0_u64;
while ti < 5000 {
table = table.bind("\{ti}", ti);
ti = ti + 1;
};

ti = 0_u64;
while ti < 5000 {
assert(table.lookup("\{ti}", 0_u64) == ti);
ti = ti + 1;
};
Loading