Re: How to add unique items to array?
use a sequence: var numbers = seq[int] numbers.add(1) numbers.add(2) # ...
Re: How to add unique items to array?
Hey @dataman, thanks for info on `intsets` FYI, `intsets` has a problem compiling the `card|len` method on `0.17.2` but not on `0.18.0`. Also, while `intsets` indeed will take the correct number of set members, it's at least 3x slower than using `sets`, across the board. So for this case, using a `seq` array is the better alternative. Well, at least I learned some new things today.
Re: How to add unique items to array?
import intsets var s = initIntSet() s.incl(1) s.incl(10) echo s echo s.card
Re: How to add unique items to array?
Hey @dataman can you show how to use this to replace using `sets`. Below is a code prototype using `sets`, what would be the equivalent with `IntSet`. proc example(a, b, c) = var aset: set[uint16] while n < max aset = {} for b in x..y: . incl(aset, k.uint16) . count += card(aset))
Re: How to add unique items to array?
@jzakiya > Is there a way to increase the size, or work around this? Try [IntSet](https://nim-lang.org/docs/intsets.html).
Re: How to add unique items to array?
So @miran and @Stefan_Salewski I used a `set` to replace a `seq`, and it is pretty fast for this case, as I don't have to worry about `deduplicating` the array, which was vey slow as the array size increased. `Sets` did create a much better logical inplace replacement for this case. The structural problem with `sets` is, it only takes up to `uint16` size (2^16-1 = 65,535) elements, and my sets could take upto ~250K elements, so when I do `card(set)` (in place of `arry.len`) I start getting wrong answers once the input size passes a certain point. Is there a way to increase the size, or work around this?
Re: How to add unique items to array?
Thanks @SolitudeSF. @Araq, when you're coming from one language to another (software or human) what is `obvious` to one fluent in the language is not to someone trying to learn the language. As has been brought up many, many times before, Nim's documentation needs to seriously improve, to make it more accessible to more people, who are coming from many different language paradigms. Also, it is better to attract people with honey than vinegar.
Re: How to add unique items to array?
@jzakiya, its in [sequtils](https://nim-lang.org/docs/sequtils.html#deduplicate,openArray%5BT%5D)
Re: How to add unique items to array?
Another red herring. I never got an answer from you what is wrong with using the index to find things. (In this case where to find the symbol `deduplicate`.)
Re: How to add unique items to array?
[https://nim-lang.org/docs/theindex.html](https://nim-lang.org/docs/theindex.html) CTRL+F: "deduplicate" \--> [https://nim-lang.org/docs/sequtils.html#deduplicate,openArray%5BT%5D](https://nim-lang.org/docs/sequtils.html#deduplicate,openArray%5BT%5D) Yes I know jzakiya is immune to Nim's index/documentation, but maybe others benefit from my occasional hints.