diff --git a/src/util/map/_impl/_hashmap_put_impl.scad b/src/util/map/_impl/_hashmap_put_impl.scad index 9cc140b7..de841512 100644 --- a/src/util/map/_impl/_hashmap_put_impl.scad +++ b/src/util/map/_impl/_hashmap_put_impl.scad @@ -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);