1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00

add hashset_len

This commit is contained in:
Justin Lin 2021-03-06 08:59:04 +08:00
parent 4ba7a2ee73
commit 5e716fb5f6
2 changed files with 8 additions and 0 deletions

View File

@ -0,0 +1,6 @@
use <../util/sum.scad>;
function hashset_len(set) = sum([
for(bucket = set)
len(bucket)
]);

View File

@ -4,12 +4,14 @@ use <collection/hashset_list.scad>;
use <collection/hashset_add.scad>;
use <collection/hashset_del.scad>;
use <collection/hashset_has.scad>;
use <collection/hashset_len.scad>;
module test_hashset() {
echo("==== test_hashset ====");
s = hashset([1, 2, 3, 4, 5, 2, 3, 5]);
assert(hashset_list(s) == [1, 2, 3, 4, 5]);
assert(hashset_len(s) == 5);
s2 = hashset_add(s, 9);
assert(hashset_list(s2) == [1, 2, 3, 4, 5, 9]);