// Next returns the next column/row ID pair.
353672
func (itr *roaringIterator) Next() (rowID, columnID uint64, eof bool) {
	v, eof := itr.itr.Next()
	return v / ShardWidth, v % ShardWidth, eof
}
225945
func (n *NUID) Next() string {
	// Increment and capture.
	n.seq += n.inc
	if n.seq >= maxSeq {
		n.RandomizePrefix()
		n.resetSequential()
	}
	seq := n.seq

	// Copy prefix
	var b [totalLen]byte
	bs := b[:preLen]
	copy(bs, n.pre)

	// copy in the seq in base62.
	for i, l := len(b), seq; i > preLen; l /= base {
		i -= 1
		b[i] = digits[l%base]
	}
	return string(b[:])
}
124873
func (i *Uint16) Next() uint16 {
	i.lock.Lock()
	defer i.lock.Unlock()
	i.increment++
	return i.increment
}
872632
func (it *iterator4List) Next() Row {
	if it.chkCursor >= it.li.NumChunks() {
		it.chkCursor = it.li.NumChunks() + 1
		return it.End()
	}
	chk := it.li.GetChunk(it.chkCursor)
	row := chk.GetRow(it.rowCursor)
	it.rowCursor++
	if it.rowCursor == chk.NumRows() {
		it.rowCursor = 0
		it.chkCursor++
	}
	return row
}
642279
func (i *Uint8) Next() uint8 {
	i.lock.Lock()
	defer i.lock.Unlock()
	i.increment++
	return i.increment
}
234973
func (itr *mergeSegmentIterator) next() (s0, s1 *rowSegment) {
	// Find current segments.
	if len(itr.a0) > 0 {
		s0 = &itr.a0[0]
	}
	if len(itr.a1) > 0 {
		s1 = &itr.a1[0]
	}

	// Return if either or both are nil.
	if s0 == nil && s1 == nil {
		return
	} else if s0 == nil {
		itr.a1 = itr.a1[1:]
		return
	} else if s1 == nil {
		itr.a0 = itr.a0[1:]
		return
	}

	// Otherwise determine which is first.
	if s0.shard < s1.shard {
		itr.a0 = itr.a0[1:]
		return s0, nil
	} else if s0.shard > s1.shard {
		itr.a1 = itr.a1[1:]
		return s1, nil
	}

	// Return both if shards are equal.
	itr.a0, itr.a1 = itr.a0[1:], itr.a1[1:]
	return s0, s1
}
1246207
func (rows *OCI8Rows) Next(dest []driver.Value) error {
	if rows.closed {
		return nil
	}

	result := C.OCIStmtFetch2(
		rows.stmt.stmt,
		rows.stmt.conn.errHandle,
		1,
		C.OCI_FETCH_NEXT,
		0,
		C.OCI_DEFAULT)
	if result == C.OCI_NO_DATA {
		return io.EOF
	} else if result != C.OCI_SUCCESS && result != C.OCI_SUCCESS_WITH_INFO {
		return rows.stmt.conn.getError(result)
	}

	for i := range dest {
		if *rows.defines[i].indicator == -1 { // Null
			dest[i] = nil
			continue
		} else if *rows.defines[i].indicator != 0 {
			return fmt.Errorf("unknown indicator %d for column %s", *rows.defines[i].indicator, rows.defines[i].name)
		}

		switch rows.defines[i].dataType {

		// SQLT_DAT
		case C.SQLT_DAT: // for test, date are return as timestamp
			buf := (*[1 << 30]byte)(rows.defines[i].pbuf)[0:*rows.defines[i].length]
			// TODO: Handle BCE dates (http://docs.oracle.com/cd/B12037_01/appdev.101/b10779/oci03typ.htm#438305)
			// TODO: Handle timezones (http://docs.oracle.com/cd/B12037_01/appdev.101/b10779/oci03typ.htm#443601)
			dest[i] = time.Date(
				(int(buf[0])-100)*100+(int(buf[1])-100),
				time.Month(int(buf[2])),
				int(buf[3]),
				int(buf[4])-1,
				int(buf[5])-1,
				int(buf[6])-1,
				0,
				rows.stmt.conn.location)

		// SQLT_BLOB and SQLT_CLOB
		case C.SQLT_BLOB, C.SQLT_CLOB:
			lobLocator := (**C.OCILobLocator)(rows.defines[i].pbuf)

			// set character set form
			form := C.ub1(C.SQLCS_IMPLICIT)
			result = C.OCILobCharSetForm(
				rows.stmt.conn.env,       // environment handle
				rows.stmt.conn.errHandle, // error handle
				*lobLocator,              // LOB locator
				&form,                    // character set form
			)
			if result != C.OCI_SUCCESS {
				return rows.stmt.conn.getError(result)
			}

			buffer, err := rows.stmt.conn.ociLobRead(*lobLocator, form)
			if err != nil {
				return err
			}

			// set dest to buffer
			if rows.defines[i].dataType == C.SQLT_BLOB {
				dest[i] = buffer
			} else {
				dest[i] = string(buffer)
			}

		// SQLT_CHR, SQLT_STR, SQLT_AFC, SQLT_AVC, and SQLT_LNG
		case C.SQLT_CHR, C.SQLT_STR, C.SQLT_AFC, C.SQLT_AVC, C.SQLT_LNG:
			dest[i] = C.GoStringN((*C.char)(rows.defines[i].pbuf), C.int(*rows.defines[i].length))

		// SQLT_BIN
		case C.SQLT_BIN: // RAW
			buf := (*[1 << 30]byte)(rows.defines[i].pbuf)[0:*rows.defines[i].length]
			dest[i] = buf

		// SQLT_NUM
		case C.SQLT_NUM: // NUMBER
			buf := (*[21]byte)(rows.defines[i].pbuf)[0:*rows.defines[i].length]
			dest[i] = buf

		// SQLT_VNU
		case C.SQLT_VNU: // VARNUM
			buf := (*[22]byte)(rows.defines[i].pbuf)[0:*rows.defines[i].length]
			dest[i] = buf

		// SQLT_INT
		case C.SQLT_INT: // INT
			buf := (*[8]byte)(rows.defines[i].pbuf)[0:*rows.defines[i].length]
			var data int64
			err := binary.Read(bytes.NewReader(buf), binary.LittleEndian, &data)
			if err != nil {
				return fmt.Errorf("binary read for column %v - error: %v", i, err)
			}
			dest[i] = data

		// SQLT_BDOUBLE
		case C.SQLT_BDOUBLE: // native double
			buf := (*[8]byte)(rows.defines[i].pbuf)[0:*rows.defines[i].length]
			var data float64
			err := binary.Read(bytes.NewReader(buf), binary.LittleEndian, &data)
			if err != nil {
				return fmt.Errorf("binary read for column %v - error: %v", i, err)
			}
			dest[i] = data

		// SQLT_TIMESTAMP
		case C.SQLT_TIMESTAMP:
			if rv := C.WrapOCIDateTimeGetDateTime(
				rows.stmt.conn.env,
				rows.stmt.conn.errHandle,
				*(**C.OCIDateTime)(rows.defines[i].pbuf),
			); rv.rv != C.OCI_SUCCESS {
				return rows.stmt.conn.getError(rv.rv)
			} else {
				dest[i] = time.Date(
					int(rv.y),
					time.Month(rv.m),
					int(rv.d),
					int(rv.hh),
					int(rv.mm),
					int(rv.ss),
					int(rv.ff),
					rows.stmt.conn.location,
				)
			}

		// SQLT_TIMESTAMP_TZ and SQLT_TIMESTAMP_LTZ
		case C.SQLT_TIMESTAMP_TZ, C.SQLT_TIMESTAMP_LTZ:
			tptr := *(**C.OCIDateTime)(rows.defines[i].pbuf)
			rv := C.WrapOCIDateTimeGetDateTime(
				rows.stmt.conn.env,
				rows.stmt.conn.errHandle,
				tptr)
			if rv.rv != C.OCI_SUCCESS {
				return rows.stmt.conn.getError(rv.rv)
			}
			rvz := C.WrapOCIDateTimeGetTimeZoneNameOffset(
				rows.stmt.conn.env,
				rows.stmt.conn.errHandle,
				tptr)
			if rvz.rv != C.OCI_SUCCESS {
				return rows.stmt.conn.getError(rvz.rv)
			}
			nnn := C.GoStringN((*C.char)((unsafe.Pointer)(&rvz.zone[0])), C.int(rvz.zlen))
			loc, err := time.LoadLocation(nnn)
			if err != nil {
				// TODO: reuse locations
				loc = time.FixedZone(nnn, int(rvz.h)*60*60+int(rvz.m)*60)
			}
			dest[i] = time.Date(
				int(rv.y),
				time.Month(rv.m),
				int(rv.d),
				int(rv.hh),
				int(rv.mm),
				int(rv.ss),
				int(rv.ff),
				loc)

		// SQLT_INTERVAL_DS
		case C.SQLT_INTERVAL_DS:
			var days C.sb4
			var hours C.sb4
			var minutes C.sb4
			var seconds C.sb4
			var fracSeconds C.sb4
			interval := *(**C.OCIInterval)(rows.defines[i].pbuf)
			result = C.OCIIntervalGetDaySecond(
				unsafe.Pointer(rows.stmt.conn.env), // environment handle
				rows.stmt.conn.errHandle,           // error handle
				&days,                              // days
				&hours,                             // hours
				&minutes,                           // minutes
				&seconds,                           // seconds
				&fracSeconds,                       // fractional seconds
				interval,                           // interval
			)
			if result != C.OCI_SUCCESS {
				return rows.stmt.conn.getError(result)
			}

			dest[i] = (int64(days) * 24 * int64(time.Hour)) + (int64(hours) * int64(time.Hour)) +
				(int64(minutes) * int64(time.Minute)) + (int64(seconds) * int64(time.Second)) + int64(fracSeconds)

		// SQLT_INTERVAL_YM
		case C.SQLT_INTERVAL_YM:
			var years C.sb4
			var months C.sb4
			interval := *(**C.OCIInterval)(rows.defines[i].pbuf)
			result = C.OCIIntervalGetYearMonth(
				unsafe.Pointer(rows.stmt.conn.env), // environment handle
				rows.stmt.conn.errHandle,           // error handle
				&years,                             // year
				&months,                            // month
				interval,                           // interval
			)
			if result != C.OCI_SUCCESS {
				return rows.stmt.conn.getError(result)
			}
			dest[i] = (int64(years) * 12) + int64(months)

		// default
		default:
			return fmt.Errorf("Unhandled column type: %d", rows.defines[i].dataType)

		}

	}

	return nil
}
263410
func (id KSUID) Next() KSUID {
	zero := makeUint128(0, 0)

	t := id.Timestamp()
	u := uint128Payload(id)
	v := add128(u, makeUint128(0, 1))

	if v == zero { // overflow
		t++
	}

	return v.ksuid(t)
}
1286553
func (e *element) Next() *element {
	if p := e.next; e.list != nil && p != &e.list.root {
		return p
	}
	return nil
}
218267
func (c *Cursor) Next() (key []byte, value []byte) {
	_assert(c.bucket.tx.db != nil, "tx closed")
	k, v, flags := c.next()
	if (flags & uint32(bucketLeafFlag)) != 0 {
		return k, nil
	}
	return k, v
}
439594
func (s *Sequence) Next() BNode {
	n := atomic.AddUint64(&s.last, 1)
	return BNode(fmt.Sprintf("n%d", n))
}
722577
func (c *indexSeriesCursor) Next() *reads.SeriesRow {
	if c.eof {
		return nil
	}

	// next series key
	sr, err := c.sqry.Next()
	if err != nil {
		c.err = err
		c.Close()
		return nil
	} else if sr == nil {
		c.Close()
		return nil
	}

	if len(sr.Tags) < 2 {
		// Invariant broken.
		c.err = fmt.Errorf("attempted to emit key with only tags: %s", sr.Tags)
		return nil
	}

	c.row.Name = sr.Name
	//TODO(edd): check this.
	c.row.SeriesTags = copyTags(c.row.SeriesTags, sr.Tags)
	c.row.Tags = copyTags(c.row.Tags, sr.Tags)
	fv := c.row.Tags.Get(models.FieldKeyTagKeyBytes)
	c.row.Field = string(fv)

	if c.cond != nil && c.hasValueExpr {
		// TODO(sgc): lazily evaluate valueCond
		c.row.ValueCond = influxql.Reduce(c.cond, c)
		if reads.IsTrueBooleanLiteral(c.row.ValueCond) {
			// we've reduced the expression to "true"
			c.row.ValueCond = nil
		}
	}

	// Normalise the special tag keys to the emitted format.
	mv := c.row.Tags.Get(models.MeasurementTagKeyBytes)
	c.row.Tags.Delete(models.MeasurementTagKeyBytes)
	c.row.Tags.Set(measurementKeyBytes, mv)
	c.row.Tags.Delete(models.FieldKeyTagKeyBytes)
	c.row.Tags.Set(fieldKeyBytes, fv)

	return &c.row
}
88480
func (rows *Rows) Next() bool {
	if rows.total >= rows.current+1 {
		rows.current++
		return true
	}
	return false
}
261271
func (nfei *NotFoundErrorIterator) Next() (*cb.Block, cb.Status) {
	return nil, cb.Status_NOT_FOUND
}
229072
func (iter *sparseBitArrayIterator) Next() bool {
	iter.index++
	return iter.index < int64(len(iter.sba.indices))
}
1056578
func (c *indexIter) Next() (val []types.Datum, h int64, err error) {
	if !c.it.Valid() {
		return nil, 0, errors.Trace(io.EOF)
	}
	if !c.it.Key().HasPrefix(c.prefix) {
		return nil, 0, errors.Trace(io.EOF)
	}
	// get indexedValues
	buf := c.it.Key()[len(c.prefix):]
	vv, err := codec.Decode(buf, len(c.idx.idxInfo.Columns))
	if err != nil {
		return nil, 0, err
	}
	if len(vv) > len(c.idx.idxInfo.Columns) {
		h = vv[len(vv)-1].GetInt64()
		val = vv[0 : len(vv)-1]
	} else {
		// If the index is unique and the value isn't nil, the handle is in value.
		h, err = DecodeHandle(c.it.Value())
		if err != nil {
			return nil, 0, err
		}
		val = vv
	}
	// update new iter to next
	err = c.it.Next()
	if err != nil {
		return nil, 0, err
	}
	return
}
274140
func (e *TableDualExec) Next(ctx context.Context, req *chunk.RecordBatch) error {
	if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
		span1 := span.Tracer().StartSpan("tableDual.Next", opentracing.ChildOf(span.Context()))
		defer span1.Finish()
	}
	if e.runtimeStats != nil {
		start := time.Now()
		defer func() { e.runtimeStats.Record(time.Since(start), req.NumRows()) }()
	}
	req.Reset()
	if e.numReturned >= e.numDualRows {
		return nil
	}
	if e.Schema().Len() == 0 {
		req.SetNumVirtualRows(1)
	} else {
		for i := range e.Schema().Columns {
			req.AppendNull(i)
		}
	}
	e.numReturned = e.numDualRows
	return nil
}