Semifinal revision of bitsets

This commit is contained in:
flaviut 2014-07-13 17:14:38 -04:00
commit 5ce99493f6

View file

@ -4,16 +4,21 @@ title: Bitsets
# Bitsets
Nimrod comes with a built in way to build a set of ordinal types. The requirements for a type to be usable inside a bitset is that it must be an ordinal and «\texttt{high(T)} < 2^{15}».
Nimrod comes with a built in way to build a set of ordinal types. In order for a type to be usable in a bitset, it must be an ordinal and <<\texttt{high(T)} < 2^{16}>>.
|Operator | Operation | Example Code |
However, best practice is to keep bitset size significantly smaller since each possible element in the set consumes one bit, therefore a bitset of <<2^{16}>> elements will consume 64KiB.
Bitsets have all the useful operations of mathematical sets:
|Operator | Description | Example Code |
|-------------|-------------------------------|----------------------------------------------|
| `A in B` | is A an element of B? | `'d' in {'a'..'z'}` |
| `A notin B` | is A not an element of B? | `40 notin {2..20} ` |
| `a in B` | is a an element of B? | `'d' in {'a'..'z'}` |
| `a notin B` | is a not an element of B? | `40 notin {2..20} ` |
| `A + B` | union of A with B | `{'a'..'m'} + {'n'..'z'} == {'a'..'z'}` |
| `A * B` | intersection of A with B | `{'a'..'m'} * {'c'..'z} == {'c'..'m'}` |
| `A - B` | relative complement of A in B | `{'a'..'z'} - {'b'..'d'} == {'a', 'e'..'z'}` |
| `A <= B` | is A a subset of B? | `{'a'..'c'} <= {'a'..'z'}` |
| `A < B` | is A a strict subset of B? | `{'b'..'c'} < {'a'..'z'}` |
| `A + b` | add element b to set A | `{'b'..'z'} + 'a' == {'a'..'z'}` |
| `A - b` | remove element b from set A | `{'a'..'z'} - 'a' == {'b'..'z'}` |
| `A * B` | intersection of A with B | `{'a'..'m'} * {'c'..'z} == {'c'..'m'}` |
| `A <= B` | is A a subset of B? | `{'a'..'c'} <= {'a'..'z'}` |
| `A < B` | is A a strict subset of B? | `{'b'..'c'} < {'a'..'z'}` |