U
U
uvelichitel2019-12-14 15:13:15
go
uvelichitel, 2019-12-14 15:13:15

How to efficiently store large bit masks?

Sometimes you need []bit for algorithmic problems with memory requirements . bool uses byte and not bit (on my machine) //Prints 1000. And that's in bytes not bits https://golang.org/pkg/unsafe/#Sizeof There was an interesting " math/bits " in stdlib, but it limited in size to uint64 and has no trivial get(n) set(n) methods . Advise where to dig. The code is not required, approaches are enough. Is it possible to sculpt your type from []uint64 and hang it with methods?
fmt.Println(unsafe.Sizeof([1000]bool{}))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Pavlyuk, 2019-12-14
@uvelichitel

You can use https://godoc.org/github.com/golang-collections/go...
Or write your own implementation based on []byte, for example. Shifts or masks to get the bit you need.

L
Leonid Nikolaev, 2019-12-14
@nikonor

https://goplay.space/#aBmYRHvEg6u
I think that's how it should be, probably. if I understand the question correctly. just compare bit by bit

I
index0h, 2019-12-14
@index0h

How do you measure efficiency? In convenience/memory/performance?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question