Browse Source

Refactored the iterator to follow Go constructor conventions.

pull/1842/head
Paul W. Homer 8 years ago
parent
commit
4fdcf51467
1 changed files with 14 additions and 17 deletions
  1. +14
    -17
      mem_db.go

+ 14
- 17
mem_db.go View File

@ -77,21 +77,8 @@ type memDBIterator struct {
db *MemDB
}
func (it *memDBIterator) Create(db *MemDB) *memDBIterator {
db.mtx.Lock()
defer db.mtx.Unlock()
if it == nil {
it = &memDBIterator{}
}
it.db = db
it.last = -1
// unfortunately we need a copy of all of the keys
for key, _ := range db.db {
it.keys = append(it.keys, key)
}
return it
func newMemDBIterator() *memDBIterator {
return &memDBIterator{}
}
func (it *memDBIterator) Next() bool {
@ -114,8 +101,18 @@ func (it *memDBIterator) Value() []byte {
}
func (db *MemDB) Iterator() Iterator {
var it *memDBIterator
return it.Create(db)
it := newMemDBIterator()
it.db = db
it.last = -1
db.mtx.Lock()
defer db.mtx.Unlock()
// unfortunately we need a copy of all of the keys
for key, _ := range db.db {
it.keys = append(it.keys, key)
}
return it
}
func (db *MemDB) NewBatch() Batch {


Loading…
Cancel
Save