This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
110 lines (98 loc) · 2.68 KB
/
interface.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package roaring64
import (
"io"
"github.com/RoaringBitmap/roaring"
"github.com/tidwall/btree"
)
func splitHiLo(val uint64) (uint32, uint32) {
return uint32(val >> 32), uint32(val)
}
func joinHiLo(hi uint32, lo uint32) uint64 {
return (uint64(hi) << 32) | uint64(lo)
}
type keyedBitmap struct {
*roaring.Bitmap
HighBits uint32
}
func (kb *keyedBitmap) Less(than btree.Item, ctx interface{}) bool {
return kb.HighBits < than.(*keyedBitmap).HighBits
}
func (kb keyedBitmap) Clone() keyedBitmap {
return keyedBitmap{
HighBits: kb.HighBits,
Bitmap: kb.Bitmap.Clone(),
}
}
func (kb *keyedBitmap) ClonePtr() *keyedBitmap {
return &keyedBitmap{
HighBits: kb.HighBits,
Bitmap: kb.Bitmap.Clone(),
}
}
type Bitmap64 interface {
ToBase64() (string, error)
FromBase64(str string) (int64, error)
WriteTo(stream io.Writer) (int64, error)
ToBytes() ([]byte, error)
ReadFrom(reader io.Reader) (p int64, err error)
FromBuffer(buf []byte) (p int64, err error)
RunOptimize()
MarshalBinary() ([]byte, error)
UnmarshalBinary(data []byte) error
Clear()
ToArray() []uint64
GetSizeInBytes() uint64
GetSerializedSizeInBytes() uint64
String() string
Iterate(cb func(x uint64) bool)
Iterator() IntPeekable
ReverseIterator() IntIterable
ManyIterator() ManyIntIterable
Clone() *BTreemap
Minimum() uint64
Maximum() uint64
Contains(x uint64) bool
ContainsInt(x int) bool
Equals(o interface{}) bool
Add(x uint64)
CheckedAdd(x uint64) bool
AddInt(x int)
Remove(x uint64)
CheckedRemove(x uint64) bool
IsEmpty() bool
GetCardinality() uint64
And(other *BTreemap)
OrCardinality(other *BTreemap) uint64
AndCardinality(other *BTreemap) uint64
Intersects(other *BTreemap) bool
Xor(other *BTreemap)
Or(other *BTreemap)
AndNot(other *BTreemap)
AddMany(dat []uint64)
Rank(x uint64) uint64
Select(x uint64) (uint64, error)
Flip(rangeStart, rangeEnd uint64)
FlipInt(rangeStart, rangeEnd int)
AddRange(rangeStart, rangeEnd uint64)
RemoveRange(rangeStart, rangeEnd uint64)
Stats() roaring.Statistics
}
// IntIterable allows you to iterate over the values in a Bitmap
type IntIterable interface {
HasNext() bool
Next() uint64
}
// IntPeekable allows you to look at the next value without advancing and
// advance as long as the next value is smaller than minval
type IntPeekable interface {
IntIterable
// PeekNext peeks the next value without advancing the iterator
PeekNext() uint64
// AdvanceIfNeeded advances as long as the next value is smaller than minval
AdvanceIfNeeded(minval uint64)
}
// ManyIntIterable allows you to iterate over the values in a Bitmap
type ManyIntIterable interface {
// pass in a buffer to fill up with values, returns how many values were returned
NextMany([]uint64) int
}