github.com/lbryio/lbcd@v0.22.119/database/ffldb/ldbtreapiter.go (about) 1 // Copyright (c) 2015-2016 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package ffldb 6 7 import ( 8 "github.com/lbryio/lbcd/database/internal/treap" 9 "github.com/syndtr/goleveldb/leveldb/iterator" 10 "github.com/syndtr/goleveldb/leveldb/util" 11 ) 12 13 // ldbTreapIter wraps a treap iterator to provide the additional functionality 14 // needed to satisfy the leveldb iterator.Iterator interface. 15 type ldbTreapIter struct { 16 *treap.Iterator 17 tx *transaction 18 released bool 19 } 20 21 // Enforce ldbTreapIter implements the leveldb iterator.Iterator interface. 22 var _ iterator.Iterator = (*ldbTreapIter)(nil) 23 24 // Error is only provided to satisfy the iterator interface as there are no 25 // errors for this memory-only structure. 26 // 27 // This is part of the leveldb iterator.Iterator interface implementation. 28 func (iter *ldbTreapIter) Error() error { 29 return nil 30 } 31 32 // SetReleaser is only provided to satisfy the iterator interface as there is no 33 // need to override it. 34 // 35 // This is part of the leveldb iterator.Iterator interface implementation. 36 func (iter *ldbTreapIter) SetReleaser(releaser util.Releaser) { 37 } 38 39 // Release releases the iterator by removing the underlying treap iterator from 40 // the list of active iterators against the pending keys treap. 41 // 42 // This is part of the leveldb iterator.Iterator interface implementation. 43 func (iter *ldbTreapIter) Release() { 44 if !iter.released { 45 iter.tx.removeActiveIter(iter.Iterator) 46 iter.released = true 47 } 48 } 49 50 // newLdbTreapIter creates a new treap iterator for the given slice against the 51 // pending keys for the passed transaction and returns it wrapped in an 52 // ldbTreapIter so it can be used as a leveldb iterator. It also adds the new 53 // iterator to the list of active iterators for the transaction. 54 func newLdbTreapIter(tx *transaction, slice *util.Range) *ldbTreapIter { 55 iter := tx.pendingKeys.Iterator(slice.Start, slice.Limit) 56 tx.addActiveIter(iter) 57 return &ldbTreapIter{Iterator: iter, tx: tx} 58 }