hashset


This function models the mathematical set, backed by a hash table. You can use the following to process the returned set.

Since: 3.0

Parameters

  • lt : Constructs a new set containing the elements in the specified list. It can be ignored if you want an empty set.
  • eq : A equality function. If it's ignored, use == to compare elements.
  • hash : A hash function. If it's ignored, convert each element to a string and hash it.
  • number_of_buckets : The function uses a hash table internally. Change the number of buckets if you're trying to do optimization.

Examples

use <util/set/hashset.scad>;
use <util/set/hashset_add.scad>;
use <util/set/hashset_has.scad>;
use <util/set/hashset_del.scad>;
use <util/set/hashset_len.scad>;
use <util/set/hashset_elems.scad>;

s1 = hashset([1, 2, 3, 4, 5, 2, 3, 5]);
assert(hashset_len(s1) == 5);

s2 = hashset_add(s1, 9);
assert(hashset_has(s2, 9));

s3 = hashset_del(s2, 2);
assert(!hashset_has(s3, 2));

echo(hashset_elems(s3)); // a list contains 1, 3, 4, 5, 9