diff options
Diffstat (limited to 'doc/sets_fragment.txt')
-rw-r--r-- | doc/sets_fragment.txt | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/doc/sets_fragment.txt b/doc/sets_fragment.txt index 4aac75191..35b1fc023 100644 --- a/doc/sets_fragment.txt +++ b/doc/sets_fragment.txt @@ -5,24 +5,25 @@ only be an ordinal type of a certain size, namely: * `uint8`/`byte`-`uint16` * `char` * `enum` +* Ordinal subrange types, i.e. `range[-10..10]` -or equivalent. For signed integers the set's base type is defined to be in the -range `0 .. MaxSetElements-1` where `MaxSetElements` is currently always -2^16. +or equivalent. When constructing a set with signed integer literals, the set's +base type is defined to be in the range `0 .. DefaultSetElements-1` where +`DefaultSetElements` is currently always 2^8. The maximum range length for the +base type of a set is `MaxSetElements` which is currently always 2^16. Types +with a bigger range length are coerced into the range `0 .. MaxSetElements-1`. The reason is that sets are implemented as high performance bit vectors. Attempting to declare a set with a larger type will result in an error: ```nim - var s: set[int64] # Error: set is too large; use `std/sets` for ordinal types # with more than 2^16 elements - ``` **Note:** Nim also offers [hash sets](sets.html) (which you need to import -with `import sets`), which have no such restrictions. +with `import std/sets`), which have no such restrictions. Sets can be constructed via the set constructor: `{}` is the empty set. The empty set is type compatible with any concrete set type. The constructor @@ -38,6 +39,14 @@ can also be used to include elements (and ranges of elements): # from '0' to '9' ``` +The module [`std/setutils`](setutils.html) provides a way to initialize a set from an iterable: + +```nim +import std/setutils + +let uniqueChars = myString.toSet +``` + These operations are supported by sets: ================== ======================================================== |