mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-11 09:14:29 +02:00
add hashset_len
This commit is contained in:
6
src/collection/hashset_len.scad
Normal file
6
src/collection/hashset_len.scad
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
use <../util/sum.scad>;
|
||||||
|
|
||||||
|
function hashset_len(set) = sum([
|
||||||
|
for(bucket = set)
|
||||||
|
len(bucket)
|
||||||
|
]);
|
@@ -4,12 +4,14 @@ use <collection/hashset_list.scad>;
|
|||||||
use <collection/hashset_add.scad>;
|
use <collection/hashset_add.scad>;
|
||||||
use <collection/hashset_del.scad>;
|
use <collection/hashset_del.scad>;
|
||||||
use <collection/hashset_has.scad>;
|
use <collection/hashset_has.scad>;
|
||||||
|
use <collection/hashset_len.scad>;
|
||||||
|
|
||||||
module test_hashset() {
|
module test_hashset() {
|
||||||
echo("==== test_hashset ====");
|
echo("==== test_hashset ====");
|
||||||
|
|
||||||
s = hashset([1, 2, 3, 4, 5, 2, 3, 5]);
|
s = hashset([1, 2, 3, 4, 5, 2, 3, 5]);
|
||||||
assert(hashset_list(s) == [1, 2, 3, 4, 5]);
|
assert(hashset_list(s) == [1, 2, 3, 4, 5]);
|
||||||
|
assert(hashset_len(s) == 5);
|
||||||
|
|
||||||
s2 = hashset_add(s, 9);
|
s2 = hashset_add(s, 9);
|
||||||
assert(hashset_list(s2) == [1, 2, 3, 4, 5, 9]);
|
assert(hashset_list(s2) == [1, 2, 3, 4, 5, 9]);
|
||||||
|
Reference in New Issue
Block a user