github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/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 "github.com/zuoyebang/bitalostable/internal/base"
    21  
    22  // flushIterator is an iterator over the skiplist object. Use Skiplist.NewFlushIter
    23  // to construct an iterator. The current state of the iterator can be cloned by
    24  // simply value copying the struct.
    25  type flushIterator struct {
    26  	Iterator
    27  	bytesIterated *uint64
    28  }
    29  
    30  // flushIterator implements the base.InternalIterator interface.
    31  var _ base.InternalIterator = (*flushIterator)(nil)
    32  
    33  func (it *flushIterator) String() string {
    34  	return "memtable"
    35  }
    36  
    37  func (it *flushIterator) SeekGE(key []byte, flags base.SeekGEFlags) (*base.InternalKey, []byte) {
    38  	panic("bitalostable: SeekGE unimplemented")
    39  }
    40  
    41  func (it *flushIterator) SeekPrefixGE(
    42  	prefix, key []byte, flags base.SeekGEFlags,
    43  ) (*base.InternalKey, []byte) {
    44  	panic("bitalostable: SeekPrefixGE unimplemented")
    45  }
    46  
    47  func (it *flushIterator) SeekLT(key []byte, flags base.SeekLTFlags) (*base.InternalKey, []byte) {
    48  	panic("bitalostable: SeekLT unimplemented")
    49  }
    50  
    51  // First seeks position at the first entry in list. Returns the key and value
    52  // if the iterator is pointing at a valid entry, and (nil, nil) otherwise. Note
    53  // that First only checks the upper bound. It is up to the caller to ensure
    54  // that key is greater than or equal to the lower bound.
    55  func (it *flushIterator) First() (*base.InternalKey, []byte) {
    56  	key, val := it.Iterator.First()
    57  	if key == nil {
    58  		return nil, nil
    59  	}
    60  	*it.bytesIterated += uint64(it.nd.allocSize)
    61  	return key, val
    62  }
    63  
    64  // Next advances to the next position. Returns the key and value if the
    65  // iterator is pointing at a valid entry, and (nil, nil) otherwise.
    66  // Note: flushIterator.Next mirrors the implementation of Iterator.Next
    67  // due to performance. Keep the two in sync.
    68  func (it *flushIterator) Next() (*base.InternalKey, []byte) {
    69  	it.nd = it.list.getSkipNext(it.nd)
    70  	if it.nd == it.list.tail {
    71  		return nil, nil
    72  	}
    73  	it.decodeKey()
    74  	*it.bytesIterated += uint64(it.nd.allocSize)
    75  	return &it.key, it.value()
    76  }
    77  
    78  func (it *flushIterator) Prev() (*base.InternalKey, []byte) {
    79  	panic("bitalostable: Prev unimplemented")
    80  }