// Return number of the next chained bucket.
342816
func (ht *HashTable) nextBucket(bucket int) int {
	if bucket >= ht.numBuckets {
		return 0
	}
	bucketAddr := bucket * ht.BucketSize
	nextUint, err := binary.Varint(ht.Buf[bucketAddr : bucketAddr+10])
	next := int(nextUint)
	if next == 0 {
		return 0
	} else if err < 0 || next <= bucket || next >= ht.numBuckets || next < ht.InitialBuckets {
		tdlog.CritNoRepeat("Bad hash table - repair ASAP %s", ht.Path)
		return 0
	} else {
		return next
	}
}
118628
func (s *StoragePacker) BucketIndex(key string) uint8 {
	hf := md5.New()
	hf.Write([]byte(key))
	return uint8(hf.Sum(nil)[0])
}
603017
func (b *PackBuffer) Next(n int) []byte {
	oldR := b.r
	b.r += n
	return b.s[oldR:b.r]
}
801538
func (s *StorageDescriptor) SetNumberOfBuckets(v int64) *StorageDescriptor {
	s.NumberOfBuckets = &v
	return s
}
523711
func (e *CheckIndexRangeExec) Next(ctx context.Context, req *chunk.RecordBatch) error {
	req.Reset()
	handleIdx := e.schema.Len() - 1
	for {
		err := e.result.Next(ctx, e.srcChunk)
		if err != nil {
			return err
		}
		if e.srcChunk.NumRows() == 0 {
			return nil
		}
		iter := chunk.NewIterator4Chunk(e.srcChunk)
		for row := iter.Begin(); row != iter.End(); row = iter.Next() {
			handle := row.GetInt64(handleIdx)
			for _, hr := range e.handleRanges {
				if handle >= hr.Begin && handle < hr.End {
					req.AppendRow(row)
					break
				}
			}
		}
		if req.NumRows() > 0 {
			return nil
		}
	}
}
1019623
func (tx *Tx) Bucket(name []byte) *Bucket {
	return tx.root.Bucket(name)
}
641856
func (i *Int) Next() int {
	i.lock.Lock()
	defer i.lock.Unlock()
	i.increment++
	return i.increment
}
1372313
func (iterator *LinkedBlockingDequeIterator) Next() interface{} {
	if iterator.next == nil {
		//TODO error or nil ?
		//panic(errors.New("NoSuchElement"))
		return nil
	}
	iterator.lastRet = iterator.next
	x := iterator.nextItem
	iterator.advance()
	return x
}
138218
func Chained(rule Rule, next ...Rule) Rule {
	if len(next) == 0 {
		return chainedSingle(rule, nil)
	}
	c := chainedSingle(rule, next[0])

	for i := 1; i < len(next); i++ {
		c = chainedSingle(c, next[i])
	}

	return c

}
566180
func (c *cursor) Next() bool {
	// Ensure transaction state is valid.
	if err := c.bucket.tx.checkClosed(); err != nil {
		return false
	}

	// Nothing to return if cursor is exhausted.
	if c.currentIter == nil {
		return false
	}

	// Move the current iterator to the next entry and choose the iterator
	// that is both valid and has the smaller key.
	c.currentIter.Next()
	return c.chooseIterator(true)
}
1177583
func (l *Limiter) Bucket(name string) (b *Bucket, ok bool) {
	l.m.Lock()
	defer l.m.Unlock()
	b, ok = l.buckets[name]
	return
}
829862
func (it *Optional) Next(ctx context.Context) bool {
	clog.Errorf("Nexting an un-nextable iterator: %T", it)
	return false
}
423367
func (h *PCPHistogram) Buckets() []*HistogramBucket {
	b := h.h.Distribution()
	buckets := make([]*HistogramBucket, len(b))
	for i := 0; i < len(b); i++ {
		buckets[i] = &HistogramBucket{b[i].From, b[i].To, b[i].Count}
	}
	return buckets
}
591974
func (d *ManyToOne) Next() []byte {
	data := d.d.Next()
	return *(*[]byte)(data)
}
518710
func (gbi *groupByIterator) Next() (ret GroupCount, done bool) {
	// loop until we find a result with count > 0
	for {
		if gbi.done {
			return ret, true
		}
		if len(gbi.rows) == 1 {
			ret.Count = gbi.rows[len(gbi.rows)-1].row.Count()
		} else {
			ret.Count = gbi.rows[len(gbi.rows)-1].row.intersectionCount(gbi.rows[len(gbi.rows)-2].row)
		}
		if ret.Count == 0 {
			gbi.nextAtIdx(len(gbi.rows) - 1)
			continue
		}
		break
	}

	ret.Group = make([]FieldRow, len(gbi.rows))
	copy(ret.Group, gbi.fields)
	for i, r := range gbi.rows {
		ret.Group[i].RowID = r.id
	}

	// set up for next call

	gbi.nextAtIdx(len(gbi.rows) - 1)

	return ret, false
}
151151
func (c *Continuum) Bucket(ringLocation uint32) Bucket {
	if c == nil || len(c.ring) == 0 {
		return nil
	}
	i := uint(sort.Search(len(c.ring), func(i int) bool { return c.ring[i].point >= ringLocation }))
	if i >= uint(len(c.ring)) {
		i = 0
	}

	return c.ring[i].bucket
}
114281
func (i *Int16) Next() int16 {
	i.lock.Lock()
	defer i.lock.Unlock()
	i.increment++
	return i.increment
}