id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
144,600
schollz/progressbar
progressbar.go
OptionSetWidth
func OptionSetWidth(s int) Option { return func(p *ProgressBar) { p.config.width = s } }
go
func OptionSetWidth(s int) Option { return func(p *ProgressBar) { p.config.width = s } }
[ "func", "OptionSetWidth", "(", "s", "int", ")", "Option", "{", "return", "func", "(", "p", "*", "ProgressBar", ")", "{", "p", ".", "config", ".", "width", "=", "s", "\n", "}", "\n", "}" ]
// OptionSetWidth sets the width of the bar
[ "OptionSetWidth", "sets", "the", "width", "of", "the", "bar" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L86-L90
144,601
schollz/progressbar
progressbar.go
OptionSetTheme
func OptionSetTheme(t Theme) Option { return func(p *ProgressBar) { p.config.theme = t } }
go
func OptionSetTheme(t Theme) Option { return func(p *ProgressBar) { p.config.theme = t } }
[ "func", "OptionSetTheme", "(", "t", "Theme", ")", "Option", "{", "return", "func", "(", "p", "*", "ProgressBar", ")", "{", "p", ".", "config", ".", "theme", "=", "t", "\n", "}", "\n", "}" ]
// OptionSetTheme sets the elements the bar is constructed of
[ "OptionSetTheme", "sets", "the", "elements", "the", "bar", "is", "constructed", "of" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L93-L97
144,602
schollz/progressbar
progressbar.go
OptionSetRenderBlankState
func OptionSetRenderBlankState(r bool) Option { return func(p *ProgressBar) { p.config.renderWithBlankState = r } }
go
func OptionSetRenderBlankState(r bool) Option { return func(p *ProgressBar) { p.config.renderWithBlankState = r } }
[ "func", "OptionSetRenderBlankState", "(", "r", "bool", ")", "Option", "{", "return", "func", "(", "p", "*", "ProgressBar", ")", "{", "p", ".", "config", ".", "renderWithBlankState", "=", "r", "\n", "}", "\n", "}" ]
// OptionSetRenderBlankState sets whether or not to render a 0% bar on construction
[ "OptionSetRenderBlankState", "sets", "whether", "or", "not", "to", "render", "a", "0%", "bar", "on", "construction" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L107-L111
144,603
schollz/progressbar
progressbar.go
OptionSetDescription
func OptionSetDescription(description string) Option { return func(p *ProgressBar) { p.config.description = description } }
go
func OptionSetDescription(description string) Option { return func(p *ProgressBar) { p.config.description = description } }
[ "func", "OptionSetDescription", "(", "description", "string", ")", "Option", "{", "return", "func", "(", "p", "*", "ProgressBar", ")", "{", "p", ".", "config", ".", "description", "=", "description", "\n", "}", "\n", "}" ]
// OptionSetDescription sets the description of the bar to render in front of it
[ "OptionSetDescription", "sets", "the", "description", "of", "the", "bar", "to", "render", "in", "front", "of", "it" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L114-L118
144,604
schollz/progressbar
progressbar.go
OptionThrottle
func OptionThrottle(duration time.Duration) Option { return func(p *ProgressBar) { p.config.throttleDuration = duration } }
go
func OptionThrottle(duration time.Duration) Option { return func(p *ProgressBar) { p.config.throttleDuration = duration } }
[ "func", "OptionThrottle", "(", "duration", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "p", "*", "ProgressBar", ")", "{", "p", ".", "config", ".", "throttleDuration", "=", "duration", "\n", "}", "\n", "}" ]
// OptionThrottle will wait the specified duration before updating again. The default // duration is 0 seconds.
[ "OptionThrottle", "will", "wait", "the", "specified", "duration", "before", "updating", "again", ".", "The", "default", "duration", "is", "0", "seconds", "." ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L156-L160
144,605
schollz/progressbar
progressbar.go
NewOptions
func NewOptions(max int, options ...Option) *ProgressBar { return NewOptions64(int64(max), options...) }
go
func NewOptions(max int, options ...Option) *ProgressBar { return NewOptions64(int64(max), options...) }
[ "func", "NewOptions", "(", "max", "int", ",", "options", "...", "Option", ")", "*", "ProgressBar", "{", "return", "NewOptions64", "(", "int64", "(", "max", ")", ",", "options", "...", ")", "\n", "}" ]
// NewOptions constructs a new instance of ProgressBar, with any options you specify
[ "NewOptions", "constructs", "a", "new", "instance", "of", "ProgressBar", "with", "any", "options", "you", "specify" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L178-L180
144,606
schollz/progressbar
progressbar.go
NewOptions64
func NewOptions64(max int64, options ...Option) *ProgressBar { b := ProgressBar{ state: getBlankState(), config: config{ writer: os.Stdout, theme: defaultTheme, width: 40, max: max, throttleDuration: 0 * time.Nanosecond, }, } for _, o := range options { o(&b) } if b.config.renderWithBlankState { b.RenderBlank() } return &b }
go
func NewOptions64(max int64, options ...Option) *ProgressBar { b := ProgressBar{ state: getBlankState(), config: config{ writer: os.Stdout, theme: defaultTheme, width: 40, max: max, throttleDuration: 0 * time.Nanosecond, }, } for _, o := range options { o(&b) } if b.config.renderWithBlankState { b.RenderBlank() } return &b }
[ "func", "NewOptions64", "(", "max", "int64", ",", "options", "...", "Option", ")", "*", "ProgressBar", "{", "b", ":=", "ProgressBar", "{", "state", ":", "getBlankState", "(", ")", ",", "config", ":", "config", "{", "writer", ":", "os", ".", "Stdout", ",", "theme", ":", "defaultTheme", ",", "width", ":", "40", ",", "max", ":", "max", ",", "throttleDuration", ":", "0", "*", "time", ".", "Nanosecond", ",", "}", ",", "}", "\n\n", "for", "_", ",", "o", ":=", "range", "options", "{", "o", "(", "&", "b", ")", "\n", "}", "\n\n", "if", "b", ".", "config", ".", "renderWithBlankState", "{", "b", ".", "RenderBlank", "(", ")", "\n", "}", "\n\n", "return", "&", "b", "\n", "}" ]
// NewOptions64 constructs a new instance of ProgressBar, with any options you specify
[ "NewOptions64", "constructs", "a", "new", "instance", "of", "ProgressBar", "with", "any", "options", "you", "specify" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L183-L204
144,607
schollz/progressbar
progressbar.go
Reset
func (p *ProgressBar) Reset() { p.lock.Lock() defer p.lock.Unlock() p.state = getBlankState() }
go
func (p *ProgressBar) Reset() { p.lock.Lock() defer p.lock.Unlock() p.state = getBlankState() }
[ "func", "(", "p", "*", "ProgressBar", ")", "Reset", "(", ")", "{", "p", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "p", ".", "state", "=", "getBlankState", "(", ")", "\n", "}" ]
// Reset will reset the clock that is used // to calculate current time and the time left.
[ "Reset", "will", "reset", "the", "clock", "that", "is", "used", "to", "calculate", "current", "time", "and", "the", "time", "left", "." ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L227-L232
144,608
schollz/progressbar
progressbar.go
Finish
func (p *ProgressBar) Finish() error { p.lock.Lock() p.state.currentNum = p.config.max p.lock.Unlock() return p.Add(0) }
go
func (p *ProgressBar) Finish() error { p.lock.Lock() p.state.currentNum = p.config.max p.lock.Unlock() return p.Add(0) }
[ "func", "(", "p", "*", "ProgressBar", ")", "Finish", "(", ")", "error", "{", "p", ".", "lock", ".", "Lock", "(", ")", "\n", "p", ".", "state", ".", "currentNum", "=", "p", ".", "config", ".", "max", "\n", "p", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "p", ".", "Add", "(", "0", ")", "\n", "}" ]
// Finish will fill the bar to full
[ "Finish", "will", "fill", "the", "bar", "to", "full" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L235-L240
144,609
schollz/progressbar
progressbar.go
render
func (p *ProgressBar) render() error { // make sure that the rendering is not happening too quickly // but always show if the currentNum reaches the max if time.Since(p.state.lastShown).Nanoseconds() < p.config.throttleDuration.Nanoseconds() && p.state.currentNum < p.config.max { return nil } // first, clear the existing progress bar err := clearProgressBar(p.config, p.state) if err != nil { return err } // check if the progress bar is finished if !p.state.finished && p.state.currentNum >= p.config.max { p.state.finished = true if !p.config.clearOnFinish { renderProgressBar(p.config, p.state) } if p.config.onCompletion != nil { p.config.onCompletion() } } if p.state.finished { return nil } // then, re-render the current progress bar w, err := renderProgressBar(p.config, p.state) if err != nil { return err } if w > p.state.maxLineWidth { p.state.maxLineWidth = w } p.state.lastShown = time.Now() return nil }
go
func (p *ProgressBar) render() error { // make sure that the rendering is not happening too quickly // but always show if the currentNum reaches the max if time.Since(p.state.lastShown).Nanoseconds() < p.config.throttleDuration.Nanoseconds() && p.state.currentNum < p.config.max { return nil } // first, clear the existing progress bar err := clearProgressBar(p.config, p.state) if err != nil { return err } // check if the progress bar is finished if !p.state.finished && p.state.currentNum >= p.config.max { p.state.finished = true if !p.config.clearOnFinish { renderProgressBar(p.config, p.state) } if p.config.onCompletion != nil { p.config.onCompletion() } } if p.state.finished { return nil } // then, re-render the current progress bar w, err := renderProgressBar(p.config, p.state) if err != nil { return err } if w > p.state.maxLineWidth { p.state.maxLineWidth = w } p.state.lastShown = time.Now() return nil }
[ "func", "(", "p", "*", "ProgressBar", ")", "render", "(", ")", "error", "{", "// make sure that the rendering is not happening too quickly", "// but always show if the currentNum reaches the max", "if", "time", ".", "Since", "(", "p", ".", "state", ".", "lastShown", ")", ".", "Nanoseconds", "(", ")", "<", "p", ".", "config", ".", "throttleDuration", ".", "Nanoseconds", "(", ")", "&&", "p", ".", "state", ".", "currentNum", "<", "p", ".", "config", ".", "max", "{", "return", "nil", "\n", "}", "\n\n", "// first, clear the existing progress bar", "err", ":=", "clearProgressBar", "(", "p", ".", "config", ",", "p", ".", "state", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// check if the progress bar is finished", "if", "!", "p", ".", "state", ".", "finished", "&&", "p", ".", "state", ".", "currentNum", ">=", "p", ".", "config", ".", "max", "{", "p", ".", "state", ".", "finished", "=", "true", "\n", "if", "!", "p", ".", "config", ".", "clearOnFinish", "{", "renderProgressBar", "(", "p", ".", "config", ",", "p", ".", "state", ")", "\n", "}", "\n\n", "if", "p", ".", "config", ".", "onCompletion", "!=", "nil", "{", "p", ".", "config", ".", "onCompletion", "(", ")", "\n", "}", "\n", "}", "\n", "if", "p", ".", "state", ".", "finished", "{", "return", "nil", "\n", "}", "\n\n", "// then, re-render the current progress bar", "w", ",", "err", ":=", "renderProgressBar", "(", "p", ".", "config", ",", "p", ".", "state", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "w", ">", "p", ".", "state", ".", "maxLineWidth", "{", "p", ".", "state", ".", "maxLineWidth", "=", "w", "\n", "}", "\n\n", "p", ".", "state", ".", "lastShown", "=", "time", ".", "Now", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// render renders the progress bar, updating the maximum // rendered line width. this function is not thread-safe, // so it must be called with an acquired lock.
[ "render", "renders", "the", "progress", "bar", "updating", "the", "maximum", "rendered", "line", "width", ".", "this", "function", "is", "not", "thread", "-", "safe", "so", "it", "must", "be", "called", "with", "an", "acquired", "lock", "." ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L297-L339
144,610
schollz/progressbar
progressbar.go
State
func (p *ProgressBar) State() State { p.lock.Lock() defer p.lock.Unlock() s := State{} s.CurrentPercent = float64(p.state.currentNum) / float64(p.config.max) s.CurrentBytes = p.state.currentBytes s.MaxBytes = p.config.maxBytes s.SecondsSince = time.Since(p.state.startTime).Seconds() if p.state.currentNum > 0 { s.SecondsLeft = s.SecondsSince / float64(p.state.currentNum) * (float64(p.config.max) - float64(p.state.currentNum)) } s.KBsPerSecond = float64(p.state.currentBytes) / 1000.0 / s.SecondsSince return s }
go
func (p *ProgressBar) State() State { p.lock.Lock() defer p.lock.Unlock() s := State{} s.CurrentPercent = float64(p.state.currentNum) / float64(p.config.max) s.CurrentBytes = p.state.currentBytes s.MaxBytes = p.config.maxBytes s.SecondsSince = time.Since(p.state.startTime).Seconds() if p.state.currentNum > 0 { s.SecondsLeft = s.SecondsSince / float64(p.state.currentNum) * (float64(p.config.max) - float64(p.state.currentNum)) } s.KBsPerSecond = float64(p.state.currentBytes) / 1000.0 / s.SecondsSince return s }
[ "func", "(", "p", "*", "ProgressBar", ")", "State", "(", ")", "State", "{", "p", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "lock", ".", "Unlock", "(", ")", "\n", "s", ":=", "State", "{", "}", "\n", "s", ".", "CurrentPercent", "=", "float64", "(", "p", ".", "state", ".", "currentNum", ")", "/", "float64", "(", "p", ".", "config", ".", "max", ")", "\n", "s", ".", "CurrentBytes", "=", "p", ".", "state", ".", "currentBytes", "\n", "s", ".", "MaxBytes", "=", "p", ".", "config", ".", "maxBytes", "\n", "s", ".", "SecondsSince", "=", "time", ".", "Since", "(", "p", ".", "state", ".", "startTime", ")", ".", "Seconds", "(", ")", "\n", "if", "p", ".", "state", ".", "currentNum", ">", "0", "{", "s", ".", "SecondsLeft", "=", "s", ".", "SecondsSince", "/", "float64", "(", "p", ".", "state", ".", "currentNum", ")", "*", "(", "float64", "(", "p", ".", "config", ".", "max", ")", "-", "float64", "(", "p", ".", "state", ".", "currentNum", ")", ")", "\n", "}", "\n", "s", ".", "KBsPerSecond", "=", "float64", "(", "p", ".", "state", ".", "currentBytes", ")", "/", "1000.0", "/", "s", ".", "SecondsSince", "\n", "return", "s", "\n", "}" ]
// State returns the current state
[ "State", "returns", "the", "current", "state" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L342-L355
144,611
schollz/progressbar
progressbar.go
Close
func (r *Reader) Close() (err error) { if closer, ok := r.Reader.(io.Closer); ok { return closer.Close() } return }
go
func (r *Reader) Close() (err error) { if closer, ok := r.Reader.(io.Closer); ok { return closer.Close() } return }
[ "func", "(", "r", "*", "Reader", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "if", "closer", ",", "ok", ":=", "r", ".", "Reader", ".", "(", "io", ".", "Closer", ")", ";", "ok", "{", "return", "closer", ".", "Close", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Close the reader when it implements io.Closer
[ "Close", "the", "reader", "when", "it", "implements", "io", ".", "Closer" ]
8607ead5339fbde7efa7dafff8e2d4b5e3cd046b
https://github.com/schollz/progressbar/blob/8607ead5339fbde7efa7dafff8e2d4b5e3cd046b/progressbar.go#L467-L472
144,612
RoaringBitmap/roaring
bitmapcontainer.go
clz
func clz(i uint64) int { n := 1 x := uint32(i >> 32) if x == 0 { n += 32 x = uint32(i) } if x>>16 == 0 { n += 16 x = x << 16 } if x>>24 == 0 { n += 8 x = x << 8 } if x>>28 == 0 { n += 4 x = x << 4 } if x>>30 == 0 { n += 2 x = x << 2 } return n - int(x>>31) }
go
func clz(i uint64) int { n := 1 x := uint32(i >> 32) if x == 0 { n += 32 x = uint32(i) } if x>>16 == 0 { n += 16 x = x << 16 } if x>>24 == 0 { n += 8 x = x << 8 } if x>>28 == 0 { n += 4 x = x << 4 } if x>>30 == 0 { n += 2 x = x << 2 } return n - int(x>>31) }
[ "func", "clz", "(", "i", "uint64", ")", "int", "{", "n", ":=", "1", "\n", "x", ":=", "uint32", "(", "i", ">>", "32", ")", "\n", "if", "x", "==", "0", "{", "n", "+=", "32", "\n", "x", "=", "uint32", "(", "i", ")", "\n", "}", "\n", "if", "x", ">>", "16", "==", "0", "{", "n", "+=", "16", "\n", "x", "=", "x", "<<", "16", "\n", "}", "\n", "if", "x", ">>", "24", "==", "0", "{", "n", "+=", "8", "\n", "x", "=", "x", "<<", "8", "\n", "}", "\n", "if", "x", ">>", "28", "==", "0", "{", "n", "+=", "4", "\n", "x", "=", "x", "<<", "4", "\n", "}", "\n", "if", "x", ">>", "30", "==", "0", "{", "n", "+=", "2", "\n", "x", "=", "x", "<<", "2", "\n", "}", "\n", "return", "n", "-", "int", "(", "x", ">>", "31", ")", "\n", "}" ]
// i should be non-zero
[ "i", "should", "be", "non", "-", "zero" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/bitmapcontainer.go#L62-L86
144,613
RoaringBitmap/roaring
bitmapcontainer.go
iremove
func (bc *bitmapContainer) iremove(i uint16) bool { if bc.contains(i) { bc.cardinality-- bc.bitmap[i/64] &^= (uint64(1) << (i % 64)) return true } return false }
go
func (bc *bitmapContainer) iremove(i uint16) bool { if bc.contains(i) { bc.cardinality-- bc.bitmap[i/64] &^= (uint64(1) << (i % 64)) return true } return false }
[ "func", "(", "bc", "*", "bitmapContainer", ")", "iremove", "(", "i", "uint16", ")", "bool", "{", "if", "bc", ".", "contains", "(", "i", ")", "{", "bc", ".", "cardinality", "--", "\n", "bc", ".", "bitmap", "[", "i", "/", "64", "]", "&^=", "(", "uint64", "(", "1", ")", "<<", "(", "i", "%", "64", ")", ")", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// iremove returns true if i was found.
[ "iremove", "returns", "true", "if", "i", "was", "found", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/bitmapcontainer.go#L288-L295
144,614
RoaringBitmap/roaring
bitmapcontainer.go
iaddRange
func (bc *bitmapContainer) iaddRange(firstOfRange, lastOfRange int) container { bc.cardinality += setBitmapRangeAndCardinalityChange(bc.bitmap, firstOfRange, lastOfRange) return bc }
go
func (bc *bitmapContainer) iaddRange(firstOfRange, lastOfRange int) container { bc.cardinality += setBitmapRangeAndCardinalityChange(bc.bitmap, firstOfRange, lastOfRange) return bc }
[ "func", "(", "bc", "*", "bitmapContainer", ")", "iaddRange", "(", "firstOfRange", ",", "lastOfRange", "int", ")", "container", "{", "bc", ".", "cardinality", "+=", "setBitmapRangeAndCardinalityChange", "(", "bc", ".", "bitmap", ",", "firstOfRange", ",", "lastOfRange", ")", "\n", "return", "bc", "\n", "}" ]
// add all values in range [firstOfRange,lastOfRange)
[ "add", "all", "values", "in", "range", "[", "firstOfRange", "lastOfRange", ")" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/bitmapcontainer.go#L312-L315
144,615
RoaringBitmap/roaring
bitmapcontainer.go
iremoveRange
func (bc *bitmapContainer) iremoveRange(firstOfRange, lastOfRange int) container { bc.cardinality += resetBitmapRangeAndCardinalityChange(bc.bitmap, firstOfRange, lastOfRange) if bc.getCardinality() <= arrayDefaultMaxSize { return bc.toArrayContainer() } return bc }
go
func (bc *bitmapContainer) iremoveRange(firstOfRange, lastOfRange int) container { bc.cardinality += resetBitmapRangeAndCardinalityChange(bc.bitmap, firstOfRange, lastOfRange) if bc.getCardinality() <= arrayDefaultMaxSize { return bc.toArrayContainer() } return bc }
[ "func", "(", "bc", "*", "bitmapContainer", ")", "iremoveRange", "(", "firstOfRange", ",", "lastOfRange", "int", ")", "container", "{", "bc", ".", "cardinality", "+=", "resetBitmapRangeAndCardinalityChange", "(", "bc", ".", "bitmap", ",", "firstOfRange", ",", "lastOfRange", ")", "\n", "if", "bc", ".", "getCardinality", "(", ")", "<=", "arrayDefaultMaxSize", "{", "return", "bc", ".", "toArrayContainer", "(", ")", "\n", "}", "\n", "return", "bc", "\n", "}" ]
// remove all values in range [firstOfRange,lastOfRange)
[ "remove", "all", "values", "in", "range", "[", "firstOfRange", "lastOfRange", ")" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/bitmapcontainer.go#L318-L324
144,616
RoaringBitmap/roaring
runcontainer.go
newRunContainer16FromVals
func newRunContainer16FromVals(alreadySorted bool, vals ...uint16) *runContainer16 { // keep this in sync with newRunContainer16FromArray below rc := &runContainer16{} ah := addHelper16{rc: rc} if !alreadySorted { sort.Sort(uint16Slice(vals)) } n := len(vals) var cur, prev uint16 switch { case n == 0: // nothing more case n == 1: ah.m = append(ah.m, newInterval16Range(vals[0], vals[0])) ah.actuallyAdded++ default: ah.runstart = vals[0] ah.actuallyAdded++ for i := 1; i < n; i++ { prev = vals[i-1] cur = vals[i] ah.add(cur, prev, i) } ah.storeIval(ah.runstart, ah.runlen) } rc.iv = ah.m rc.card = int64(ah.actuallyAdded) return rc }
go
func newRunContainer16FromVals(alreadySorted bool, vals ...uint16) *runContainer16 { // keep this in sync with newRunContainer16FromArray below rc := &runContainer16{} ah := addHelper16{rc: rc} if !alreadySorted { sort.Sort(uint16Slice(vals)) } n := len(vals) var cur, prev uint16 switch { case n == 0: // nothing more case n == 1: ah.m = append(ah.m, newInterval16Range(vals[0], vals[0])) ah.actuallyAdded++ default: ah.runstart = vals[0] ah.actuallyAdded++ for i := 1; i < n; i++ { prev = vals[i-1] cur = vals[i] ah.add(cur, prev, i) } ah.storeIval(ah.runstart, ah.runlen) } rc.iv = ah.m rc.card = int64(ah.actuallyAdded) return rc }
[ "func", "newRunContainer16FromVals", "(", "alreadySorted", "bool", ",", "vals", "...", "uint16", ")", "*", "runContainer16", "{", "// keep this in sync with newRunContainer16FromArray below", "rc", ":=", "&", "runContainer16", "{", "}", "\n", "ah", ":=", "addHelper16", "{", "rc", ":", "rc", "}", "\n\n", "if", "!", "alreadySorted", "{", "sort", ".", "Sort", "(", "uint16Slice", "(", "vals", ")", ")", "\n", "}", "\n", "n", ":=", "len", "(", "vals", ")", "\n", "var", "cur", ",", "prev", "uint16", "\n", "switch", "{", "case", "n", "==", "0", ":", "// nothing more", "case", "n", "==", "1", ":", "ah", ".", "m", "=", "append", "(", "ah", ".", "m", ",", "newInterval16Range", "(", "vals", "[", "0", "]", ",", "vals", "[", "0", "]", ")", ")", "\n", "ah", ".", "actuallyAdded", "++", "\n", "default", ":", "ah", ".", "runstart", "=", "vals", "[", "0", "]", "\n", "ah", ".", "actuallyAdded", "++", "\n", "for", "i", ":=", "1", ";", "i", "<", "n", ";", "i", "++", "{", "prev", "=", "vals", "[", "i", "-", "1", "]", "\n", "cur", "=", "vals", "[", "i", "]", "\n", "ah", ".", "add", "(", "cur", ",", "prev", ",", "i", ")", "\n", "}", "\n", "ah", ".", "storeIval", "(", "ah", ".", "runstart", ",", "ah", ".", "runlen", ")", "\n", "}", "\n", "rc", ".", "iv", "=", "ah", ".", "m", "\n", "rc", ".", "card", "=", "int64", "(", "ah", ".", "actuallyAdded", ")", "\n", "return", "rc", "\n", "}" ]
// newRunContainer16FromVals makes a new container from vals. // // For efficiency, vals should be sorted in ascending order. // Ideally vals should not contain duplicates, but we detect and // ignore them. If vals is already sorted in ascending order, then // pass alreadySorted = true. Otherwise, for !alreadySorted, // we will sort vals before creating a runContainer16 of them. // We sort the original vals, so this will change what the // caller sees in vals as a side effect.
[ "newRunContainer16FromVals", "makes", "a", "new", "container", "from", "vals", ".", "For", "efficiency", "vals", "should", "be", "sorted", "in", "ascending", "order", ".", "Ideally", "vals", "should", "not", "contain", "duplicates", "but", "we", "detect", "and", "ignore", "them", ".", "If", "vals", "is", "already", "sorted", "in", "ascending", "order", "then", "pass", "alreadySorted", "=", "true", ".", "Otherwise", "for", "!alreadySorted", "we", "will", "sort", "vals", "before", "creating", "a", "runContainer16", "of", "them", ".", "We", "sort", "the", "original", "vals", "so", "this", "will", "change", "what", "the", "caller", "sees", "in", "vals", "as", "a", "side", "effect", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L176-L206
144,617
RoaringBitmap/roaring
runcontainer.go
newRunContainer16FromArray
func newRunContainer16FromArray(arr *arrayContainer) *runContainer16 { // keep this in sync with newRunContainer16FromVals above rc := &runContainer16{} ah := addHelper16{rc: rc} n := arr.getCardinality() var cur, prev uint16 switch { case n == 0: // nothing more case n == 1: ah.m = append(ah.m, newInterval16Range(arr.content[0], arr.content[0])) ah.actuallyAdded++ default: ah.runstart = arr.content[0] ah.actuallyAdded++ for i := 1; i < n; i++ { prev = arr.content[i-1] cur = arr.content[i] ah.add(cur, prev, i) } ah.storeIval(ah.runstart, ah.runlen) } rc.iv = ah.m rc.card = int64(ah.actuallyAdded) return rc }
go
func newRunContainer16FromArray(arr *arrayContainer) *runContainer16 { // keep this in sync with newRunContainer16FromVals above rc := &runContainer16{} ah := addHelper16{rc: rc} n := arr.getCardinality() var cur, prev uint16 switch { case n == 0: // nothing more case n == 1: ah.m = append(ah.m, newInterval16Range(arr.content[0], arr.content[0])) ah.actuallyAdded++ default: ah.runstart = arr.content[0] ah.actuallyAdded++ for i := 1; i < n; i++ { prev = arr.content[i-1] cur = arr.content[i] ah.add(cur, prev, i) } ah.storeIval(ah.runstart, ah.runlen) } rc.iv = ah.m rc.card = int64(ah.actuallyAdded) return rc }
[ "func", "newRunContainer16FromArray", "(", "arr", "*", "arrayContainer", ")", "*", "runContainer16", "{", "// keep this in sync with newRunContainer16FromVals above", "rc", ":=", "&", "runContainer16", "{", "}", "\n", "ah", ":=", "addHelper16", "{", "rc", ":", "rc", "}", "\n\n", "n", ":=", "arr", ".", "getCardinality", "(", ")", "\n", "var", "cur", ",", "prev", "uint16", "\n", "switch", "{", "case", "n", "==", "0", ":", "// nothing more", "case", "n", "==", "1", ":", "ah", ".", "m", "=", "append", "(", "ah", ".", "m", ",", "newInterval16Range", "(", "arr", ".", "content", "[", "0", "]", ",", "arr", ".", "content", "[", "0", "]", ")", ")", "\n", "ah", ".", "actuallyAdded", "++", "\n", "default", ":", "ah", ".", "runstart", "=", "arr", ".", "content", "[", "0", "]", "\n", "ah", ".", "actuallyAdded", "++", "\n", "for", "i", ":=", "1", ";", "i", "<", "n", ";", "i", "++", "{", "prev", "=", "arr", ".", "content", "[", "i", "-", "1", "]", "\n", "cur", "=", "arr", ".", "content", "[", "i", "]", "\n", "ah", ".", "add", "(", "cur", ",", "prev", ",", "i", ")", "\n", "}", "\n", "ah", ".", "storeIval", "(", "ah", ".", "runstart", ",", "ah", ".", "runlen", ")", "\n", "}", "\n", "rc", ".", "iv", "=", "ah", ".", "m", "\n", "rc", ".", "card", "=", "int64", "(", "ah", ".", "actuallyAdded", ")", "\n", "return", "rc", "\n", "}" ]
// // newRunContainer16FromArray populates a new // runContainer16 from the contents of arr. //
[ "newRunContainer16FromArray", "populates", "a", "new", "runContainer16", "from", "the", "contents", "of", "arr", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L269-L296
144,618
RoaringBitmap/roaring
runcontainer.go
canMerge16
func canMerge16(a, b interval16) bool { if int64(a.last())+1 < int64(b.start) { return false } return int64(b.last())+1 >= int64(a.start) }
go
func canMerge16(a, b interval16) bool { if int64(a.last())+1 < int64(b.start) { return false } return int64(b.last())+1 >= int64(a.start) }
[ "func", "canMerge16", "(", "a", ",", "b", "interval16", ")", "bool", "{", "if", "int64", "(", "a", ".", "last", "(", ")", ")", "+", "1", "<", "int64", "(", "b", ".", "start", ")", "{", "return", "false", "\n", "}", "\n", "return", "int64", "(", "b", ".", "last", "(", ")", ")", "+", "1", ">=", "int64", "(", "a", ".", "start", ")", "\n", "}" ]
// canMerge returns true iff the intervals // a and b either overlap or they are // contiguous and so can be merged into // a single interval.
[ "canMerge", "returns", "true", "iff", "the", "intervals", "a", "and", "b", "either", "overlap", "or", "they", "are", "contiguous", "and", "so", "can", "be", "merged", "into", "a", "single", "interval", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L318-L323
144,619
RoaringBitmap/roaring
runcontainer.go
mergeInterval16s
func mergeInterval16s(a, b interval16) (res interval16) { if !canMerge16(a, b) { panic(fmt.Sprintf("cannot merge %#v and %#v", a, b)) } if b.start < a.start { res.start = b.start } else { res.start = a.start } if b.last() > a.last() { res.length = b.last() - res.start } else { res.length = a.last() - res.start } return }
go
func mergeInterval16s(a, b interval16) (res interval16) { if !canMerge16(a, b) { panic(fmt.Sprintf("cannot merge %#v and %#v", a, b)) } if b.start < a.start { res.start = b.start } else { res.start = a.start } if b.last() > a.last() { res.length = b.last() - res.start } else { res.length = a.last() - res.start } return }
[ "func", "mergeInterval16s", "(", "a", ",", "b", "interval16", ")", "(", "res", "interval16", ")", "{", "if", "!", "canMerge16", "(", "a", ",", "b", ")", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ",", "b", ")", ")", "\n", "}", "\n\n", "if", "b", ".", "start", "<", "a", ".", "start", "{", "res", ".", "start", "=", "b", ".", "start", "\n", "}", "else", "{", "res", ".", "start", "=", "a", ".", "start", "\n", "}", "\n\n", "if", "b", ".", "last", "(", ")", ">", "a", ".", "last", "(", ")", "{", "res", ".", "length", "=", "b", ".", "last", "(", ")", "-", "res", ".", "start", "\n", "}", "else", "{", "res", ".", "length", "=", "a", ".", "last", "(", ")", "-", "res", ".", "start", "\n", "}", "\n\n", "return", "\n", "}" ]
// mergeInterval16s joins a and b into a // new interval, and panics if it cannot.
[ "mergeInterval16s", "joins", "a", "and", "b", "into", "a", "new", "interval", "and", "panics", "if", "it", "cannot", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L339-L357
144,620
RoaringBitmap/roaring
runcontainer.go
intersectInterval16s
func intersectInterval16s(a, b interval16) (res interval16, isEmpty bool) { if !haveOverlap16(a, b) { isEmpty = true return } if b.start > a.start { res.start = b.start } else { res.start = a.start } bEnd := b.last() aEnd := a.last() var resEnd uint16 if bEnd < aEnd { resEnd = bEnd } else { resEnd = aEnd } res.length = resEnd - res.start return }
go
func intersectInterval16s(a, b interval16) (res interval16, isEmpty bool) { if !haveOverlap16(a, b) { isEmpty = true return } if b.start > a.start { res.start = b.start } else { res.start = a.start } bEnd := b.last() aEnd := a.last() var resEnd uint16 if bEnd < aEnd { resEnd = bEnd } else { resEnd = aEnd } res.length = resEnd - res.start return }
[ "func", "intersectInterval16s", "(", "a", ",", "b", "interval16", ")", "(", "res", "interval16", ",", "isEmpty", "bool", ")", "{", "if", "!", "haveOverlap16", "(", "a", ",", "b", ")", "{", "isEmpty", "=", "true", "\n", "return", "\n", "}", "\n", "if", "b", ".", "start", ">", "a", ".", "start", "{", "res", ".", "start", "=", "b", ".", "start", "\n", "}", "else", "{", "res", ".", "start", "=", "a", ".", "start", "\n", "}", "\n\n", "bEnd", ":=", "b", ".", "last", "(", ")", "\n", "aEnd", ":=", "a", ".", "last", "(", ")", "\n", "var", "resEnd", "uint16", "\n\n", "if", "bEnd", "<", "aEnd", "{", "resEnd", "=", "bEnd", "\n", "}", "else", "{", "resEnd", "=", "aEnd", "\n", "}", "\n", "res", ".", "length", "=", "resEnd", "-", "res", ".", "start", "\n", "return", "\n", "}" ]
// intersectInterval16s returns the intersection // of a and b. The isEmpty flag will be true if // a and b were disjoint.
[ "intersectInterval16s", "returns", "the", "intersection", "of", "a", "and", "b", ".", "The", "isEmpty", "flag", "will", "be", "true", "if", "a", "and", "b", "were", "disjoint", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L362-L384
144,621
RoaringBitmap/roaring
runcontainer.go
indexOfIntervalAtOrAfter
func (rc *runContainer16) indexOfIntervalAtOrAfter(key int64, startIndex int64) int64 { rc.myOpts.startIndex = startIndex rc.myOpts.endxIndex = 0 w, already, _ := rc.search(key, &rc.myOpts) if already { return w } return w + 1 }
go
func (rc *runContainer16) indexOfIntervalAtOrAfter(key int64, startIndex int64) int64 { rc.myOpts.startIndex = startIndex rc.myOpts.endxIndex = 0 w, already, _ := rc.search(key, &rc.myOpts) if already { return w } return w + 1 }
[ "func", "(", "rc", "*", "runContainer16", ")", "indexOfIntervalAtOrAfter", "(", "key", "int64", ",", "startIndex", "int64", ")", "int64", "{", "rc", ".", "myOpts", ".", "startIndex", "=", "startIndex", "\n", "rc", ".", "myOpts", ".", "endxIndex", "=", "0", "\n\n", "w", ",", "already", ",", "_", ":=", "rc", ".", "search", "(", "key", ",", "&", "rc", ".", "myOpts", ")", "\n", "if", "already", "{", "return", "w", "\n", "}", "\n", "return", "w", "+", "1", "\n", "}" ]
// indexOfIntervalAtOrAfter is a helper for union.
[ "indexOfIntervalAtOrAfter", "is", "a", "helper", "for", "union", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L619-L628
144,622
RoaringBitmap/roaring
runcontainer.go
contains
func (rc *runContainer16) contains(key uint16) bool { _, in, _ := rc.search(int64(key), nil) return in }
go
func (rc *runContainer16) contains(key uint16) bool { _, in, _ := rc.search(int64(key), nil) return in }
[ "func", "(", "rc", "*", "runContainer16", ")", "contains", "(", "key", "uint16", ")", "bool", "{", "_", ",", "in", ",", "_", ":=", "rc", ".", "search", "(", "int64", "(", "key", ")", ",", "nil", ")", "\n", "return", "in", "\n", "}" ]
// get returns true iff key is in the container.
[ "get", "returns", "true", "iff", "key", "is", "in", "the", "container", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L846-L849
144,623
RoaringBitmap/roaring
runcontainer.go
cardinality
func (rc *runContainer16) cardinality() int64 { if len(rc.iv) == 0 { rc.card = 0 return 0 } if rc.card > 0 { return rc.card // already cached } // have to compute it var n int64 for _, p := range rc.iv { n += p.runlen() } rc.card = n // cache it return n }
go
func (rc *runContainer16) cardinality() int64 { if len(rc.iv) == 0 { rc.card = 0 return 0 } if rc.card > 0 { return rc.card // already cached } // have to compute it var n int64 for _, p := range rc.iv { n += p.runlen() } rc.card = n // cache it return n }
[ "func", "(", "rc", "*", "runContainer16", ")", "cardinality", "(", ")", "int64", "{", "if", "len", "(", "rc", ".", "iv", ")", "==", "0", "{", "rc", ".", "card", "=", "0", "\n", "return", "0", "\n", "}", "\n", "if", "rc", ".", "card", ">", "0", "{", "return", "rc", ".", "card", "// already cached", "\n", "}", "\n", "// have to compute it", "var", "n", "int64", "\n", "for", "_", ",", "p", ":=", "range", "rc", ".", "iv", "{", "n", "+=", "p", ".", "runlen", "(", ")", "\n", "}", "\n", "rc", ".", "card", "=", "n", "// cache it", "\n", "return", "n", "\n", "}" ]
// cardinality returns the count of the integers stored in the // runContainer16.
[ "cardinality", "returns", "the", "count", "of", "the", "integers", "stored", "in", "the", "runContainer16", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L984-L999
144,624
RoaringBitmap/roaring
runcontainer.go
newRunContainer16CopyIv
func newRunContainer16CopyIv(iv []interval16) *runContainer16 { rc := &runContainer16{ iv: make([]interval16, len(iv)), } copy(rc.iv, iv) return rc }
go
func newRunContainer16CopyIv(iv []interval16) *runContainer16 { rc := &runContainer16{ iv: make([]interval16, len(iv)), } copy(rc.iv, iv) return rc }
[ "func", "newRunContainer16CopyIv", "(", "iv", "[", "]", "interval16", ")", "*", "runContainer16", "{", "rc", ":=", "&", "runContainer16", "{", "iv", ":", "make", "(", "[", "]", "interval16", ",", "len", "(", "iv", ")", ")", ",", "}", "\n", "copy", "(", "rc", ".", "iv", ",", "iv", ")", "\n", "return", "rc", "\n", "}" ]
// newRunContainer16CopyIv creates a run container, initializing // with a copy of the supplied iv slice. //
[ "newRunContainer16CopyIv", "creates", "a", "run", "container", "initializing", "with", "a", "copy", "of", "the", "supplied", "iv", "slice", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1022-L1028
144,625
RoaringBitmap/roaring
runcontainer.go
Add
func (rc *runContainer16) Add(k uint16) (wasNew bool) { // TODO comment from runContainer16.java: // it might be better and simpler to do return // toBitmapOrArrayContainer(getCardinality()).add(k) // but note that some unit tests use this method to build up test // runcontainers without calling runOptimize k64 := int64(k) index, present, _ := rc.search(k64, nil) if present { return // already there } wasNew = true // increment card if it is cached already if rc.card > 0 { rc.card++ } n := int64(len(rc.iv)) if index == -1 { // we may need to extend the first run if n > 0 { if rc.iv[0].start == k+1 { rc.iv[0].start = k rc.iv[0].length++ return } } // nope, k stands alone, starting the new first interval16. rc.iv = append([]interval16{newInterval16Range(k, k)}, rc.iv...) return } // are we off the end? handle both index == n and index == n-1: if index >= n-1 { if int64(rc.iv[n-1].last())+1 == k64 { rc.iv[n-1].length++ return } rc.iv = append(rc.iv, newInterval16Range(k, k)) return } // INVAR: index and index+1 both exist, and k goes between them. // // Now: add k into the middle, // possibly fusing with index or index+1 interval16 // and possibly resulting in fusing of two interval16s // that had a one integer gap. left := index right := index + 1 // are we fusing left and right by adding k? if int64(rc.iv[left].last())+1 == k64 && int64(rc.iv[right].start) == k64+1 { // fuse into left rc.iv[left].length = rc.iv[right].last() - rc.iv[left].start // remove redundant right rc.iv = append(rc.iv[:left+1], rc.iv[right+1:]...) return } // are we an addition to left? if int64(rc.iv[left].last())+1 == k64 { // yes rc.iv[left].length++ return } // are we an addition to right? if int64(rc.iv[right].start) == k64+1 { // yes rc.iv[right].start = k rc.iv[right].length++ return } // k makes a standalone new interval16, inserted in the middle tail := append([]interval16{newInterval16Range(k, k)}, rc.iv[right:]...) rc.iv = append(rc.iv[:left+1], tail...) return }
go
func (rc *runContainer16) Add(k uint16) (wasNew bool) { // TODO comment from runContainer16.java: // it might be better and simpler to do return // toBitmapOrArrayContainer(getCardinality()).add(k) // but note that some unit tests use this method to build up test // runcontainers without calling runOptimize k64 := int64(k) index, present, _ := rc.search(k64, nil) if present { return // already there } wasNew = true // increment card if it is cached already if rc.card > 0 { rc.card++ } n := int64(len(rc.iv)) if index == -1 { // we may need to extend the first run if n > 0 { if rc.iv[0].start == k+1 { rc.iv[0].start = k rc.iv[0].length++ return } } // nope, k stands alone, starting the new first interval16. rc.iv = append([]interval16{newInterval16Range(k, k)}, rc.iv...) return } // are we off the end? handle both index == n and index == n-1: if index >= n-1 { if int64(rc.iv[n-1].last())+1 == k64 { rc.iv[n-1].length++ return } rc.iv = append(rc.iv, newInterval16Range(k, k)) return } // INVAR: index and index+1 both exist, and k goes between them. // // Now: add k into the middle, // possibly fusing with index or index+1 interval16 // and possibly resulting in fusing of two interval16s // that had a one integer gap. left := index right := index + 1 // are we fusing left and right by adding k? if int64(rc.iv[left].last())+1 == k64 && int64(rc.iv[right].start) == k64+1 { // fuse into left rc.iv[left].length = rc.iv[right].last() - rc.iv[left].start // remove redundant right rc.iv = append(rc.iv[:left+1], rc.iv[right+1:]...) return } // are we an addition to left? if int64(rc.iv[left].last())+1 == k64 { // yes rc.iv[left].length++ return } // are we an addition to right? if int64(rc.iv[right].start) == k64+1 { // yes rc.iv[right].start = k rc.iv[right].length++ return } // k makes a standalone new interval16, inserted in the middle tail := append([]interval16{newInterval16Range(k, k)}, rc.iv[right:]...) rc.iv = append(rc.iv[:left+1], tail...) return }
[ "func", "(", "rc", "*", "runContainer16", ")", "Add", "(", "k", "uint16", ")", "(", "wasNew", "bool", ")", "{", "// TODO comment from runContainer16.java:", "// it might be better and simpler to do return", "// toBitmapOrArrayContainer(getCardinality()).add(k)", "// but note that some unit tests use this method to build up test", "// runcontainers without calling runOptimize", "k64", ":=", "int64", "(", "k", ")", "\n\n", "index", ",", "present", ",", "_", ":=", "rc", ".", "search", "(", "k64", ",", "nil", ")", "\n", "if", "present", "{", "return", "// already there", "\n", "}", "\n", "wasNew", "=", "true", "\n\n", "// increment card if it is cached already", "if", "rc", ".", "card", ">", "0", "{", "rc", ".", "card", "++", "\n", "}", "\n", "n", ":=", "int64", "(", "len", "(", "rc", ".", "iv", ")", ")", "\n", "if", "index", "==", "-", "1", "{", "// we may need to extend the first run", "if", "n", ">", "0", "{", "if", "rc", ".", "iv", "[", "0", "]", ".", "start", "==", "k", "+", "1", "{", "rc", ".", "iv", "[", "0", "]", ".", "start", "=", "k", "\n", "rc", ".", "iv", "[", "0", "]", ".", "length", "++", "\n", "return", "\n", "}", "\n", "}", "\n", "// nope, k stands alone, starting the new first interval16.", "rc", ".", "iv", "=", "append", "(", "[", "]", "interval16", "{", "newInterval16Range", "(", "k", ",", "k", ")", "}", ",", "rc", ".", "iv", "...", ")", "\n", "return", "\n", "}", "\n\n", "// are we off the end? handle both index == n and index == n-1:", "if", "index", ">=", "n", "-", "1", "{", "if", "int64", "(", "rc", ".", "iv", "[", "n", "-", "1", "]", ".", "last", "(", ")", ")", "+", "1", "==", "k64", "{", "rc", ".", "iv", "[", "n", "-", "1", "]", ".", "length", "++", "\n", "return", "\n", "}", "\n", "rc", ".", "iv", "=", "append", "(", "rc", ".", "iv", ",", "newInterval16Range", "(", "k", ",", "k", ")", ")", "\n", "return", "\n", "}", "\n\n", "// INVAR: index and index+1 both exist, and k goes between them.", "//", "// Now: add k into the middle,", "// possibly fusing with index or index+1 interval16", "// and possibly resulting in fusing of two interval16s", "// that had a one integer gap.", "left", ":=", "index", "\n", "right", ":=", "index", "+", "1", "\n\n", "// are we fusing left and right by adding k?", "if", "int64", "(", "rc", ".", "iv", "[", "left", "]", ".", "last", "(", ")", ")", "+", "1", "==", "k64", "&&", "int64", "(", "rc", ".", "iv", "[", "right", "]", ".", "start", ")", "==", "k64", "+", "1", "{", "// fuse into left", "rc", ".", "iv", "[", "left", "]", ".", "length", "=", "rc", ".", "iv", "[", "right", "]", ".", "last", "(", ")", "-", "rc", ".", "iv", "[", "left", "]", ".", "start", "\n", "// remove redundant right", "rc", ".", "iv", "=", "append", "(", "rc", ".", "iv", "[", ":", "left", "+", "1", "]", ",", "rc", ".", "iv", "[", "right", "+", "1", ":", "]", "...", ")", "\n", "return", "\n", "}", "\n\n", "// are we an addition to left?", "if", "int64", "(", "rc", ".", "iv", "[", "left", "]", ".", "last", "(", ")", ")", "+", "1", "==", "k64", "{", "// yes", "rc", ".", "iv", "[", "left", "]", ".", "length", "++", "\n", "return", "\n", "}", "\n\n", "// are we an addition to right?", "if", "int64", "(", "rc", ".", "iv", "[", "right", "]", ".", "start", ")", "==", "k64", "+", "1", "{", "// yes", "rc", ".", "iv", "[", "right", "]", ".", "start", "=", "k", "\n", "rc", ".", "iv", "[", "right", "]", ".", "length", "++", "\n", "return", "\n", "}", "\n\n", "// k makes a standalone new interval16, inserted in the middle", "tail", ":=", "append", "(", "[", "]", "interval16", "{", "newInterval16Range", "(", "k", ",", "k", ")", "}", ",", "rc", ".", "iv", "[", "right", ":", "]", "...", ")", "\n", "rc", ".", "iv", "=", "append", "(", "rc", ".", "iv", "[", ":", "left", "+", "1", "]", ",", "tail", "...", ")", "\n", "return", "\n", "}" ]
// Add adds a single value k to the set.
[ "Add", "adds", "a", "single", "value", "k", "to", "the", "set", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1066-L1148
144,626
RoaringBitmap/roaring
runcontainer.go
hasNext
func (ri *runIterator16) hasNext() bool { if len(ri.rc.iv) == 0 { return false } if ri.curIndex == -1 { return true } return ri.curSeq+1 < ri.rc.cardinality() }
go
func (ri *runIterator16) hasNext() bool { if len(ri.rc.iv) == 0 { return false } if ri.curIndex == -1 { return true } return ri.curSeq+1 < ri.rc.cardinality() }
[ "func", "(", "ri", "*", "runIterator16", ")", "hasNext", "(", ")", "bool", "{", "if", "len", "(", "ri", ".", "rc", ".", "iv", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "if", "ri", ".", "curIndex", "==", "-", "1", "{", "return", "true", "\n", "}", "\n", "return", "ri", ".", "curSeq", "+", "1", "<", "ri", ".", "rc", ".", "cardinality", "(", ")", "\n", "}" ]
// HasNext returns false if calling Next will panic. It // returns true when there is at least one more value // available in the iteration sequence.
[ "HasNext", "returns", "false", "if", "calling", "Next", "will", "panic", ".", "It", "returns", "true", "when", "there", "is", "at", "least", "one", "more", "value", "available", "in", "the", "iteration", "sequence", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1170-L1178
144,627
RoaringBitmap/roaring
runcontainer.go
next
func (ri *runIterator16) next() uint16 { if !ri.hasNext() { panic("no Next available") } if ri.curIndex >= int64(len(ri.rc.iv)) { panic("runIterator.Next() going beyond what is available") } if ri.curIndex == -1 { // first time is special ri.curIndex = 0 } else { ri.curPosInIndex++ if int64(ri.rc.iv[ri.curIndex].start)+int64(ri.curPosInIndex) == int64(ri.rc.iv[ri.curIndex].last())+1 { ri.curPosInIndex = 0 ri.curIndex++ } ri.curSeq++ } return ri.cur() }
go
func (ri *runIterator16) next() uint16 { if !ri.hasNext() { panic("no Next available") } if ri.curIndex >= int64(len(ri.rc.iv)) { panic("runIterator.Next() going beyond what is available") } if ri.curIndex == -1 { // first time is special ri.curIndex = 0 } else { ri.curPosInIndex++ if int64(ri.rc.iv[ri.curIndex].start)+int64(ri.curPosInIndex) == int64(ri.rc.iv[ri.curIndex].last())+1 { ri.curPosInIndex = 0 ri.curIndex++ } ri.curSeq++ } return ri.cur() }
[ "func", "(", "ri", "*", "runIterator16", ")", "next", "(", ")", "uint16", "{", "if", "!", "ri", ".", "hasNext", "(", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "ri", ".", "curIndex", ">=", "int64", "(", "len", "(", "ri", ".", "rc", ".", "iv", ")", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "ri", ".", "curIndex", "==", "-", "1", "{", "// first time is special", "ri", ".", "curIndex", "=", "0", "\n", "}", "else", "{", "ri", ".", "curPosInIndex", "++", "\n", "if", "int64", "(", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "start", ")", "+", "int64", "(", "ri", ".", "curPosInIndex", ")", "==", "int64", "(", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "last", "(", ")", ")", "+", "1", "{", "ri", ".", "curPosInIndex", "=", "0", "\n", "ri", ".", "curIndex", "++", "\n", "}", "\n", "ri", ".", "curSeq", "++", "\n", "}", "\n", "return", "ri", ".", "cur", "(", ")", "\n", "}" ]
// Next returns the next value in the iteration sequence.
[ "Next", "returns", "the", "next", "value", "in", "the", "iteration", "sequence", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1186-L1205
144,628
RoaringBitmap/roaring
runcontainer.go
cur
func (ri *runReverseIterator16) cur() uint16 { return ri.rc.iv[ri.curIndex].start + ri.curPosInIndex }
go
func (ri *runReverseIterator16) cur() uint16 { return ri.rc.iv[ri.curIndex].start + ri.curPosInIndex }
[ "func", "(", "ri", "*", "runReverseIterator16", ")", "cur", "(", ")", "uint16", "{", "return", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "start", "+", "ri", ".", "curPosInIndex", "\n", "}" ]
// cur returns the current value pointed to by the iterator.
[ "cur", "returns", "the", "current", "value", "pointed", "to", "by", "the", "iterator", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1251-L1253
144,629
RoaringBitmap/roaring
runcontainer.go
next
func (ri *runReverseIterator16) next() uint16 { if !ri.hasNext() { panic("no next available") } if ri.curIndex == -1 { panic("runReverseIterator.next() going beyond what is available") } if ri.curIndex == -2 { // first time is special ri.curIndex = int64(len(ri.rc.iv)) - 1 ri.curPosInIndex = ri.rc.iv[ri.curIndex].length } else { if ri.curPosInIndex > 0 { ri.curPosInIndex-- } else { ri.curIndex-- ri.curPosInIndex = ri.rc.iv[ri.curIndex].length } ri.curSeq++ } return ri.cur() }
go
func (ri *runReverseIterator16) next() uint16 { if !ri.hasNext() { panic("no next available") } if ri.curIndex == -1 { panic("runReverseIterator.next() going beyond what is available") } if ri.curIndex == -2 { // first time is special ri.curIndex = int64(len(ri.rc.iv)) - 1 ri.curPosInIndex = ri.rc.iv[ri.curIndex].length } else { if ri.curPosInIndex > 0 { ri.curPosInIndex-- } else { ri.curIndex-- ri.curPosInIndex = ri.rc.iv[ri.curIndex].length } ri.curSeq++ } return ri.cur() }
[ "func", "(", "ri", "*", "runReverseIterator16", ")", "next", "(", ")", "uint16", "{", "if", "!", "ri", ".", "hasNext", "(", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "ri", ".", "curIndex", "==", "-", "1", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "ri", ".", "curIndex", "==", "-", "2", "{", "// first time is special", "ri", ".", "curIndex", "=", "int64", "(", "len", "(", "ri", ".", "rc", ".", "iv", ")", ")", "-", "1", "\n", "ri", ".", "curPosInIndex", "=", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "length", "\n", "}", "else", "{", "if", "ri", ".", "curPosInIndex", ">", "0", "{", "ri", ".", "curPosInIndex", "--", "\n", "}", "else", "{", "ri", ".", "curIndex", "--", "\n", "ri", ".", "curPosInIndex", "=", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "length", "\n", "}", "\n", "ri", ".", "curSeq", "++", "\n", "}", "\n", "return", "ri", ".", "cur", "(", ")", "\n", "}" ]
// next returns the next value in the iteration sequence.
[ "next", "returns", "the", "next", "value", "in", "the", "iteration", "sequence", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1256-L1277
144,630
RoaringBitmap/roaring
runcontainer.go
remove
func (ri *runReverseIterator16) remove() uint16 { n := ri.rc.cardinality() if n == 0 { panic("runReverseIterator.Remove called on empty runContainer16") } cur := ri.cur() ri.rc.deleteAt(&ri.curIndex, &ri.curPosInIndex, &ri.curSeq) return cur }
go
func (ri *runReverseIterator16) remove() uint16 { n := ri.rc.cardinality() if n == 0 { panic("runReverseIterator.Remove called on empty runContainer16") } cur := ri.cur() ri.rc.deleteAt(&ri.curIndex, &ri.curPosInIndex, &ri.curSeq) return cur }
[ "func", "(", "ri", "*", "runReverseIterator16", ")", "remove", "(", ")", "uint16", "{", "n", ":=", "ri", ".", "rc", ".", "cardinality", "(", ")", "\n", "if", "n", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "cur", ":=", "ri", ".", "cur", "(", ")", "\n\n", "ri", ".", "rc", ".", "deleteAt", "(", "&", "ri", ".", "curIndex", ",", "&", "ri", ".", "curPosInIndex", ",", "&", "ri", ".", "curSeq", ")", "\n", "return", "cur", "\n", "}" ]
// remove removes the element that the iterator // is on from the run container. You can use // cur if you want to double check what is about // to be deleted.
[ "remove", "removes", "the", "element", "that", "the", "iterator", "is", "on", "from", "the", "run", "container", ".", "You", "can", "use", "cur", "if", "you", "want", "to", "double", "check", "what", "is", "about", "to", "be", "deleted", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1283-L1292
144,631
RoaringBitmap/roaring
runcontainer.go
nextMany
func (ri *manyRunIterator16) nextMany(hs uint32, buf []uint32) int { n := 0 if !ri.hasNext() { return n } // start and end are inclusive for n < len(buf) { if ri.curIndex == -1 || int(ri.rc.iv[ri.curIndex].length-ri.curPosInIndex) <= 0 { ri.curPosInIndex = 0 ri.curIndex++ if ri.curIndex == int64(len(ri.rc.iv)) { break } buf[n] = uint32(ri.rc.iv[ri.curIndex].start) | hs if ri.curIndex != 0 { ri.curSeq++ } n++ // not strictly necessarily due to len(buf)-n min check, but saves some work continue } // add as many as you can from this seq moreVals := minOfInt(int(ri.rc.iv[ri.curIndex].length-ri.curPosInIndex), len(buf)-n) base := uint32(ri.rc.iv[ri.curIndex].start+ri.curPosInIndex+1) | hs // allows BCE buf2 := buf[n : n+moreVals] for i := range buf2 { buf2[i] = base + uint32(i) } // update values ri.curPosInIndex += uint16(moreVals) //moreVals always fits in uint16 ri.curSeq += int64(moreVals) n += moreVals } return n }
go
func (ri *manyRunIterator16) nextMany(hs uint32, buf []uint32) int { n := 0 if !ri.hasNext() { return n } // start and end are inclusive for n < len(buf) { if ri.curIndex == -1 || int(ri.rc.iv[ri.curIndex].length-ri.curPosInIndex) <= 0 { ri.curPosInIndex = 0 ri.curIndex++ if ri.curIndex == int64(len(ri.rc.iv)) { break } buf[n] = uint32(ri.rc.iv[ri.curIndex].start) | hs if ri.curIndex != 0 { ri.curSeq++ } n++ // not strictly necessarily due to len(buf)-n min check, but saves some work continue } // add as many as you can from this seq moreVals := minOfInt(int(ri.rc.iv[ri.curIndex].length-ri.curPosInIndex), len(buf)-n) base := uint32(ri.rc.iv[ri.curIndex].start+ri.curPosInIndex+1) | hs // allows BCE buf2 := buf[n : n+moreVals] for i := range buf2 { buf2[i] = base + uint32(i) } // update values ri.curPosInIndex += uint16(moreVals) //moreVals always fits in uint16 ri.curSeq += int64(moreVals) n += moreVals } return n }
[ "func", "(", "ri", "*", "manyRunIterator16", ")", "nextMany", "(", "hs", "uint32", ",", "buf", "[", "]", "uint32", ")", "int", "{", "n", ":=", "0", "\n", "if", "!", "ri", ".", "hasNext", "(", ")", "{", "return", "n", "\n", "}", "\n", "// start and end are inclusive", "for", "n", "<", "len", "(", "buf", ")", "{", "if", "ri", ".", "curIndex", "==", "-", "1", "||", "int", "(", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "length", "-", "ri", ".", "curPosInIndex", ")", "<=", "0", "{", "ri", ".", "curPosInIndex", "=", "0", "\n", "ri", ".", "curIndex", "++", "\n", "if", "ri", ".", "curIndex", "==", "int64", "(", "len", "(", "ri", ".", "rc", ".", "iv", ")", ")", "{", "break", "\n", "}", "\n", "buf", "[", "n", "]", "=", "uint32", "(", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "start", ")", "|", "hs", "\n", "if", "ri", ".", "curIndex", "!=", "0", "{", "ri", ".", "curSeq", "++", "\n", "}", "\n", "n", "++", "\n", "// not strictly necessarily due to len(buf)-n min check, but saves some work", "continue", "\n", "}", "\n", "// add as many as you can from this seq", "moreVals", ":=", "minOfInt", "(", "int", "(", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "length", "-", "ri", ".", "curPosInIndex", ")", ",", "len", "(", "buf", ")", "-", "n", ")", "\n\n", "base", ":=", "uint32", "(", "ri", ".", "rc", ".", "iv", "[", "ri", ".", "curIndex", "]", ".", "start", "+", "ri", ".", "curPosInIndex", "+", "1", ")", "|", "hs", "\n\n", "// allows BCE", "buf2", ":=", "buf", "[", "n", ":", "n", "+", "moreVals", "]", "\n", "for", "i", ":=", "range", "buf2", "{", "buf2", "[", "i", "]", "=", "base", "+", "uint32", "(", "i", ")", "\n", "}", "\n\n", "// update values", "ri", ".", "curPosInIndex", "+=", "uint16", "(", "moreVals", ")", "//moreVals always fits in uint16", "\n", "ri", ".", "curSeq", "+=", "int64", "(", "moreVals", ")", "\n", "n", "+=", "moreVals", "\n", "}", "\n", "return", "n", "\n", "}" ]
// hs are the high bits to include to avoid needing to reiterate over the buffer in NextMany
[ "hs", "are", "the", "high", "bits", "to", "include", "to", "avoid", "needing", "to", "reiterate", "over", "the", "buffer", "in", "NextMany" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1316-L1354
144,632
RoaringBitmap/roaring
runcontainer.go
removeKey
func (rc *runContainer16) removeKey(key uint16) (wasPresent bool) { var index int64 var curSeq int64 index, wasPresent, _ = rc.search(int64(key), nil) if !wasPresent { return // already removed, nothing to do. } pos := key - rc.iv[index].start rc.deleteAt(&index, &pos, &curSeq) return }
go
func (rc *runContainer16) removeKey(key uint16) (wasPresent bool) { var index int64 var curSeq int64 index, wasPresent, _ = rc.search(int64(key), nil) if !wasPresent { return // already removed, nothing to do. } pos := key - rc.iv[index].start rc.deleteAt(&index, &pos, &curSeq) return }
[ "func", "(", "rc", "*", "runContainer16", ")", "removeKey", "(", "key", "uint16", ")", "(", "wasPresent", "bool", ")", "{", "var", "index", "int64", "\n", "var", "curSeq", "int64", "\n", "index", ",", "wasPresent", ",", "_", "=", "rc", ".", "search", "(", "int64", "(", "key", ")", ",", "nil", ")", "\n", "if", "!", "wasPresent", "{", "return", "// already removed, nothing to do.", "\n", "}", "\n", "pos", ":=", "key", "-", "rc", ".", "iv", "[", "index", "]", ".", "start", "\n", "rc", ".", "deleteAt", "(", "&", "index", ",", "&", "pos", ",", "&", "curSeq", ")", "\n", "return", "\n", "}" ]
// remove removes key from the container.
[ "remove", "removes", "key", "from", "the", "container", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1357-L1368
144,633
RoaringBitmap/roaring
runcontainer.go
selectInt16
func (rc *runContainer16) selectInt16(j uint16) int { n := rc.cardinality() if int64(j) > n { panic(fmt.Sprintf("Cannot select %v since Cardinality is %v", j, n)) } var offset int64 for k := range rc.iv { nextOffset := offset + rc.iv[k].runlen() + 1 if nextOffset > int64(j) { return int(int64(rc.iv[k].start) + (int64(j) - offset)) } offset = nextOffset } panic(fmt.Sprintf("Cannot select %v since Cardinality is %v", j, n)) }
go
func (rc *runContainer16) selectInt16(j uint16) int { n := rc.cardinality() if int64(j) > n { panic(fmt.Sprintf("Cannot select %v since Cardinality is %v", j, n)) } var offset int64 for k := range rc.iv { nextOffset := offset + rc.iv[k].runlen() + 1 if nextOffset > int64(j) { return int(int64(rc.iv[k].start) + (int64(j) - offset)) } offset = nextOffset } panic(fmt.Sprintf("Cannot select %v since Cardinality is %v", j, n)) }
[ "func", "(", "rc", "*", "runContainer16", ")", "selectInt16", "(", "j", "uint16", ")", "int", "{", "n", ":=", "rc", ".", "cardinality", "(", ")", "\n", "if", "int64", "(", "j", ")", ">", "n", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "j", ",", "n", ")", ")", "\n", "}", "\n\n", "var", "offset", "int64", "\n", "for", "k", ":=", "range", "rc", ".", "iv", "{", "nextOffset", ":=", "offset", "+", "rc", ".", "iv", "[", "k", "]", ".", "runlen", "(", ")", "+", "1", "\n", "if", "nextOffset", ">", "int64", "(", "j", ")", "{", "return", "int", "(", "int64", "(", "rc", ".", "iv", "[", "k", "]", ".", "start", ")", "+", "(", "int64", "(", "j", ")", "-", "offset", ")", ")", "\n", "}", "\n", "offset", "=", "nextOffset", "\n", "}", "\n", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "j", ",", "n", ")", ")", "\n", "}" ]
// selectInt16 returns the j-th value in the container. // We panic of j is out of bounds.
[ "selectInt16", "returns", "the", "j", "-", "th", "value", "in", "the", "container", ".", "We", "panic", "of", "j", "is", "out", "of", "bounds", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1483-L1498
144,634
RoaringBitmap/roaring
runcontainer.go
invertlastInterval
func (rc *runContainer16) invertlastInterval(origin uint16, lastIdx int) []interval16 { cur := rc.iv[lastIdx] if cur.last() == MaxUint16 { if cur.start == origin { return nil // empty container } return []interval16{newInterval16Range(origin, cur.start-1)} } if cur.start == origin { return []interval16{newInterval16Range(cur.last()+1, MaxUint16)} } // invert splits return []interval16{ newInterval16Range(origin, cur.start-1), newInterval16Range(cur.last()+1, MaxUint16), } }
go
func (rc *runContainer16) invertlastInterval(origin uint16, lastIdx int) []interval16 { cur := rc.iv[lastIdx] if cur.last() == MaxUint16 { if cur.start == origin { return nil // empty container } return []interval16{newInterval16Range(origin, cur.start-1)} } if cur.start == origin { return []interval16{newInterval16Range(cur.last()+1, MaxUint16)} } // invert splits return []interval16{ newInterval16Range(origin, cur.start-1), newInterval16Range(cur.last()+1, MaxUint16), } }
[ "func", "(", "rc", "*", "runContainer16", ")", "invertlastInterval", "(", "origin", "uint16", ",", "lastIdx", "int", ")", "[", "]", "interval16", "{", "cur", ":=", "rc", ".", "iv", "[", "lastIdx", "]", "\n", "if", "cur", ".", "last", "(", ")", "==", "MaxUint16", "{", "if", "cur", ".", "start", "==", "origin", "{", "return", "nil", "// empty container", "\n", "}", "\n", "return", "[", "]", "interval16", "{", "newInterval16Range", "(", "origin", ",", "cur", ".", "start", "-", "1", ")", "}", "\n", "}", "\n", "if", "cur", ".", "start", "==", "origin", "{", "return", "[", "]", "interval16", "{", "newInterval16Range", "(", "cur", ".", "last", "(", ")", "+", "1", ",", "MaxUint16", ")", "}", "\n", "}", "\n", "// invert splits", "return", "[", "]", "interval16", "{", "newInterval16Range", "(", "origin", ",", "cur", ".", "start", "-", "1", ")", ",", "newInterval16Range", "(", "cur", ".", "last", "(", ")", "+", "1", ",", "MaxUint16", ")", ",", "}", "\n", "}" ]
// helper for invert
[ "helper", "for", "invert" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1501-L1517
144,635
RoaringBitmap/roaring
runcontainer.go
andBitmapContainer
func (rc *runContainer16) andBitmapContainer(bc *bitmapContainer) container { bc2 := newBitmapContainerFromRun(rc) return bc2.andBitmap(bc) }
go
func (rc *runContainer16) andBitmapContainer(bc *bitmapContainer) container { bc2 := newBitmapContainerFromRun(rc) return bc2.andBitmap(bc) }
[ "func", "(", "rc", "*", "runContainer16", ")", "andBitmapContainer", "(", "bc", "*", "bitmapContainer", ")", "container", "{", "bc2", ":=", "newBitmapContainerFromRun", "(", "rc", ")", "\n", "return", "bc2", ".", "andBitmap", "(", "bc", ")", "\n", "}" ]
// andBitmapContainer finds the intersection of rc and b.
[ "andBitmapContainer", "finds", "the", "intersection", "of", "rc", "and", "b", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L1878-L1881
144,636
RoaringBitmap/roaring
runcontainer.go
iaddRange
func (rc *runContainer16) iaddRange(firstOfRange, endx int) container { if firstOfRange >= endx { panic(fmt.Sprintf("invalid %v = endx >= firstOfRange", endx)) } addme := newRunContainer16TakeOwnership([]interval16{ { start: uint16(firstOfRange), length: uint16(endx - 1 - firstOfRange), }, }) *rc = *rc.union(addme) return rc }
go
func (rc *runContainer16) iaddRange(firstOfRange, endx int) container { if firstOfRange >= endx { panic(fmt.Sprintf("invalid %v = endx >= firstOfRange", endx)) } addme := newRunContainer16TakeOwnership([]interval16{ { start: uint16(firstOfRange), length: uint16(endx - 1 - firstOfRange), }, }) *rc = *rc.union(addme) return rc }
[ "func", "(", "rc", "*", "runContainer16", ")", "iaddRange", "(", "firstOfRange", ",", "endx", "int", ")", "container", "{", "if", "firstOfRange", ">=", "endx", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "endx", ")", ")", "\n", "}", "\n", "addme", ":=", "newRunContainer16TakeOwnership", "(", "[", "]", "interval16", "{", "{", "start", ":", "uint16", "(", "firstOfRange", ")", ",", "length", ":", "uint16", "(", "endx", "-", "1", "-", "firstOfRange", ")", ",", "}", ",", "}", ")", "\n", "*", "rc", "=", "*", "rc", ".", "union", "(", "addme", ")", "\n", "return", "rc", "\n", "}" ]
// add the values in the range [firstOfRange, endx). endx // is still abe to express 2^16 because it is an int not an uint16.
[ "add", "the", "values", "in", "the", "range", "[", "firstOfRange", "endx", ")", ".", "endx", "is", "still", "abe", "to", "express", "2^16", "because", "it", "is", "an", "int", "not", "an", "uint16", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L2010-L2023
144,637
RoaringBitmap/roaring
runcontainer.go
equals
func (rc *runContainer16) equals(o container) bool { srb, ok := o.(*runContainer16) if !ok { // maybe value instead of pointer val, valok := o.(*runContainer16) if valok { srb = val ok = true } } if ok { // Check if the containers are the same object. if rc == srb { return true } if len(srb.iv) != len(rc.iv) { return false } for i, v := range rc.iv { if v != srb.iv[i] { return false } } return true } // use generic comparison if o.getCardinality() != rc.getCardinality() { return false } rit := rc.getShortIterator() bit := o.getShortIterator() //k := 0 for rit.hasNext() { if bit.next() != rit.next() { return false } //k++ } return true }
go
func (rc *runContainer16) equals(o container) bool { srb, ok := o.(*runContainer16) if !ok { // maybe value instead of pointer val, valok := o.(*runContainer16) if valok { srb = val ok = true } } if ok { // Check if the containers are the same object. if rc == srb { return true } if len(srb.iv) != len(rc.iv) { return false } for i, v := range rc.iv { if v != srb.iv[i] { return false } } return true } // use generic comparison if o.getCardinality() != rc.getCardinality() { return false } rit := rc.getShortIterator() bit := o.getShortIterator() //k := 0 for rit.hasNext() { if bit.next() != rit.next() { return false } //k++ } return true }
[ "func", "(", "rc", "*", "runContainer16", ")", "equals", "(", "o", "container", ")", "bool", "{", "srb", ",", "ok", ":=", "o", ".", "(", "*", "runContainer16", ")", "\n\n", "if", "!", "ok", "{", "// maybe value instead of pointer", "val", ",", "valok", ":=", "o", ".", "(", "*", "runContainer16", ")", "\n", "if", "valok", "{", "srb", "=", "val", "\n", "ok", "=", "true", "\n", "}", "\n", "}", "\n", "if", "ok", "{", "// Check if the containers are the same object.", "if", "rc", "==", "srb", "{", "return", "true", "\n", "}", "\n\n", "if", "len", "(", "srb", ".", "iv", ")", "!=", "len", "(", "rc", ".", "iv", ")", "{", "return", "false", "\n", "}", "\n\n", "for", "i", ",", "v", ":=", "range", "rc", ".", "iv", "{", "if", "v", "!=", "srb", ".", "iv", "[", "i", "]", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}", "\n\n", "// use generic comparison", "if", "o", ".", "getCardinality", "(", ")", "!=", "rc", ".", "getCardinality", "(", ")", "{", "return", "false", "\n", "}", "\n", "rit", ":=", "rc", ".", "getShortIterator", "(", ")", "\n", "bit", ":=", "o", ".", "getShortIterator", "(", ")", "\n\n", "//k := 0", "for", "rit", ".", "hasNext", "(", ")", "{", "if", "bit", ".", "next", "(", ")", "!=", "rit", ".", "next", "(", ")", "{", "return", "false", "\n", "}", "\n", "//k++", "}", "\n", "return", "true", "\n", "}" ]
// equals is now logical equals; it does not require the // same underlying container type.
[ "equals", "is", "now", "logical", "equals", ";", "it", "does", "not", "require", "the", "same", "underlying", "container", "type", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L2087-L2131
144,638
RoaringBitmap/roaring
runcontainer.go
orBitmapContainer
func (rc *runContainer16) orBitmapContainer(bc *bitmapContainer) container { bc2 := newBitmapContainerFromRun(rc) return bc2.iorBitmap(bc) }
go
func (rc *runContainer16) orBitmapContainer(bc *bitmapContainer) container { bc2 := newBitmapContainerFromRun(rc) return bc2.iorBitmap(bc) }
[ "func", "(", "rc", "*", "runContainer16", ")", "orBitmapContainer", "(", "bc", "*", "bitmapContainer", ")", "container", "{", "bc2", ":=", "newBitmapContainerFromRun", "(", "rc", ")", "\n", "return", "bc2", ".", "iorBitmap", "(", "bc", ")", "\n", "}" ]
// orBitmapContainer finds the union of rc and bc.
[ "orBitmapContainer", "finds", "the", "union", "of", "rc", "and", "bc", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L2179-L2182
144,639
RoaringBitmap/roaring
runcontainer.go
And
func (rc *runContainer16) And(b *Bitmap) *Bitmap { out := NewBitmap() for _, p := range rc.iv { plast := p.last() for i := p.start; i <= plast; i++ { if b.Contains(uint32(i)) { out.Add(uint32(i)) } } } return out }
go
func (rc *runContainer16) And(b *Bitmap) *Bitmap { out := NewBitmap() for _, p := range rc.iv { plast := p.last() for i := p.start; i <= plast; i++ { if b.Contains(uint32(i)) { out.Add(uint32(i)) } } } return out }
[ "func", "(", "rc", "*", "runContainer16", ")", "And", "(", "b", "*", "Bitmap", ")", "*", "Bitmap", "{", "out", ":=", "NewBitmap", "(", ")", "\n", "for", "_", ",", "p", ":=", "range", "rc", ".", "iv", "{", "plast", ":=", "p", ".", "last", "(", ")", "\n", "for", "i", ":=", "p", ".", "start", ";", "i", "<=", "plast", ";", "i", "++", "{", "if", "b", ".", "Contains", "(", "uint32", "(", "i", ")", ")", "{", "out", ".", "Add", "(", "uint32", "(", "i", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "out", "\n", "}" ]
// And finds the intersection of rc and b.
[ "And", "finds", "the", "intersection", "of", "rc", "and", "b", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L2490-L2501
144,640
RoaringBitmap/roaring
runcontainer.go
Xor
func (rc *runContainer16) Xor(b *Bitmap) *Bitmap { out := b.Clone() for _, p := range rc.iv { plast := p.last() for v := p.start; v <= plast; v++ { w := uint32(v) if out.Contains(w) { out.RemoveRange(uint64(w), uint64(w+1)) } else { out.Add(w) } } } return out }
go
func (rc *runContainer16) Xor(b *Bitmap) *Bitmap { out := b.Clone() for _, p := range rc.iv { plast := p.last() for v := p.start; v <= plast; v++ { w := uint32(v) if out.Contains(w) { out.RemoveRange(uint64(w), uint64(w+1)) } else { out.Add(w) } } } return out }
[ "func", "(", "rc", "*", "runContainer16", ")", "Xor", "(", "b", "*", "Bitmap", ")", "*", "Bitmap", "{", "out", ":=", "b", ".", "Clone", "(", ")", "\n", "for", "_", ",", "p", ":=", "range", "rc", ".", "iv", "{", "plast", ":=", "p", ".", "last", "(", ")", "\n", "for", "v", ":=", "p", ".", "start", ";", "v", "<=", "plast", ";", "v", "++", "{", "w", ":=", "uint32", "(", "v", ")", "\n", "if", "out", ".", "Contains", "(", "w", ")", "{", "out", ".", "RemoveRange", "(", "uint64", "(", "w", ")", ",", "uint64", "(", "w", "+", "1", ")", ")", "\n", "}", "else", "{", "out", ".", "Add", "(", "w", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "out", "\n", "}" ]
// Xor returns the exclusive-or of rc and b.
[ "Xor", "returns", "the", "exclusive", "-", "or", "of", "rc", "and", "b", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L2504-L2518
144,641
RoaringBitmap/roaring
runcontainer.go
Or
func (rc *runContainer16) Or(b *Bitmap) *Bitmap { out := b.Clone() for _, p := range rc.iv { plast := p.last() for v := p.start; v <= plast; v++ { out.Add(uint32(v)) } } return out }
go
func (rc *runContainer16) Or(b *Bitmap) *Bitmap { out := b.Clone() for _, p := range rc.iv { plast := p.last() for v := p.start; v <= plast; v++ { out.Add(uint32(v)) } } return out }
[ "func", "(", "rc", "*", "runContainer16", ")", "Or", "(", "b", "*", "Bitmap", ")", "*", "Bitmap", "{", "out", ":=", "b", ".", "Clone", "(", ")", "\n", "for", "_", ",", "p", ":=", "range", "rc", ".", "iv", "{", "plast", ":=", "p", ".", "last", "(", ")", "\n", "for", "v", ":=", "p", ".", "start", ";", "v", "<=", "plast", ";", "v", "++", "{", "out", ".", "Add", "(", "uint32", "(", "v", ")", ")", "\n", "}", "\n", "}", "\n", "return", "out", "\n", "}" ]
// Or returns the union of rc and b.
[ "Or", "returns", "the", "union", "of", "rc", "and", "b", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/runcontainer.go#L2521-L2530
144,642
RoaringBitmap/roaring
serialization_littleendian.go
byteSliceAsUint16Slice
func byteSliceAsUint16Slice(slice []byte) []uint16 { if len(slice)%2 != 0 { panic("Slice size should be divisible by 2") } // make a new slice header header := *(*reflect.SliceHeader)(unsafe.Pointer(&slice)) // update its capacity and length header.Len /= 2 header.Cap /= 2 // return it return *(*[]uint16)(unsafe.Pointer(&header)) }
go
func byteSliceAsUint16Slice(slice []byte) []uint16 { if len(slice)%2 != 0 { panic("Slice size should be divisible by 2") } // make a new slice header header := *(*reflect.SliceHeader)(unsafe.Pointer(&slice)) // update its capacity and length header.Len /= 2 header.Cap /= 2 // return it return *(*[]uint16)(unsafe.Pointer(&header)) }
[ "func", "byteSliceAsUint16Slice", "(", "slice", "[", "]", "byte", ")", "[", "]", "uint16", "{", "if", "len", "(", "slice", ")", "%", "2", "!=", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// make a new slice header", "header", ":=", "*", "(", "*", "reflect", ".", "SliceHeader", ")", "(", "unsafe", ".", "Pointer", "(", "&", "slice", ")", ")", "\n\n", "// update its capacity and length", "header", ".", "Len", "/=", "2", "\n", "header", ".", "Cap", "/=", "2", "\n\n", "// return it", "return", "*", "(", "*", "[", "]", "uint16", ")", "(", "unsafe", ".", "Pointer", "(", "&", "header", ")", ")", "\n", "}" ]
// Deserialization code follows
[ "Deserialization", "code", "follows" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/serialization_littleendian.go#L71-L85
144,643
RoaringBitmap/roaring
ctz_compat.go
countTrailingZeros
func countTrailingZeros(x uint64) int { // x & -x leaves only the right-most bit set in the word. Let k be the // index of that bit. Since only a single bit is set, the value is two // to the power of k. Multiplying by a power of two is equivalent to // left shifting, in this case by k bits. The de Bruijn constant is // such that all six bit, consecutive substrings are distinct. // Therefore, if we have a left shifted version of this constant we can // find by how many bits it was shifted by looking at which six bit // substring ended up at the top of the word. // (Knuth, volume 4, section 7.3.1) if x == 0 { // We have to special case 0; the fomula // below doesn't work for 0. return 64 } return int(deBruijn64Lookup[((x&-x)*(deBruijn64))>>58]) }
go
func countTrailingZeros(x uint64) int { // x & -x leaves only the right-most bit set in the word. Let k be the // index of that bit. Since only a single bit is set, the value is two // to the power of k. Multiplying by a power of two is equivalent to // left shifting, in this case by k bits. The de Bruijn constant is // such that all six bit, consecutive substrings are distinct. // Therefore, if we have a left shifted version of this constant we can // find by how many bits it was shifted by looking at which six bit // substring ended up at the top of the word. // (Knuth, volume 4, section 7.3.1) if x == 0 { // We have to special case 0; the fomula // below doesn't work for 0. return 64 } return int(deBruijn64Lookup[((x&-x)*(deBruijn64))>>58]) }
[ "func", "countTrailingZeros", "(", "x", "uint64", ")", "int", "{", "// x & -x leaves only the right-most bit set in the word. Let k be the", "// index of that bit. Since only a single bit is set, the value is two", "// to the power of k. Multiplying by a power of two is equivalent to", "// left shifting, in this case by k bits. The de Bruijn constant is", "// such that all six bit, consecutive substrings are distinct.", "// Therefore, if we have a left shifted version of this constant we can", "// find by how many bits it was shifted by looking at which six bit", "// substring ended up at the top of the word.", "// (Knuth, volume 4, section 7.3.1)", "if", "x", "==", "0", "{", "// We have to special case 0; the fomula", "// below doesn't work for 0.", "return", "64", "\n", "}", "\n", "return", "int", "(", "deBruijn64Lookup", "[", "(", "(", "x", "&", "-", "x", ")", "*", "(", "deBruijn64", ")", ")", ">>", "58", "]", ")", "\n", "}" ]
// trailingZeroBits returns the number of consecutive least significant zero // bits of x.
[ "trailingZeroBits", "returns", "the", "number", "of", "consecutive", "least", "significant", "zero", "bits", "of", "x", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/ctz_compat.go#L55-L71
144,644
RoaringBitmap/roaring
fastaggregation.go
lazyOR
func lazyOR(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2) pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { c1 := x1.highlowcontainer.getContainerAtIndex(pos1) switch t := c1.(type) { case *arrayContainer: c1 = t.toBitmapContainer() case *runContainer16: if !t.isFull() { c1 = t.toBitmapContainer() } } answer.highlowcontainer.appendContainer(s1, c1.lazyOR(x2.highlowcontainer.getContainerAtIndex(pos2)), false) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } else if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
go
func lazyOR(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2) pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { c1 := x1.highlowcontainer.getContainerAtIndex(pos1) switch t := c1.(type) { case *arrayContainer: c1 = t.toBitmapContainer() case *runContainer16: if !t.isFull() { c1 = t.toBitmapContainer() } } answer.highlowcontainer.appendContainer(s1, c1.lazyOR(x2.highlowcontainer.getContainerAtIndex(pos2)), false) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } else if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
[ "func", "lazyOR", "(", "x1", ",", "x2", "*", "Bitmap", ")", "*", "Bitmap", "{", "answer", ":=", "NewBitmap", "(", ")", "\n", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "x1", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "main", ":", "for", "(", "pos1", "<", "length1", ")", "&&", "(", "pos2", "<", "length2", ")", "{", "s1", ":=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n\n", "for", "{", "if", "s1", "<", "s2", "{", "answer", ".", "highlowcontainer", ".", "appendCopy", "(", "x1", ".", "highlowcontainer", ",", "pos1", ")", "\n", "pos1", "++", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "if", "s1", ">", "s2", "{", "answer", ".", "highlowcontainer", ".", "appendCopy", "(", "x2", ".", "highlowcontainer", ",", "pos2", ")", "\n", "pos2", "++", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "{", "c1", ":=", "x1", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "switch", "t", ":=", "c1", ".", "(", "type", ")", "{", "case", "*", "arrayContainer", ":", "c1", "=", "t", ".", "toBitmapContainer", "(", ")", "\n", "case", "*", "runContainer16", ":", "if", "!", "t", ".", "isFull", "(", ")", "{", "c1", "=", "t", ".", "toBitmapContainer", "(", ")", "\n", "}", "\n", "}", "\n\n", "answer", ".", "highlowcontainer", ".", "appendContainer", "(", "s1", ",", "c1", ".", "lazyOR", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", ",", "false", ")", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "pos1", "==", "length1", "{", "answer", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x2", ".", "highlowcontainer", ",", "pos2", ",", "length2", ")", "\n", "}", "else", "if", "pos2", "==", "length2", "{", "answer", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x1", ".", "highlowcontainer", ",", "pos1", ",", "length1", ")", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// Or function that requires repairAfterLazy
[ "Or", "function", "that", "requires", "repairAfterLazy" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/fastaggregation.go#L8-L62
144,645
RoaringBitmap/roaring
fastaggregation.go
lazyOR
func (x1 *Bitmap) lazyOR(x2 *Bitmap) *Bitmap { pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { x1.highlowcontainer.insertNewKeyValueAt(pos1, s2, x2.highlowcontainer.getContainerAtIndex(pos2).clone()) pos2++ pos1++ length1++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { c1 := x1.highlowcontainer.getContainerAtIndex(pos1) switch t := c1.(type) { case *arrayContainer: c1 = t.toBitmapContainer() case *runContainer16: if !t.isFull() { c1 = t.toBitmapContainer() } case *bitmapContainer: c1 = x1.highlowcontainer.getWritableContainerAtIndex(pos1) } x1.highlowcontainer.containers[pos1] = c1.lazyIOR(x2.highlowcontainer.getContainerAtIndex(pos2)) x1.highlowcontainer.needCopyOnWrite[pos1] = false pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { x1.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } return x1 }
go
func (x1 *Bitmap) lazyOR(x2 *Bitmap) *Bitmap { pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { x1.highlowcontainer.insertNewKeyValueAt(pos1, s2, x2.highlowcontainer.getContainerAtIndex(pos2).clone()) pos2++ pos1++ length1++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { c1 := x1.highlowcontainer.getContainerAtIndex(pos1) switch t := c1.(type) { case *arrayContainer: c1 = t.toBitmapContainer() case *runContainer16: if !t.isFull() { c1 = t.toBitmapContainer() } case *bitmapContainer: c1 = x1.highlowcontainer.getWritableContainerAtIndex(pos1) } x1.highlowcontainer.containers[pos1] = c1.lazyIOR(x2.highlowcontainer.getContainerAtIndex(pos2)) x1.highlowcontainer.needCopyOnWrite[pos1] = false pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { x1.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } return x1 }
[ "func", "(", "x1", "*", "Bitmap", ")", "lazyOR", "(", "x2", "*", "Bitmap", ")", "*", "Bitmap", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "x1", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "main", ":", "for", "(", "pos1", "<", "length1", ")", "&&", "(", "pos2", "<", "length2", ")", "{", "s1", ":=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n\n", "for", "{", "if", "s1", "<", "s2", "{", "pos1", "++", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "if", "s1", ">", "s2", "{", "x1", ".", "highlowcontainer", ".", "insertNewKeyValueAt", "(", "pos1", ",", "s2", ",", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ".", "clone", "(", ")", ")", "\n", "pos2", "++", "\n", "pos1", "++", "\n", "length1", "++", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "{", "c1", ":=", "x1", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "switch", "t", ":=", "c1", ".", "(", "type", ")", "{", "case", "*", "arrayContainer", ":", "c1", "=", "t", ".", "toBitmapContainer", "(", ")", "\n", "case", "*", "runContainer16", ":", "if", "!", "t", ".", "isFull", "(", ")", "{", "c1", "=", "t", ".", "toBitmapContainer", "(", ")", "\n", "}", "\n", "case", "*", "bitmapContainer", ":", "c1", "=", "x1", ".", "highlowcontainer", ".", "getWritableContainerAtIndex", "(", "pos1", ")", "\n", "}", "\n\n", "x1", ".", "highlowcontainer", ".", "containers", "[", "pos1", "]", "=", "c1", ".", "lazyIOR", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", "\n", "x1", ".", "highlowcontainer", ".", "needCopyOnWrite", "[", "pos1", "]", "=", "false", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "pos1", "==", "length1", "{", "x1", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x2", ".", "highlowcontainer", ",", "pos2", ",", "length2", ")", "\n", "}", "\n", "return", "x1", "\n", "}" ]
// In-place Or function that requires repairAfterLazy
[ "In", "-", "place", "Or", "function", "that", "requires", "repairAfterLazy" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/fastaggregation.go#L65-L120
144,646
RoaringBitmap/roaring
fastaggregation.go
repairAfterLazy
func (x1 *Bitmap) repairAfterLazy() { for pos := 0; pos < x1.highlowcontainer.size(); pos++ { c := x1.highlowcontainer.getContainerAtIndex(pos) switch c.(type) { case *bitmapContainer: if c.(*bitmapContainer).cardinality == invalidCardinality { c = x1.highlowcontainer.getWritableContainerAtIndex(pos) c.(*bitmapContainer).computeCardinality() if c.(*bitmapContainer).getCardinality() <= arrayDefaultMaxSize { x1.highlowcontainer.setContainerAtIndex(pos, c.(*bitmapContainer).toArrayContainer()) } else if c.(*bitmapContainer).isFull() { x1.highlowcontainer.setContainerAtIndex(pos, newRunContainer16Range(0, MaxUint16)) } } } } }
go
func (x1 *Bitmap) repairAfterLazy() { for pos := 0; pos < x1.highlowcontainer.size(); pos++ { c := x1.highlowcontainer.getContainerAtIndex(pos) switch c.(type) { case *bitmapContainer: if c.(*bitmapContainer).cardinality == invalidCardinality { c = x1.highlowcontainer.getWritableContainerAtIndex(pos) c.(*bitmapContainer).computeCardinality() if c.(*bitmapContainer).getCardinality() <= arrayDefaultMaxSize { x1.highlowcontainer.setContainerAtIndex(pos, c.(*bitmapContainer).toArrayContainer()) } else if c.(*bitmapContainer).isFull() { x1.highlowcontainer.setContainerAtIndex(pos, newRunContainer16Range(0, MaxUint16)) } } } } }
[ "func", "(", "x1", "*", "Bitmap", ")", "repairAfterLazy", "(", ")", "{", "for", "pos", ":=", "0", ";", "pos", "<", "x1", ".", "highlowcontainer", ".", "size", "(", ")", ";", "pos", "++", "{", "c", ":=", "x1", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos", ")", "\n", "switch", "c", ".", "(", "type", ")", "{", "case", "*", "bitmapContainer", ":", "if", "c", ".", "(", "*", "bitmapContainer", ")", ".", "cardinality", "==", "invalidCardinality", "{", "c", "=", "x1", ".", "highlowcontainer", ".", "getWritableContainerAtIndex", "(", "pos", ")", "\n", "c", ".", "(", "*", "bitmapContainer", ")", ".", "computeCardinality", "(", ")", "\n", "if", "c", ".", "(", "*", "bitmapContainer", ")", ".", "getCardinality", "(", ")", "<=", "arrayDefaultMaxSize", "{", "x1", ".", "highlowcontainer", ".", "setContainerAtIndex", "(", "pos", ",", "c", ".", "(", "*", "bitmapContainer", ")", ".", "toArrayContainer", "(", ")", ")", "\n", "}", "else", "if", "c", ".", "(", "*", "bitmapContainer", ")", ".", "isFull", "(", ")", "{", "x1", ".", "highlowcontainer", ".", "setContainerAtIndex", "(", "pos", ",", "newRunContainer16Range", "(", "0", ",", "MaxUint16", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// to be called after lazy aggregates
[ "to", "be", "called", "after", "lazy", "aggregates" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/fastaggregation.go#L123-L139
144,647
RoaringBitmap/roaring
fastaggregation.go
FastAnd
func FastAnd(bitmaps ...*Bitmap) *Bitmap { if len(bitmaps) == 0 { return NewBitmap() } else if len(bitmaps) == 1 { return bitmaps[0].Clone() } answer := And(bitmaps[0], bitmaps[1]) for _, bm := range bitmaps[2:] { answer.And(bm) } return answer }
go
func FastAnd(bitmaps ...*Bitmap) *Bitmap { if len(bitmaps) == 0 { return NewBitmap() } else if len(bitmaps) == 1 { return bitmaps[0].Clone() } answer := And(bitmaps[0], bitmaps[1]) for _, bm := range bitmaps[2:] { answer.And(bm) } return answer }
[ "func", "FastAnd", "(", "bitmaps", "...", "*", "Bitmap", ")", "*", "Bitmap", "{", "if", "len", "(", "bitmaps", ")", "==", "0", "{", "return", "NewBitmap", "(", ")", "\n", "}", "else", "if", "len", "(", "bitmaps", ")", "==", "1", "{", "return", "bitmaps", "[", "0", "]", ".", "Clone", "(", ")", "\n", "}", "\n", "answer", ":=", "And", "(", "bitmaps", "[", "0", "]", ",", "bitmaps", "[", "1", "]", ")", "\n", "for", "_", ",", "bm", ":=", "range", "bitmaps", "[", "2", ":", "]", "{", "answer", ".", "And", "(", "bm", ")", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// FastAnd computes the intersection between many bitmaps quickly // Compared to the And function, it can take many bitmaps as input, thus saving the trouble // of manually calling "And" many times.
[ "FastAnd", "computes", "the", "intersection", "between", "many", "bitmaps", "quickly", "Compared", "to", "the", "And", "function", "it", "can", "take", "many", "bitmaps", "as", "input", "thus", "saving", "the", "trouble", "of", "manually", "calling", "And", "many", "times", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/fastaggregation.go#L144-L155
144,648
RoaringBitmap/roaring
fastaggregation.go
FastOr
func FastOr(bitmaps ...*Bitmap) *Bitmap { if len(bitmaps) == 0 { return NewBitmap() } else if len(bitmaps) == 1 { return bitmaps[0].Clone() } answer := lazyOR(bitmaps[0], bitmaps[1]) for _, bm := range bitmaps[2:] { answer = answer.lazyOR(bm) } // here is where repairAfterLazy is called. answer.repairAfterLazy() return answer }
go
func FastOr(bitmaps ...*Bitmap) *Bitmap { if len(bitmaps) == 0 { return NewBitmap() } else if len(bitmaps) == 1 { return bitmaps[0].Clone() } answer := lazyOR(bitmaps[0], bitmaps[1]) for _, bm := range bitmaps[2:] { answer = answer.lazyOR(bm) } // here is where repairAfterLazy is called. answer.repairAfterLazy() return answer }
[ "func", "FastOr", "(", "bitmaps", "...", "*", "Bitmap", ")", "*", "Bitmap", "{", "if", "len", "(", "bitmaps", ")", "==", "0", "{", "return", "NewBitmap", "(", ")", "\n", "}", "else", "if", "len", "(", "bitmaps", ")", "==", "1", "{", "return", "bitmaps", "[", "0", "]", ".", "Clone", "(", ")", "\n", "}", "\n", "answer", ":=", "lazyOR", "(", "bitmaps", "[", "0", "]", ",", "bitmaps", "[", "1", "]", ")", "\n", "for", "_", ",", "bm", ":=", "range", "bitmaps", "[", "2", ":", "]", "{", "answer", "=", "answer", ".", "lazyOR", "(", "bm", ")", "\n", "}", "\n", "// here is where repairAfterLazy is called.", "answer", ".", "repairAfterLazy", "(", ")", "\n", "return", "answer", "\n", "}" ]
// FastOr computes the union between many bitmaps quickly, as opposed to having to call Or repeatedly. // It might also be faster than calling Or repeatedly.
[ "FastOr", "computes", "the", "union", "between", "many", "bitmaps", "quickly", "as", "opposed", "to", "having", "to", "call", "Or", "repeatedly", ".", "It", "might", "also", "be", "faster", "than", "calling", "Or", "repeatedly", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/fastaggregation.go#L159-L172
144,649
RoaringBitmap/roaring
fastaggregation.go
HeapOr
func HeapOr(bitmaps ...*Bitmap) *Bitmap { if len(bitmaps) == 0 { return NewBitmap() } // TODO: for better speed, we could do the operation lazily, see Java implementation pq := make(priorityQueue, len(bitmaps)) for i, bm := range bitmaps { pq[i] = &item{bm, i} } heap.Init(&pq) for pq.Len() > 1 { x1 := heap.Pop(&pq).(*item) x2 := heap.Pop(&pq).(*item) heap.Push(&pq, &item{Or(x1.value, x2.value), 0}) } return heap.Pop(&pq).(*item).value }
go
func HeapOr(bitmaps ...*Bitmap) *Bitmap { if len(bitmaps) == 0 { return NewBitmap() } // TODO: for better speed, we could do the operation lazily, see Java implementation pq := make(priorityQueue, len(bitmaps)) for i, bm := range bitmaps { pq[i] = &item{bm, i} } heap.Init(&pq) for pq.Len() > 1 { x1 := heap.Pop(&pq).(*item) x2 := heap.Pop(&pq).(*item) heap.Push(&pq, &item{Or(x1.value, x2.value), 0}) } return heap.Pop(&pq).(*item).value }
[ "func", "HeapOr", "(", "bitmaps", "...", "*", "Bitmap", ")", "*", "Bitmap", "{", "if", "len", "(", "bitmaps", ")", "==", "0", "{", "return", "NewBitmap", "(", ")", "\n", "}", "\n", "// TODO: for better speed, we could do the operation lazily, see Java implementation", "pq", ":=", "make", "(", "priorityQueue", ",", "len", "(", "bitmaps", ")", ")", "\n", "for", "i", ",", "bm", ":=", "range", "bitmaps", "{", "pq", "[", "i", "]", "=", "&", "item", "{", "bm", ",", "i", "}", "\n", "}", "\n", "heap", ".", "Init", "(", "&", "pq", ")", "\n\n", "for", "pq", ".", "Len", "(", ")", ">", "1", "{", "x1", ":=", "heap", ".", "Pop", "(", "&", "pq", ")", ".", "(", "*", "item", ")", "\n", "x2", ":=", "heap", ".", "Pop", "(", "&", "pq", ")", ".", "(", "*", "item", ")", "\n", "heap", ".", "Push", "(", "&", "pq", ",", "&", "item", "{", "Or", "(", "x1", ".", "value", ",", "x2", ".", "value", ")", ",", "0", "}", ")", "\n", "}", "\n", "return", "heap", ".", "Pop", "(", "&", "pq", ")", ".", "(", "*", "item", ")", ".", "value", "\n", "}" ]
// HeapOr computes the union between many bitmaps quickly using a heap. // It might be faster than calling Or repeatedly.
[ "HeapOr", "computes", "the", "union", "between", "many", "bitmaps", "quickly", "using", "a", "heap", ".", "It", "might", "be", "faster", "than", "calling", "Or", "repeatedly", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/fastaggregation.go#L176-L193
144,650
RoaringBitmap/roaring
roaring.go
ToBase64
func (rb *Bitmap) ToBase64() (string, error) { buf := new(bytes.Buffer) _, err := rb.WriteTo(buf) return base64.StdEncoding.EncodeToString(buf.Bytes()), err }
go
func (rb *Bitmap) ToBase64() (string, error) { buf := new(bytes.Buffer) _, err := rb.WriteTo(buf) return base64.StdEncoding.EncodeToString(buf.Bytes()), err }
[ "func", "(", "rb", "*", "Bitmap", ")", "ToBase64", "(", ")", "(", "string", ",", "error", ")", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "_", ",", "err", ":=", "rb", ".", "WriteTo", "(", "buf", ")", "\n", "return", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "buf", ".", "Bytes", "(", ")", ")", ",", "err", "\n\n", "}" ]
// ToBase64 serializes a bitmap as Base64
[ "ToBase64", "serializes", "a", "bitmap", "as", "Base64" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L23-L28
144,651
RoaringBitmap/roaring
roaring.go
FromBase64
func (rb *Bitmap) FromBase64(str string) (int64, error) { data, err := base64.StdEncoding.DecodeString(str) if err != nil { return 0, err } buf := bytes.NewBuffer(data) return rb.ReadFrom(buf) }
go
func (rb *Bitmap) FromBase64(str string) (int64, error) { data, err := base64.StdEncoding.DecodeString(str) if err != nil { return 0, err } buf := bytes.NewBuffer(data) return rb.ReadFrom(buf) }
[ "func", "(", "rb", "*", "Bitmap", ")", "FromBase64", "(", "str", "string", ")", "(", "int64", ",", "error", ")", "{", "data", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "str", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "data", ")", "\n\n", "return", "rb", ".", "ReadFrom", "(", "buf", ")", "\n", "}" ]
// FromBase64 deserializes a bitmap from Base64
[ "FromBase64", "deserializes", "a", "bitmap", "from", "Base64" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L31-L39
144,652
RoaringBitmap/roaring
roaring.go
MarshalBinary
func (rb *Bitmap) MarshalBinary() ([]byte, error) { var buf bytes.Buffer writer := bufio.NewWriter(&buf) _, err := rb.WriteTo(writer) if err != nil { return nil, err } err = writer.Flush() if err != nil { return nil, err } return buf.Bytes(), nil }
go
func (rb *Bitmap) MarshalBinary() ([]byte, error) { var buf bytes.Buffer writer := bufio.NewWriter(&buf) _, err := rb.WriteTo(writer) if err != nil { return nil, err } err = writer.Flush() if err != nil { return nil, err } return buf.Bytes(), nil }
[ "func", "(", "rb", "*", "Bitmap", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "writer", ":=", "bufio", ".", "NewWriter", "(", "&", "buf", ")", "\n", "_", ",", "err", ":=", "rb", ".", "WriteTo", "(", "writer", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", "=", "writer", ".", "Flush", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary implements the encoding.BinaryMarshaler interface for the bitmap
[ "MarshalBinary", "implements", "the", "encoding", ".", "BinaryMarshaler", "interface", "for", "the", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L113-L125
144,653
RoaringBitmap/roaring
roaring.go
UnmarshalBinary
func (rb *Bitmap) UnmarshalBinary(data []byte) error { var buf bytes.Buffer _, err := buf.Write(data) if err != nil { return err } reader := bufio.NewReader(&buf) _, err = rb.ReadFrom(reader) return err }
go
func (rb *Bitmap) UnmarshalBinary(data []byte) error { var buf bytes.Buffer _, err := buf.Write(data) if err != nil { return err } reader := bufio.NewReader(&buf) _, err = rb.ReadFrom(reader) return err }
[ "func", "(", "rb", "*", "Bitmap", ")", "UnmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "_", ",", "err", ":=", "buf", ".", "Write", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "reader", ":=", "bufio", ".", "NewReader", "(", "&", "buf", ")", "\n", "_", ",", "err", "=", "rb", ".", "ReadFrom", "(", "reader", ")", "\n", "return", "err", "\n", "}" ]
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for the bitmap
[ "UnmarshalBinary", "implements", "the", "encoding", ".", "BinaryUnmarshaler", "interface", "for", "the", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L128-L137
144,654
RoaringBitmap/roaring
roaring.go
ToArray
func (rb *Bitmap) ToArray() []uint32 { array := make([]uint32, rb.GetCardinality()) pos := 0 pos2 := 0 for pos < rb.highlowcontainer.size() { hs := uint32(rb.highlowcontainer.getKeyAtIndex(pos)) << 16 c := rb.highlowcontainer.getContainerAtIndex(pos) pos++ c.fillLeastSignificant16bits(array, pos2, hs) pos2 += c.getCardinality() } return array }
go
func (rb *Bitmap) ToArray() []uint32 { array := make([]uint32, rb.GetCardinality()) pos := 0 pos2 := 0 for pos < rb.highlowcontainer.size() { hs := uint32(rb.highlowcontainer.getKeyAtIndex(pos)) << 16 c := rb.highlowcontainer.getContainerAtIndex(pos) pos++ c.fillLeastSignificant16bits(array, pos2, hs) pos2 += c.getCardinality() } return array }
[ "func", "(", "rb", "*", "Bitmap", ")", "ToArray", "(", ")", "[", "]", "uint32", "{", "array", ":=", "make", "(", "[", "]", "uint32", ",", "rb", ".", "GetCardinality", "(", ")", ")", "\n", "pos", ":=", "0", "\n", "pos2", ":=", "0", "\n\n", "for", "pos", "<", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "{", "hs", ":=", "uint32", "(", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos", ")", ")", "<<", "16", "\n", "c", ":=", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos", ")", "\n", "pos", "++", "\n", "c", ".", "fillLeastSignificant16bits", "(", "array", ",", "pos2", ",", "hs", ")", "\n", "pos2", "+=", "c", ".", "getCardinality", "(", ")", "\n", "}", "\n", "return", "array", "\n", "}" ]
// ToArray creates a new slice containing all of the integers stored in the Bitmap in sorted order
[ "ToArray", "creates", "a", "new", "slice", "containing", "all", "of", "the", "integers", "stored", "in", "the", "Bitmap", "in", "sorted", "order" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L156-L169
144,655
RoaringBitmap/roaring
roaring.go
GetSizeInBytes
func (rb *Bitmap) GetSizeInBytes() uint64 { size := uint64(8) for _, c := range rb.highlowcontainer.containers { size += uint64(2) + uint64(c.getSizeInBytes()) } return size }
go
func (rb *Bitmap) GetSizeInBytes() uint64 { size := uint64(8) for _, c := range rb.highlowcontainer.containers { size += uint64(2) + uint64(c.getSizeInBytes()) } return size }
[ "func", "(", "rb", "*", "Bitmap", ")", "GetSizeInBytes", "(", ")", "uint64", "{", "size", ":=", "uint64", "(", "8", ")", "\n", "for", "_", ",", "c", ":=", "range", "rb", ".", "highlowcontainer", ".", "containers", "{", "size", "+=", "uint64", "(", "2", ")", "+", "uint64", "(", "c", ".", "getSizeInBytes", "(", ")", ")", "\n", "}", "\n", "return", "size", "\n", "}" ]
// GetSizeInBytes estimates the memory usage of the Bitmap. Note that this // might differ slightly from the amount of bytes required for persistent storage
[ "GetSizeInBytes", "estimates", "the", "memory", "usage", "of", "the", "Bitmap", ".", "Note", "that", "this", "might", "differ", "slightly", "from", "the", "amount", "of", "bytes", "required", "for", "persistent", "storage" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L173-L179
144,656
RoaringBitmap/roaring
roaring.go
BoundSerializedSizeInBytes
func BoundSerializedSizeInBytes(cardinality uint64, universeSize uint64) uint64 { contnbr := (universeSize + uint64(65535)) / uint64(65536) if contnbr > cardinality { contnbr = cardinality // we can't have more containers than we have values } headermax := 8*contnbr + 4 if 4 > (contnbr+7)/8 { headermax += 4 } else { headermax += (contnbr + 7) / 8 } valsarray := uint64(arrayContainerSizeInBytes(int(cardinality))) valsbitmap := contnbr * uint64(bitmapContainerSizeInBytes()) valsbest := valsarray if valsbest > valsbitmap { valsbest = valsbitmap } return valsbest + headermax }
go
func BoundSerializedSizeInBytes(cardinality uint64, universeSize uint64) uint64 { contnbr := (universeSize + uint64(65535)) / uint64(65536) if contnbr > cardinality { contnbr = cardinality // we can't have more containers than we have values } headermax := 8*contnbr + 4 if 4 > (contnbr+7)/8 { headermax += 4 } else { headermax += (contnbr + 7) / 8 } valsarray := uint64(arrayContainerSizeInBytes(int(cardinality))) valsbitmap := contnbr * uint64(bitmapContainerSizeInBytes()) valsbest := valsarray if valsbest > valsbitmap { valsbest = valsbitmap } return valsbest + headermax }
[ "func", "BoundSerializedSizeInBytes", "(", "cardinality", "uint64", ",", "universeSize", "uint64", ")", "uint64", "{", "contnbr", ":=", "(", "universeSize", "+", "uint64", "(", "65535", ")", ")", "/", "uint64", "(", "65536", ")", "\n", "if", "contnbr", ">", "cardinality", "{", "contnbr", "=", "cardinality", "\n", "// we can't have more containers than we have values", "}", "\n", "headermax", ":=", "8", "*", "contnbr", "+", "4", "\n", "if", "4", ">", "(", "contnbr", "+", "7", ")", "/", "8", "{", "headermax", "+=", "4", "\n", "}", "else", "{", "headermax", "+=", "(", "contnbr", "+", "7", ")", "/", "8", "\n", "}", "\n", "valsarray", ":=", "uint64", "(", "arrayContainerSizeInBytes", "(", "int", "(", "cardinality", ")", ")", ")", "\n", "valsbitmap", ":=", "contnbr", "*", "uint64", "(", "bitmapContainerSizeInBytes", "(", ")", ")", "\n", "valsbest", ":=", "valsarray", "\n", "if", "valsbest", ">", "valsbitmap", "{", "valsbest", "=", "valsbitmap", "\n", "}", "\n", "return", "valsbest", "+", "headermax", "\n", "}" ]
// BoundSerializedSizeInBytes returns an upper bound on the serialized size in bytes // assuming that one wants to store "cardinality" integers in [0, universe_size)
[ "BoundSerializedSizeInBytes", "returns", "an", "upper", "bound", "on", "the", "serialized", "size", "in", "bytes", "assuming", "that", "one", "wants", "to", "store", "cardinality", "integers", "in", "[", "0", "universe_size", ")" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L191-L210
144,657
RoaringBitmap/roaring
roaring.go
Next
func (ii *intIterator) Next() uint32 { x := uint32(ii.iter.next()) | ii.hs if !ii.iter.hasNext() { ii.pos = ii.pos + 1 ii.init() } return x }
go
func (ii *intIterator) Next() uint32 { x := uint32(ii.iter.next()) | ii.hs if !ii.iter.hasNext() { ii.pos = ii.pos + 1 ii.init() } return x }
[ "func", "(", "ii", "*", "intIterator", ")", "Next", "(", ")", "uint32", "{", "x", ":=", "uint32", "(", "ii", ".", "iter", ".", "next", "(", ")", ")", "|", "ii", ".", "hs", "\n", "if", "!", "ii", ".", "iter", ".", "hasNext", "(", ")", "{", "ii", ".", "pos", "=", "ii", ".", "pos", "+", "1", "\n", "ii", ".", "init", "(", ")", "\n", "}", "\n", "return", "x", "\n", "}" ]
// Next returns the next integer
[ "Next", "returns", "the", "next", "integer" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L238-L245
144,658
RoaringBitmap/roaring
roaring.go
Clone
func (rb *Bitmap) Clone() *Bitmap { ptr := new(Bitmap) ptr.highlowcontainer = *rb.highlowcontainer.clone() return ptr }
go
func (rb *Bitmap) Clone() *Bitmap { ptr := new(Bitmap) ptr.highlowcontainer = *rb.highlowcontainer.clone() return ptr }
[ "func", "(", "rb", "*", "Bitmap", ")", "Clone", "(", ")", "*", "Bitmap", "{", "ptr", ":=", "new", "(", "Bitmap", ")", "\n", "ptr", ".", "highlowcontainer", "=", "*", "rb", ".", "highlowcontainer", ".", "clone", "(", ")", "\n", "return", "ptr", "\n", "}" ]
// Clone creates a copy of the Bitmap
[ "Clone", "creates", "a", "copy", "of", "the", "Bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L386-L390
144,659
RoaringBitmap/roaring
roaring.go
Minimum
func (rb *Bitmap) Minimum() uint32 { return uint32(rb.highlowcontainer.containers[0].minimum()) | (uint32(rb.highlowcontainer.keys[0]) << 16) }
go
func (rb *Bitmap) Minimum() uint32 { return uint32(rb.highlowcontainer.containers[0].minimum()) | (uint32(rb.highlowcontainer.keys[0]) << 16) }
[ "func", "(", "rb", "*", "Bitmap", ")", "Minimum", "(", ")", "uint32", "{", "return", "uint32", "(", "rb", ".", "highlowcontainer", ".", "containers", "[", "0", "]", ".", "minimum", "(", ")", ")", "|", "(", "uint32", "(", "rb", ".", "highlowcontainer", ".", "keys", "[", "0", "]", ")", "<<", "16", ")", "\n", "}" ]
// Minimum get the smallest value stored in this roaring bitmap, assumes that it is not empty
[ "Minimum", "get", "the", "smallest", "value", "stored", "in", "this", "roaring", "bitmap", "assumes", "that", "it", "is", "not", "empty" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L393-L395
144,660
RoaringBitmap/roaring
roaring.go
Maximum
func (rb *Bitmap) Maximum() uint32 { lastindex := len(rb.highlowcontainer.containers) - 1 return uint32(rb.highlowcontainer.containers[lastindex].maximum()) | (uint32(rb.highlowcontainer.keys[lastindex]) << 16) }
go
func (rb *Bitmap) Maximum() uint32 { lastindex := len(rb.highlowcontainer.containers) - 1 return uint32(rb.highlowcontainer.containers[lastindex].maximum()) | (uint32(rb.highlowcontainer.keys[lastindex]) << 16) }
[ "func", "(", "rb", "*", "Bitmap", ")", "Maximum", "(", ")", "uint32", "{", "lastindex", ":=", "len", "(", "rb", ".", "highlowcontainer", ".", "containers", ")", "-", "1", "\n", "return", "uint32", "(", "rb", ".", "highlowcontainer", ".", "containers", "[", "lastindex", "]", ".", "maximum", "(", ")", ")", "|", "(", "uint32", "(", "rb", ".", "highlowcontainer", ".", "keys", "[", "lastindex", "]", ")", "<<", "16", ")", "\n", "}" ]
// Maximum get the largest value stored in this roaring bitmap, assumes that it is not empty
[ "Maximum", "get", "the", "largest", "value", "stored", "in", "this", "roaring", "bitmap", "assumes", "that", "it", "is", "not", "empty" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L398-L401
144,661
RoaringBitmap/roaring
roaring.go
Contains
func (rb *Bitmap) Contains(x uint32) bool { hb := highbits(x) c := rb.highlowcontainer.getContainer(hb) return c != nil && c.contains(lowbits(x)) }
go
func (rb *Bitmap) Contains(x uint32) bool { hb := highbits(x) c := rb.highlowcontainer.getContainer(hb) return c != nil && c.contains(lowbits(x)) }
[ "func", "(", "rb", "*", "Bitmap", ")", "Contains", "(", "x", "uint32", ")", "bool", "{", "hb", ":=", "highbits", "(", "x", ")", "\n", "c", ":=", "rb", ".", "highlowcontainer", ".", "getContainer", "(", "hb", ")", "\n", "return", "c", "!=", "nil", "&&", "c", ".", "contains", "(", "lowbits", "(", "x", ")", ")", "\n", "}" ]
// Contains returns true if the integer is contained in the bitmap
[ "Contains", "returns", "true", "if", "the", "integer", "is", "contained", "in", "the", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L404-L408
144,662
RoaringBitmap/roaring
roaring.go
Equals
func (rb *Bitmap) Equals(o interface{}) bool { srb, ok := o.(*Bitmap) if ok { return srb.highlowcontainer.equals(rb.highlowcontainer) } return false }
go
func (rb *Bitmap) Equals(o interface{}) bool { srb, ok := o.(*Bitmap) if ok { return srb.highlowcontainer.equals(rb.highlowcontainer) } return false }
[ "func", "(", "rb", "*", "Bitmap", ")", "Equals", "(", "o", "interface", "{", "}", ")", "bool", "{", "srb", ",", "ok", ":=", "o", ".", "(", "*", "Bitmap", ")", "\n", "if", "ok", "{", "return", "srb", ".", "highlowcontainer", ".", "equals", "(", "rb", ".", "highlowcontainer", ")", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Equals returns true if the two bitmaps contain the same integers
[ "Equals", "returns", "true", "if", "the", "two", "bitmaps", "contain", "the", "same", "integers" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L416-L422
144,663
RoaringBitmap/roaring
roaring.go
AddOffset
func AddOffset(x *Bitmap, offset uint32) (answer *Bitmap) { containerOffset := highbits(offset) inOffset := lowbits(offset) if inOffset == 0 { answer = x.Clone() for pos := 0; pos < answer.highlowcontainer.size(); pos++ { key := answer.highlowcontainer.getKeyAtIndex(pos) key += containerOffset answer.highlowcontainer.keys[pos] = key } } else { answer = New() for pos := 0; pos < x.highlowcontainer.size(); pos++ { key := x.highlowcontainer.getKeyAtIndex(pos) key += containerOffset c := x.highlowcontainer.getContainerAtIndex(pos) offsetted := c.addOffset(inOffset) if offsetted[0].getCardinality() > 0 { curSize := answer.highlowcontainer.size() lastkey := uint16(0) if curSize > 0 { lastkey = answer.highlowcontainer.getKeyAtIndex(curSize - 1) } if curSize > 0 && lastkey == key { prev := answer.highlowcontainer.getContainerAtIndex(curSize - 1) orrseult := prev.ior(offsetted[0]) answer.highlowcontainer.setContainerAtIndex(curSize-1, orrseult) } else { answer.highlowcontainer.appendContainer(key, offsetted[0], false) } } if offsetted[1].getCardinality() > 0 { answer.highlowcontainer.appendContainer(key+1, offsetted[1], false) } } } return answer }
go
func AddOffset(x *Bitmap, offset uint32) (answer *Bitmap) { containerOffset := highbits(offset) inOffset := lowbits(offset) if inOffset == 0 { answer = x.Clone() for pos := 0; pos < answer.highlowcontainer.size(); pos++ { key := answer.highlowcontainer.getKeyAtIndex(pos) key += containerOffset answer.highlowcontainer.keys[pos] = key } } else { answer = New() for pos := 0; pos < x.highlowcontainer.size(); pos++ { key := x.highlowcontainer.getKeyAtIndex(pos) key += containerOffset c := x.highlowcontainer.getContainerAtIndex(pos) offsetted := c.addOffset(inOffset) if offsetted[0].getCardinality() > 0 { curSize := answer.highlowcontainer.size() lastkey := uint16(0) if curSize > 0 { lastkey = answer.highlowcontainer.getKeyAtIndex(curSize - 1) } if curSize > 0 && lastkey == key { prev := answer.highlowcontainer.getContainerAtIndex(curSize - 1) orrseult := prev.ior(offsetted[0]) answer.highlowcontainer.setContainerAtIndex(curSize-1, orrseult) } else { answer.highlowcontainer.appendContainer(key, offsetted[0], false) } } if offsetted[1].getCardinality() > 0 { answer.highlowcontainer.appendContainer(key+1, offsetted[1], false) } } } return answer }
[ "func", "AddOffset", "(", "x", "*", "Bitmap", ",", "offset", "uint32", ")", "(", "answer", "*", "Bitmap", ")", "{", "containerOffset", ":=", "highbits", "(", "offset", ")", "\n", "inOffset", ":=", "lowbits", "(", "offset", ")", "\n", "if", "inOffset", "==", "0", "{", "answer", "=", "x", ".", "Clone", "(", ")", "\n", "for", "pos", ":=", "0", ";", "pos", "<", "answer", ".", "highlowcontainer", ".", "size", "(", ")", ";", "pos", "++", "{", "key", ":=", "answer", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos", ")", "\n", "key", "+=", "containerOffset", "\n", "answer", ".", "highlowcontainer", ".", "keys", "[", "pos", "]", "=", "key", "\n", "}", "\n", "}", "else", "{", "answer", "=", "New", "(", ")", "\n", "for", "pos", ":=", "0", ";", "pos", "<", "x", ".", "highlowcontainer", ".", "size", "(", ")", ";", "pos", "++", "{", "key", ":=", "x", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos", ")", "\n", "key", "+=", "containerOffset", "\n", "c", ":=", "x", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos", ")", "\n", "offsetted", ":=", "c", ".", "addOffset", "(", "inOffset", ")", "\n", "if", "offsetted", "[", "0", "]", ".", "getCardinality", "(", ")", ">", "0", "{", "curSize", ":=", "answer", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "lastkey", ":=", "uint16", "(", "0", ")", "\n", "if", "curSize", ">", "0", "{", "lastkey", "=", "answer", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "curSize", "-", "1", ")", "\n", "}", "\n", "if", "curSize", ">", "0", "&&", "lastkey", "==", "key", "{", "prev", ":=", "answer", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "curSize", "-", "1", ")", "\n", "orrseult", ":=", "prev", ".", "ior", "(", "offsetted", "[", "0", "]", ")", "\n", "answer", ".", "highlowcontainer", ".", "setContainerAtIndex", "(", "curSize", "-", "1", ",", "orrseult", ")", "\n", "}", "else", "{", "answer", ".", "highlowcontainer", ".", "appendContainer", "(", "key", ",", "offsetted", "[", "0", "]", ",", "false", ")", "\n", "}", "\n", "}", "\n", "if", "offsetted", "[", "1", "]", ".", "getCardinality", "(", ")", ">", "0", "{", "answer", ".", "highlowcontainer", ".", "appendContainer", "(", "key", "+", "1", ",", "offsetted", "[", "1", "]", ",", "false", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// AddOffset adds the value 'offset' to each and every value in a bitmap, generating a new bitmap in the process
[ "AddOffset", "adds", "the", "value", "offset", "to", "each", "and", "every", "value", "in", "a", "bitmap", "generating", "a", "new", "bitmap", "in", "the", "process" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L425-L462
144,664
RoaringBitmap/roaring
roaring.go
Add
func (rb *Bitmap) Add(x uint32) { hb := highbits(x) ra := &rb.highlowcontainer i := ra.getIndex(hb) if i >= 0 { var c container c = ra.getWritableContainerAtIndex(i).iaddReturnMinimized(lowbits(x)) rb.highlowcontainer.setContainerAtIndex(i, c) } else { newac := newArrayContainer() rb.highlowcontainer.insertNewKeyValueAt(-i-1, hb, newac.iaddReturnMinimized(lowbits(x))) } }
go
func (rb *Bitmap) Add(x uint32) { hb := highbits(x) ra := &rb.highlowcontainer i := ra.getIndex(hb) if i >= 0 { var c container c = ra.getWritableContainerAtIndex(i).iaddReturnMinimized(lowbits(x)) rb.highlowcontainer.setContainerAtIndex(i, c) } else { newac := newArrayContainer() rb.highlowcontainer.insertNewKeyValueAt(-i-1, hb, newac.iaddReturnMinimized(lowbits(x))) } }
[ "func", "(", "rb", "*", "Bitmap", ")", "Add", "(", "x", "uint32", ")", "{", "hb", ":=", "highbits", "(", "x", ")", "\n", "ra", ":=", "&", "rb", ".", "highlowcontainer", "\n", "i", ":=", "ra", ".", "getIndex", "(", "hb", ")", "\n", "if", "i", ">=", "0", "{", "var", "c", "container", "\n", "c", "=", "ra", ".", "getWritableContainerAtIndex", "(", "i", ")", ".", "iaddReturnMinimized", "(", "lowbits", "(", "x", ")", ")", "\n", "rb", ".", "highlowcontainer", ".", "setContainerAtIndex", "(", "i", ",", "c", ")", "\n", "}", "else", "{", "newac", ":=", "newArrayContainer", "(", ")", "\n", "rb", ".", "highlowcontainer", ".", "insertNewKeyValueAt", "(", "-", "i", "-", "1", ",", "hb", ",", "newac", ".", "iaddReturnMinimized", "(", "lowbits", "(", "x", ")", ")", ")", "\n", "}", "\n", "}" ]
// Add the integer x to the bitmap
[ "Add", "the", "integer", "x", "to", "the", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L465-L477
144,665
RoaringBitmap/roaring
roaring.go
Remove
func (rb *Bitmap) Remove(x uint32) { hb := highbits(x) i := rb.highlowcontainer.getIndex(hb) if i >= 0 { c := rb.highlowcontainer.getWritableContainerAtIndex(i).iremoveReturnMinimized(lowbits(x)) rb.highlowcontainer.setContainerAtIndex(i, c) if rb.highlowcontainer.getContainerAtIndex(i).getCardinality() == 0 { rb.highlowcontainer.removeAtIndex(i) } } }
go
func (rb *Bitmap) Remove(x uint32) { hb := highbits(x) i := rb.highlowcontainer.getIndex(hb) if i >= 0 { c := rb.highlowcontainer.getWritableContainerAtIndex(i).iremoveReturnMinimized(lowbits(x)) rb.highlowcontainer.setContainerAtIndex(i, c) if rb.highlowcontainer.getContainerAtIndex(i).getCardinality() == 0 { rb.highlowcontainer.removeAtIndex(i) } } }
[ "func", "(", "rb", "*", "Bitmap", ")", "Remove", "(", "x", "uint32", ")", "{", "hb", ":=", "highbits", "(", "x", ")", "\n", "i", ":=", "rb", ".", "highlowcontainer", ".", "getIndex", "(", "hb", ")", "\n", "if", "i", ">=", "0", "{", "c", ":=", "rb", ".", "highlowcontainer", ".", "getWritableContainerAtIndex", "(", "i", ")", ".", "iremoveReturnMinimized", "(", "lowbits", "(", "x", ")", ")", "\n", "rb", ".", "highlowcontainer", ".", "setContainerAtIndex", "(", "i", ",", "c", ")", "\n", "if", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "i", ")", ".", "getCardinality", "(", ")", "==", "0", "{", "rb", ".", "highlowcontainer", ".", "removeAtIndex", "(", "i", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Remove the integer x from the bitmap
[ "Remove", "the", "integer", "x", "from", "the", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L520-L530
144,666
RoaringBitmap/roaring
roaring.go
GetCardinality
func (rb *Bitmap) GetCardinality() uint64 { size := uint64(0) for _, c := range rb.highlowcontainer.containers { size += uint64(c.getCardinality()) } return size }
go
func (rb *Bitmap) GetCardinality() uint64 { size := uint64(0) for _, c := range rb.highlowcontainer.containers { size += uint64(c.getCardinality()) } return size }
[ "func", "(", "rb", "*", "Bitmap", ")", "GetCardinality", "(", ")", "uint64", "{", "size", ":=", "uint64", "(", "0", ")", "\n", "for", "_", ",", "c", ":=", "range", "rb", ".", "highlowcontainer", ".", "containers", "{", "size", "+=", "uint64", "(", "c", ".", "getCardinality", "(", ")", ")", "\n", "}", "\n", "return", "size", "\n", "}" ]
// GetCardinality returns the number of integers contained in the bitmap
[ "GetCardinality", "returns", "the", "number", "of", "integers", "contained", "in", "the", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L558-L564
144,667
RoaringBitmap/roaring
roaring.go
Select
func (rb *Bitmap) Select(x uint32) (uint32, error) { if rb.GetCardinality() <= uint64(x) { return 0, fmt.Errorf("can't find %dth integer in a bitmap with only %d items", x, rb.GetCardinality()) } remaining := x for i := 0; i < rb.highlowcontainer.size(); i++ { c := rb.highlowcontainer.getContainerAtIndex(i) if remaining >= uint32(c.getCardinality()) { remaining -= uint32(c.getCardinality()) } else { key := rb.highlowcontainer.getKeyAtIndex(i) return uint32(key)<<16 + uint32(c.selectInt(uint16(remaining))), nil } } return 0, fmt.Errorf("can't find %dth integer in a bitmap with only %d items", x, rb.GetCardinality()) }
go
func (rb *Bitmap) Select(x uint32) (uint32, error) { if rb.GetCardinality() <= uint64(x) { return 0, fmt.Errorf("can't find %dth integer in a bitmap with only %d items", x, rb.GetCardinality()) } remaining := x for i := 0; i < rb.highlowcontainer.size(); i++ { c := rb.highlowcontainer.getContainerAtIndex(i) if remaining >= uint32(c.getCardinality()) { remaining -= uint32(c.getCardinality()) } else { key := rb.highlowcontainer.getKeyAtIndex(i) return uint32(key)<<16 + uint32(c.selectInt(uint16(remaining))), nil } } return 0, fmt.Errorf("can't find %dth integer in a bitmap with only %d items", x, rb.GetCardinality()) }
[ "func", "(", "rb", "*", "Bitmap", ")", "Select", "(", "x", "uint32", ")", "(", "uint32", ",", "error", ")", "{", "if", "rb", ".", "GetCardinality", "(", ")", "<=", "uint64", "(", "x", ")", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "x", ",", "rb", ".", "GetCardinality", "(", ")", ")", "\n", "}", "\n\n", "remaining", ":=", "x", "\n", "for", "i", ":=", "0", ";", "i", "<", "rb", ".", "highlowcontainer", ".", "size", "(", ")", ";", "i", "++", "{", "c", ":=", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "i", ")", "\n", "if", "remaining", ">=", "uint32", "(", "c", ".", "getCardinality", "(", ")", ")", "{", "remaining", "-=", "uint32", "(", "c", ".", "getCardinality", "(", ")", ")", "\n", "}", "else", "{", "key", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "i", ")", "\n", "return", "uint32", "(", "key", ")", "<<", "16", "+", "uint32", "(", "c", ".", "selectInt", "(", "uint16", "(", "remaining", ")", ")", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "x", ",", "rb", ".", "GetCardinality", "(", ")", ")", "\n", "}" ]
// Select returns the xth integer in the bitmap
[ "Select", "returns", "the", "xth", "integer", "in", "the", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L584-L600
144,668
RoaringBitmap/roaring
roaring.go
And
func (rb *Bitmap) And(x2 *Bitmap) { pos1 := 0 pos2 := 0 intersectionsize := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) diff := c1.iand(c2) if diff.getCardinality() > 0 { rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, diff, false) intersectionsize++ } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } rb.highlowcontainer.resize(intersectionsize) }
go
func (rb *Bitmap) And(x2 *Bitmap) { pos1 := 0 pos2 := 0 intersectionsize := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) diff := c1.iand(c2) if diff.getCardinality() > 0 { rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, diff, false) intersectionsize++ } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } rb.highlowcontainer.resize(intersectionsize) }
[ "func", "(", "rb", "*", "Bitmap", ")", "And", "(", "x2", "*", "Bitmap", ")", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "intersectionsize", ":=", "0", "\n", "length1", ":=", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n\n", "main", ":", "for", "{", "if", "pos1", "<", "length1", "&&", "pos2", "<", "length2", "{", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "for", "{", "if", "s1", "==", "s2", "{", "c1", ":=", "rb", ".", "highlowcontainer", ".", "getWritableContainerAtIndex", "(", "pos1", ")", "\n", "c2", ":=", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", "\n", "diff", ":=", "c1", ".", "iand", "(", "c2", ")", "\n", "if", "diff", ".", "getCardinality", "(", ")", ">", "0", "{", "rb", ".", "highlowcontainer", ".", "replaceKeyAndContainerAtIndex", "(", "intersectionsize", ",", "s1", ",", "diff", ",", "false", ")", "\n", "intersectionsize", "++", "\n", "}", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "if", "s1", "<", "s2", "{", "pos1", "=", "rb", ".", "highlowcontainer", ".", "advanceUntil", "(", "s2", ",", "pos1", ")", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "{", "//s1 > s2", "pos2", "=", "x2", ".", "highlowcontainer", ".", "advanceUntil", "(", "s1", ",", "pos2", ")", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "rb", ".", "highlowcontainer", ".", "resize", "(", "intersectionsize", ")", "\n", "}" ]
// And computes the intersection between two bitmaps and stores the result in the current bitmap
[ "And", "computes", "the", "intersection", "between", "two", "bitmaps", "and", "stores", "the", "result", "in", "the", "current", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L603-L650
144,669
RoaringBitmap/roaring
roaring.go
OrCardinality
func (rb *Bitmap) OrCardinality(x2 *Bitmap) uint64 { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() answer := uint64(0) main: for { if (pos1 < length1) && (pos2 < length2) { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer += uint64(rb.highlowcontainer.getContainerAtIndex(pos1).getCardinality()) pos1++ if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { answer += uint64(x2.highlowcontainer.getContainerAtIndex(pos2).getCardinality()) pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { // TODO: could be faster if we did not have to materialize the container answer += uint64(rb.highlowcontainer.getContainerAtIndex(pos1).or(x2.highlowcontainer.getContainerAtIndex(pos2)).getCardinality()) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } for ; pos1 < length1; pos1++ { answer += uint64(rb.highlowcontainer.getContainerAtIndex(pos1).getCardinality()) } for ; pos2 < length2; pos2++ { answer += uint64(x2.highlowcontainer.getContainerAtIndex(pos2).getCardinality()) } return answer }
go
func (rb *Bitmap) OrCardinality(x2 *Bitmap) uint64 { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() answer := uint64(0) main: for { if (pos1 < length1) && (pos2 < length2) { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer += uint64(rb.highlowcontainer.getContainerAtIndex(pos1).getCardinality()) pos1++ if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { answer += uint64(x2.highlowcontainer.getContainerAtIndex(pos2).getCardinality()) pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { // TODO: could be faster if we did not have to materialize the container answer += uint64(rb.highlowcontainer.getContainerAtIndex(pos1).or(x2.highlowcontainer.getContainerAtIndex(pos2)).getCardinality()) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } for ; pos1 < length1; pos1++ { answer += uint64(rb.highlowcontainer.getContainerAtIndex(pos1).getCardinality()) } for ; pos2 < length2; pos2++ { answer += uint64(x2.highlowcontainer.getContainerAtIndex(pos2).getCardinality()) } return answer }
[ "func", "(", "rb", "*", "Bitmap", ")", "OrCardinality", "(", "x2", "*", "Bitmap", ")", "uint64", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "answer", ":=", "uint64", "(", "0", ")", "\n", "main", ":", "for", "{", "if", "(", "pos1", "<", "length1", ")", "&&", "(", "pos2", "<", "length2", ")", "{", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n\n", "for", "{", "if", "s1", "<", "s2", "{", "answer", "+=", "uint64", "(", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", ".", "getCardinality", "(", ")", ")", "\n", "pos1", "++", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "if", "s1", ">", "s2", "{", "answer", "+=", "uint64", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ".", "getCardinality", "(", ")", ")", "\n", "pos2", "++", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "{", "// TODO: could be faster if we did not have to materialize the container", "answer", "+=", "uint64", "(", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", ".", "or", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", ".", "getCardinality", "(", ")", ")", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "for", ";", "pos1", "<", "length1", ";", "pos1", "++", "{", "answer", "+=", "uint64", "(", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", ".", "getCardinality", "(", ")", ")", "\n", "}", "\n", "for", ";", "pos2", "<", "length2", ";", "pos2", "++", "{", "answer", "+=", "uint64", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ".", "getCardinality", "(", ")", ")", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// OrCardinality returns the cardinality of the union between two bitmaps, bitmaps are not modified
[ "OrCardinality", "returns", "the", "cardinality", "of", "the", "union", "between", "two", "bitmaps", "bitmaps", "are", "not", "modified" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L653-L703
144,670
RoaringBitmap/roaring
roaring.go
AndCardinality
func (rb *Bitmap) AndCardinality(x2 *Bitmap) uint64 { pos1 := 0 pos2 := 0 answer := uint64(0) length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) answer += uint64(c1.andCardinality(c2)) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } return answer }
go
func (rb *Bitmap) AndCardinality(x2 *Bitmap) uint64 { pos1 := 0 pos2 := 0 answer := uint64(0) length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) answer += uint64(c1.andCardinality(c2)) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } return answer }
[ "func", "(", "rb", "*", "Bitmap", ")", "AndCardinality", "(", "x2", "*", "Bitmap", ")", "uint64", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "answer", ":=", "uint64", "(", "0", ")", "\n", "length1", ":=", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n\n", "main", ":", "for", "{", "if", "pos1", "<", "length1", "&&", "pos2", "<", "length2", "{", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "for", "{", "if", "s1", "==", "s2", "{", "c1", ":=", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "c2", ":=", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", "\n", "answer", "+=", "uint64", "(", "c1", ".", "andCardinality", "(", "c2", ")", ")", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "if", "s1", "<", "s2", "{", "pos1", "=", "rb", ".", "highlowcontainer", ".", "advanceUntil", "(", "s2", ",", "pos1", ")", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "{", "//s1 > s2", "pos2", "=", "x2", ".", "highlowcontainer", ".", "advanceUntil", "(", "s1", ",", "pos2", ")", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// AndCardinality returns the cardinality of the intersection between two bitmaps, bitmaps are not modified
[ "AndCardinality", "returns", "the", "cardinality", "of", "the", "intersection", "between", "two", "bitmaps", "bitmaps", "are", "not", "modified" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L706-L749
144,671
RoaringBitmap/roaring
roaring.go
Intersects
func (rb *Bitmap) Intersects(x2 *Bitmap) bool { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) if c1.intersects(c2) { return true } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } return false }
go
func (rb *Bitmap) Intersects(x2 *Bitmap) bool { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) if c1.intersects(c2) { return true } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } return false }
[ "func", "(", "rb", "*", "Bitmap", ")", "Intersects", "(", "x2", "*", "Bitmap", ")", "bool", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n\n", "main", ":", "for", "{", "if", "pos1", "<", "length1", "&&", "pos2", "<", "length2", "{", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "for", "{", "if", "s1", "==", "s2", "{", "c1", ":=", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "c2", ":=", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", "\n", "if", "c1", ".", "intersects", "(", "c2", ")", "{", "return", "true", "\n", "}", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "if", "s1", "<", "s2", "{", "pos1", "=", "rb", ".", "highlowcontainer", ".", "advanceUntil", "(", "s2", ",", "pos1", ")", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "{", "//s1 > s2", "pos2", "=", "x2", ".", "highlowcontainer", ".", "advanceUntil", "(", "s1", ",", "pos2", ")", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Intersects checks whether two bitmap intersects, bitmaps are not modified
[ "Intersects", "checks", "whether", "two", "bitmap", "intersects", "bitmaps", "are", "not", "modified" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L752-L796
144,672
RoaringBitmap/roaring
roaring.go
Xor
func (rb *Bitmap) Xor(x2 *Bitmap) { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() for { if (pos1 < length1) && (pos2 < length2) { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break } } else if s1 > s2 { c := x2.highlowcontainer.getWritableContainerAtIndex(pos2) rb.highlowcontainer.insertNewKeyValueAt(pos1, x2.highlowcontainer.getKeyAtIndex(pos2), c) length1++ pos1++ pos2++ } else { // TODO: couple be computed in-place for reduced memory usage c := rb.highlowcontainer.getContainerAtIndex(pos1).xor(x2.highlowcontainer.getContainerAtIndex(pos2)) if c.getCardinality() > 0 { rb.highlowcontainer.setContainerAtIndex(pos1, c) pos1++ } else { rb.highlowcontainer.removeAtIndex(pos1) length1-- } pos2++ } } else { break } } if pos1 == length1 { rb.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } }
go
func (rb *Bitmap) Xor(x2 *Bitmap) { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() for { if (pos1 < length1) && (pos2 < length2) { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) if s1 < s2 { pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break } } else if s1 > s2 { c := x2.highlowcontainer.getWritableContainerAtIndex(pos2) rb.highlowcontainer.insertNewKeyValueAt(pos1, x2.highlowcontainer.getKeyAtIndex(pos2), c) length1++ pos1++ pos2++ } else { // TODO: couple be computed in-place for reduced memory usage c := rb.highlowcontainer.getContainerAtIndex(pos1).xor(x2.highlowcontainer.getContainerAtIndex(pos2)) if c.getCardinality() > 0 { rb.highlowcontainer.setContainerAtIndex(pos1, c) pos1++ } else { rb.highlowcontainer.removeAtIndex(pos1) length1-- } pos2++ } } else { break } } if pos1 == length1 { rb.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } }
[ "func", "(", "rb", "*", "Bitmap", ")", "Xor", "(", "x2", "*", "Bitmap", ")", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "for", "{", "if", "(", "pos1", "<", "length1", ")", "&&", "(", "pos2", "<", "length2", ")", "{", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "if", "s1", "<", "s2", "{", "pos1", "=", "rb", ".", "highlowcontainer", ".", "advanceUntil", "(", "s2", ",", "pos1", ")", "\n", "if", "pos1", "==", "length1", "{", "break", "\n", "}", "\n", "}", "else", "if", "s1", ">", "s2", "{", "c", ":=", "x2", ".", "highlowcontainer", ".", "getWritableContainerAtIndex", "(", "pos2", ")", "\n", "rb", ".", "highlowcontainer", ".", "insertNewKeyValueAt", "(", "pos1", ",", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", ",", "c", ")", "\n", "length1", "++", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "}", "else", "{", "// TODO: couple be computed in-place for reduced memory usage", "c", ":=", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", ".", "xor", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", "\n", "if", "c", ".", "getCardinality", "(", ")", ">", "0", "{", "rb", ".", "highlowcontainer", ".", "setContainerAtIndex", "(", "pos1", ",", "c", ")", "\n", "pos1", "++", "\n", "}", "else", "{", "rb", ".", "highlowcontainer", ".", "removeAtIndex", "(", "pos1", ")", "\n", "length1", "--", "\n", "}", "\n", "pos2", "++", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "if", "pos1", "==", "length1", "{", "rb", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x2", ".", "highlowcontainer", ",", "pos2", ",", "length2", ")", "\n", "}", "\n", "}" ]
// Xor computes the symmetric difference between two bitmaps and stores the result in the current bitmap
[ "Xor", "computes", "the", "symmetric", "difference", "between", "two", "bitmaps", "and", "stores", "the", "result", "in", "the", "current", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L799-L838
144,673
RoaringBitmap/roaring
roaring.go
Or
func (rb *Bitmap) Or(x2 *Bitmap) { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { pos1++ if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { rb.highlowcontainer.insertNewKeyValueAt(pos1, s2, x2.highlowcontainer.getContainerAtIndex(pos2).clone()) pos1++ length1++ pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { rb.highlowcontainer.replaceKeyAndContainerAtIndex(pos1, s1, rb.highlowcontainer.getWritableContainerAtIndex(pos1).ior(x2.highlowcontainer.getContainerAtIndex(pos2)), false) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { rb.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } }
go
func (rb *Bitmap) Or(x2 *Bitmap) { pos1 := 0 pos2 := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { pos1++ if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { rb.highlowcontainer.insertNewKeyValueAt(pos1, s2, x2.highlowcontainer.getContainerAtIndex(pos2).clone()) pos1++ length1++ pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { rb.highlowcontainer.replaceKeyAndContainerAtIndex(pos1, s1, rb.highlowcontainer.getWritableContainerAtIndex(pos1).ior(x2.highlowcontainer.getContainerAtIndex(pos2)), false) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { rb.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } }
[ "func", "(", "rb", "*", "Bitmap", ")", "Or", "(", "x2", "*", "Bitmap", ")", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "main", ":", "for", "(", "pos1", "<", "length1", ")", "&&", "(", "pos2", "<", "length2", ")", "{", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n\n", "for", "{", "if", "s1", "<", "s2", "{", "pos1", "++", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "if", "s1", ">", "s2", "{", "rb", ".", "highlowcontainer", ".", "insertNewKeyValueAt", "(", "pos1", ",", "s2", ",", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ".", "clone", "(", ")", ")", "\n", "pos1", "++", "\n", "length1", "++", "\n", "pos2", "++", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "{", "rb", ".", "highlowcontainer", ".", "replaceKeyAndContainerAtIndex", "(", "pos1", ",", "s1", ",", "rb", ".", "highlowcontainer", ".", "getWritableContainerAtIndex", "(", "pos1", ")", ".", "ior", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", ",", "false", ")", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "pos1", "==", "length1", "{", "rb", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x2", ".", "highlowcontainer", ",", "pos2", ",", "length2", ")", "\n", "}", "\n", "}" ]
// Or computes the union between two bitmaps and stores the result in the current bitmap
[ "Or", "computes", "the", "union", "between", "two", "bitmaps", "and", "stores", "the", "result", "in", "the", "current", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L841-L882
144,674
RoaringBitmap/roaring
roaring.go
AndNot
func (rb *Bitmap) AndNot(x2 *Bitmap) { pos1 := 0 pos2 := 0 intersectionsize := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) diff := c1.iandNot(c2) if diff.getCardinality() > 0 { rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, diff, false) intersectionsize++ } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1) rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite) intersectionsize++ pos1++ if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } // TODO:implement as a copy for pos1 < length1 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) s1 := rb.highlowcontainer.getKeyAtIndex(pos1) mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1) rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite) intersectionsize++ pos1++ } rb.highlowcontainer.resize(intersectionsize) }
go
func (rb *Bitmap) AndNot(x2 *Bitmap) { pos1 := 0 pos2 := 0 intersectionsize := 0 length1 := rb.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := rb.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) diff := c1.iandNot(c2) if diff.getCardinality() > 0 { rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, diff, false) intersectionsize++ } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1) rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite) intersectionsize++ pos1++ if pos1 == length1 { break main } s1 = rb.highlowcontainer.getKeyAtIndex(pos1) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } // TODO:implement as a copy for pos1 < length1 { c1 := rb.highlowcontainer.getContainerAtIndex(pos1) s1 := rb.highlowcontainer.getKeyAtIndex(pos1) mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1) rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite) intersectionsize++ pos1++ } rb.highlowcontainer.resize(intersectionsize) }
[ "func", "(", "rb", "*", "Bitmap", ")", "AndNot", "(", "x2", "*", "Bitmap", ")", "{", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "intersectionsize", ":=", "0", "\n", "length1", ":=", "rb", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n\n", "main", ":", "for", "{", "if", "pos1", "<", "length1", "&&", "pos2", "<", "length2", "{", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "for", "{", "if", "s1", "==", "s2", "{", "c1", ":=", "rb", ".", "highlowcontainer", ".", "getWritableContainerAtIndex", "(", "pos1", ")", "\n", "c2", ":=", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", "\n", "diff", ":=", "c1", ".", "iandNot", "(", "c2", ")", "\n", "if", "diff", ".", "getCardinality", "(", ")", ">", "0", "{", "rb", ".", "highlowcontainer", ".", "replaceKeyAndContainerAtIndex", "(", "intersectionsize", ",", "s1", ",", "diff", ",", "false", ")", "\n", "intersectionsize", "++", "\n", "}", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "if", "s1", "<", "s2", "{", "c1", ":=", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "mustCopyOnWrite", ":=", "rb", ".", "highlowcontainer", ".", "needsCopyOnWrite", "(", "pos1", ")", "\n", "rb", ".", "highlowcontainer", ".", "replaceKeyAndContainerAtIndex", "(", "intersectionsize", ",", "s1", ",", "c1", ",", "mustCopyOnWrite", ")", "\n", "intersectionsize", "++", "\n", "pos1", "++", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "{", "//s1 > s2", "pos2", "=", "x2", ".", "highlowcontainer", ".", "advanceUntil", "(", "s1", ",", "pos2", ")", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "// TODO:implement as a copy", "for", "pos1", "<", "length1", "{", "c1", ":=", "rb", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "s1", ":=", "rb", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "mustCopyOnWrite", ":=", "rb", ".", "highlowcontainer", ".", "needsCopyOnWrite", "(", "pos1", ")", "\n", "rb", ".", "highlowcontainer", ".", "replaceKeyAndContainerAtIndex", "(", "intersectionsize", ",", "s1", ",", "c1", ",", "mustCopyOnWrite", ")", "\n", "intersectionsize", "++", "\n", "pos1", "++", "\n", "}", "\n", "rb", ".", "highlowcontainer", ".", "resize", "(", "intersectionsize", ")", "\n", "}" ]
// AndNot computes the difference between two bitmaps and stores the result in the current bitmap
[ "AndNot", "computes", "the", "difference", "between", "two", "bitmaps", "and", "stores", "the", "result", "in", "the", "current", "bitmap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L885-L945
144,675
RoaringBitmap/roaring
roaring.go
Or
func Or(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2) pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { answer.highlowcontainer.appendContainer(s1, x1.highlowcontainer.getContainerAtIndex(pos1).or(x2.highlowcontainer.getContainerAtIndex(pos2)), false) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } else if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
go
func Or(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 > s2 { answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2) pos2++ if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { answer.highlowcontainer.appendContainer(s1, x1.highlowcontainer.getContainerAtIndex(pos1).or(x2.highlowcontainer.getContainerAtIndex(pos2)), false) pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } if pos1 == length1 { answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } else if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
[ "func", "Or", "(", "x1", ",", "x2", "*", "Bitmap", ")", "*", "Bitmap", "{", "answer", ":=", "NewBitmap", "(", ")", "\n", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "x1", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "main", ":", "for", "(", "pos1", "<", "length1", ")", "&&", "(", "pos2", "<", "length2", ")", "{", "s1", ":=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n\n", "for", "{", "if", "s1", "<", "s2", "{", "answer", ".", "highlowcontainer", ".", "appendCopy", "(", "x1", ".", "highlowcontainer", ",", "pos1", ")", "\n", "pos1", "++", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "if", "s1", ">", "s2", "{", "answer", ".", "highlowcontainer", ".", "appendCopy", "(", "x2", ".", "highlowcontainer", ",", "pos2", ")", "\n", "pos2", "++", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "{", "answer", ".", "highlowcontainer", ".", "appendContainer", "(", "s1", ",", "x1", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", ".", "or", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", ",", "false", ")", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "pos1", "==", "length1", "{", "answer", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x2", ".", "highlowcontainer", ",", "pos2", ",", "length2", ")", "\n", "}", "else", "if", "pos2", "==", "length2", "{", "answer", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x1", ".", "highlowcontainer", ",", "pos1", ",", "length1", ")", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// Or computes the union between two bitmaps and returns the result
[ "Or", "computes", "the", "union", "between", "two", "bitmaps", "and", "returns", "the", "result" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L948-L993
144,676
RoaringBitmap/roaring
roaring.go
And
func And(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for pos1 < length1 && pos2 < length2 { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { C := x1.highlowcontainer.getContainerAtIndex(pos1) C = C.and(x2.highlowcontainer.getContainerAtIndex(pos2)) if C.getCardinality() > 0 { answer.highlowcontainer.appendContainer(s1, C, false) } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = x1.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else { // s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } return answer }
go
func And(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for pos1 < length1 && pos2 < length2 { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 == s2 { C := x1.highlowcontainer.getContainerAtIndex(pos1) C = C.and(x2.highlowcontainer.getContainerAtIndex(pos2)) if C.getCardinality() > 0 { answer.highlowcontainer.appendContainer(s1, C, false) } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else if s1 < s2 { pos1 = x1.highlowcontainer.advanceUntil(s2, pos1) if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else { // s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } return answer }
[ "func", "And", "(", "x1", ",", "x2", "*", "Bitmap", ")", "*", "Bitmap", "{", "answer", ":=", "NewBitmap", "(", ")", "\n", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "x1", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "main", ":", "for", "pos1", "<", "length1", "&&", "pos2", "<", "length2", "{", "s1", ":=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "for", "{", "if", "s1", "==", "s2", "{", "C", ":=", "x1", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "C", "=", "C", ".", "and", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", "\n\n", "if", "C", ".", "getCardinality", "(", ")", ">", "0", "{", "answer", ".", "highlowcontainer", ".", "appendContainer", "(", "s1", ",", "C", ",", "false", ")", "\n", "}", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "if", "s1", "<", "s2", "{", "pos1", "=", "x1", ".", "highlowcontainer", ".", "advanceUntil", "(", "s2", ",", "pos1", ")", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "{", "// s1 > s2", "pos2", "=", "x2", ".", "highlowcontainer", ".", "advanceUntil", "(", "s1", ",", "pos2", ")", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// And computes the intersection between two bitmaps and returns the result
[ "And", "computes", "the", "intersection", "between", "two", "bitmaps", "and", "returns", "the", "result" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L996-L1037
144,677
RoaringBitmap/roaring
roaring.go
Xor
func Xor(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() for { if (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ } else if s1 > s2 { answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2) pos2++ } else { c := x1.highlowcontainer.getContainerAtIndex(pos1).xor(x2.highlowcontainer.getContainerAtIndex(pos2)) if c.getCardinality() > 0 { answer.highlowcontainer.appendContainer(s1, c, false) } pos1++ pos2++ } } else { break } } if pos1 == length1 { answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } else if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
go
func Xor(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() for { if (pos1 < length1) && (pos2 < length2) { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ } else if s1 > s2 { answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2) pos2++ } else { c := x1.highlowcontainer.getContainerAtIndex(pos1).xor(x2.highlowcontainer.getContainerAtIndex(pos2)) if c.getCardinality() > 0 { answer.highlowcontainer.appendContainer(s1, c, false) } pos1++ pos2++ } } else { break } } if pos1 == length1 { answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) } else if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
[ "func", "Xor", "(", "x1", ",", "x2", "*", "Bitmap", ")", "*", "Bitmap", "{", "answer", ":=", "NewBitmap", "(", ")", "\n", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "x1", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "for", "{", "if", "(", "pos1", "<", "length1", ")", "&&", "(", "pos2", "<", "length2", ")", "{", "s1", ":=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "if", "s1", "<", "s2", "{", "answer", ".", "highlowcontainer", ".", "appendCopy", "(", "x1", ".", "highlowcontainer", ",", "pos1", ")", "\n", "pos1", "++", "\n", "}", "else", "if", "s1", ">", "s2", "{", "answer", ".", "highlowcontainer", ".", "appendCopy", "(", "x2", ".", "highlowcontainer", ",", "pos2", ")", "\n", "pos2", "++", "\n", "}", "else", "{", "c", ":=", "x1", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", ".", "xor", "(", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", ")", "\n", "if", "c", ".", "getCardinality", "(", ")", ">", "0", "{", "answer", ".", "highlowcontainer", ".", "appendContainer", "(", "s1", ",", "c", ",", "false", ")", "\n", "}", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "if", "pos1", "==", "length1", "{", "answer", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x2", ".", "highlowcontainer", ",", "pos2", ",", "length2", ")", "\n", "}", "else", "if", "pos2", "==", "length2", "{", "answer", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x1", ".", "highlowcontainer", ",", "pos1", ",", "length1", ")", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// Xor computes the symmetric difference between two bitmaps and returns the result
[ "Xor", "computes", "the", "symmetric", "difference", "between", "two", "bitmaps", "and", "returns", "the", "result" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L1040-L1074
144,678
RoaringBitmap/roaring
roaring.go
AndNot
func AndNot(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 == s2 { c1 := x1.highlowcontainer.getContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) diff := c1.andNot(c2) if diff.getCardinality() > 0 { answer.highlowcontainer.appendContainer(s1, diff, false) } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
go
func AndNot(x1, x2 *Bitmap) *Bitmap { answer := NewBitmap() pos1 := 0 pos2 := 0 length1 := x1.highlowcontainer.size() length2 := x2.highlowcontainer.size() main: for { if pos1 < length1 && pos2 < length2 { s1 := x1.highlowcontainer.getKeyAtIndex(pos1) s2 := x2.highlowcontainer.getKeyAtIndex(pos2) for { if s1 < s2 { answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) pos1++ if pos1 == length1 { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) } else if s1 == s2 { c1 := x1.highlowcontainer.getContainerAtIndex(pos1) c2 := x2.highlowcontainer.getContainerAtIndex(pos2) diff := c1.andNot(c2) if diff.getCardinality() > 0 { answer.highlowcontainer.appendContainer(s1, diff, false) } pos1++ pos2++ if (pos1 == length1) || (pos2 == length2) { break main } s1 = x1.highlowcontainer.getKeyAtIndex(pos1) s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } else { //s1 > s2 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) if pos2 == length2 { break main } s2 = x2.highlowcontainer.getKeyAtIndex(pos2) } } } else { break } } if pos2 == length2 { answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) } return answer }
[ "func", "AndNot", "(", "x1", ",", "x2", "*", "Bitmap", ")", "*", "Bitmap", "{", "answer", ":=", "NewBitmap", "(", ")", "\n", "pos1", ":=", "0", "\n", "pos2", ":=", "0", "\n", "length1", ":=", "x1", ".", "highlowcontainer", ".", "size", "(", ")", "\n", "length2", ":=", "x2", ".", "highlowcontainer", ".", "size", "(", ")", "\n\n", "main", ":", "for", "{", "if", "pos1", "<", "length1", "&&", "pos2", "<", "length2", "{", "s1", ":=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", ":=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "for", "{", "if", "s1", "<", "s2", "{", "answer", ".", "highlowcontainer", ".", "appendCopy", "(", "x1", ".", "highlowcontainer", ",", "pos1", ")", "\n", "pos1", "++", "\n", "if", "pos1", "==", "length1", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "}", "else", "if", "s1", "==", "s2", "{", "c1", ":=", "x1", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos1", ")", "\n", "c2", ":=", "x2", ".", "highlowcontainer", ".", "getContainerAtIndex", "(", "pos2", ")", "\n", "diff", ":=", "c1", ".", "andNot", "(", "c2", ")", "\n", "if", "diff", ".", "getCardinality", "(", ")", ">", "0", "{", "answer", ".", "highlowcontainer", ".", "appendContainer", "(", "s1", ",", "diff", ",", "false", ")", "\n", "}", "\n", "pos1", "++", "\n", "pos2", "++", "\n", "if", "(", "pos1", "==", "length1", ")", "||", "(", "pos2", "==", "length2", ")", "{", "break", "main", "\n", "}", "\n", "s1", "=", "x1", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos1", ")", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "else", "{", "//s1 > s2", "pos2", "=", "x2", ".", "highlowcontainer", ".", "advanceUntil", "(", "s1", ",", "pos2", ")", "\n", "if", "pos2", "==", "length2", "{", "break", "main", "\n", "}", "\n", "s2", "=", "x2", ".", "highlowcontainer", ".", "getKeyAtIndex", "(", "pos2", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "if", "pos2", "==", "length2", "{", "answer", ".", "highlowcontainer", ".", "appendCopyMany", "(", "x1", ".", "highlowcontainer", ",", "pos1", ",", "length1", ")", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// AndNot computes the difference between two bitmaps and returns the result
[ "AndNot", "computes", "the", "difference", "between", "two", "bitmaps", "and", "returns", "the", "result" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L1077-L1127
144,679
RoaringBitmap/roaring
roaring.go
AddMany
func (rb *Bitmap) AddMany(dat []uint32) { if len(dat) == 0 { return } prev := dat[0] idx, c := rb.addwithptr(prev) for _, i := range dat[1:] { if highbits(prev) == highbits(i) { c = c.iaddReturnMinimized(lowbits(i)) rb.highlowcontainer.setContainerAtIndex(idx, c) } else { idx, c = rb.addwithptr(i) } prev = i } }
go
func (rb *Bitmap) AddMany(dat []uint32) { if len(dat) == 0 { return } prev := dat[0] idx, c := rb.addwithptr(prev) for _, i := range dat[1:] { if highbits(prev) == highbits(i) { c = c.iaddReturnMinimized(lowbits(i)) rb.highlowcontainer.setContainerAtIndex(idx, c) } else { idx, c = rb.addwithptr(i) } prev = i } }
[ "func", "(", "rb", "*", "Bitmap", ")", "AddMany", "(", "dat", "[", "]", "uint32", ")", "{", "if", "len", "(", "dat", ")", "==", "0", "{", "return", "\n", "}", "\n", "prev", ":=", "dat", "[", "0", "]", "\n", "idx", ",", "c", ":=", "rb", ".", "addwithptr", "(", "prev", ")", "\n", "for", "_", ",", "i", ":=", "range", "dat", "[", "1", ":", "]", "{", "if", "highbits", "(", "prev", ")", "==", "highbits", "(", "i", ")", "{", "c", "=", "c", ".", "iaddReturnMinimized", "(", "lowbits", "(", "i", ")", ")", "\n", "rb", ".", "highlowcontainer", ".", "setContainerAtIndex", "(", "idx", ",", "c", ")", "\n", "}", "else", "{", "idx", ",", "c", "=", "rb", ".", "addwithptr", "(", "i", ")", "\n", "}", "\n", "prev", "=", "i", "\n", "}", "\n", "}" ]
// AddMany add all of the values in dat
[ "AddMany", "add", "all", "of", "the", "values", "in", "dat" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L1130-L1145
144,680
RoaringBitmap/roaring
roaring.go
BitmapOf
func BitmapOf(dat ...uint32) *Bitmap { ans := NewBitmap() ans.AddMany(dat) return ans }
go
func BitmapOf(dat ...uint32) *Bitmap { ans := NewBitmap() ans.AddMany(dat) return ans }
[ "func", "BitmapOf", "(", "dat", "...", "uint32", ")", "*", "Bitmap", "{", "ans", ":=", "NewBitmap", "(", ")", "\n", "ans", ".", "AddMany", "(", "dat", ")", "\n", "return", "ans", "\n", "}" ]
// BitmapOf generates a new bitmap filled with the specified integers
[ "BitmapOf", "generates", "a", "new", "bitmap", "filled", "with", "the", "specified", "integers" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L1148-L1152
144,681
RoaringBitmap/roaring
roaring.go
Stats
func (rb *Bitmap) Stats() Statistics { stats := Statistics{} stats.Containers = uint64(len(rb.highlowcontainer.containers)) for _, c := range rb.highlowcontainer.containers { stats.Cardinality += uint64(c.getCardinality()) switch c.(type) { case *arrayContainer: stats.ArrayContainers++ stats.ArrayContainerBytes += uint64(c.getSizeInBytes()) stats.ArrayContainerValues += uint64(c.getCardinality()) case *bitmapContainer: stats.BitmapContainers++ stats.BitmapContainerBytes += uint64(c.getSizeInBytes()) stats.BitmapContainerValues += uint64(c.getCardinality()) case *runContainer16: stats.RunContainers++ stats.RunContainerBytes += uint64(c.getSizeInBytes()) stats.RunContainerValues += uint64(c.getCardinality()) } } return stats }
go
func (rb *Bitmap) Stats() Statistics { stats := Statistics{} stats.Containers = uint64(len(rb.highlowcontainer.containers)) for _, c := range rb.highlowcontainer.containers { stats.Cardinality += uint64(c.getCardinality()) switch c.(type) { case *arrayContainer: stats.ArrayContainers++ stats.ArrayContainerBytes += uint64(c.getSizeInBytes()) stats.ArrayContainerValues += uint64(c.getCardinality()) case *bitmapContainer: stats.BitmapContainers++ stats.BitmapContainerBytes += uint64(c.getSizeInBytes()) stats.BitmapContainerValues += uint64(c.getCardinality()) case *runContainer16: stats.RunContainers++ stats.RunContainerBytes += uint64(c.getSizeInBytes()) stats.RunContainerValues += uint64(c.getCardinality()) } } return stats }
[ "func", "(", "rb", "*", "Bitmap", ")", "Stats", "(", ")", "Statistics", "{", "stats", ":=", "Statistics", "{", "}", "\n", "stats", ".", "Containers", "=", "uint64", "(", "len", "(", "rb", ".", "highlowcontainer", ".", "containers", ")", ")", "\n", "for", "_", ",", "c", ":=", "range", "rb", ".", "highlowcontainer", ".", "containers", "{", "stats", ".", "Cardinality", "+=", "uint64", "(", "c", ".", "getCardinality", "(", ")", ")", "\n\n", "switch", "c", ".", "(", "type", ")", "{", "case", "*", "arrayContainer", ":", "stats", ".", "ArrayContainers", "++", "\n", "stats", ".", "ArrayContainerBytes", "+=", "uint64", "(", "c", ".", "getSizeInBytes", "(", ")", ")", "\n", "stats", ".", "ArrayContainerValues", "+=", "uint64", "(", "c", ".", "getCardinality", "(", ")", ")", "\n", "case", "*", "bitmapContainer", ":", "stats", ".", "BitmapContainers", "++", "\n", "stats", ".", "BitmapContainerBytes", "+=", "uint64", "(", "c", ".", "getSizeInBytes", "(", ")", ")", "\n", "stats", ".", "BitmapContainerValues", "+=", "uint64", "(", "c", ".", "getCardinality", "(", ")", ")", "\n", "case", "*", "runContainer16", ":", "stats", ".", "RunContainers", "++", "\n", "stats", ".", "RunContainerBytes", "+=", "uint64", "(", "c", ".", "getSizeInBytes", "(", ")", ")", "\n", "stats", ".", "RunContainerValues", "+=", "uint64", "(", "c", ".", "getCardinality", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "stats", "\n", "}" ]
// Stats returns details on container type usage in a Statistics struct.
[ "Stats", "returns", "details", "on", "container", "type", "usage", "in", "a", "Statistics", "struct", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaring.go#L1405-L1427
144,682
RoaringBitmap/roaring
arraycontainer.go
iaddRange
func (ac *arrayContainer) iaddRange(firstOfRange, endx int) container { if firstOfRange >= endx { return ac } indexstart := binarySearch(ac.content, uint16(firstOfRange)) if indexstart < 0 { indexstart = -indexstart - 1 } indexend := binarySearch(ac.content, uint16(endx-1)) if indexend < 0 { indexend = -indexend - 1 } else { indexend++ } rangelength := endx - firstOfRange newcardinality := indexstart + (ac.getCardinality() - indexend) + rangelength if newcardinality > arrayDefaultMaxSize { a := ac.toBitmapContainer() return a.iaddRange(firstOfRange, endx) } if cap(ac.content) < newcardinality { tmp := make([]uint16, newcardinality, newcardinality) copy(tmp[:indexstart], ac.content[:indexstart]) copy(tmp[indexstart+rangelength:], ac.content[indexend:]) ac.content = tmp } else { ac.content = ac.content[:newcardinality] copy(ac.content[indexstart+rangelength:], ac.content[indexend:]) } for k := 0; k < rangelength; k++ { ac.content[k+indexstart] = uint16(firstOfRange + k) } return ac }
go
func (ac *arrayContainer) iaddRange(firstOfRange, endx int) container { if firstOfRange >= endx { return ac } indexstart := binarySearch(ac.content, uint16(firstOfRange)) if indexstart < 0 { indexstart = -indexstart - 1 } indexend := binarySearch(ac.content, uint16(endx-1)) if indexend < 0 { indexend = -indexend - 1 } else { indexend++ } rangelength := endx - firstOfRange newcardinality := indexstart + (ac.getCardinality() - indexend) + rangelength if newcardinality > arrayDefaultMaxSize { a := ac.toBitmapContainer() return a.iaddRange(firstOfRange, endx) } if cap(ac.content) < newcardinality { tmp := make([]uint16, newcardinality, newcardinality) copy(tmp[:indexstart], ac.content[:indexstart]) copy(tmp[indexstart+rangelength:], ac.content[indexend:]) ac.content = tmp } else { ac.content = ac.content[:newcardinality] copy(ac.content[indexstart+rangelength:], ac.content[indexend:]) } for k := 0; k < rangelength; k++ { ac.content[k+indexstart] = uint16(firstOfRange + k) } return ac }
[ "func", "(", "ac", "*", "arrayContainer", ")", "iaddRange", "(", "firstOfRange", ",", "endx", "int", ")", "container", "{", "if", "firstOfRange", ">=", "endx", "{", "return", "ac", "\n", "}", "\n", "indexstart", ":=", "binarySearch", "(", "ac", ".", "content", ",", "uint16", "(", "firstOfRange", ")", ")", "\n", "if", "indexstart", "<", "0", "{", "indexstart", "=", "-", "indexstart", "-", "1", "\n", "}", "\n", "indexend", ":=", "binarySearch", "(", "ac", ".", "content", ",", "uint16", "(", "endx", "-", "1", ")", ")", "\n", "if", "indexend", "<", "0", "{", "indexend", "=", "-", "indexend", "-", "1", "\n", "}", "else", "{", "indexend", "++", "\n", "}", "\n", "rangelength", ":=", "endx", "-", "firstOfRange", "\n", "newcardinality", ":=", "indexstart", "+", "(", "ac", ".", "getCardinality", "(", ")", "-", "indexend", ")", "+", "rangelength", "\n", "if", "newcardinality", ">", "arrayDefaultMaxSize", "{", "a", ":=", "ac", ".", "toBitmapContainer", "(", ")", "\n", "return", "a", ".", "iaddRange", "(", "firstOfRange", ",", "endx", ")", "\n", "}", "\n", "if", "cap", "(", "ac", ".", "content", ")", "<", "newcardinality", "{", "tmp", ":=", "make", "(", "[", "]", "uint16", ",", "newcardinality", ",", "newcardinality", ")", "\n", "copy", "(", "tmp", "[", ":", "indexstart", "]", ",", "ac", ".", "content", "[", ":", "indexstart", "]", ")", "\n", "copy", "(", "tmp", "[", "indexstart", "+", "rangelength", ":", "]", ",", "ac", ".", "content", "[", "indexend", ":", "]", ")", "\n\n", "ac", ".", "content", "=", "tmp", "\n", "}", "else", "{", "ac", ".", "content", "=", "ac", ".", "content", "[", ":", "newcardinality", "]", "\n", "copy", "(", "ac", ".", "content", "[", "indexstart", "+", "rangelength", ":", "]", ",", "ac", ".", "content", "[", "indexend", ":", "]", ")", "\n\n", "}", "\n", "for", "k", ":=", "0", ";", "k", "<", "rangelength", ";", "k", "++", "{", "ac", ".", "content", "[", "k", "+", "indexstart", "]", "=", "uint16", "(", "firstOfRange", "+", "k", ")", "\n", "}", "\n", "return", "ac", "\n", "}" ]
// add the values in the range [firstOfRange,endx)
[ "add", "the", "values", "in", "the", "range", "[", "firstOfRange", "endx", ")" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/arraycontainer.go#L60-L95
144,683
RoaringBitmap/roaring
arraycontainer.go
iremoveReturnMinimized
func (ac *arrayContainer) iremoveReturnMinimized(x uint16) container { ac.iremove(x) return ac }
go
func (ac *arrayContainer) iremoveReturnMinimized(x uint16) container { ac.iremove(x) return ac }
[ "func", "(", "ac", "*", "arrayContainer", ")", "iremoveReturnMinimized", "(", "x", "uint16", ")", "container", "{", "ac", ".", "iremove", "(", "x", ")", "\n", "return", "ac", "\n", "}" ]
// iremoveReturnMinimized is allowed to change the return type to minimize storage.
[ "iremoveReturnMinimized", "is", "allowed", "to", "change", "the", "return", "type", "to", "minimize", "storage", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/arraycontainer.go#L273-L276
144,684
RoaringBitmap/roaring
serialization_generic.go
byteSliceAsInterval16Slice
func byteSliceAsInterval16Slice(byteSlice []byte) []interval16 { if len(byteSlice)%4 != 0 { panic("Slice size should be divisible by 4") } intervalSlice := make([]interval16, len(byteSlice)/4) for i := range intervalSlice { intervalSlice[i] = interval16{ start: binary.LittleEndian.Uint16(byteSlice[i*4:]), length: binary.LittleEndian.Uint16(byteSlice[i*4+2:]), } } return intervalSlice }
go
func byteSliceAsInterval16Slice(byteSlice []byte) []interval16 { if len(byteSlice)%4 != 0 { panic("Slice size should be divisible by 4") } intervalSlice := make([]interval16, len(byteSlice)/4) for i := range intervalSlice { intervalSlice[i] = interval16{ start: binary.LittleEndian.Uint16(byteSlice[i*4:]), length: binary.LittleEndian.Uint16(byteSlice[i*4+2:]), } } return intervalSlice }
[ "func", "byteSliceAsInterval16Slice", "(", "byteSlice", "[", "]", "byte", ")", "[", "]", "interval16", "{", "if", "len", "(", "byteSlice", ")", "%", "4", "!=", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "intervalSlice", ":=", "make", "(", "[", "]", "interval16", ",", "len", "(", "byteSlice", ")", "/", "4", ")", "\n\n", "for", "i", ":=", "range", "intervalSlice", "{", "intervalSlice", "[", "i", "]", "=", "interval16", "{", "start", ":", "binary", ".", "LittleEndian", ".", "Uint16", "(", "byteSlice", "[", "i", "*", "4", ":", "]", ")", ",", "length", ":", "binary", ".", "LittleEndian", ".", "Uint16", "(", "byteSlice", "[", "i", "*", "4", "+", "2", ":", "]", ")", ",", "}", "\n", "}", "\n\n", "return", "intervalSlice", "\n", "}" ]
// Converts a byte slice to a interval16 slice. // The function assumes that the slice byte buffer is run container data // encoded according to Roaring Format Spec
[ "Converts", "a", "byte", "slice", "to", "a", "interval16", "slice", ".", "The", "function", "assumes", "that", "the", "slice", "byte", "buffer", "is", "run", "container", "data", "encoded", "according", "to", "Roaring", "Format", "Spec" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/serialization_generic.go#L108-L123
144,685
RoaringBitmap/roaring
clz_compat.go
countLeadingZeros
func countLeadingZeros(i uint64) int { if i == 0 { return 64 } n := 1 x := uint32(i >> 32) if x == 0 { n += 32 x = uint32(i) } if (x >> 16) == 0 { n += 16 x <<= 16 } if (x >> 24) == 0 { n += 8 x <<= 8 } if x>>28 == 0 { n += 4 x <<= 4 } if x>>30 == 0 { n += 2 x <<= 2 } n -= int(x >> 31) return n }
go
func countLeadingZeros(i uint64) int { if i == 0 { return 64 } n := 1 x := uint32(i >> 32) if x == 0 { n += 32 x = uint32(i) } if (x >> 16) == 0 { n += 16 x <<= 16 } if (x >> 24) == 0 { n += 8 x <<= 8 } if x>>28 == 0 { n += 4 x <<= 4 } if x>>30 == 0 { n += 2 x <<= 2 } n -= int(x >> 31) return n }
[ "func", "countLeadingZeros", "(", "i", "uint64", ")", "int", "{", "if", "i", "==", "0", "{", "return", "64", "\n", "}", "\n", "n", ":=", "1", "\n", "x", ":=", "uint32", "(", "i", ">>", "32", ")", "\n", "if", "x", "==", "0", "{", "n", "+=", "32", "\n", "x", "=", "uint32", "(", "i", ")", "\n", "}", "\n", "if", "(", "x", ">>", "16", ")", "==", "0", "{", "n", "+=", "16", "\n", "x", "<<=", "16", "\n", "}", "\n", "if", "(", "x", ">>", "24", ")", "==", "0", "{", "n", "+=", "8", "\n", "x", "<<=", "8", "\n", "}", "\n", "if", "x", ">>", "28", "==", "0", "{", "n", "+=", "4", "\n", "x", "<<=", "4", "\n", "}", "\n", "if", "x", ">>", "30", "==", "0", "{", "n", "+=", "2", "\n", "x", "<<=", "2", "\n\n", "}", "\n", "n", "-=", "int", "(", "x", ">>", "31", ")", "\n", "return", "n", "\n", "}" ]
// LeadingZeroBits returns the number of consecutive most significant zero // bits of x.
[ "LeadingZeroBits", "returns", "the", "number", "of", "consecutive", "most", "significant", "zero", "bits", "of", "x", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/clz_compat.go#L7-L36
144,686
RoaringBitmap/roaring
roaringarray.go
serializedSizeInBytes
func (ra *roaringArray) serializedSizeInBytes() uint64 { answer := ra.headerSize() for _, c := range ra.containers { answer += uint64(c.serializedSizeInBytes()) } return answer }
go
func (ra *roaringArray) serializedSizeInBytes() uint64 { answer := ra.headerSize() for _, c := range ra.containers { answer += uint64(c.serializedSizeInBytes()) } return answer }
[ "func", "(", "ra", "*", "roaringArray", ")", "serializedSizeInBytes", "(", ")", "uint64", "{", "answer", ":=", "ra", ".", "headerSize", "(", ")", "\n", "for", "_", ",", "c", ":=", "range", "ra", ".", "containers", "{", "answer", "+=", "uint64", "(", "c", ".", "serializedSizeInBytes", "(", ")", ")", "\n", "}", "\n", "return", "answer", "\n", "}" ]
// should be dirt cheap
[ "should", "be", "dirt", "cheap" ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/roaringarray.go#L451-L457
144,687
RoaringBitmap/roaring
smat.go
smatWrap
func smatWrap(cb func(c *smatContext)) func(smat.Context) (next smat.State, err error) { return func(ctx smat.Context) (next smat.State, err error) { c := ctx.(*smatContext) cb(c) return smatRunning, nil } }
go
func smatWrap(cb func(c *smatContext)) func(smat.Context) (next smat.State, err error) { return func(ctx smat.Context) (next smat.State, err error) { c := ctx.(*smatContext) cb(c) return smatRunning, nil } }
[ "func", "smatWrap", "(", "cb", "func", "(", "c", "*", "smatContext", ")", ")", "func", "(", "smat", ".", "Context", ")", "(", "next", "smat", ".", "State", ",", "err", "error", ")", "{", "return", "func", "(", "ctx", "smat", ".", "Context", ")", "(", "next", "smat", ".", "State", ",", "err", "error", ")", "{", "c", ":=", "ctx", ".", "(", "*", "smatContext", ")", "\n", "cb", "(", "c", ")", "\n", "return", "smatRunning", ",", "nil", "\n", "}", "\n", "}" ]
// Creates an smat action func based on a simple callback.
[ "Creates", "an", "smat", "action", "func", "based", "on", "a", "simple", "callback", "." ]
8d778e47dd84f169ef4436abb474b0e0101a6dae
https://github.com/RoaringBitmap/roaring/blob/8d778e47dd84f169ef4436abb474b0e0101a6dae/smat.go#L173-L179
144,688
mesosphere/mesos-dns
records/state/client/cli.go
NewStateLoader
func NewStateLoader(doer httpcli.Doer, initialEndpoint urls.Builder, unmarshal Unmarshaler) StateLoader { return func(masters []string) (state.State, error) { return LoadMasterStateTryAll(masters, func(ip, port string) (state.State, error) { return LoadMasterStateFailover(ip, func(tryIP string) (state.State, error) { return LoadMasterState(doer, initialEndpoint, tryIP, port, unmarshal) }) }) } }
go
func NewStateLoader(doer httpcli.Doer, initialEndpoint urls.Builder, unmarshal Unmarshaler) StateLoader { return func(masters []string) (state.State, error) { return LoadMasterStateTryAll(masters, func(ip, port string) (state.State, error) { return LoadMasterStateFailover(ip, func(tryIP string) (state.State, error) { return LoadMasterState(doer, initialEndpoint, tryIP, port, unmarshal) }) }) } }
[ "func", "NewStateLoader", "(", "doer", "httpcli", ".", "Doer", ",", "initialEndpoint", "urls", ".", "Builder", ",", "unmarshal", "Unmarshaler", ")", "StateLoader", "{", "return", "func", "(", "masters", "[", "]", "string", ")", "(", "state", ".", "State", ",", "error", ")", "{", "return", "LoadMasterStateTryAll", "(", "masters", ",", "func", "(", "ip", ",", "port", "string", ")", "(", "state", ".", "State", ",", "error", ")", "{", "return", "LoadMasterStateFailover", "(", "ip", ",", "func", "(", "tryIP", "string", ")", "(", "state", ".", "State", ",", "error", ")", "{", "return", "LoadMasterState", "(", "doer", ",", "initialEndpoint", ",", "tryIP", ",", "port", ",", "unmarshal", ")", "\n", "}", ")", "\n", "}", ")", "\n", "}", "\n\n", "}" ]
// NewStateLoader generates a new Mesos master state loader using the given http client and initial endpoint.
[ "NewStateLoader", "generates", "a", "new", "Mesos", "master", "state", "loader", "using", "the", "given", "http", "client", "and", "initial", "endpoint", "." ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/state/client/cli.go#L27-L36
144,689
mesosphere/mesos-dns
records/state/client/cli.go
LoadMasterStateTryAll
func LoadMasterStateTryAll(masters []string, stateLoader func(ip, port string) (state.State, error)) (state.State, error) { var sj state.State var leader string if len(masters) > 0 { leader, masters = masters[0], masters[1:] } else { return sj, errors.New("no masters given to fetch state.json") } // Check if ZK leader is correct if leader != "" { logging.VeryVerbose.Println("Zookeeper says the leader is: ", leader) ip, port, err := urls.SplitHostPort(leader) if err != nil { logging.Error.Println(err) } else { if sj, err = stateLoader(ip, port); err == nil { return sj, nil } logging.Error.Println("Failed to fetch state from leader. Error: ", err) if len(masters) == 0 { logging.Error.Println("No more masters to try, returning last error") return sj, err } logging.Error.Println("Falling back to remaining masters: ", masters) } } // try each listed mesos master before dying var ( ip, port string err error ) for _, master := range masters { ip, port, err = urls.SplitHostPort(master) if err != nil { logging.Error.Println(err) continue } if sj, err = stateLoader(ip, port); err != nil { logging.Error.Println("Failed to fetch state - trying next one. Error: ", err) continue } return sj, nil } logging.Error.Println("No more masters eligible for state query, returning last error") return sj, err }
go
func LoadMasterStateTryAll(masters []string, stateLoader func(ip, port string) (state.State, error)) (state.State, error) { var sj state.State var leader string if len(masters) > 0 { leader, masters = masters[0], masters[1:] } else { return sj, errors.New("no masters given to fetch state.json") } // Check if ZK leader is correct if leader != "" { logging.VeryVerbose.Println("Zookeeper says the leader is: ", leader) ip, port, err := urls.SplitHostPort(leader) if err != nil { logging.Error.Println(err) } else { if sj, err = stateLoader(ip, port); err == nil { return sj, nil } logging.Error.Println("Failed to fetch state from leader. Error: ", err) if len(masters) == 0 { logging.Error.Println("No more masters to try, returning last error") return sj, err } logging.Error.Println("Falling back to remaining masters: ", masters) } } // try each listed mesos master before dying var ( ip, port string err error ) for _, master := range masters { ip, port, err = urls.SplitHostPort(master) if err != nil { logging.Error.Println(err) continue } if sj, err = stateLoader(ip, port); err != nil { logging.Error.Println("Failed to fetch state - trying next one. Error: ", err) continue } return sj, nil } logging.Error.Println("No more masters eligible for state query, returning last error") return sj, err }
[ "func", "LoadMasterStateTryAll", "(", "masters", "[", "]", "string", ",", "stateLoader", "func", "(", "ip", ",", "port", "string", ")", "(", "state", ".", "State", ",", "error", ")", ")", "(", "state", ".", "State", ",", "error", ")", "{", "var", "sj", "state", ".", "State", "\n", "var", "leader", "string", "\n\n", "if", "len", "(", "masters", ")", ">", "0", "{", "leader", ",", "masters", "=", "masters", "[", "0", "]", ",", "masters", "[", "1", ":", "]", "\n", "}", "else", "{", "return", "sj", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if ZK leader is correct", "if", "leader", "!=", "\"", "\"", "{", "logging", ".", "VeryVerbose", ".", "Println", "(", "\"", "\"", ",", "leader", ")", "\n", "ip", ",", "port", ",", "err", ":=", "urls", ".", "SplitHostPort", "(", "leader", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "}", "else", "{", "if", "sj", ",", "err", "=", "stateLoader", "(", "ip", ",", "port", ")", ";", "err", "==", "nil", "{", "return", "sj", ",", "nil", "\n", "}", "\n", "logging", ".", "Error", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "if", "len", "(", "masters", ")", "==", "0", "{", "logging", ".", "Error", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "sj", ",", "err", "\n", "}", "\n", "logging", ".", "Error", ".", "Println", "(", "\"", "\"", ",", "masters", ")", "\n", "}", "\n", "}", "\n\n", "// try each listed mesos master before dying", "var", "(", "ip", ",", "port", "string", "\n", "err", "error", "\n", ")", "\n", "for", "_", ",", "master", ":=", "range", "masters", "{", "ip", ",", "port", ",", "err", "=", "urls", ".", "SplitHostPort", "(", "master", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "continue", "\n", "}", "\n\n", "if", "sj", ",", "err", "=", "stateLoader", "(", "ip", ",", "port", ")", ";", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "return", "sj", ",", "nil", "\n", "}", "\n\n", "logging", ".", "Error", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "sj", ",", "err", "\n", "}" ]
// LoadMasterStateTryAll tries each master and looks for the leader; if no leader responds it errors. // The first master in the list is assumed to be the leading mesos master.
[ "LoadMasterStateTryAll", "tries", "each", "master", "and", "looks", "for", "the", "leader", ";", "if", "no", "leader", "responds", "it", "errors", ".", "The", "first", "master", "in", "the", "list", "is", "assumed", "to", "be", "the", "leading", "mesos", "master", "." ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/state/client/cli.go#L40-L90
144,690
mesosphere/mesos-dns
records/state/client/cli.go
LoadMasterStateFailover
func LoadMasterStateFailover(initialMasterIP string, stateLoader func(ip string) (state.State, error)) (state.State, error) { var err error var sj state.State logging.VeryVerbose.Println("reloading from master " + initialMasterIP) sj, err = stateLoader(initialMasterIP) if err != nil { return state.State{}, err } if sj.Leader != "" { var stateLeaderIP string stateLeaderIP, err = leaderIP(sj.Leader) if err != nil { return sj, err } if stateLeaderIP != initialMasterIP { logging.VeryVerbose.Println("Warning: master changed to " + stateLeaderIP) return stateLoader(stateLeaderIP) } return sj, nil } err = errors.New("fetched state does not contain leader information") return sj, err }
go
func LoadMasterStateFailover(initialMasterIP string, stateLoader func(ip string) (state.State, error)) (state.State, error) { var err error var sj state.State logging.VeryVerbose.Println("reloading from master " + initialMasterIP) sj, err = stateLoader(initialMasterIP) if err != nil { return state.State{}, err } if sj.Leader != "" { var stateLeaderIP string stateLeaderIP, err = leaderIP(sj.Leader) if err != nil { return sj, err } if stateLeaderIP != initialMasterIP { logging.VeryVerbose.Println("Warning: master changed to " + stateLeaderIP) return stateLoader(stateLeaderIP) } return sj, nil } err = errors.New("fetched state does not contain leader information") return sj, err }
[ "func", "LoadMasterStateFailover", "(", "initialMasterIP", "string", ",", "stateLoader", "func", "(", "ip", "string", ")", "(", "state", ".", "State", ",", "error", ")", ")", "(", "state", ".", "State", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "sj", "state", ".", "State", "\n\n", "logging", ".", "VeryVerbose", ".", "Println", "(", "\"", "\"", "+", "initialMasterIP", ")", "\n", "sj", ",", "err", "=", "stateLoader", "(", "initialMasterIP", ")", "\n", "if", "err", "!=", "nil", "{", "return", "state", ".", "State", "{", "}", ",", "err", "\n", "}", "\n", "if", "sj", ".", "Leader", "!=", "\"", "\"", "{", "var", "stateLeaderIP", "string", "\n\n", "stateLeaderIP", ",", "err", "=", "leaderIP", "(", "sj", ".", "Leader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "sj", ",", "err", "\n", "}", "\n", "if", "stateLeaderIP", "!=", "initialMasterIP", "{", "logging", ".", "VeryVerbose", ".", "Println", "(", "\"", "\"", "+", "stateLeaderIP", ")", "\n", "return", "stateLoader", "(", "stateLeaderIP", ")", "\n", "}", "\n", "return", "sj", ",", "nil", "\n", "}", "\n", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "return", "sj", ",", "err", "\n", "}" ]
// LoadMasterStateFailover catches an attempt to load state from a mesos master. // Attempts can fail from due to a down server or if contacting a mesos master secondary. // It reloads from a different master if the contacted master is a secondary.
[ "LoadMasterStateFailover", "catches", "an", "attempt", "to", "load", "state", "from", "a", "mesos", "master", ".", "Attempts", "can", "fail", "from", "due", "to", "a", "down", "server", "or", "if", "contacting", "a", "mesos", "master", "secondary", ".", "It", "reloads", "from", "a", "different", "master", "if", "the", "contacted", "master", "is", "a", "secondary", "." ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/state/client/cli.go#L95-L119
144,691
mesosphere/mesos-dns
records/state/client/cli.go
LoadMasterState
func LoadMasterState(client httpcli.Doer, stateEndpoint urls.Builder, ip, port string, unmarshal Unmarshaler) (sj state.State, _ error) { // REFACTOR: state security u := url.URL(stateEndpoint.With(urls.Host(net.JoinHostPort(ip, port)))) req, err := http.NewRequest("GET", u.String(), nil) if err != nil { logging.Error.Println(err) return state.State{}, err } req.Header.Set("Content-Type", "application/json") // TODO(jdef) unclear why Content-Type vs. Accept req.Header.Set("User-Agent", "Mesos-DNS") resp, err := client.Do(req) if err != nil { logging.Error.Println(err) return sj, err } defer errorutil.Ignore(resp.Body.Close) body, err := ioutil.ReadAll(resp.Body) if err != nil { logging.Error.Println(err) return sj, err } err = unmarshal(body, &sj) if err != nil { logging.Error.Println(err) return sj, err } return }
go
func LoadMasterState(client httpcli.Doer, stateEndpoint urls.Builder, ip, port string, unmarshal Unmarshaler) (sj state.State, _ error) { // REFACTOR: state security u := url.URL(stateEndpoint.With(urls.Host(net.JoinHostPort(ip, port)))) req, err := http.NewRequest("GET", u.String(), nil) if err != nil { logging.Error.Println(err) return state.State{}, err } req.Header.Set("Content-Type", "application/json") // TODO(jdef) unclear why Content-Type vs. Accept req.Header.Set("User-Agent", "Mesos-DNS") resp, err := client.Do(req) if err != nil { logging.Error.Println(err) return sj, err } defer errorutil.Ignore(resp.Body.Close) body, err := ioutil.ReadAll(resp.Body) if err != nil { logging.Error.Println(err) return sj, err } err = unmarshal(body, &sj) if err != nil { logging.Error.Println(err) return sj, err } return }
[ "func", "LoadMasterState", "(", "client", "httpcli", ".", "Doer", ",", "stateEndpoint", "urls", ".", "Builder", ",", "ip", ",", "port", "string", ",", "unmarshal", "Unmarshaler", ")", "(", "sj", "state", ".", "State", ",", "_", "error", ")", "{", "// REFACTOR: state security", "u", ":=", "url", ".", "URL", "(", "stateEndpoint", ".", "With", "(", "urls", ".", "Host", "(", "net", ".", "JoinHostPort", "(", "ip", ",", "port", ")", ")", ")", ")", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "return", "state", ".", "State", "{", "}", ",", "err", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "// TODO(jdef) unclear why Content-Type vs. Accept", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "resp", ",", "err", ":=", "client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "return", "sj", ",", "err", "\n", "}", "\n\n", "defer", "errorutil", ".", "Ignore", "(", "resp", ".", "Body", ".", "Close", ")", "\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "return", "sj", ",", "err", "\n", "}", "\n\n", "err", "=", "unmarshal", "(", "body", ",", "&", "sj", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "return", "sj", ",", "err", "\n", "}", "\n\n", "return", "\n", "}" ]
// LoadMasterState loads state from mesos master
[ "LoadMasterState", "loads", "state", "from", "mesos", "master" ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/state/client/cli.go#L122-L156
144,692
mesosphere/mesos-dns
records/state/client/cli.go
leaderIP
func leaderIP(leader string) (string, error) { // TODO(jdef) it's unclear why we drop the port here nameAddressPair := strings.Split(leader, "@") if len(nameAddressPair) != 2 { return "", errors.New("Invalid leader address: " + leader) } hostPort := nameAddressPair[1] host, _, err := net.SplitHostPort(hostPort) if err != nil { return "", err } return host, nil }
go
func leaderIP(leader string) (string, error) { // TODO(jdef) it's unclear why we drop the port here nameAddressPair := strings.Split(leader, "@") if len(nameAddressPair) != 2 { return "", errors.New("Invalid leader address: " + leader) } hostPort := nameAddressPair[1] host, _, err := net.SplitHostPort(hostPort) if err != nil { return "", err } return host, nil }
[ "func", "leaderIP", "(", "leader", "string", ")", "(", "string", ",", "error", ")", "{", "// TODO(jdef) it's unclear why we drop the port here", "nameAddressPair", ":=", "strings", ".", "Split", "(", "leader", ",", "\"", "\"", ")", "\n", "if", "len", "(", "nameAddressPair", ")", "!=", "2", "{", "return", "\"", "\"", ",", "errors", ".", "New", "(", "\"", "\"", "+", "leader", ")", "\n", "}", "\n", "hostPort", ":=", "nameAddressPair", "[", "1", "]", "\n", "host", ",", "_", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "hostPort", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "host", ",", "nil", "\n", "}" ]
// leaderIP returns the ip for the mesos master // input format master@ip:port
[ "leaderIP", "returns", "the", "ip", "for", "the", "mesos", "master", "input", "format", "master" ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/state/client/cli.go#L160-L172
144,693
mesosphere/mesos-dns
records/validation.go
validateUniqueStrings
func validateUniqueStrings(strings []string, normalize func(string) (string, error)) error { valid := make(map[string]struct{}, len(strings)) for _, str := range strings { normalized, err := normalize(str) if err != nil { return err } if _, found := valid[normalized]; found { return fmt.Errorf("duplicate found: %v", str) } valid[normalized] = struct{}{} } return nil }
go
func validateUniqueStrings(strings []string, normalize func(string) (string, error)) error { valid := make(map[string]struct{}, len(strings)) for _, str := range strings { normalized, err := normalize(str) if err != nil { return err } if _, found := valid[normalized]; found { return fmt.Errorf("duplicate found: %v", str) } valid[normalized] = struct{}{} } return nil }
[ "func", "validateUniqueStrings", "(", "strings", "[", "]", "string", ",", "normalize", "func", "(", "string", ")", "(", "string", ",", "error", ")", ")", "error", "{", "valid", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ",", "len", "(", "strings", ")", ")", "\n", "for", "_", ",", "str", ":=", "range", "strings", "{", "normalized", ",", "err", ":=", "normalize", "(", "str", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "_", ",", "found", ":=", "valid", "[", "normalized", "]", ";", "found", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "str", ")", "\n", "}", "\n", "valid", "[", "normalized", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// validateUniqueStrings runs a normalize function on each string in a list and // retuns an error if any duplicates are found.
[ "validateUniqueStrings", "runs", "a", "normalize", "function", "on", "each", "string", "in", "a", "list", "and", "retuns", "an", "error", "if", "any", "duplicates", "are", "found", "." ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/validation.go#L122-L135
144,694
mesosphere/mesos-dns
records/validation.go
validateIPSources
func validateIPSources(srcs []string) error { if len(srcs) == 0 { return fmt.Errorf("empty ip sources") } if len(srcs) != len(unique(srcs)) { return fmt.Errorf("duplicate ip source specified") } for _, src := range srcs { switch src { case "host", "docker", "mesos", "netinfo": default: return fmt.Errorf("invalid ip source %q", src) } } return nil }
go
func validateIPSources(srcs []string) error { if len(srcs) == 0 { return fmt.Errorf("empty ip sources") } if len(srcs) != len(unique(srcs)) { return fmt.Errorf("duplicate ip source specified") } for _, src := range srcs { switch src { case "host", "docker", "mesos", "netinfo": default: return fmt.Errorf("invalid ip source %q", src) } } return nil }
[ "func", "validateIPSources", "(", "srcs", "[", "]", "string", ")", "error", "{", "if", "len", "(", "srcs", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "srcs", ")", "!=", "len", "(", "unique", "(", "srcs", ")", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "src", ":=", "range", "srcs", "{", "switch", "src", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "src", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// validateIPSources checks validity of ip sources
[ "validateIPSources", "checks", "validity", "of", "ip", "sources" ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/validation.go#L138-L154
144,695
mesosphere/mesos-dns
records/validation.go
validPortString
func validPortString(portString string) bool { port, err := strconv.Atoi(portString) return err == nil && port > 0 && port <= 65535 }
go
func validPortString(portString string) bool { port, err := strconv.Atoi(portString) return err == nil && port > 0 && port <= 65535 }
[ "func", "validPortString", "(", "portString", "string", ")", "bool", "{", "port", ",", "err", ":=", "strconv", ".", "Atoi", "(", "portString", ")", "\n", "return", "err", "==", "nil", "&&", "port", ">", "0", "&&", "port", "<=", "65535", "\n", "}" ]
// validPortString retuns true if the given port string is // an integer between 1 and 65535, false otherwise.
[ "validPortString", "retuns", "true", "if", "the", "given", "port", "string", "is", "an", "integer", "between", "1", "and", "65535", "false", "otherwise", "." ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/validation.go#L158-L161
144,696
mesosphere/mesos-dns
records/generator.go
ToAXFRResourceRecordSet
func (r rrs) ToAXFRResourceRecordSet() models.AXFRResourceRecordSet { ret := make(models.AXFRResourceRecordSet, len(r)) for host, values := range r { ret[host] = make([]string, 0, len(values)) for record := range values { ret[host] = append(ret[host], record) } } return ret }
go
func (r rrs) ToAXFRResourceRecordSet() models.AXFRResourceRecordSet { ret := make(models.AXFRResourceRecordSet, len(r)) for host, values := range r { ret[host] = make([]string, 0, len(values)) for record := range values { ret[host] = append(ret[host], record) } } return ret }
[ "func", "(", "r", "rrs", ")", "ToAXFRResourceRecordSet", "(", ")", "models", ".", "AXFRResourceRecordSet", "{", "ret", ":=", "make", "(", "models", ".", "AXFRResourceRecordSet", ",", "len", "(", "r", ")", ")", "\n", "for", "host", ",", "values", ":=", "range", "r", "{", "ret", "[", "host", "]", "=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "values", ")", ")", "\n", "for", "record", ":=", "range", "values", "{", "ret", "[", "host", "]", "=", "append", "(", "ret", "[", "host", "]", ",", "record", ")", "\n", "}", "\n", "}", "\n", "return", "ret", "\n", "}" ]
// Transform the record set into something exportable via the REST API
[ "Transform", "the", "record", "set", "into", "something", "exportable", "via", "the", "REST", "API" ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/generator.go#L59-L68
144,697
mesosphere/mesos-dns
records/generator.go
NewRecordGenerator
func NewRecordGenerator(options ...Option) *RecordGenerator { rg := &RecordGenerator{} rg.stateLoader = func(_ []string) (s state.State, err error) { return } for i := range options { if options[i] != nil { options[i](rg) } } return rg }
go
func NewRecordGenerator(options ...Option) *RecordGenerator { rg := &RecordGenerator{} rg.stateLoader = func(_ []string) (s state.State, err error) { return } for i := range options { if options[i] != nil { options[i](rg) } } return rg }
[ "func", "NewRecordGenerator", "(", "options", "...", "Option", ")", "*", "RecordGenerator", "{", "rg", ":=", "&", "RecordGenerator", "{", "}", "\n", "rg", ".", "stateLoader", "=", "func", "(", "_", "[", "]", "string", ")", "(", "s", "state", ".", "State", ",", "err", "error", ")", "{", "return", "}", "\n", "for", "i", ":=", "range", "options", "{", "if", "options", "[", "i", "]", "!=", "nil", "{", "options", "[", "i", "]", "(", "rg", ")", "\n", "}", "\n", "}", "\n", "return", "rg", "\n", "}" ]
// NewRecordGenerator returns a RecordGenerator that's been configured with a timeout.
[ "NewRecordGenerator", "returns", "a", "RecordGenerator", "that", "s", "been", "configured", "with", "a", "timeout", "." ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/generator.go#L160-L169
144,698
mesosphere/mesos-dns
records/generator.go
InsertState
func (rg *RecordGenerator) InsertState(sj state.State, domain, ns, listener string, masters, ipSources []string, spec labels.Func) error { rg.SlaveIPs = map[string][]string{} rg.SRVs = rrs{} rg.As = rrs{} rg.AAAAs = rrs{} rg.frameworkRecords(sj, domain, spec) rg.slaveRecords(sj, domain, spec) rg.listenerRecord(listener, ns) rg.masterRecord(domain, masters, sj.Leader) rg.taskRecords(sj, domain, spec, ipSources) return nil }
go
func (rg *RecordGenerator) InsertState(sj state.State, domain, ns, listener string, masters, ipSources []string, spec labels.Func) error { rg.SlaveIPs = map[string][]string{} rg.SRVs = rrs{} rg.As = rrs{} rg.AAAAs = rrs{} rg.frameworkRecords(sj, domain, spec) rg.slaveRecords(sj, domain, spec) rg.listenerRecord(listener, ns) rg.masterRecord(domain, masters, sj.Leader) rg.taskRecords(sj, domain, spec, ipSources) return nil }
[ "func", "(", "rg", "*", "RecordGenerator", ")", "InsertState", "(", "sj", "state", ".", "State", ",", "domain", ",", "ns", ",", "listener", "string", ",", "masters", ",", "ipSources", "[", "]", "string", ",", "spec", "labels", ".", "Func", ")", "error", "{", "rg", ".", "SlaveIPs", "=", "map", "[", "string", "]", "[", "]", "string", "{", "}", "\n", "rg", ".", "SRVs", "=", "rrs", "{", "}", "\n", "rg", ".", "As", "=", "rrs", "{", "}", "\n", "rg", ".", "AAAAs", "=", "rrs", "{", "}", "\n", "rg", ".", "frameworkRecords", "(", "sj", ",", "domain", ",", "spec", ")", "\n", "rg", ".", "slaveRecords", "(", "sj", ",", "domain", ",", "spec", ")", "\n", "rg", ".", "listenerRecord", "(", "listener", ",", "ns", ")", "\n", "rg", ".", "masterRecord", "(", "domain", ",", "masters", ",", "sj", ".", "Leader", ")", "\n", "rg", ".", "taskRecords", "(", "sj", ",", "domain", ",", "spec", ",", "ipSources", ")", "\n\n", "return", "nil", "\n", "}" ]
// InsertState transforms a StateJSON into RecordGenerator RRs
[ "InsertState", "transforms", "a", "StateJSON", "into", "RecordGenerator", "RRs" ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/generator.go#L205-L217
144,699
mesosphere/mesos-dns
records/generator.go
setFromLocal
func (rg *RecordGenerator) setFromLocal(host string, ns string) { ifaces, err := net.Interfaces() if err != nil { logging.Error.Println(err) } // handle err for _, i := range ifaces { addrs, err := i.Addrs() if err != nil { logging.Error.Println(err) } for _, addr := range addrs { var ip net.IP switch v := addr.(type) { case *net.IPNet: ip = v.IP case *net.IPAddr: ip = v.IP } if ip == nil || ip.IsLoopback() { continue } rg.insertRR(ns, ip.String(), rrsKindForIP(ip)) } } }
go
func (rg *RecordGenerator) setFromLocal(host string, ns string) { ifaces, err := net.Interfaces() if err != nil { logging.Error.Println(err) } // handle err for _, i := range ifaces { addrs, err := i.Addrs() if err != nil { logging.Error.Println(err) } for _, addr := range addrs { var ip net.IP switch v := addr.(type) { case *net.IPNet: ip = v.IP case *net.IPAddr: ip = v.IP } if ip == nil || ip.IsLoopback() { continue } rg.insertRR(ns, ip.String(), rrsKindForIP(ip)) } } }
[ "func", "(", "rg", "*", "RecordGenerator", ")", "setFromLocal", "(", "host", "string", ",", "ns", "string", ")", "{", "ifaces", ",", "err", ":=", "net", ".", "Interfaces", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "}", "\n\n", "// handle err", "for", "_", ",", "i", ":=", "range", "ifaces", "{", "addrs", ",", "err", ":=", "i", ".", "Addrs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logging", ".", "Error", ".", "Println", "(", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "addr", ":=", "range", "addrs", "{", "var", "ip", "net", ".", "IP", "\n", "switch", "v", ":=", "addr", ".", "(", "type", ")", "{", "case", "*", "net", ".", "IPNet", ":", "ip", "=", "v", ".", "IP", "\n", "case", "*", "net", ".", "IPAddr", ":", "ip", "=", "v", ".", "IP", "\n", "}", "\n\n", "if", "ip", "==", "nil", "||", "ip", ".", "IsLoopback", "(", ")", "{", "continue", "\n", "}", "\n\n", "rg", ".", "insertRR", "(", "ns", ",", "ip", ".", "String", "(", ")", ",", "rrsKindForIP", "(", "ip", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// A and AAAA records for each local interface // If this causes problems you should explicitly set the // listener address in config.json
[ "A", "and", "AAAA", "records", "for", "each", "local", "interface", "If", "this", "causes", "problems", "you", "should", "explicitly", "set", "the", "listener", "address", "in", "config", ".", "json" ]
65cb06fff5493c3caa8fc00d26e89fbedab9d95e
https://github.com/mesosphere/mesos-dns/blob/65cb06fff5493c3caa8fc00d26e89fbedab9d95e/records/generator.go#L500-L531