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
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
openzipkin-contrib/zipkin-go-opentracing
examples/cli_with_2_services/svc1/httpserver.go
concatHandler
func (s *httpService) concatHandler(w http.ResponseWriter, req *http.Request) { // parse query parameters v := req.URL.Query() result, err := s.service.Concat(req.Context(), v.Get("a"), v.Get("b")) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } // return the result w.Write([]byte(result)) }
go
func (s *httpService) concatHandler(w http.ResponseWriter, req *http.Request) { // parse query parameters v := req.URL.Query() result, err := s.service.Concat(req.Context(), v.Get("a"), v.Get("b")) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } // return the result w.Write([]byte(result)) }
[ "func", "(", "s", "*", "httpService", ")", "concatHandler", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "// parse query parameters", "v", ":=", "req", ".", "URL", ".", "Query", "(", ")", "\n", "result", ",", "err", ":=", "s", ".", "service", ".", "Concat", "(", "req", ".", "Context", "(", ")", ",", "v", ".", "Get", "(", "\"", "\"", ")", ",", "v", ".", "Get", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n", "// return the result", "w", ".", "Write", "(", "[", "]", "byte", "(", "result", ")", ")", "\n", "}" ]
// concatHandler is our HTTP HandlerFunc for a Concat request.
[ "concatHandler", "is", "our", "HTTP", "HandlerFunc", "for", "a", "Concat", "request", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc1/httpserver.go#L20-L30
train
openzipkin-contrib/zipkin-go-opentracing
examples/cli_with_2_services/svc1/httpserver.go
sumHandler
func (s *httpService) sumHandler(w http.ResponseWriter, req *http.Request) { // parse query parameters v := req.URL.Query() a, err := strconv.ParseInt(v.Get("a"), 10, 64) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } b, err := strconv.ParseInt(v.Get("b"), 10, 64) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } // call our Sum binding result, err := s.service.Sum(req.Context(), a, b) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } // return the result w.Write([]byte(fmt.Sprintf("%d", result))) }
go
func (s *httpService) sumHandler(w http.ResponseWriter, req *http.Request) { // parse query parameters v := req.URL.Query() a, err := strconv.ParseInt(v.Get("a"), 10, 64) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } b, err := strconv.ParseInt(v.Get("b"), 10, 64) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } // call our Sum binding result, err := s.service.Sum(req.Context(), a, b) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } // return the result w.Write([]byte(fmt.Sprintf("%d", result))) }
[ "func", "(", "s", "*", "httpService", ")", "sumHandler", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "// parse query parameters", "v", ":=", "req", ".", "URL", ".", "Query", "(", ")", "\n", "a", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "v", ".", "Get", "(", "\"", "\"", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n", "b", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "v", ".", "Get", "(", "\"", "\"", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n", "// call our Sum binding", "result", ",", "err", ":=", "s", ".", "service", ".", "Sum", "(", "req", ".", "Context", "(", ")", ",", "a", ",", "b", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n", "// return the result", "w", ".", "Write", "(", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "result", ")", ")", ")", "\n", "}" ]
// sumHandler is our HTTP Handlerfunc for a Sum request.
[ "sumHandler", "is", "our", "HTTP", "Handlerfunc", "for", "a", "Sum", "request", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc1/httpserver.go#L33-L54
train
openzipkin-contrib/zipkin-go-opentracing
examples/cli_with_2_services/svc1/httpserver.go
NewHTTPHandler
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler { // Create our HTTP Service. svc := &httpService{service: service} // Create the mux. mux := http.NewServeMux() // Create the Concat handler. var concatHandler http.Handler concatHandler = http.HandlerFunc(svc.concatHandler) // Wrap the Concat handler with our tracing middleware. concatHandler = middleware.FromHTTPRequest(tracer, "Concat")(concatHandler) // Create the Sum handler. var sumHandler http.Handler sumHandler = http.HandlerFunc(svc.sumHandler) // Wrap the Sum handler with our tracing middleware. sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler) // Wire up the mux. mux.Handle("/concat/", concatHandler) mux.Handle("/sum/", sumHandler) // Return the mux. return mux }
go
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler { // Create our HTTP Service. svc := &httpService{service: service} // Create the mux. mux := http.NewServeMux() // Create the Concat handler. var concatHandler http.Handler concatHandler = http.HandlerFunc(svc.concatHandler) // Wrap the Concat handler with our tracing middleware. concatHandler = middleware.FromHTTPRequest(tracer, "Concat")(concatHandler) // Create the Sum handler. var sumHandler http.Handler sumHandler = http.HandlerFunc(svc.sumHandler) // Wrap the Sum handler with our tracing middleware. sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler) // Wire up the mux. mux.Handle("/concat/", concatHandler) mux.Handle("/sum/", sumHandler) // Return the mux. return mux }
[ "func", "NewHTTPHandler", "(", "tracer", "opentracing", ".", "Tracer", ",", "service", "Service", ")", "http", ".", "Handler", "{", "// Create our HTTP Service.", "svc", ":=", "&", "httpService", "{", "service", ":", "service", "}", "\n\n", "// Create the mux.", "mux", ":=", "http", ".", "NewServeMux", "(", ")", "\n\n", "// Create the Concat handler.", "var", "concatHandler", "http", ".", "Handler", "\n", "concatHandler", "=", "http", ".", "HandlerFunc", "(", "svc", ".", "concatHandler", ")", "\n\n", "// Wrap the Concat handler with our tracing middleware.", "concatHandler", "=", "middleware", ".", "FromHTTPRequest", "(", "tracer", ",", "\"", "\"", ")", "(", "concatHandler", ")", "\n\n", "// Create the Sum handler.", "var", "sumHandler", "http", ".", "Handler", "\n", "sumHandler", "=", "http", ".", "HandlerFunc", "(", "svc", ".", "sumHandler", ")", "\n\n", "// Wrap the Sum handler with our tracing middleware.", "sumHandler", "=", "middleware", ".", "FromHTTPRequest", "(", "tracer", ",", "\"", "\"", ")", "(", "sumHandler", ")", "\n\n", "// Wire up the mux.", "mux", ".", "Handle", "(", "\"", "\"", ",", "concatHandler", ")", "\n", "mux", ".", "Handle", "(", "\"", "\"", ",", "sumHandler", ")", "\n\n", "// Return the mux.", "return", "mux", "\n", "}" ]
// NewHTTPHandler returns a new HTTP handler our svc1.
[ "NewHTTPHandler", "returns", "a", "new", "HTTP", "handler", "our", "svc1", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc1/httpserver.go#L57-L84
train
openzipkin-contrib/zipkin-go-opentracing
collector-kafka.go
KafkaProducer
func KafkaProducer(p sarama.AsyncProducer) KafkaOption { return func(c *KafkaCollector) { c.producer = p } }
go
func KafkaProducer(p sarama.AsyncProducer) KafkaOption { return func(c *KafkaCollector) { c.producer = p } }
[ "func", "KafkaProducer", "(", "p", "sarama", ".", "AsyncProducer", ")", "KafkaOption", "{", "return", "func", "(", "c", "*", "KafkaCollector", ")", "{", "c", ".", "producer", "=", "p", "}", "\n", "}" ]
// KafkaProducer sets the producer used to produce to Kafka.
[ "KafkaProducer", "sets", "the", "producer", "used", "to", "produce", "to", "Kafka", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-kafka.go#L34-L36
train
openzipkin-contrib/zipkin-go-opentracing
collector-scribe.go
ScribeBatchInterval
func ScribeBatchInterval(d time.Duration) ScribeOption { return func(s *ScribeCollector) { s.batchInterval = d } }
go
func ScribeBatchInterval(d time.Duration) ScribeOption { return func(s *ScribeCollector) { s.batchInterval = d } }
[ "func", "ScribeBatchInterval", "(", "d", "time", ".", "Duration", ")", "ScribeOption", "{", "return", "func", "(", "s", "*", "ScribeCollector", ")", "{", "s", ".", "batchInterval", "=", "d", "}", "\n", "}" ]
// ScribeBatchInterval sets the maximum duration we will buffer traces before // emitting them to the collector. The default batch interval is 1 second.
[ "ScribeBatchInterval", "sets", "the", "maximum", "duration", "we", "will", "buffer", "traces", "before", "emitting", "them", "to", "the", "collector", ".", "The", "default", "batch", "interval", "is", "1", "second", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-scribe.go#L69-L71
train
openzipkin-contrib/zipkin-go-opentracing
tracer.go
WithSampler
func WithSampler(sampler Sampler) TracerOption { return func(opts *TracerOptions) error { opts.shouldSample = sampler return nil } }
go
func WithSampler(sampler Sampler) TracerOption { return func(opts *TracerOptions) error { opts.shouldSample = sampler return nil } }
[ "func", "WithSampler", "(", "sampler", "Sampler", ")", "TracerOption", "{", "return", "func", "(", "opts", "*", "TracerOptions", ")", "error", "{", "opts", ".", "shouldSample", "=", "sampler", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithSampler allows one to add a Sampler function
[ "WithSampler", "allows", "one", "to", "add", "a", "Sampler", "function" ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L120-L125
train
openzipkin-contrib/zipkin-go-opentracing
tracer.go
DebugMode
func DebugMode(val bool) TracerOption { return func(opts *TracerOptions) error { opts.debugMode = val return nil } }
go
func DebugMode(val bool) TracerOption { return func(opts *TracerOptions) error { opts.debugMode = val return nil } }
[ "func", "DebugMode", "(", "val", "bool", ")", "TracerOption", "{", "return", "func", "(", "opts", "*", "TracerOptions", ")", "error", "{", "opts", ".", "debugMode", "=", "val", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// DebugMode allows to set the tracer to Zipkin debug mode
[ "DebugMode", "allows", "to", "set", "the", "tracer", "to", "Zipkin", "debug", "mode" ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L189-L194
train
openzipkin-contrib/zipkin-go-opentracing
tracer.go
NewTracer
func NewTracer(recorder SpanRecorder, options ...TracerOption) (opentracing.Tracer, error) { opts := &TracerOptions{ recorder: recorder, shouldSample: alwaysSample, trimUnsampledSpans: false, newSpanEventListener: func() func(SpanEvent) { return nil }, logger: &nopLogger{}, debugAssertSingleGoroutine: false, debugAssertUseAfterFinish: false, clientServerSameSpan: true, debugMode: false, traceID128Bit: false, maxLogsPerSpan: 10000, observer: nil, } for _, o := range options { err := o(opts) if err != nil { return nil, err } } rval := &tracerImpl{options: *opts} rval.textPropagator = &textMapPropagator{rval} rval.binaryPropagator = &binaryPropagator{rval} rval.accessorPropagator = &accessorPropagator{rval} return rval, nil }
go
func NewTracer(recorder SpanRecorder, options ...TracerOption) (opentracing.Tracer, error) { opts := &TracerOptions{ recorder: recorder, shouldSample: alwaysSample, trimUnsampledSpans: false, newSpanEventListener: func() func(SpanEvent) { return nil }, logger: &nopLogger{}, debugAssertSingleGoroutine: false, debugAssertUseAfterFinish: false, clientServerSameSpan: true, debugMode: false, traceID128Bit: false, maxLogsPerSpan: 10000, observer: nil, } for _, o := range options { err := o(opts) if err != nil { return nil, err } } rval := &tracerImpl{options: *opts} rval.textPropagator = &textMapPropagator{rval} rval.binaryPropagator = &binaryPropagator{rval} rval.accessorPropagator = &accessorPropagator{rval} return rval, nil }
[ "func", "NewTracer", "(", "recorder", "SpanRecorder", ",", "options", "...", "TracerOption", ")", "(", "opentracing", ".", "Tracer", ",", "error", ")", "{", "opts", ":=", "&", "TracerOptions", "{", "recorder", ":", "recorder", ",", "shouldSample", ":", "alwaysSample", ",", "trimUnsampledSpans", ":", "false", ",", "newSpanEventListener", ":", "func", "(", ")", "func", "(", "SpanEvent", ")", "{", "return", "nil", "}", ",", "logger", ":", "&", "nopLogger", "{", "}", ",", "debugAssertSingleGoroutine", ":", "false", ",", "debugAssertUseAfterFinish", ":", "false", ",", "clientServerSameSpan", ":", "true", ",", "debugMode", ":", "false", ",", "traceID128Bit", ":", "false", ",", "maxLogsPerSpan", ":", "10000", ",", "observer", ":", "nil", ",", "}", "\n", "for", "_", ",", "o", ":=", "range", "options", "{", "err", ":=", "o", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "rval", ":=", "&", "tracerImpl", "{", "options", ":", "*", "opts", "}", "\n", "rval", ".", "textPropagator", "=", "&", "textMapPropagator", "{", "rval", "}", "\n", "rval", ".", "binaryPropagator", "=", "&", "binaryPropagator", "{", "rval", "}", "\n", "rval", ".", "accessorPropagator", "=", "&", "accessorPropagator", "{", "rval", "}", "\n", "return", "rval", ",", "nil", "\n", "}" ]
// NewTracer creates a new OpenTracing compatible Zipkin Tracer.
[ "NewTracer", "creates", "a", "new", "OpenTracing", "compatible", "Zipkin", "Tracer", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L224-L250
train
openzipkin-contrib/zipkin-go-opentracing
tracer.go
WithObserver
func WithObserver(observer otobserver.Observer) TracerOption { return func(opts *TracerOptions) error { opts.observer = observer return nil } }
go
func WithObserver(observer otobserver.Observer) TracerOption { return func(opts *TracerOptions) error { opts.observer = observer return nil } }
[ "func", "WithObserver", "(", "observer", "otobserver", ".", "Observer", ")", "TracerOption", "{", "return", "func", "(", "opts", "*", "TracerOptions", ")", "error", "{", "opts", ".", "observer", "=", "observer", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithObserver assigns an initialized observer to opts.observer
[ "WithObserver", "assigns", "an", "initialized", "observer", "to", "opts", ".", "observer" ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L435-L440
train
openzipkin-contrib/zipkin-go-opentracing
collector-http.go
HTTPTimeout
func HTTPTimeout(duration time.Duration) HTTPOption { return func(c *HTTPCollector) { c.client.Timeout = duration } }
go
func HTTPTimeout(duration time.Duration) HTTPOption { return func(c *HTTPCollector) { c.client.Timeout = duration } }
[ "func", "HTTPTimeout", "(", "duration", "time", ".", "Duration", ")", "HTTPOption", "{", "return", "func", "(", "c", "*", "HTTPCollector", ")", "{", "c", ".", "client", ".", "Timeout", "=", "duration", "}", "\n", "}" ]
// HTTPTimeout sets maximum timeout for http request.
[ "HTTPTimeout", "sets", "maximum", "timeout", "for", "http", "request", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L53-L55
train
openzipkin-contrib/zipkin-go-opentracing
collector-http.go
HTTPBatchInterval
func HTTPBatchInterval(d time.Duration) HTTPOption { return func(c *HTTPCollector) { c.batchInterval = d } }
go
func HTTPBatchInterval(d time.Duration) HTTPOption { return func(c *HTTPCollector) { c.batchInterval = d } }
[ "func", "HTTPBatchInterval", "(", "d", "time", ".", "Duration", ")", "HTTPOption", "{", "return", "func", "(", "c", "*", "HTTPCollector", ")", "{", "c", ".", "batchInterval", "=", "d", "}", "\n", "}" ]
// HTTPBatchInterval sets the maximum duration we will buffer traces before // emitting them to the collector. The default batch interval is 1 second.
[ "HTTPBatchInterval", "sets", "the", "maximum", "duration", "we", "will", "buffer", "traces", "before", "emitting", "them", "to", "the", "collector", ".", "The", "default", "batch", "interval", "is", "1", "second", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L72-L74
train
openzipkin-contrib/zipkin-go-opentracing
collector-http.go
HTTPClient
func HTTPClient(client *http.Client) HTTPOption { return func(c *HTTPCollector) { c.client = client } }
go
func HTTPClient(client *http.Client) HTTPOption { return func(c *HTTPCollector) { c.client = client } }
[ "func", "HTTPClient", "(", "client", "*", "http", ".", "Client", ")", "HTTPOption", "{", "return", "func", "(", "c", "*", "HTTPCollector", ")", "{", "c", ".", "client", "=", "client", "}", "\n", "}" ]
// HTTPClient sets a custom http client to use.
[ "HTTPClient", "sets", "a", "custom", "http", "client", "to", "use", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L77-L79
train
openzipkin-contrib/zipkin-go-opentracing
collector-http.go
NewHTTPCollector
func NewHTTPCollector(url string, options ...HTTPOption) (Collector, error) { c := &HTTPCollector{ logger: NewNopLogger(), url: url, client: &http.Client{Timeout: defaultHTTPTimeout}, batchInterval: defaultHTTPBatchInterval * time.Second, batchSize: defaultHTTPBatchSize, maxBacklog: defaultHTTPMaxBacklog, quit: make(chan struct{}, 1), shutdown: make(chan error, 1), } for _, option := range options { option(c) } // spanc can immediately accept maxBacklog spans and everything else is dropped. c.spanc = make(chan *zipkincore.Span, c.maxBacklog) go c.loop() return c, nil }
go
func NewHTTPCollector(url string, options ...HTTPOption) (Collector, error) { c := &HTTPCollector{ logger: NewNopLogger(), url: url, client: &http.Client{Timeout: defaultHTTPTimeout}, batchInterval: defaultHTTPBatchInterval * time.Second, batchSize: defaultHTTPBatchSize, maxBacklog: defaultHTTPMaxBacklog, quit: make(chan struct{}, 1), shutdown: make(chan error, 1), } for _, option := range options { option(c) } // spanc can immediately accept maxBacklog spans and everything else is dropped. c.spanc = make(chan *zipkincore.Span, c.maxBacklog) go c.loop() return c, nil }
[ "func", "NewHTTPCollector", "(", "url", "string", ",", "options", "...", "HTTPOption", ")", "(", "Collector", ",", "error", ")", "{", "c", ":=", "&", "HTTPCollector", "{", "logger", ":", "NewNopLogger", "(", ")", ",", "url", ":", "url", ",", "client", ":", "&", "http", ".", "Client", "{", "Timeout", ":", "defaultHTTPTimeout", "}", ",", "batchInterval", ":", "defaultHTTPBatchInterval", "*", "time", ".", "Second", ",", "batchSize", ":", "defaultHTTPBatchSize", ",", "maxBacklog", ":", "defaultHTTPMaxBacklog", ",", "quit", ":", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", ",", "shutdown", ":", "make", "(", "chan", "error", ",", "1", ")", ",", "}", "\n\n", "for", "_", ",", "option", ":=", "range", "options", "{", "option", "(", "c", ")", "\n", "}", "\n\n", "// spanc can immediately accept maxBacklog spans and everything else is dropped.", "c", ".", "spanc", "=", "make", "(", "chan", "*", "zipkincore", ".", "Span", ",", "c", ".", "maxBacklog", ")", "\n\n", "go", "c", ".", "loop", "(", ")", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewHTTPCollector returns a new HTTP-backend Collector. url should be a http // url for handle post request. timeout is passed to http client. queueSize control // the maximum size of buffer of async queue. The logger is used to log errors, // such as send failures;
[ "NewHTTPCollector", "returns", "a", "new", "HTTP", "-", "backend", "Collector", ".", "url", "should", "be", "a", "http", "url", "for", "handle", "post", "request", ".", "timeout", "is", "passed", "to", "http", "client", ".", "queueSize", "control", "the", "maximum", "size", "of", "buffer", "of", "async", "queue", ".", "The", "logger", "is", "used", "to", "log", "errors", "such", "as", "send", "failures", ";" ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L91-L112
train
openzipkin-contrib/zipkin-go-opentracing
collector-http.go
Collect
func (c *HTTPCollector) Collect(s *zipkincore.Span) error { select { case c.spanc <- s: // Accepted. case <-c.quit: // Collector concurrently closed. default: c.logger.Log("msg", "queue full, disposing spans.", "size", len(c.spanc)) } return nil }
go
func (c *HTTPCollector) Collect(s *zipkincore.Span) error { select { case c.spanc <- s: // Accepted. case <-c.quit: // Collector concurrently closed. default: c.logger.Log("msg", "queue full, disposing spans.", "size", len(c.spanc)) } return nil }
[ "func", "(", "c", "*", "HTTPCollector", ")", "Collect", "(", "s", "*", "zipkincore", ".", "Span", ")", "error", "{", "select", "{", "case", "c", ".", "spanc", "<-", "s", ":", "// Accepted.", "case", "<-", "c", ".", "quit", ":", "// Collector concurrently closed.", "default", ":", "c", ".", "logger", ".", "Log", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "len", "(", "c", ".", "spanc", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Collect implements Collector. // attempts a non blocking send on the channel.
[ "Collect", "implements", "Collector", ".", "attempts", "a", "non", "blocking", "send", "on", "the", "channel", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L116-L126
train
openzipkin-contrib/zipkin-go-opentracing
wire/carrier.go
State
func (p *ProtobufCarrier) State() (traceID types.TraceID, spanID uint64, parentSpanID *uint64, sampled bool, flags flag.Flags) { traceID.Low = p.TraceId traceID.High = p.TraceIdHigh spanID = p.SpanId sampled = p.Sampled flags = flag.Flags(p.Flags) if flags&flag.IsRoot == 0 { parentSpanID = &p.ParentSpanId } return traceID, spanID, parentSpanID, sampled, flags }
go
func (p *ProtobufCarrier) State() (traceID types.TraceID, spanID uint64, parentSpanID *uint64, sampled bool, flags flag.Flags) { traceID.Low = p.TraceId traceID.High = p.TraceIdHigh spanID = p.SpanId sampled = p.Sampled flags = flag.Flags(p.Flags) if flags&flag.IsRoot == 0 { parentSpanID = &p.ParentSpanId } return traceID, spanID, parentSpanID, sampled, flags }
[ "func", "(", "p", "*", "ProtobufCarrier", ")", "State", "(", ")", "(", "traceID", "types", ".", "TraceID", ",", "spanID", "uint64", ",", "parentSpanID", "*", "uint64", ",", "sampled", "bool", ",", "flags", "flag", ".", "Flags", ")", "{", "traceID", ".", "Low", "=", "p", ".", "TraceId", "\n", "traceID", ".", "High", "=", "p", ".", "TraceIdHigh", "\n", "spanID", "=", "p", ".", "SpanId", "\n", "sampled", "=", "p", ".", "Sampled", "\n", "flags", "=", "flag", ".", "Flags", "(", "p", ".", "Flags", ")", "\n", "if", "flags", "&", "flag", ".", "IsRoot", "==", "0", "{", "parentSpanID", "=", "&", "p", ".", "ParentSpanId", "\n", "}", "\n", "return", "traceID", ",", "spanID", ",", "parentSpanID", ",", "sampled", ",", "flags", "\n", "}" ]
// State returns the tracer state.
[ "State", "returns", "the", "tracer", "state", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/wire/carrier.go#L37-L47
train
openzipkin-contrib/zipkin-go-opentracing
wire/carrier.go
SetBaggageItem
func (p *ProtobufCarrier) SetBaggageItem(key, value string) { if p.BaggageItems == nil { p.BaggageItems = map[string]string{key: value} return } p.BaggageItems[key] = value }
go
func (p *ProtobufCarrier) SetBaggageItem(key, value string) { if p.BaggageItems == nil { p.BaggageItems = map[string]string{key: value} return } p.BaggageItems[key] = value }
[ "func", "(", "p", "*", "ProtobufCarrier", ")", "SetBaggageItem", "(", "key", ",", "value", "string", ")", "{", "if", "p", ".", "BaggageItems", "==", "nil", "{", "p", ".", "BaggageItems", "=", "map", "[", "string", "]", "string", "{", "key", ":", "value", "}", "\n", "return", "\n", "}", "\n\n", "p", ".", "BaggageItems", "[", "key", "]", "=", "value", "\n", "}" ]
// SetBaggageItem sets a baggage item.
[ "SetBaggageItem", "sets", "a", "baggage", "item", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/wire/carrier.go#L50-L57
train
openzipkin-contrib/zipkin-go-opentracing
examples/middleware/http.go
ToHTTPRequest
func ToHTTPRequest(tracer opentracing.Tracer) RequestFunc { return func(req *http.Request) *http.Request { // Retrieve the Span from context. if span := opentracing.SpanFromContext(req.Context()); span != nil { // We are going to use this span in a client request, so mark as such. ext.SpanKindRPCClient.Set(span) // Add some standard OpenTracing tags, useful in an HTTP request. ext.HTTPMethod.Set(span, req.Method) span.SetTag(zipkincore.HTTP_HOST, req.URL.Host) span.SetTag(zipkincore.HTTP_PATH, req.URL.Path) ext.HTTPUrl.Set( span, fmt.Sprintf("%s://%s%s", req.URL.Scheme, req.URL.Host, req.URL.Path), ) // Add information on the peer service we're about to contact. if host, portString, err := net.SplitHostPort(req.URL.Host); err == nil { ext.PeerHostname.Set(span, host) if port, err := strconv.Atoi(portString); err != nil { ext.PeerPort.Set(span, uint16(port)) } } else { ext.PeerHostname.Set(span, req.URL.Host) } // Inject the Span context into the outgoing HTTP Request. if err := tracer.Inject( span.Context(), opentracing.TextMap, opentracing.HTTPHeadersCarrier(req.Header), ); err != nil { fmt.Printf("error encountered while trying to inject span: %+v\n", err) } } return req } }
go
func ToHTTPRequest(tracer opentracing.Tracer) RequestFunc { return func(req *http.Request) *http.Request { // Retrieve the Span from context. if span := opentracing.SpanFromContext(req.Context()); span != nil { // We are going to use this span in a client request, so mark as such. ext.SpanKindRPCClient.Set(span) // Add some standard OpenTracing tags, useful in an HTTP request. ext.HTTPMethod.Set(span, req.Method) span.SetTag(zipkincore.HTTP_HOST, req.URL.Host) span.SetTag(zipkincore.HTTP_PATH, req.URL.Path) ext.HTTPUrl.Set( span, fmt.Sprintf("%s://%s%s", req.URL.Scheme, req.URL.Host, req.URL.Path), ) // Add information on the peer service we're about to contact. if host, portString, err := net.SplitHostPort(req.URL.Host); err == nil { ext.PeerHostname.Set(span, host) if port, err := strconv.Atoi(portString); err != nil { ext.PeerPort.Set(span, uint16(port)) } } else { ext.PeerHostname.Set(span, req.URL.Host) } // Inject the Span context into the outgoing HTTP Request. if err := tracer.Inject( span.Context(), opentracing.TextMap, opentracing.HTTPHeadersCarrier(req.Header), ); err != nil { fmt.Printf("error encountered while trying to inject span: %+v\n", err) } } return req } }
[ "func", "ToHTTPRequest", "(", "tracer", "opentracing", ".", "Tracer", ")", "RequestFunc", "{", "return", "func", "(", "req", "*", "http", ".", "Request", ")", "*", "http", ".", "Request", "{", "// Retrieve the Span from context.", "if", "span", ":=", "opentracing", ".", "SpanFromContext", "(", "req", ".", "Context", "(", ")", ")", ";", "span", "!=", "nil", "{", "// We are going to use this span in a client request, so mark as such.", "ext", ".", "SpanKindRPCClient", ".", "Set", "(", "span", ")", "\n\n", "// Add some standard OpenTracing tags, useful in an HTTP request.", "ext", ".", "HTTPMethod", ".", "Set", "(", "span", ",", "req", ".", "Method", ")", "\n", "span", ".", "SetTag", "(", "zipkincore", ".", "HTTP_HOST", ",", "req", ".", "URL", ".", "Host", ")", "\n", "span", ".", "SetTag", "(", "zipkincore", ".", "HTTP_PATH", ",", "req", ".", "URL", ".", "Path", ")", "\n", "ext", ".", "HTTPUrl", ".", "Set", "(", "span", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "req", ".", "URL", ".", "Scheme", ",", "req", ".", "URL", ".", "Host", ",", "req", ".", "URL", ".", "Path", ")", ",", ")", "\n\n", "// Add information on the peer service we're about to contact.", "if", "host", ",", "portString", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "req", ".", "URL", ".", "Host", ")", ";", "err", "==", "nil", "{", "ext", ".", "PeerHostname", ".", "Set", "(", "span", ",", "host", ")", "\n", "if", "port", ",", "err", ":=", "strconv", ".", "Atoi", "(", "portString", ")", ";", "err", "!=", "nil", "{", "ext", ".", "PeerPort", ".", "Set", "(", "span", ",", "uint16", "(", "port", ")", ")", "\n", "}", "\n", "}", "else", "{", "ext", ".", "PeerHostname", ".", "Set", "(", "span", ",", "req", ".", "URL", ".", "Host", ")", "\n", "}", "\n\n", "// Inject the Span context into the outgoing HTTP Request.", "if", "err", ":=", "tracer", ".", "Inject", "(", "span", ".", "Context", "(", ")", ",", "opentracing", ".", "TextMap", ",", "opentracing", ".", "HTTPHeadersCarrier", "(", "req", ".", "Header", ")", ",", ")", ";", "err", "!=", "nil", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "req", "\n", "}", "\n", "}" ]
// ToHTTPRequest returns a RequestFunc that injects an OpenTracing Span found in // context into the HTTP Headers. If no such Span can be found, the RequestFunc // is a noop.
[ "ToHTTPRequest", "returns", "a", "RequestFunc", "that", "injects", "an", "OpenTracing", "Span", "found", "in", "context", "into", "the", "HTTP", "Headers", ".", "If", "no", "such", "Span", "can", "be", "found", "the", "RequestFunc", "is", "a", "noop", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/middleware/http.go#L25-L63
train
openzipkin-contrib/zipkin-go-opentracing
log-materializers.go
MaterializeWithLogFmt
func MaterializeWithLogFmt(logFields []log.Field) ([]byte, error) { var ( buffer = bytes.NewBuffer(nil) encoder = logfmt.NewEncoder(buffer) ) for _, field := range logFields { if err := encoder.EncodeKeyval(field.Key(), field.Value()); err != nil { encoder.EncodeKeyval(field.Key(), err.Error()) } } return buffer.Bytes(), nil }
go
func MaterializeWithLogFmt(logFields []log.Field) ([]byte, error) { var ( buffer = bytes.NewBuffer(nil) encoder = logfmt.NewEncoder(buffer) ) for _, field := range logFields { if err := encoder.EncodeKeyval(field.Key(), field.Value()); err != nil { encoder.EncodeKeyval(field.Key(), err.Error()) } } return buffer.Bytes(), nil }
[ "func", "MaterializeWithLogFmt", "(", "logFields", "[", "]", "log", ".", "Field", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "(", "buffer", "=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n", "encoder", "=", "logfmt", ".", "NewEncoder", "(", "buffer", ")", "\n", ")", "\n", "for", "_", ",", "field", ":=", "range", "logFields", "{", "if", "err", ":=", "encoder", ".", "EncodeKeyval", "(", "field", ".", "Key", "(", ")", ",", "field", ".", "Value", "(", ")", ")", ";", "err", "!=", "nil", "{", "encoder", ".", "EncodeKeyval", "(", "field", ".", "Key", "(", ")", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "buffer", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// MaterializeWithLogFmt converts log Fields into LogFmt string
[ "MaterializeWithLogFmt", "converts", "log", "Fields", "into", "LogFmt", "string" ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/log-materializers.go#L48-L59
train
openzipkin-contrib/zipkin-go-opentracing
log-materializers.go
StrictZipkinMaterializer
func StrictZipkinMaterializer(logFields []log.Field) ([]byte, error) { for _, field := range logFields { if field.Key() == "event" { return []byte(fmt.Sprintf("%+v", field.Value())), nil } } return nil, errEventLogNotFound }
go
func StrictZipkinMaterializer(logFields []log.Field) ([]byte, error) { for _, field := range logFields { if field.Key() == "event" { return []byte(fmt.Sprintf("%+v", field.Value())), nil } } return nil, errEventLogNotFound }
[ "func", "StrictZipkinMaterializer", "(", "logFields", "[", "]", "log", ".", "Field", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "for", "_", ",", "field", ":=", "range", "logFields", "{", "if", "field", ".", "Key", "(", ")", "==", "\"", "\"", "{", "return", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "field", ".", "Value", "(", ")", ")", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "errEventLogNotFound", "\n", "}" ]
// StrictZipkinMaterializer will only record a log.Field of type "event".
[ "StrictZipkinMaterializer", "will", "only", "record", "a", "log", ".", "Field", "of", "type", "event", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/log-materializers.go#L62-L69
train
openzipkin-contrib/zipkin-go-opentracing
recorder.go
GetSpans
func (r *InMemorySpanRecorder) GetSpans() []RawSpan { r.RLock() defer r.RUnlock() spans := make([]RawSpan, len(r.spans)) copy(spans, r.spans) return spans }
go
func (r *InMemorySpanRecorder) GetSpans() []RawSpan { r.RLock() defer r.RUnlock() spans := make([]RawSpan, len(r.spans)) copy(spans, r.spans) return spans }
[ "func", "(", "r", "*", "InMemorySpanRecorder", ")", "GetSpans", "(", ")", "[", "]", "RawSpan", "{", "r", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "RUnlock", "(", ")", "\n", "spans", ":=", "make", "(", "[", "]", "RawSpan", ",", "len", "(", "r", ".", "spans", ")", ")", "\n", "copy", "(", "spans", ",", "r", ".", "spans", ")", "\n", "return", "spans", "\n", "}" ]
// GetSpans returns a copy of the array of spans accumulated so far.
[ "GetSpans", "returns", "a", "copy", "of", "the", "array", "of", "spans", "accumulated", "so", "far", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/recorder.go#L34-L40
train
openzipkin-contrib/zipkin-go-opentracing
recorder.go
GetSampledSpans
func (r *InMemorySpanRecorder) GetSampledSpans() []RawSpan { r.RLock() defer r.RUnlock() spans := make([]RawSpan, 0, len(r.spans)) for _, span := range r.spans { if span.Context.Sampled { spans = append(spans, span) } } return spans }
go
func (r *InMemorySpanRecorder) GetSampledSpans() []RawSpan { r.RLock() defer r.RUnlock() spans := make([]RawSpan, 0, len(r.spans)) for _, span := range r.spans { if span.Context.Sampled { spans = append(spans, span) } } return spans }
[ "func", "(", "r", "*", "InMemorySpanRecorder", ")", "GetSampledSpans", "(", ")", "[", "]", "RawSpan", "{", "r", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "RUnlock", "(", ")", "\n", "spans", ":=", "make", "(", "[", "]", "RawSpan", ",", "0", ",", "len", "(", "r", ".", "spans", ")", ")", "\n", "for", "_", ",", "span", ":=", "range", "r", ".", "spans", "{", "if", "span", ".", "Context", ".", "Sampled", "{", "spans", "=", "append", "(", "spans", ",", "span", ")", "\n", "}", "\n", "}", "\n", "return", "spans", "\n", "}" ]
// GetSampledSpans returns a slice of spans accumulated so far which were sampled.
[ "GetSampledSpans", "returns", "a", "slice", "of", "spans", "accumulated", "so", "far", "which", "were", "sampled", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/recorder.go#L43-L53
train
openzipkin-contrib/zipkin-go-opentracing
recorder.go
Reset
func (r *InMemorySpanRecorder) Reset() { r.Lock() defer r.Unlock() r.spans = nil }
go
func (r *InMemorySpanRecorder) Reset() { r.Lock() defer r.Unlock() r.spans = nil }
[ "func", "(", "r", "*", "InMemorySpanRecorder", ")", "Reset", "(", ")", "{", "r", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Unlock", "(", ")", "\n", "r", ".", "spans", "=", "nil", "\n", "}" ]
// Reset clears the internal array of spans.
[ "Reset", "clears", "the", "internal", "array", "of", "spans", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/recorder.go#L56-L60
train
openzipkin-contrib/zipkin-go-opentracing
collector.go
Close
func (c MultiCollector) Close() error { return c.aggregateErrors(func(coll Collector) error { return coll.Close() }) }
go
func (c MultiCollector) Close() error { return c.aggregateErrors(func(coll Collector) error { return coll.Close() }) }
[ "func", "(", "c", "MultiCollector", ")", "Close", "(", ")", "error", "{", "return", "c", ".", "aggregateErrors", "(", "func", "(", "coll", "Collector", ")", "error", "{", "return", "coll", ".", "Close", "(", ")", "}", ")", "\n", "}" ]
// Close implements Collector.
[ "Close", "implements", "Collector", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector.go#L34-L36
train
openzipkin-contrib/zipkin-go-opentracing
sample.go
ModuloSampler
func ModuloSampler(mod uint64) Sampler { if mod < 2 { return alwaysSample } return func(id uint64) bool { return (id % mod) == 0 } }
go
func ModuloSampler(mod uint64) Sampler { if mod < 2 { return alwaysSample } return func(id uint64) bool { return (id % mod) == 0 } }
[ "func", "ModuloSampler", "(", "mod", "uint64", ")", "Sampler", "{", "if", "mod", "<", "2", "{", "return", "alwaysSample", "\n", "}", "\n", "return", "func", "(", "id", "uint64", ")", "bool", "{", "return", "(", "id", "%", "mod", ")", "==", "0", "\n", "}", "\n", "}" ]
// ModuloSampler provides a typical OpenTracing type Sampler.
[ "ModuloSampler", "provides", "a", "typical", "OpenTracing", "type", "Sampler", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/sample.go#L19-L26
train
openzipkin-contrib/zipkin-go-opentracing
zipkin-endpoint.go
makeEndpoint
func makeEndpoint(hostport, serviceName string) (ep *zipkincore.Endpoint) { ep = zipkincore.NewEndpoint() // Set the ServiceName ep.ServiceName = serviceName if strings.IndexByte(hostport, ':') < 0 { // "<host>" becomes "<host>:0" hostport = hostport + ":0" } // try to parse provided "<host>:<port>" host, port, err := net.SplitHostPort(hostport) if err != nil { // if unparsable, return as "undefined:0" return } // try to set port number p, _ := strconv.ParseUint(port, 10, 16) ep.Port = int16(p) // if <host> is a domain name, look it up addrs, err := net.LookupIP(host) if err != nil { // return as "undefined:<port>" return } var addr4, addr16 net.IP for i := range addrs { addr := addrs[i].To4() if addr == nil { // IPv6 if addr16 == nil { addr16 = addrs[i].To16() // IPv6 - 16 bytes } } else { // IPv4 if addr4 == nil { addr4 = addr // IPv4 - 4 bytes } } if addr16 != nil && addr4 != nil { // IPv4 & IPv6 have been set, we can stop looking further break } } // default to 0 filled 4 byte array for IPv4 if IPv6 only host was found if addr4 == nil { addr4 = make([]byte, 4) } // set IPv4 and IPv6 addresses ep.Ipv4 = (int32)(binary.BigEndian.Uint32(addr4)) ep.Ipv6 = []byte(addr16) return }
go
func makeEndpoint(hostport, serviceName string) (ep *zipkincore.Endpoint) { ep = zipkincore.NewEndpoint() // Set the ServiceName ep.ServiceName = serviceName if strings.IndexByte(hostport, ':') < 0 { // "<host>" becomes "<host>:0" hostport = hostport + ":0" } // try to parse provided "<host>:<port>" host, port, err := net.SplitHostPort(hostport) if err != nil { // if unparsable, return as "undefined:0" return } // try to set port number p, _ := strconv.ParseUint(port, 10, 16) ep.Port = int16(p) // if <host> is a domain name, look it up addrs, err := net.LookupIP(host) if err != nil { // return as "undefined:<port>" return } var addr4, addr16 net.IP for i := range addrs { addr := addrs[i].To4() if addr == nil { // IPv6 if addr16 == nil { addr16 = addrs[i].To16() // IPv6 - 16 bytes } } else { // IPv4 if addr4 == nil { addr4 = addr // IPv4 - 4 bytes } } if addr16 != nil && addr4 != nil { // IPv4 & IPv6 have been set, we can stop looking further break } } // default to 0 filled 4 byte array for IPv4 if IPv6 only host was found if addr4 == nil { addr4 = make([]byte, 4) } // set IPv4 and IPv6 addresses ep.Ipv4 = (int32)(binary.BigEndian.Uint32(addr4)) ep.Ipv6 = []byte(addr16) return }
[ "func", "makeEndpoint", "(", "hostport", ",", "serviceName", "string", ")", "(", "ep", "*", "zipkincore", ".", "Endpoint", ")", "{", "ep", "=", "zipkincore", ".", "NewEndpoint", "(", ")", "\n\n", "// Set the ServiceName", "ep", ".", "ServiceName", "=", "serviceName", "\n\n", "if", "strings", ".", "IndexByte", "(", "hostport", ",", "':'", ")", "<", "0", "{", "// \"<host>\" becomes \"<host>:0\"", "hostport", "=", "hostport", "+", "\"", "\"", "\n", "}", "\n\n", "// try to parse provided \"<host>:<port>\"", "host", ",", "port", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "hostport", ")", "\n", "if", "err", "!=", "nil", "{", "// if unparsable, return as \"undefined:0\"", "return", "\n", "}", "\n\n", "// try to set port number", "p", ",", "_", ":=", "strconv", ".", "ParseUint", "(", "port", ",", "10", ",", "16", ")", "\n", "ep", ".", "Port", "=", "int16", "(", "p", ")", "\n\n", "// if <host> is a domain name, look it up", "addrs", ",", "err", ":=", "net", ".", "LookupIP", "(", "host", ")", "\n", "if", "err", "!=", "nil", "{", "// return as \"undefined:<port>\"", "return", "\n", "}", "\n\n", "var", "addr4", ",", "addr16", "net", ".", "IP", "\n", "for", "i", ":=", "range", "addrs", "{", "addr", ":=", "addrs", "[", "i", "]", ".", "To4", "(", ")", "\n", "if", "addr", "==", "nil", "{", "// IPv6", "if", "addr16", "==", "nil", "{", "addr16", "=", "addrs", "[", "i", "]", ".", "To16", "(", ")", "// IPv6 - 16 bytes", "\n", "}", "\n", "}", "else", "{", "// IPv4", "if", "addr4", "==", "nil", "{", "addr4", "=", "addr", "// IPv4 - 4 bytes", "\n", "}", "\n", "}", "\n", "if", "addr16", "!=", "nil", "&&", "addr4", "!=", "nil", "{", "// IPv4 & IPv6 have been set, we can stop looking further", "break", "\n", "}", "\n", "}", "\n", "// default to 0 filled 4 byte array for IPv4 if IPv6 only host was found", "if", "addr4", "==", "nil", "{", "addr4", "=", "make", "(", "[", "]", "byte", ",", "4", ")", "\n", "}", "\n\n", "// set IPv4 and IPv6 addresses", "ep", ".", "Ipv4", "=", "(", "int32", ")", "(", "binary", ".", "BigEndian", ".", "Uint32", "(", "addr4", ")", ")", "\n", "ep", ".", "Ipv6", "=", "[", "]", "byte", "(", "addr16", ")", "\n", "return", "\n", "}" ]
// makeEndpoint takes the hostport and service name that represent this Zipkin // service, and returns an endpoint that's embedded into the Zipkin core Span // type. It will return a nil endpoint if the input parameters are malformed.
[ "makeEndpoint", "takes", "the", "hostport", "and", "service", "name", "that", "represent", "this", "Zipkin", "service", "and", "returns", "an", "endpoint", "that", "s", "embedded", "into", "the", "Zipkin", "core", "Span", "type", ".", "It", "will", "return", "a", "nil", "endpoint", "if", "the", "input", "parameters", "are", "malformed", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/zipkin-endpoint.go#L15-L72
train
openzipkin-contrib/zipkin-go-opentracing
examples/cli_with_2_services/svc2/httpserver.go
NewHTTPHandler
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler { // Create our HTTP Service. svc := &httpService{service: service} // Create the mux. mux := http.NewServeMux() // Create the Sum handler. var sumHandler http.Handler sumHandler = http.HandlerFunc(svc.sumHandler) // Wrap the Sum handler with our tracing middleware. sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler) // Wire up the mux. mux.Handle("/sum/", sumHandler) // Return the mux. return mux }
go
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler { // Create our HTTP Service. svc := &httpService{service: service} // Create the mux. mux := http.NewServeMux() // Create the Sum handler. var sumHandler http.Handler sumHandler = http.HandlerFunc(svc.sumHandler) // Wrap the Sum handler with our tracing middleware. sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler) // Wire up the mux. mux.Handle("/sum/", sumHandler) // Return the mux. return mux }
[ "func", "NewHTTPHandler", "(", "tracer", "opentracing", ".", "Tracer", ",", "service", "Service", ")", "http", ".", "Handler", "{", "// Create our HTTP Service.", "svc", ":=", "&", "httpService", "{", "service", ":", "service", "}", "\n\n", "// Create the mux.", "mux", ":=", "http", ".", "NewServeMux", "(", ")", "\n\n", "// Create the Sum handler.", "var", "sumHandler", "http", ".", "Handler", "\n", "sumHandler", "=", "http", ".", "HandlerFunc", "(", "svc", ".", "sumHandler", ")", "\n\n", "// Wrap the Sum handler with our tracing middleware.", "sumHandler", "=", "middleware", ".", "FromHTTPRequest", "(", "tracer", ",", "\"", "\"", ")", "(", "sumHandler", ")", "\n\n", "// Wire up the mux.", "mux", ".", "Handle", "(", "\"", "\"", ",", "sumHandler", ")", "\n\n", "// Return the mux.", "return", "mux", "\n", "}" ]
// NewHTTPHandler returns a new HTTP handler our svc2.
[ "NewHTTPHandler", "returns", "a", "new", "HTTP", "handler", "our", "svc2", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc2/httpserver.go#L44-L63
train
openzipkin-contrib/zipkin-go-opentracing
types/traceid.go
ToHex
func (t TraceID) ToHex() string { if t.High == 0 { return fmt.Sprintf("%016x", t.Low) } return fmt.Sprintf("%016x%016x", t.High, t.Low) }
go
func (t TraceID) ToHex() string { if t.High == 0 { return fmt.Sprintf("%016x", t.Low) } return fmt.Sprintf("%016x%016x", t.High, t.Low) }
[ "func", "(", "t", "TraceID", ")", "ToHex", "(", ")", "string", "{", "if", "t", ".", "High", "==", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "Low", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "High", ",", "t", ".", "Low", ")", "\n", "}" ]
// ToHex outputs the 128-bit traceID as hex string.
[ "ToHex", "outputs", "the", "128", "-", "bit", "traceID", "as", "hex", "string", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/types/traceid.go#L28-L33
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train