package bit_storage import "encoding/json" type bitU32inf struct { V []uint32 } var _ BitStorage[uint32] = &bitU32inf{} func EmptyInfiniteU32() *bitU32inf { return &bitU32inf{V: make([]uint32, 0)} } func ParseInfiniteU32(v []uint32) *bitU32inf { return &bitU32inf{V: v} } func (b *bitU32inf) Set(v uint32) { a := int(v / 32) l := len(b.V) if a > l { b.V = append(b.V, make([]uint32, a-l)...) } b.V[a] |= v % 32 } func (b *bitU32inf) Clear(v uint32) { if int(v/32) > len(b.V) { return } b.V[v/32] &^= v % 32 } func (b *bitU32inf) Get(v uint32) bool { if int(v/32) > len(b.V) { return false } return b.V[v/32]&(v%32) > 0 } func (b *bitU32inf) Unique() []uint32 { z := make([]uint32, 0) m := 0 for i := range b.V { n := b.V[i] for n > 0 { z = append(z, (n&2)<>= 1 m++ } } return z } func (b *bitU32inf) Dump() []uint32 { return b.V } func (b *bitU32inf) MarshalJSON() ([]byte, error) { return json.Marshal(b.V) } func (b *bitU32inf) UnmarshalJSON(bytes []byte) error { return json.Unmarshal(bytes, &b.V) }