Returns a new iterator. The Release method must be called when finished with the iterator.
(tx *Tx, bucket string, options IteratorOptions)
| 36 | // Returns a new iterator. |
| 37 | // The Release method must be called when finished with the iterator. |
| 38 | func NewIterator(tx *Tx, bucket string, options IteratorOptions) *Iterator { |
| 39 | b, err := tx.db.bucketMgr.GetBucket(DataStructureBTree, bucket) |
| 40 | if err != nil { |
| 41 | return nil |
| 42 | } |
| 43 | iterator := &Iterator{ |
| 44 | tx: tx, |
| 45 | options: options, |
| 46 | iter: tx.db.Index.BTree.GetWithDefault(b.Id).Iter(), |
| 47 | } |
| 48 | |
| 49 | // Initialize position and cache the first item |
| 50 | if options.Reverse { |
| 51 | iterator.valid = iterator.iter.Last() |
| 52 | } else { |
| 53 | iterator.valid = iterator.iter.First() |
| 54 | } |
| 55 | |
| 56 | if iterator.valid { |
| 57 | iterator.currentItem = iterator.iter.Item() |
| 58 | } |
| 59 | |
| 60 | return iterator |
| 61 | } |
| 62 | |
| 63 | func (it *Iterator) Rewind() bool { |
| 64 | if it.options.Reverse { |