https://nim-lang.org/docs/theindex.html CTRL+F: "deduplicate" --> 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.

2018-04-17 18:35:25

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.

2018-04-17 18:56:39
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.)
2018-04-17 21:15:32
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 verrrry 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?
2018-04-18 16:14:30

@jzakiya

Is there a way to increase the size, or work around this?

Try IntSet.

2018-04-18 16:28:17

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))
   ....

2018-04-18 16:59:47
import intsets
var
s = initIntSet()

s.incl(1) s.incl(10)

echo s echo s.card

2018-04-18 17:11:46

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.

2018-04-18 23:55:52

use a sequence:

var numbers = seq[int]
numbers.add(1)
numbers.add(2)
# ...

2018-05-15 22:52:02
<<<••12••>>>