// NewIterator creates a new levigoIterator, which follows the Iterator // interface. // // Important notes: // // For each of the iterator methods that have a return signature of (ok bool), // if ok == false, the iterator may not be used any further and must be closed. // Further work with the database requires the creation of a new iterator. This // is due to LevelDB and Levigo design. Please refer to Jeff and Sanjay's notes // in the LevelDB documentation for this behavior's rationale. // // The returned iterator must explicitly be closed; otherwise non-managed memory // will be leaked. // // The iterator is optionally snapshotable. func (l *LevelDBPersistence) NewIterator(snapshotted bool) Iterator { var ( snapshot *levigo.Snapshot readOptions *levigo.ReadOptions iterator *levigo.Iterator ) if snapshotted { snapshot = l.storage.NewSnapshot() readOptions = levigo.NewReadOptions() readOptions.SetSnapshot(snapshot) iterator = l.storage.NewIterator(readOptions) } else { iterator = l.storage.NewIterator(l.readOptions) } return &levigoIterator{ creationTime: time.Now(), iterator: iterator, readOptions: readOptions, snapshot: snapshot, storage: l.storage, } }