Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Export MapIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Dec 14, 2019
1 parent d767096 commit 2a57d67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions go/types/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,18 @@ func (m Map) Any(cb func(k, v Value) bool) (yep bool) {
return
}

func (m Map) Iterator() *mapIterator {
func (m Map) Iterator() *MapIterator {
return m.IteratorAt(0)
}

func (m Map) IteratorAt(pos uint64) *mapIterator {
return &mapIterator{
func (m Map) IteratorAt(pos uint64) *MapIterator {
return &MapIterator{
cursor: newCursorAtIndex(m.orderedSequence, pos),
}
}

func (m Map) IteratorFrom(key Value) *mapIterator {
return &mapIterator{
func (m Map) IteratorFrom(key Value) *MapIterator {
return &MapIterator{
cursor: newCursorAtValue(m.orderedSequence, key, false, false),
}
}
Expand Down
18 changes: 9 additions & 9 deletions go/types/map_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@

package types

// mapIterator can efficiently iterate through a Noms Map.
type mapIterator struct {
// MapIterator can efficiently iterate through a Noms Map.
type MapIterator struct {
cursor *sequenceCursor
currentKey Value
currentValue Value
}

func (mi *mapIterator) Valid() bool {
func (mi *MapIterator) Valid() bool {
return mi.cursor.valid()
}

func (mi *mapIterator) Entry() (k Value, v Value) {
func (mi *MapIterator) Entry() (k Value, v Value) {
return mi.Key(), mi.Value()
}

func (mi *mapIterator) Key() Value {
func (mi *MapIterator) Key() Value {
if !mi.cursor.valid() {
return nil
}
return mi.cursor.current().(mapEntry).key
}

func (mi *mapIterator) Value() Value {
func (mi *MapIterator) Value() Value {
if !mi.cursor.valid() {
return nil
}
return mi.cursor.current().(mapEntry).value
}

func (mi *mapIterator) Position() uint64 {
func (mi *MapIterator) Position() uint64 {
if !mi.cursor.valid() {
return 0
}
return uint64(mi.cursor.idx)
}

// Prev returns the previous entry from the Map. If there is no previous entry, Prev() returns nils.
func (mi *mapIterator) Prev() bool {
func (mi *MapIterator) Prev() bool {
if !mi.cursor.valid() {
return false
}
Expand All @@ -50,7 +50,7 @@ func (mi *mapIterator) Prev() bool {

// Next returns the subsequent entries from the Map, starting with the entry at which the iterator
// was created. If there are no more entries, Next() returns nils.
func (mi *mapIterator) Next() bool {
func (mi *MapIterator) Next() bool {
if !mi.cursor.valid() {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion go/types/map_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMapIterator(t *testing.T) {

for i, t := range tc {
lbl := fmt.Sprintf("test case %d", i)
var it *mapIterator
var it *MapIterator
if t.iter {
it = m.Iterator()
} else if t.iterFrom != "" {
Expand Down

0 comments on commit 2a57d67

Please sign in to comment.