github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/internal/arenaskl/flush_iterator.go (about)

     1  /*
     2   * Copyright 2017 Dgraph Labs, Inc. and Contributors
     3   * Modifications copyright (C) 2017 Andy Kimball and Contributors
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package arenaskl
    19  
    20  import (
    21  	"github.com/petermattis/pebble/internal/base"
    22  )
    23  
    24  // flushIterator is an iterator over the skiplist object. Use Skiplist.NewFlushIter
    25  // to construct an iterator. The current state of the iterator can be cloned by
    26  // simply value copying the struct.
    27  type flushIterator struct {
    28  	Iterator
    29  	bytesIterated *uint64
    30  }
    31  
    32  func (it *flushIterator) SeekGE(key []byte) (*base.InternalKey, []byte) {
    33  	panic("pebble: SeekGE unimplemented")
    34  }
    35  
    36  func (it *flushIterator) SeekPrefixGE(prefix, key []byte) (*base.InternalKey, []byte) {
    37  	panic("pebble: SeekPrefixGE unimplemented")
    38  }
    39  
    40  func (it *flushIterator) SeekLT(key []byte) (*base.InternalKey, []byte) {
    41  	panic("pebble: SeekLT unimplemented")
    42  }
    43  
    44  // First seeks position at the first entry in list. Returns the key and value
    45  // if the iterator is pointing at a valid entry, and (nil, nil) otherwise. Note
    46  // that First only checks the upper bound. It is up to the caller to ensure
    47  // that key is greater than or equal to the lower bound.
    48  func (it *flushIterator) First() (*base.InternalKey, []byte) {
    49  	key, val := it.Iterator.First()
    50  	if key == nil {
    51  		return nil, nil
    52  	}
    53  	*it.bytesIterated += uint64(it.nd.allocSize)
    54  	return key, val
    55  }
    56  
    57  // Next advances to the next position. Returns the key and value if the
    58  // iterator is pointing at a valid entry, and (nil, nil) otherwise.
    59  // Note: flushIterator.Next mirrors the implementation of Iterator.Next
    60  // due to performance. Keep the two in sync.
    61  func (it *flushIterator) Next() (*base.InternalKey, []byte) {
    62  	it.nd = it.list.getNext(it.nd, 0)
    63  	if it.nd == it.list.tail {
    64  		return nil, nil
    65  	}
    66  	it.decodeKey()
    67  	*it.bytesIterated += uint64(it.nd.allocSize)
    68  	return &it.key, it.Value()
    69  }
    70  
    71  func (it *flushIterator) Prev() (*base.InternalKey, []byte) {
    72  	panic("pebble: Prev unimplemented")
    73  }