From 5ce99493f6a9a535f2c88f7b8d54cfdd705b154c Mon Sep 17 00:00:00 2001 From: flaviut Date: Sun, 13 Jul 2014 17:14:38 -0400 Subject: [PATCH] Semifinal revision of bitsets --- content/bitsets.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/content/bitsets.md b/content/bitsets.md index ad28b03..4fa4cd9 100644 --- a/content/bitsets.md +++ b/content/bitsets.md @@ -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` | 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'}` | -| `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'}` | \ No newline at end of file +