-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathibit_set.go
64 lines (49 loc) · 1.7 KB
/
ibit_set.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Implements bitsets - both in-memory and redis.
For in-memory, https://github.com/bits-and-blooms/bitset is used while
for redis, bitset operations of redis are used.
*/
package gostatix
import "io"
const wordSize = int(64)
const wordBytes = wordSize / 8
type IBitSet interface {
// Size returns the number of bits in the bitset
getSize() uint
// Has returns true if the bit is set at index, else false
has(index uint) (bool, error)
// HasMulti returns an array of boolean values for the queried
// index values in the indexes array
hasMulti(indexes []uint) ([]bool, error)
// Insert sets the bit at index to true
insert(index uint) (bool, error)
// Insert sets the bits at the indices passed in the indexes array
insertMulti(indexes []uint) (bool, error)
// Equals checks if two bitsets are equal
equals(otherBitSet IBitSet) (bool, error)
// Max returns the first set bit in the bitset
// starting from index 0
max() (uint, bool)
// BitCount returns the total number of set bits in the bitset
bitCount() (uint, error)
// Export returns the json marshalling of the bitset
marshal() (uint, []byte, error)
// Import imports the byte array data into the bitset
unmarshal(data []byte) (bool, error)
// WriteTo writes the bitset to a stream and
// returns the number of bytes written onto the stream
writeTo(stream io.Writer) (int64, error)
// ReadFrom reads the stream and imports it into the bitset
// and returns the number of bytes read
readFrom(stream io.Reader) (int64, error)
}
// Function IsBitSetMem is used to check if the passed variable `t`
// is of type *BitSetMem or not
func isBitSetMem(t interface{}) bool {
switch t.(type) {
case *BitSetMem:
return true
default:
return false
}
}