Generic collections library: Vector (dynamic array), List (linked list), Map (ordered binary tree, O(log n)), Hash (hash table), Set, HashSet, SetHash, MultiMap, MultiHash, Stack, Queue, and Pair. Provides typed iteration, sorting, filtering, and functional operations (Reduce, Any, All). Compile with -lib gen_collect.
BloomFilter
Bloom filter: a compact set that can say "definitely not present" or "probably present". Add and MightContain are O(k) bit operations; memory is a fixed number of bits per expected key. There are no false negatives; the false positive rate is about 1% at 10 bits per key and 0.1% at 15. Keys cannot be removed.
Operations
Add #
Adds a key
method : public : Add(key:T) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| key | T | key (Nil is ignored) |
Example
b := Collection.BloomFilter->New(100, 10)<String>;
b->Add("x");
b->Count()->PrintLine(); # 1Bits #
Gets the number of bits in the filter
method : public : Bits() ~ IntReturn
| Type | Description |
|---|---|
| Int | bits |
Count #
Gets the number of Add calls (repeats count)
method : public : Count() ~ IntReturn
| Type | Description |
|---|---|
| Int | count |
MightContain #
Tests a key
method : public : MightContain(key:T) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | T | key |
Return
| Type | Description |
|---|---|
| Bool | false if the key was definitely never added, true if it probably was |
Example
b := Collection.BloomFilter->New(100, 10)<String>;
b->Add("x");
b->MightContain("y")->PrintLine(); # almost certainly falseNew # constructor
Creates a filter
New(expected:Int, bits_per_key:Int)Parameters
| Name | Type | Description |
|---|---|---|
| expected | Int | number of keys you expect to add (at least 1) |
| bits_per_key | Int | bits of memory per expected key, 10 gives about 1% false positives |
Example
b := Collection.BloomFilter->New(1000, 10)<String>;
b->Add("apple");
b->MightContain("apple")->PrintLine(); # true