mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 14:18:13 +01:00
re-calculate b_numbers
This commit is contained in:
parent
710a4a2252
commit
1d770479ce
@ -8,14 +8,15 @@ use <../util/some.scad>;
|
||||
df_hash = function(e) _str_hash(e);
|
||||
df_eq = function(e1, e2) e1 == e2;
|
||||
|
||||
function hashset(lt, eq = df_eq, hash = df_hash, bucket_numbers = 16) =
|
||||
function hashset(lt, eq = df_eq, hash = df_hash, bucket_numbers) =
|
||||
let(
|
||||
lt_undef = is_undef(lt),
|
||||
size = lt_undef ? bucket_numbers : len(lt),
|
||||
buckets = [for(i = [0:bucket_numbers - 1]) []]
|
||||
bucket_numbers_undef = is_undef(bucket_numbers),
|
||||
b_numbers = bucket_numbers_undef ?
|
||||
(lt_undef ? 16 : len(lt)) : bucket_numbers,
|
||||
buckets = [for(i = [0:b_numbers - 1]) []]
|
||||
)
|
||||
lt_undef ? buckets :
|
||||
_hashset(lt, len(lt), buckets, eq, hash);
|
||||
lt_undef ? buckets : _hashset(lt, len(lt), buckets, eq, hash);
|
||||
|
||||
function hashset_has(set, elem, eq = df_eq, hash = df_hash) =
|
||||
some(set[hash(elem) % len(set)], function(e) eq(e, elem));
|
||||
|
@ -8,11 +8,11 @@ module test_hashset() {
|
||||
assert(hashset_list(s) == [1, 2, 3, 4, 5]);
|
||||
|
||||
s2 = hashset_add(s, 9);
|
||||
assert(hashset_list(s2) == [1, 2, 3, 4, 5, 9]);
|
||||
assert(hashset_list(s2) == [1, 9, 2, 3, 4, 5]);
|
||||
|
||||
assert(!hashset_has(s2, 13));
|
||||
|
||||
assert(hashset_list(hashset_del(s2, 2)) == [1, 3, 4, 5, 9]);
|
||||
assert(hashset_list(hashset_del(s2, 2)) == [1, 9, 3, 4, 5]);
|
||||
}
|
||||
|
||||
test_hashset();
|
Loading…
x
Reference in New Issue
Block a user