1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-30 09:49:59 +02:00

refactor: check bucket []

This commit is contained in:
Justin Lin
2022-04-14 21:02:55 +08:00
parent 8e042ae635
commit 9bb9dd4260

View File

@@ -3,18 +3,20 @@ use <../../_impl/_find_eq.scad>;
function _hashmap_put(buckets, b_numbers, key, value, eq, hash) =
let(
b_idx = hash(key) % b_numbers,
bucket = buckets[b_idx],
k_idx = _find_eq(bucket, key, eq)
bucket = buckets[b_idx]
)
bucket == [] ? _put(buckets, b_numbers, bucket, key, value, b_idx) :
let(k_idx = _find_eq(bucket, key, eq))
k_idx != -1 ? _replace(buckets, b_numbers, bucket, key, value, b_idx, k_idx) :
_put(buckets, b_numbers, bucket, key, value, b_idx);
function _hashmap_put_by(buckets, b_numbers, key, value, eq, hash, f_eq) =
let(
b_idx = hash(key) % b_numbers,
bucket = buckets[b_idx],
k_idx = f_eq(bucket, key, eq)
bucket = buckets[b_idx]
)
bucket == [] ? _put(buckets, b_numbers, bucket, key, value, b_idx) :
let(k_idx = f_eq(bucket, key, eq))
k_idx != -1 ? _replace(buckets, b_numbers, bucket, key, value, b_idx, k_idx) :
_put(buckets, b_numbers, bucket, key, value, b_idx);