forked from RoaringBitmap/roaring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.go
85 lines (71 loc) · 2.69 KB
/
container.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
package roaring
/**********************************************************************/
// customize for LinDB
/**********************************************************************/
// Container represents the wrapper interface of roaring bitmap's container,
// like array container/run container/bitmap container
type Container interface {
// And computes the intersection between two bitmap's container and returns the new container
And(other Container) Container
// Or computes the union between two bitmaps's container and returns the new container
Or(other Container) Container
// PeekableIterator creates a new ShortPeekable to iterate over the shorts contained in the container
PeekableIterator() PeekableShortIterator
// GetCardinality returns the number of shorts contained in the container
GetCardinality() int
// Contains returns true if the short is contained in the container
Contains(key uint16) bool
// Rank returns the number of short that are smaller or equal to x (Rank(infinity) would be GetCardinality())
Rank(key uint16) int
// Minimum get the smallest value stored in this container, assumes that it is not empty
Minimum() uint16
// Maximum get the largest value stored in this container, assumes that it is not empty
Maximum() uint16
// ToArray creates a new slice containing all of the shorts stored in the container in sorted order
ToArray() []uint16
// getContainer gets the real container
getContainer() container
}
// containerWrapper represents the container wrapper
type containerWrapper struct {
container container
}
func (c *containerWrapper) And(other Container) Container {
result := c.container.and(other.getContainer())
return &containerWrapper{container: result}
}
func (c *containerWrapper) Or(other Container) Container {
result := c.container.or(other.getContainer())
return &containerWrapper{container: result}
}
func (c *containerWrapper) PeekableIterator() PeekableShortIterator {
return newPeekableShortIterator(c.container.getShortIterator())
}
func (c *containerWrapper) GetCardinality() int {
return c.container.getCardinality()
}
func (c *containerWrapper) Rank(key uint16) int {
return c.container.rank(key)
}
func (c *containerWrapper) Contains(key uint16) bool {
return c.container.contains(key)
}
func (c *containerWrapper) Minimum() uint16 {
return c.container.minimum()
}
func (c *containerWrapper) Maximum() uint16 {
return c.container.maximum()
}
func (c *containerWrapper) ToArray() []uint16 {
result := make([]uint16, c.container.getCardinality())
it := c.container.getShortIterator()
idx := 0
for it.hasNext() {
result[idx] = it.next()
idx++
}
return result
}
func (c *containerWrapper) getContainer() container {
return c.container
}