[noob] Help with sets

2020-09-30 Thread doofenstein
> Yes, but even, so you cannot put numbers above 65535 into a set. That's a > hard implementation limit. you can, though then you can't put small values into it anymore sorry for the nitpicking, I just wanted to express my love for ranged integers ;)

[noob] Help with sets

2020-09-30 Thread snej
> So it seems i need to write the first number's type in the set explicitly to > define the sets type. Yes, but even, so you cannot put numbers above 65535 into a set. That's a hard implementation limit. Nim's basic `set` type is simply a bit-field. It's intended for small sets of flags, that

[noob] Help with sets

2020-09-29 Thread xigoi
I don't think the point has been made clearly enough: the default `set` is a bitset. For _every possible value of the type_ , it stores a bit indicating whether it's present in the set. So you should use it only if the type has a limited range of possible values — usually with `enum` or `range`

[noob] Help with sets

2020-09-29 Thread Levlan
ok. thanks.

[noob] Help with sets

2020-09-29 Thread exelotl
> So it seems i need to write the first number's type in the set explicitly to > define the sets type. Yeah, that's right, it's the same for seqs/arrays too. For example `[1, 2, 3]` is an array of `int`, while `[1'u, 2, 3]` is an array of `uint`. The compiler needs a helping hand to figure out

[noob] Help with sets

2020-09-29 Thread exelotl
> 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. The quoted text presumably means that the set's base type will be shifted into a suitable range so that the lowest possible value (e.g. `-32768`) corresp

[noob] Help with sets

2020-09-29 Thread Levlan
I know that int alone is int64 cause int is defined to be as the size of a pointer and int64 is not allowed as written in the tutorial. So it seems i need to write the first number's type in the set explicitly to define the sets type.

[noob] Help with sets

2020-09-29 Thread juancarlospaco
`var s = {2.int16, 7, 8, 9, 10}` If you write just the literal digit its an `int` and not an `int16`. `int` is an alias for `int64`, on 64 Bit hardware.

[noob] Help with sets

2020-09-29 Thread Araq
var s: set[uint16] = {2u16, 7, 8, 9, 10} Run But the memory consumption is not what you want, instead use a hash set from `sets.nim`: import sets var s1 = toHashSet([9, 5, 1]) Run

[noob] Help with sets

2020-09-29 Thread Levlan
Hello I'm trying to create a set using this line: var s: set[int16] = {2, 7, 8, 9, 10} Run and i get error saying: Error: type mismatch: got but expected 'set[uint16]' Run I tried to read the explanation in the tutorial but i can't get to