mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-22 14:23:23 +02:00
rename
This commit is contained in:
@@ -2,14 +2,14 @@ use <../../util/slice.scad>;
|
|||||||
use <../../util/some.scad>;
|
use <../../util/some.scad>;
|
||||||
use <../../util/find_index.scad>;
|
use <../../util/find_index.scad>;
|
||||||
|
|
||||||
function _hashmap_add(map, key, value, eq, hash) =
|
function _hashmap_put(map, key, value, eq, hash) =
|
||||||
let(
|
let(
|
||||||
b_idx = hash(key) % len(map),
|
b_idx = hash(key) % len(map),
|
||||||
bucket = map[b_idx],
|
bucket = map[b_idx],
|
||||||
k_idx = find_index(bucket, function(kv) eq(kv[0], key))
|
k_idx = find_index(bucket, function(kv) eq(kv[0], key))
|
||||||
)
|
)
|
||||||
k_idx != -1 ? _replace(map, bucket, key, value, b_idx, k_idx) :
|
k_idx != -1 ? _replace(map, bucket, key, value, b_idx, k_idx) :
|
||||||
_add(map, bucket, key, value, b_idx);
|
_put(map, bucket, key, value, b_idx);
|
||||||
|
|
||||||
function _replace(map, bucket, key, value, b_idx, k_idx) =
|
function _replace(map, bucket, key, value, b_idx, k_idx) =
|
||||||
let(
|
let(
|
||||||
@@ -25,7 +25,7 @@ function _replace(map, bucket, key, value, b_idx, k_idx) =
|
|||||||
slice(map, b_idx + 1)
|
slice(map, b_idx + 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
function _add(map, bucket, key, value, b_idx) = concat(
|
function _put(map, bucket, key, value, b_idx) = concat(
|
||||||
slice(map, 0, b_idx),
|
slice(map, 0, b_idx),
|
||||||
[concat(bucket, [[key, value]])],
|
[concat(bucket, [[key, value]])],
|
||||||
slice(map, b_idx + 1)
|
slice(map, b_idx + 1)
|
@@ -1,5 +0,0 @@
|
|||||||
use <../__comm__/_str_hash.scad>;
|
|
||||||
use <_impl/_hashmap_add_impl.scad>;
|
|
||||||
|
|
||||||
function hashmap_add(map, key, value, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =
|
|
||||||
_hashmap_add(map, key, value, eq, hash);
|
|
5
src/collection/hashmap_put.scad
Normal file
5
src/collection/hashmap_put.scad
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
use <../__comm__/_str_hash.scad>;
|
||||||
|
use <_impl/_hashmap_put_impl.scad>;
|
||||||
|
|
||||||
|
function hashmap_put(map, key, value, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =
|
||||||
|
_hashmap_put(map, key, value, eq, hash);
|
@@ -1,7 +1,7 @@
|
|||||||
use <unittest.scad>;
|
use <unittest.scad>;
|
||||||
use <collection/hashmap.scad>;
|
use <collection/hashmap.scad>;
|
||||||
use <collection/hashmap_list.scad>;
|
use <collection/hashmap_list.scad>;
|
||||||
use <collection/hashmap_add.scad>;
|
use <collection/hashmap_put.scad>;
|
||||||
use <collection/hashmap_len.scad>;
|
use <collection/hashmap_len.scad>;
|
||||||
use <collection/hashmap_del.scad>;
|
use <collection/hashmap_del.scad>;
|
||||||
use <collection/hashmap_get.scad>;
|
use <collection/hashmap_get.scad>;
|
||||||
@@ -20,10 +20,10 @@ module test_hashmap() {
|
|||||||
|
|
||||||
assert(hashmap_list(s) == [["k9876", 3], ["k4444", 3], ["k1234", 1], ["k5678", 2]]);
|
assert(hashmap_list(s) == [["k9876", 3], ["k4444", 3], ["k1234", 1], ["k5678", 2]]);
|
||||||
|
|
||||||
s2 = hashmap_add(s, "k1357", 100);
|
s2 = hashmap_put(s, "k1357", 100);
|
||||||
assert(hashmap_list(s2) == [["k9876", 3], ["k4444", 3], ["k1234", 1], ["k5678", 2], ["k1357", 100]]);
|
assert(hashmap_list(s2) == [["k9876", 3], ["k4444", 3], ["k1234", 1], ["k5678", 2], ["k1357", 100]]);
|
||||||
|
|
||||||
s3 = hashmap_add(s2, "k5678", 200);
|
s3 = hashmap_put(s2, "k5678", 200);
|
||||||
assert(hashmap_list(s3) == [["k9876", 3], ["k4444", 3], ["k1234", 1], ["k5678", 200], ["k1357", 100]]);
|
assert(hashmap_list(s3) == [["k9876", 3], ["k4444", 3], ["k1234", 1], ["k5678", 200], ["k1357", 100]]);
|
||||||
|
|
||||||
s4 = hashmap_del(s3, "k4444");
|
s4 = hashmap_del(s3, "k4444");
|
||||||
|
Reference in New Issue
Block a user