Remove MultiIterator.
parent
1eda0ffcb9
commit
a6746b3a21
|
@ -774,92 +774,6 @@ func (e *Emitter) C() <-chan map[Key]interface{} { return e.c }
|
|||
// Emit sets a key and value on the emitter's bufferred data.
|
||||
func (e *Emitter) Emit(key Key, value interface{}) { e.c <- map[Key]interface{}{key: value} }
|
||||
|
||||
// MultiIterator represents an iterator that iterates over multiple iterators in sequence.
|
||||
// The iterator also allows for a maximum key value to limit the upper bound during reads.
|
||||
type MultiIterator struct {
|
||||
// The maximum allowed key that can be read from Next().
|
||||
// A value of zero means there is no maximum.
|
||||
MaxKey int64
|
||||
|
||||
itrs []Iterator
|
||||
buf []iteratorKeyValue
|
||||
lastidx int
|
||||
}
|
||||
|
||||
// NewMultiIterator return a new instance of MultiIterator.
|
||||
// At least one iterator must be passed in.
|
||||
// All iterators must share the same key.
|
||||
func NewMultiIterator(itrs []Iterator) *MultiIterator {
|
||||
return &MultiIterator{
|
||||
itrs: itrs,
|
||||
buf: make([]iteratorKeyValue, len(itrs)),
|
||||
lastidx: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// Tags returns the encoded dimensional tag values.
|
||||
func (i *MultiIterator) Tags() string {
|
||||
if i.lastidx == -1 {
|
||||
return ""
|
||||
}
|
||||
return i.itrs[i.lastidx].Tags()
|
||||
}
|
||||
|
||||
// Next returns the next value from the iterator.
|
||||
func (i *MultiIterator) Next() (key int64, value interface{}) {
|
||||
// Track the first lowest key.
|
||||
index, min := -1, int64(0)
|
||||
|
||||
// Retrieve the next key for each subiterator.
|
||||
for j, itr := range i.itrs {
|
||||
// Read next key from iterator if there's nothing in the lookahead.
|
||||
buf := &i.buf[j]
|
||||
if buf.key == 0 {
|
||||
buf.key, buf.value = itr.Next()
|
||||
}
|
||||
|
||||
// Determine which iterator's key/value to return next.
|
||||
// If this iterator's key is greater than the max key then ignore it.
|
||||
// If there is no key or the current key is the lowest then use it.
|
||||
if buf.key > i.MaxKey {
|
||||
continue
|
||||
} else if min == 0 || (buf.key != 0 && buf.key < min) {
|
||||
index, min = j, buf.key
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no more key/values then return nil.
|
||||
if index == -1 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Otherwise return the key & value and unset the buffer.
|
||||
buf := &i.buf[index]
|
||||
i.lastidx = index
|
||||
key, value = buf.key, buf.value
|
||||
buf.key, buf.value = 0, nil
|
||||
return
|
||||
}
|
||||
|
||||
// Peek returns the next value from the iterator but does not move it forward.
|
||||
func (i *MultiIterator) Peek() (key int64, value interface{}) {
|
||||
// Read the next value.
|
||||
key, value = i.Next()
|
||||
|
||||
// Put it back if anything was read.
|
||||
if i.lastidx != -1 {
|
||||
buf := &i.buf[i.lastidx]
|
||||
buf.key, buf.value = key, value
|
||||
i.lastidx = -1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type iteratorKeyValue struct {
|
||||
key int64
|
||||
value interface{}
|
||||
}
|
||||
|
||||
// Row represents a single row returned from the execution of a statement.
|
||||
type Row struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
|
|
Loading…
Reference in New Issue