Hi!

I've been playing a bit with Nim's sets to check if I can use them for my 
application.

In particular, I have to deal with a huge amount of sets, so I look for as much 
memory efficiency as possible.

>From what I have seen, it seems the standard `set` would fit my needs. This 
>would be a simplification for my _Container_ object:
    
    
    include prelude
    
    type Container = ref object
        max_val: int
        sets: HashSet[set[uint16]]
    
    proc newContainer(max_val: int): Container =
        Container(
            max_val: max_val,
            sets: HashSet[set[uint16]](),
        )
    
    proc add(c: Container, val: set[uint16]) =
        c.sets.incl(val)
    
    proc remove(c: Container, val: set[uint16]) =
        c.sets.excl(val)
    
    proc show(c: Container) =
        echo c.sets
    
    
    Run

I would like to limit the size of the inner sets as much as possible. I have 
seen that this can be achieved through Subranges, but I couldn't find out how 
could this be done in a dynamic way. For example, in my case, I would like to 
replace the `uint16` type with a more restricted bound according to `max_val`, 
as for most cases `max_val` will be much smaller than `high(uint16)`.

Thank you for your time and your help!

Reply via email to