mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-31 10:11:53 +02:00
refactor: check bucket []
This commit is contained in:
@@ -3,18 +3,20 @@ use <../../_impl/_find_eq.scad>;
|
|||||||
function _hashmap_put(buckets, b_numbers, key, value, eq, hash) =
|
function _hashmap_put(buckets, b_numbers, key, value, eq, hash) =
|
||||||
let(
|
let(
|
||||||
b_idx = hash(key) % b_numbers,
|
b_idx = hash(key) % b_numbers,
|
||||||
bucket = buckets[b_idx],
|
bucket = buckets[b_idx]
|
||||||
k_idx = _find_eq(bucket, key, eq)
|
|
||||||
)
|
)
|
||||||
|
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) :
|
k_idx != -1 ? _replace(buckets, b_numbers, bucket, key, value, b_idx, k_idx) :
|
||||||
_put(buckets, b_numbers, bucket, key, value, b_idx);
|
_put(buckets, b_numbers, bucket, key, value, b_idx);
|
||||||
|
|
||||||
function _hashmap_put_by(buckets, b_numbers, key, value, eq, hash, f_eq) =
|
function _hashmap_put_by(buckets, b_numbers, key, value, eq, hash, f_eq) =
|
||||||
let(
|
let(
|
||||||
b_idx = hash(key) % b_numbers,
|
b_idx = hash(key) % b_numbers,
|
||||||
bucket = buckets[b_idx],
|
bucket = buckets[b_idx]
|
||||||
k_idx = f_eq(bucket, key, eq)
|
|
||||||
)
|
)
|
||||||
|
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) :
|
k_idx != -1 ? _replace(buckets, b_numbers, bucket, key, value, b_idx, k_idx) :
|
||||||
_put(buckets, b_numbers, bucket, key, value, b_idx);
|
_put(buckets, b_numbers, bucket, key, value, b_idx);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user