bitset icon indicating copy to clipboard operation
bitset copied to clipboard

More compact Setter

Open rusco opened this issue 10 years ago • 3 comments

Setting bits is very verbose, I propose some shortcuts like for example:

c.Set(1, 2, 4, 6) or c.SetMultiple(1,2,4,6) and
c := &bitset.BitSet{1,2,6,6}

rusco avatar Jun 08 '15 08:06 rusco

I don't think that setting constant numbers is a common task. And if it is and one has many constants one could do:

   b := &BitSet{}
   for _, e := range []int{2,27,53,100,101,200} {
        b.Set(e)
   }

So either one has a few constants and he can use Set or has many constants in which case he can use a for loop.

What do you think?

xojoc avatar Jun 08 '15 15:06 xojoc

Well, as a library consumer I can imagine to have the range statement on your side of the fence would be useful. I am in the progress of writing a genetic algorithm from scratch. I will see whether this would be a common task or not. But right this moment this requirement came to my mind, in some weeks from now I will know better.

rusco avatar Jun 08 '15 19:06 rusco

@rusco Adding this function is no big problem for me, but I would like to avoid useless functions. Please let me know if you would find it useful and I'll add it.

When you release your algorithm please let me know :). I want to improve the performance of this library so seeing some code using it would be really helpful.

xojoc avatar Jun 09 '15 01:06 xojoc