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.
8 "github.com/btcsuite/btcd/database/internal/treap"
9 "github.com/btcsuite/goleveldb/leveldb/iterator"
10 "github.com/btcsuite/goleveldb/leveldb/util"
13 // ldbTreapIter wraps a treap iterator to provide the additional functionality
14 // needed to satisfy the leveldb iterator.Iterator interface.
15 type ldbTreapIter struct {
21 // Enforce ldbTreapIter implements the leveldb iterator.Iterator interface.
22 var _ iterator.Iterator = (*ldbTreapIter)(nil)
24 // Error is only provided to satisfy the iterator interface as there are no
25 // errors for this memory-only structure.
27 // This is part of the leveldb iterator.Iterator interface implementation.
28 func (iter *ldbTreapIter) Error() error {
32 // SetReleaser is only provided to satisfy the iterator interface as there is no
33 // need to override it.
35 // This is part of the leveldb iterator.Iterator interface implementation.
36 func (iter *ldbTreapIter) SetReleaser(releaser util.Releaser) {
39 // Release releases the iterator by removing the underlying treap iterator from
40 // the list of active iterators against the pending keys treap.
42 // This is part of the leveldb iterator.Iterator interface implementation.
43 func (iter *ldbTreapIter) Release() {
45 iter.tx.removeActiveIter(iter.Iterator)
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}