_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q33900 | Difference | train | func (b *Bitmap) Difference(other *Bitmap) *Bitmap {
output := NewBitmap()
iiter, _ := b.Containers.Iterator(0)
jiter, _ := other.Containers.Iterator(0)
i, j := iiter.Next(), jiter.Next()
ki, ci := iiter.Value()
kj, cj := jiter.Value()
for i || j {
if i && (!j || ki < kj) {
output.Containers.Put(ki, ci.Clo... | go | {
"resource": ""
} |
q33901 | Shift | train | func (b *Bitmap) Shift(n int) (*Bitmap, error) {
if n != 1 {
return nil, errors.New("cannot shift by a value other than 1")
}
output := NewBitmap()
iiter, _ := b.Containers.Iterator(0)
lastCarry := false
lastKey := uint64(0)
for iiter.Next() {
ki, ci := iiter.Value()
o, carry := shift(ci)
if lastCarry {
... | go | {
"resource": ""
} |
q33902 | removeEmptyContainers | train | func (b *Bitmap) removeEmptyContainers() {
citer, _ := b.Containers.Iterator(0)
for citer.Next() {
k, c := citer.Value()
if c.n == 0 {
b.Containers.Remove(k)
}
}
} | go | {
"resource": ""
} |
q33903 | Optimize | train | func (b *Bitmap) Optimize() {
citer, _ := b.Containers.Iterator(0)
for citer.Next() {
_, c := citer.Value()
c.optimize()
}
} | go | {
"resource": ""
} |
q33904 | WriteTo | train | func (b *Bitmap) WriteTo(w io.Writer) (n int64, err error) {
b.Optimize()
return b.writeToUnoptimized(w)
} | go | {
"resource": ""
} |
q33905 | writeOp | train | func (b *Bitmap) writeOp(op *op) error {
if b.OpWriter == nil {
return nil
}
if _, err := op.WriteTo(b.OpWriter); err != nil {
return err
}
b.opN += op.count()
return nil
} | go | {
"resource": ""
} |
q33906 | Iterator | train | func (b *Bitmap) Iterator() *Iterator {
itr := &Iterator{bitmap: b}
itr.Seek(0)
return itr
} | go | {
"resource": ""
} |
q33907 | Info | train | func (b *Bitmap) Info() bitmapInfo {
info := bitmapInfo{
OpN: b.opN,
Containers: make([]containerInfo, 0, b.Containers.Size()),
}
citer, _ := b.Containers.Iterator(0)
for citer.Next() {
k, c := citer.Value()
ci := c.info()
ci.Key = k
info.Containers = append(info.Containers, ci)
}
return info
... | go | {
"resource": ""
} |
q33908 | Check | train | func (b *Bitmap) Check() error {
var a ErrorList
// Check each container.
citer, _ := b.Containers.Iterator(0)
for citer.Next() {
k, c := citer.Value()
if err := c.check(); err != nil {
a.AppendWithPrefix(err, fmt.Sprintf("%d/", k))
}
}
if len(a) == 0 {
return nil
}
return a
} | go | {
"resource": ""
} |
q33909 | Seek | train | func (itr *Iterator) Seek(seek uint64) {
// k should always be -1 unless we're seeking into a run container. Then the
// "if c.isRun" section will take care of it.
itr.k = -1
// Move to the correct container.
itr.citer, _ = itr.bitmap.Containers.Iterator(highbits(seek))
if !itr.citer.Next() {
itr.c = nil
ret... | go | {
"resource": ""
} |
q33910 | peek | train | func (itr *Iterator) peek() uint64 {
if itr.c == nil {
return 0
}
if itr.c.isArray() {
return itr.key<<16 | uint64(itr.c.array()[itr.j])
}
if itr.c.isRun() {
return itr.key<<16 | uint64(itr.c.runs()[itr.j].start+uint16(itr.k))
}
return itr.key<<16 | uint64(itr.j)
} | go | {
"resource": ""
} |
q33911 | countRange | train | func (c *Container) countRange(start, end int32) (n int32) {
if c.isArray() {
return c.arrayCountRange(start, end)
} else if c.isRun() {
return c.runCountRange(start, end)
}
return c.bitmapCountRange(start, end)
} | go | {
"resource": ""
} |
q33912 | add | train | func (c *Container) add(v uint16) (added bool) {
if c.isArray() {
added = c.arrayAdd(v)
} else if c.isRun() {
added = c.runAdd(v)
} else {
added = c.bitmapAdd(v)
}
if added {
c.n++
}
return added
} | go | {
"resource": ""
} |
q33913 | Contains | train | func (c *Container) Contains(v uint16) bool {
if c.isArray() {
return c.arrayContains(v)
} else if c.isRun() {
return c.runContains(v)
} else {
return c.bitmapContains(v)
}
} | go | {
"resource": ""
} |
q33914 | optimize | train | func (c *Container) optimize() {
if c.n == 0 {
statsHit("optimize/empty")
return
}
runs := c.countRuns()
var newType byte
if runs <= runMaxSize && runs <= c.n/2 {
newType = containerRun
} else if c.n < ArrayMaxSize {
newType = containerArray
} else {
newType = containerBitmap
}
// Then convert acco... | go | {
"resource": ""
} |
q33915 | binSearchRuns | train | func binSearchRuns(v uint16, a []interval16) (int32, bool) {
i := int32(sort.Search(len(a),
func(i int) bool { return a[i].last >= v }))
if i < int32(len(a)) {
return i, (v >= a[i].start) && (v <= a[i].last)
}
return i, false
} | go | {
"resource": ""
} |
q33916 | runContains | train | func (c *Container) runContains(v uint16) bool {
_, found := binSearchRuns(v, c.runs())
return found
} | go | {
"resource": ""
} |
q33917 | remove | train | func (c *Container) remove(v uint16) (removed bool) {
if c.isArray() {
removed = c.arrayRemove(v)
} else if c.isRun() {
removed = c.runRemove(v)
} else {
removed = c.bitmapRemove(v)
}
return removed
} | go | {
"resource": ""
} |
q33918 | runRemove | train | func (c *Container) runRemove(v uint16) bool {
runs := c.runs()
i, contains := binSearchRuns(v, runs)
if !contains {
return false
}
c.unmapRun()
runs = c.runs()
if v == runs[i].last && v == runs[i].start {
runs = append(runs[:i], runs[i+1:]...)
} else if v == runs[i].last {
runs[i].last--
} else if v == ... | go | {
"resource": ""
} |
q33919 | max | train | func (c *Container) max() uint16 {
if c.isArray() {
return c.arrayMax()
} else if c.isRun() {
return c.runMax()
} else {
return c.bitmapMax()
}
} | go | {
"resource": ""
} |
q33920 | bitmapToArray | train | func (c *Container) bitmapToArray() {
statsHit("bitmapToArray")
bitmap := c.bitmap()
c.setBitmap(nil)
c.typ = containerArray
c.mapped = false
// return early if empty
if c.n == 0 {
c.setArray(nil)
return
}
n := int32(0)
array := make([]uint16, c.n)
for i, word := range bitmap {
for word != 0 {
t :... | go | {
"resource": ""
} |
q33921 | arrayToBitmap | train | func (c *Container) arrayToBitmap() {
statsHit("arrayToBitmap")
array := c.array()
c.typ = containerBitmap
bitmap := make([]uint64, bitmapN)
c.setBitmap(bitmap)
c.mapped = false
// return early if empty
if c.n == 0 {
return
}
for _, v := range array {
bitmap[int(v)/64] |= (uint64(1) << uint(v%64))
}
} | go | {
"resource": ""
} |
q33922 | runToBitmap | train | func (c *Container) runToBitmap() {
statsHit("runToBitmap")
runs := c.runs()
bitmap := make([]uint64, bitmapN)
c.typ = containerBitmap
c.setBitmap(bitmap)
c.mapped = false
// return early if empty
if c.n == 0 {
return
}
for _, r := range runs {
// TODO this can be ~64x faster for long runs by setting m... | go | {
"resource": ""
} |
q33923 | bitmapToRun | train | func (c *Container) bitmapToRun(numRuns int32) {
statsHit("bitmapToRun")
bitmap := c.bitmap()
c.mapped = false
c.typ = containerRun
// return early if empty
if c.n == 0 {
c.setRuns(nil)
return
}
if numRuns == 0 {
numRuns = bitmapCountRuns(bitmap)
}
runs := make([]interval16, 0, numRuns)
current := bi... | go | {
"resource": ""
} |
q33924 | arrayToRun | train | func (c *Container) arrayToRun(numRuns int32) {
statsHit("arrayToRun")
array := c.array()
c.typ = containerRun
c.mapped = false
// return early if empty
if c.n == 0 {
c.setRuns(nil)
return
}
if numRuns == 0 {
numRuns = arrayCountRuns(array)
}
runs := make([]interval16, 0, numRuns)
start := array[0]
f... | go | {
"resource": ""
} |
q33925 | runToArray | train | func (c *Container) runToArray() {
statsHit("runToArray")
runs := c.runs()
c.typ = containerArray
c.mapped = false
// return early if empty
if c.n == 0 {
c.setArray(nil)
return
}
array := make([]uint16, c.n)
n := int32(0)
for _, r := range runs {
for v := int(r.start); v <= int(r.last); v++ {
array... | go | {
"resource": ""
} |
q33926 | WriteTo | train | func (c *Container) WriteTo(w io.Writer) (n int64, err error) {
if c.isArray() {
return c.arrayWriteTo(w)
} else if c.isRun() {
return c.runWriteTo(w)
} else {
return c.bitmapWriteTo(w)
}
} | go | {
"resource": ""
} |
q33927 | size | train | func (c *Container) size() int {
if c.isArray() {
return len(c.array()) * 2 // sizeof(uint16)
} else if c.isRun() {
return len(c.runs())*interval16Size + runCountHeaderSize
} else {
return len(c.bitmap()) * 8 // sizeof(uint64)
}
} | go | {
"resource": ""
} |
q33928 | info | train | func (c *Container) info() containerInfo {
info := containerInfo{N: c.n}
if c.isArray() {
info.Type = "array"
info.Alloc = len(c.array()) * 2 // sizeof(uint16)
} else if c.isRun() {
info.Type = "run"
info.Alloc = len(c.runs())*interval16Size + runCountHeaderSize
} else {
info.Type = "bitmap"
info.Alloc... | go | {
"resource": ""
} |
q33929 | check | train | func (c *Container) check() error {
var a ErrorList
if c.isArray() {
array := c.array()
if int32(len(array)) != c.n {
a.Append(fmt.Errorf("array count mismatch: count=%d, n=%d", len(array), c.n))
}
} else if c.isRun() {
n := c.runCountRange(0, maxContainerVal+1)
if n != c.n {
a.Append(fmt.Errorf("ru... | go | {
"resource": ""
} |
q33930 | flip | train | func flip(a *Container) *Container { // nolint: deadcode
if a.isArray() {
return flipArray(a)
} else if a.isRun() {
return flipRun(a)
} else {
return flipBitmap(a)
}
} | go | {
"resource": ""
} |
q33931 | intersectRunRun | train | func intersectRunRun(a, b *Container) *Container {
statsHit("intersect/RunRun")
output := NewContainerRun(nil)
ra, rb := a.runs(), b.runs()
na, nb := len(ra), len(rb)
for i, j := 0, 0; i < na && j < nb; {
va, vb := ra[i], rb[j]
if va.last < vb.start {
// |--va--| |--vb--|
i++
} else if vb.last < va.sta... | go | {
"resource": ""
} |
q33932 | intersectBitmapRun | train | func intersectBitmapRun(a, b *Container) *Container {
statsHit("intersect/BitmapRun")
var output *Container
runs := b.runs()
if b.n <= ArrayMaxSize || a.n <= ArrayMaxSize {
// output is array container
array := make([]uint16, 0, b.n)
for _, iv := range runs {
for i := iv.start; i <= iv.last; i++ {
if a... | go | {
"resource": ""
} |
q33933 | unionArrayRun | train | func unionArrayRun(a, b *Container) *Container {
statsHit("union/ArrayRun")
if b.n == maxContainerVal+1 {
return b.Clone()
}
output := NewContainerRun(nil)
aa, rb := a.array(), b.runs()
na, nb := len(aa), len(rb)
var vb interval16
var va uint16
for i, j := 0, 0; i < na || j < nb; {
if i < na {
va = aa[i... | go | {
"resource": ""
} |
q33934 | runAppendInterval | train | func (c *Container) runAppendInterval(v interval16) int32 {
runs := c.runs()
if len(runs) == 0 {
runs = append(runs, v)
c.setRuns(runs)
return int32(v.last-v.start) + 1
}
last := runs[len(runs)-1]
if last.last == maxContainerVal { //protect against overflow
return 0
}
if last.last+1 >= v.start && v.last... | go | {
"resource": ""
} |
q33935 | unionBitmapRunInPlace | train | func unionBitmapRunInPlace(a, b *Container) {
a.unmapBitmap()
bitmap := a.bitmap()
statsHit("union/BitmapRun")
for _, run := range b.runs() {
bitmapSetRangeIgnoreN(bitmap, uint64(run.start), uint64(run.last)+1)
}
} | go | {
"resource": ""
} |
q33936 | bitmapSetRangeIgnoreN | train | func bitmapSetRangeIgnoreN(bitmap []uint64, i, j uint64) {
x := i >> 6
y := (j - 1) >> 6
var X uint64 = maxBitmap << (i % 64)
var Y uint64 = maxBitmap >> (63 - ((j - 1) % 64))
if x == y {
bitmap[x] |= (X & Y)
} else {
bitmap[x] |= X
for i := x + 1; i < y; i++ {
bitmap[i] = maxBitmap
}
bitmap[y] |= Y... | go | {
"resource": ""
} |
q33937 | unionBitmapArrayInPlace | train | func unionBitmapArrayInPlace(a, b *Container) {
a.unmapBitmap()
bitmap := a.bitmap()
for _, v := range b.array() {
bitmap[v>>6] |= (uint64(1) << (v % 64))
}
} | go | {
"resource": ""
} |
q33938 | unionBitmapBitmapInPlace | train | func unionBitmapBitmapInPlace(a, b *Container) {
a.unmapBitmap()
// local variables added to prevent BCE checks in loop
// see https://go101.org/article/bounds-check-elimination.html
var (
ab = a.bitmap()[:bitmapN]
bb = b.bitmap()[:bitmapN]
)
// Manually unroll loop to make it a little faster.
// TODO(rart... | go | {
"resource": ""
} |
q33939 | differenceArrayArray | train | func differenceArrayArray(a, b *Container) *Container {
statsHit("difference/ArrayArray")
output := NewContainerArray(nil)
aa, ab := a.array(), b.array()
na, nb := len(aa), len(ab)
for i, j := 0, 0; i < na; {
va := aa[i]
if j >= nb {
output.add(va)
i++
continue
}
vb := ab[j]
if va < vb {
out... | go | {
"resource": ""
} |
q33940 | differenceArrayRun | train | func differenceArrayRun(a, b *Container) *Container {
statsHit("difference/ArrayRun")
// func (ac *arrayContainer) iandNotRun16(rc *runContainer16) container {
if a.n == 0 || b.n == 0 {
return a.Clone()
}
output := NewContainerArray(make([]uint16, 0, a.n))
// cardinality upper bound: card(A)
i := 0 // array... | go | {
"resource": ""
} |
q33941 | differenceBitmapRun | train | func differenceBitmapRun(a, b *Container) *Container {
statsHit("difference/BitmapRun")
if a.n == 0 || b.n == 0 {
return a.Clone()
}
output := a.Clone()
for _, run := range b.runs() {
output.bitmapZeroRange(uint64(run.start), uint64(run.last)+1)
}
return output
} | go | {
"resource": ""
} |
q33942 | differenceRunArray | train | func differenceRunArray(a, b *Container) *Container {
statsHit("difference/RunArray")
if a.n == 0 || b.n == 0 {
return a.Clone()
}
ra, ab := a.runs(), b.array()
runs := make([]interval16, 0, len(ra))
bidx := 0
vb := ab[bidx]
RUNLOOP:
for _, run := range ra {
start := run.start
for vb < run.start {
bi... | go | {
"resource": ""
} |
q33943 | differenceRunBitmap | train | func differenceRunBitmap(a, b *Container) *Container {
statsHit("difference/RunBitmap")
ra := a.runs()
// If a is full, difference is the flip of b.
if len(ra) > 0 && ra[0].start == 0 && ra[0].last == 65535 {
return flipBitmap(b)
}
output := NewContainerRun(nil)
runs := output.runs()
if len(ra) == 0 {
retur... | go | {
"resource": ""
} |
q33944 | differenceRunRun | train | func differenceRunRun(a, b *Container) *Container {
statsHit("difference/RunRun")
if a.n == 0 || b.n == 0 {
return a.Clone()
}
ra, rb := a.runs(), b.runs()
apos := 0 // current a-run index
bpos := 0 // current b-run index
astart := ra[apos].start
alast := ra[apos].last
bstart := rb[bpos].start
blast := rb[... | go | {
"resource": ""
} |
q33945 | apply | train | func (op *op) apply(b *Bitmap) (changed bool) {
switch op.typ {
case opTypeAdd:
return b.DirectAdd(op.value)
case opTypeRemove:
return b.remove(op.value)
case opTypeAddBatch:
changed = b.DirectAddN(op.values...) > 0
case opTypeRemoveBatch:
changed = b.DirectRemoveN(op.values...) > 0
default:
panic(fmt.S... | go | {
"resource": ""
} |
q33946 | WriteTo | train | func (op *op) WriteTo(w io.Writer) (n int64, err error) {
buf := make([]byte, op.size())
// Write type and value.
buf[0] = byte(op.typ)
if op.typ <= 1 {
binary.LittleEndian.PutUint64(buf[1:9], op.value)
} else {
binary.LittleEndian.PutUint64(buf[1:9], uint64(len(op.values)))
p := 13 // start of values (skip... | go | {
"resource": ""
} |
q33947 | UnmarshalBinary | train | func (op *op) UnmarshalBinary(data []byte) error {
if len(data) < minOpSize {
return fmt.Errorf("op data out of bounds: len=%d", len(data))
}
statsHit("op/UnmarshalBinary")
op.typ = opType(data[0])
// op.value will actually contain the length of values for batch ops
op.value = binary.LittleEndian.Uint64(data[1... | go | {
"resource": ""
} |
q33948 | size | train | func (op *op) size() int {
if op.typ == opTypeAdd || op.typ == opTypeRemove {
return 1 + 8 + 4
}
return 1 + 8 + 4 + len(op.values)*8
} | go | {
"resource": ""
} |
q33949 | count | train | func (op *op) count() int {
switch op.typ {
case 0, 1:
return 1
case 2, 3:
return len(op.values)
default:
panic(fmt.Sprintf("unknown operation type: %d", op.typ))
}
} | go | {
"resource": ""
} |
q33950 | search32 | train | func search32(a []uint16, value uint16) int32 {
statsHit("search32")
// Optimize for elements and the last element.
n := int32(len(a))
if n == 0 {
return -1
} else if a[n-1] == value {
return n - 1
}
// Otherwise perform binary search for exact match.
lo, hi := int32(0), n-1
for lo+16 <= hi {
i := int32... | go | {
"resource": ""
} |
q33951 | Append | train | func (a *ErrorList) Append(err error) {
switch err := err.(type) {
case ErrorList:
*a = append(*a, err...)
default:
*a = append(*a, err)
}
} | go | {
"resource": ""
} |
q33952 | AppendWithPrefix | train | func (a *ErrorList) AppendWithPrefix(err error, prefix string) {
switch err := err.(type) {
case ErrorList:
for i := range err {
*a = append(*a, fmt.Errorf("%s%s", prefix, err[i]))
}
default:
*a = append(*a, fmt.Errorf("%s%s", prefix, err))
}
} | go | {
"resource": ""
} |
q33953 | xorArrayRun | train | func xorArrayRun(a, b *Container) *Container {
statsHit("xor/ArrayRun")
output := NewContainerRun(nil)
aa, rb := a.array(), b.runs()
na, nb := len(aa), len(rb)
var vb interval16
var va uint16
lastI, lastJ := -1, -1
for i, j := 0, 0; i < na || j < nb; {
if i < na && i != lastI {
va = aa[i]
}
if j < nb &... | go | {
"resource": ""
} |
q33954 | xorRunRun | train | func xorRunRun(a, b *Container) *Container {
statsHit("xor/RunRun")
ra, rb := a.runs(), b.runs()
na, nb := len(ra), len(rb)
if na == 0 {
return b.Clone()
}
if nb == 0 {
return a.Clone()
}
output := NewContainerRun(nil)
lastI, lastJ := -1, -1
state := &xorstm{}
for i, j := 0, 0; i < na || j < nb; {
i... | go | {
"resource": ""
} |
q33955 | xorBitmapRun | train | func xorBitmapRun(a, b *Container) *Container {
statsHit("xor/BitmapRun")
output := a.Clone()
for _, run := range b.runs() {
output.bitmapXorRange(uint64(run.start), uint64(run.last)+1)
}
return output
} | go | {
"resource": ""
} |
q33956 | UnmarshalBinary | train | func (b *Bitmap) UnmarshalBinary(data []byte) error {
if data == nil {
// Nothing to unmarshal
return nil
}
statsHit("Bitmap/UnmarshalBinary")
b.opN = 0 // reset opN since we're reading new data.
fileMagic := uint32(binary.LittleEndian.Uint16(data[0:2]))
if fileMagic == MagicNumber { // if pilosa roaring
re... | go | {
"resource": ""
} |
q33957 | markItersWithKeyAsHandled | train | func (w handledIters) markItersWithKeyAsHandled(startIdx int, key uint64) {
for i := startIdx; i < len(w); i++ {
wrapped := w[i]
currKey, _ := wrapped.iter.Value()
if currKey == key {
w[i].handled = true
}
}
} | go | {
"resource": ""
} |
q33958 | Seek | train | func (t *tree) Seek(k uint64) (e *enumerator, ok bool) {
q := t.r
if q == nil {
e = btEPool.get(nil, false, 0, k, nil, t, t.ver)
return
}
for {
var i int
if i, ok = t.find(q, k); ok {
switch x := q.(type) {
case *x:
q = x.x[i+1].ch
continue
case *d:
return btEPool.get(nil, ok, i, k, x,... | go | {
"resource": ""
} |
q33959 | Prev | train | func (e *enumerator) Prev() (k uint64, v *Container, err error) {
if err = e.err; err != nil {
return 0, nil, err
}
if e.ver != e.t.ver {
f, _ := e.t.Seek(e.k)
*e = *f
f.Close()
}
if e.q == nil {
e.err, err = io.EOF, io.EOF
return 0, nil, err
}
if !e.hit {
// move to previous because Seek oversho... | go | {
"resource": ""
} |
q33960 | OptTranslateFileMapSize | train | func OptTranslateFileMapSize(mapSize int) TranslateFileOption {
return func(f *TranslateFile) error {
f.mapSize = mapSize
return nil
}
} | go | {
"resource": ""
} |
q33961 | OptTranslateFileLogger | train | func OptTranslateFileLogger(l logger.Logger) TranslateFileOption {
return func(s *TranslateFile) error {
s.logger = l
return nil
}
} | go | {
"resource": ""
} |
q33962 | NewTranslateFile | train | func NewTranslateFile(opts ...TranslateFileOption) *TranslateFile {
var defaultMapSize64 int64 = 10 * (1 << 30)
var defaultMapSize int
if ^uint(0)>>32 > 0 {
// 10GB default map size
defaultMapSize = int(defaultMapSize64)
} else {
// Use 2GB default map size on 32-bit systems
defaultMapSize = (1 << 31) - 1
... | go | {
"resource": ""
} |
q33963 | Open | train | func (s *TranslateFile) Open() (err error) {
// Open writer & buffered writer.
if err := os.MkdirAll(filepath.Dir(s.Path), 0777); err != nil {
return errors.Wrapf(err, "mkdir %s", filepath.Dir(s.Path))
} else if s.file, err = os.OpenFile(s.Path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666); err != nil {
return error... | go | {
"resource": ""
} |
q33964 | handlePrimaryStoreEvent | train | func (s *TranslateFile) handlePrimaryStoreEvent(ev primaryStoreEvent) error {
s.mu.Lock()
defer s.mu.Unlock()
if ev.id == s.primaryID {
return nil
}
// Stop translate store replication.
close(s.replicationClosing)
s.repWG.Wait()
// Set the primary node for translate store replication.
s.logger.Debugf("set... | go | {
"resource": ""
} |
q33965 | Close | train | func (s *TranslateFile) Close() (err error) {
s.once.Do(func() {
close(s.closing)
if s.file != nil {
if e := s.file.Close(); e != nil && err == nil {
err = e
}
}
if s.data != nil {
if e := syscall.Munmap(s.data); e != nil && err == nil {
err = e
}
}
})
s.wg.Wait()
return err
} | go | {
"resource": ""
} |
q33966 | size | train | func (s *TranslateFile) size() int64 {
s.mu.RLock()
n := s.n
s.mu.RUnlock()
return n
} | go | {
"resource": ""
} |
q33967 | WriteNotify | train | func (s *TranslateFile) WriteNotify() <-chan struct{} {
s.mu.RLock()
ch := s.writeNotify
s.mu.RUnlock()
return ch
} | go | {
"resource": ""
} |
q33968 | monitorReplication | train | func (s *TranslateFile) monitorReplication() {
// Create context that will cancel on close.
ctx, cancel := context.WithCancel(context.Background())
go func() {
select {
case <-s.closing:
case <-s.replicationClosing:
}
cancel()
}()
// Keep attempting to replicate until the store closes.
for {
if err :... | go | {
"resource": ""
} |
q33969 | monitorPrimaryStoreEvents | train | func (s *TranslateFile) monitorPrimaryStoreEvents() {
// Keep handling events until the store closes.
for {
select {
case <-s.closing:
return
case ev := <-s.primaryStoreEvents:
if err := s.handlePrimaryStoreEvent(ev); err != nil {
s.logger.Printf("handle primary store event")
}
}
}
} | go | {
"resource": ""
} |
q33970 | TranslateColumnsToUint64 | train | func (s *TranslateFile) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
ret := make([]uint64, len(values))
// Read value under read lock.
s.mu.RLock()
if idx := s.cols[index]; idx != nil {
var writeRequired bool
for i := range values {
v, ok := idx.idByKey([]byte(values[i]))
i... | go | {
"resource": ""
} |
q33971 | TranslateRowToString | train | func (s *TranslateFile) TranslateRowToString(index, field string, id uint64) (string, error) {
s.mu.RLock()
if idx := s.rows[fieldKey{index, field}]; idx != nil {
if ret, ok := idx.keyByID(id); ok {
s.mu.RUnlock()
return string(ret), nil
}
}
s.mu.RUnlock()
return "", nil
} | go | {
"resource": ""
} |
q33972 | Reader | train | func (s *TranslateFile) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
rc := newTranslateFileReader(ctx, s, offset)
if err := rc.Open(); err != nil {
return nil, err
}
return rc, nil
} | go | {
"resource": ""
} |
q33973 | headerSize | train | func (e *LogEntry) headerSize() int64 {
sz := uVarintSize(e.Length) + // total entry length
1 + // type
uVarintSize(uint64(len(e.Index))) + len(e.Index) + // Index length and data
uVarintSize(uint64(len(e.Field))) + len(e.Field) + // Field length and data
uVarintSize(uint64(len(e.IDs))) // ID/Key pair count
r... | go | {
"resource": ""
} |
q33974 | WriteTo | train | func (e *LogEntry) WriteTo(w io.Writer) (_ int64, err error) {
var buf bytes.Buffer
b := make([]byte, binary.MaxVarintLen64)
// Write the entry type.
if err := binary.Write(&buf, binary.BigEndian, e.Type); err != nil {
return 0, err
}
// Write the index name.
sz := binary.PutUvarint(b, uint64(len(e.Index)))
... | go | {
"resource": ""
} |
q33975 | validLogEntriesLen | train | func validLogEntriesLen(p []byte) (n int) {
r := bytes.NewReader(p)
for {
if sz, err := binary.ReadUvarint(r); err != nil {
return n
} else if off, err := r.Seek(int64(sz), io.SeekCurrent); err != nil {
return n
} else if off > int64(len(p)) {
return n
} else {
n = int(off)
}
}
} | go | {
"resource": ""
} |
q33976 | keyByID | train | func (idx *index) keyByID(id uint64) ([]byte, bool) {
offset, ok := idx.offsetsByID[id]
if !ok {
return nil, false
}
return idx.lookupKey(offset), true
} | go | {
"resource": ""
} |
q33977 | idByKey | train | func (idx *index) idByKey(key []byte) (uint64, bool) {
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
if e := &idx.elems[pos]; e.hash == 0 {
return 0, false
} else if dist > idx.dist(e.hash, pos) {
return 0, false
} else if e.hash == hash && bytes.Equal(idx.lookupKey(e.offset), key) ... | go | {
"resource": ""
} |
q33978 | insertIDbyOffset | train | func (idx *index) insertIDbyOffset(offset int64, id uint64) (overwritten bool) {
key := idx.lookupKey(offset)
hash := hashKey(key)
pos := hash & idx.mask
var dist uint64
for {
e := &idx.elems[pos]
// Exit if a matching or empty slot exists.
if e.hash == 0 {
e.hash, e.offset, e.id = hash, offset, id
r... | go | {
"resource": ""
} |
q33979 | lookupKey | train | func (idx *index) lookupKey(offset int64) []byte {
data := idx.data[offset:]
n, sz := binary.Uvarint(data)
if sz == 0 {
return nil
}
return data[sz : sz+int(n)]
} | go | {
"resource": ""
} |
q33980 | newTranslateFileReader | train | func newTranslateFileReader(ctx context.Context, store *TranslateFile, offset int64) *translateFileReader {
return &translateFileReader{
ctx: ctx,
store: store,
offset: offset,
notify: store.WriteNotify(),
closing: make(chan struct{}),
}
} | go | {
"resource": ""
} |
q33981 | Open | train | func (r *translateFileReader) Open() (err error) {
r.file, err = os.Open(r.store.Path)
return err
} | go | {
"resource": ""
} |
q33982 | Close | train | func (r *translateFileReader) Close() error {
r.once.Do(func() { close(r.closing) })
if r.file != nil {
return r.file.Close()
}
return nil
} | go | {
"resource": ""
} |
q33983 | Read | train | func (r *translateFileReader) Read(p []byte) (n int, err error) {
for {
// Obtain notification channel before we check for new data.
notify := r.store.WriteNotify()
// Exit if we can read one or more valid entries or we receive an error.
if n, err = r.read(p); n > 0 || err != nil {
return n, err
}
// ... | go | {
"resource": ""
} |
q33984 | read | train | func (r *translateFileReader) read(p []byte) (n int, err error) {
sz := r.store.size()
// Exit if there is no new data.
if sz < r.offset {
return 0, fmt.Errorf("pilosa: translate store reader past file size: sz=%d off=%d", sz, r.offset)
} else if sz == r.offset {
return 0, nil
}
if max := sz - r.offset; max... | go | {
"resource": ""
} |
q33985 | TranslateColumnToString | train | func (s nopTranslateStore) TranslateColumnToString(index string, values uint64) (string, error) {
return "", nil
} | go | {
"resource": ""
} |
q33986 | TranslateRowsToUint64 | train | func (s nopTranslateStore) TranslateRowsToUint64(index, field string, values []string) ([]uint64, error) {
return []uint64{}, nil
} | go | {
"resource": ""
} |
q33987 | Reader | train | func (s nopTranslateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(nil)), nil
} | go | {
"resource": ""
} |
q33988 | setupLogger | train | func (m *Command) setupLogger() error {
if m.Config.LogPath == "" {
m.logOutput = m.Stderr
} else {
f, err := os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return errors.Wrap(err, "opening file")
}
m.logOutput = f
err = syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd... | go | {
"resource": ""
} |
q33989 | OptFieldTypeDefault | train | func OptFieldTypeDefault() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = DefaultCacheType
fo.CacheSize = DefaultCacheSize
return nil
}
} | go | {
"resource": ""
} |
q33990 | OptFieldTypeSet | train | func OptFieldTypeSet(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeSet
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
} | go | {
"resource": ""
} |
q33991 | OptFieldTypeInt | train | func OptFieldTypeInt(min, max int64) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if min > max {
return ErrInvalidBSIGroupRange
}
fo.Type = FieldTypeInt
fo.Min = min
fo.Max = max
return nil
}
} | go | {
"resource": ""
} |
q33992 | OptFieldTypeTime | train | func OptFieldTypeTime(timeQuantum TimeQuantum, opt ...bool) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
if !timeQuantum.Valid() {
return ErrInvalidTimeQuantum
}
fo.Type = FieldTypeTime
fo.TimeQuantum = time... | go | {
"resource": ""
} |
q33993 | OptFieldTypeMutex | train | func OptFieldTypeMutex(cacheType string, cacheSize uint32) FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeMutex
fo.CacheType = cacheType
fo.CacheSize = cacheSize
return nil
}
} | go | {
"resource": ""
} |
q33994 | OptFieldTypeBool | train | func OptFieldTypeBool() FieldOption {
return func(fo *FieldOptions) error {
if fo.Type != "" {
return errors.Errorf("field type is already set to: %s", fo.Type)
}
fo.Type = FieldTypeBool
return nil
}
} | go | {
"resource": ""
} |
q33995 | NewField | train | func NewField(path, index, name string, opts FieldOption) (*Field, error) {
err := validateName(name)
if err != nil {
return nil, errors.Wrap(err, "validating name")
}
return newField(path, index, name, opts)
} | go | {
"resource": ""
} |
q33996 | AvailableShards | train | func (f *Field) AvailableShards() *roaring.Bitmap {
f.mu.RLock()
defer f.mu.RUnlock()
b := f.remoteAvailableShards.Clone()
for _, view := range f.viewMap {
b = b.Union(view.availableShards())
}
return b
} | go | {
"resource": ""
} |
q33997 | AddRemoteAvailableShards | train | func (f *Field) AddRemoteAvailableShards(b *roaring.Bitmap) error {
f.mergeRemoteAvailableShards(b)
// Save the updated bitmap to the data store.
return f.saveAvailableShards()
} | go | {
"resource": ""
} |
q33998 | mergeRemoteAvailableShards | train | func (f *Field) mergeRemoteAvailableShards(b *roaring.Bitmap) {
f.mu.Lock()
defer f.mu.Unlock()
f.remoteAvailableShards = f.remoteAvailableShards.Union(b)
} | go | {
"resource": ""
} |
q33999 | loadAvailableShards | train | func (f *Field) loadAvailableShards() error {
bm := roaring.NewBitmap()
// Read data from meta file.
path := filepath.Join(f.path, ".available.shards")
buf, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Wrap(err, "reading available shards")
} else {
if... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.