Skip to content

Commit

Permalink
Doc comments for each functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Mar 27, 2022
1 parent f0494da commit de71a42
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions btree/btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (t *Tree[K, V]) split(h *node[K, V]) *node[K, V] {
return n
}

// Each calls 'fn' on every node in the tree in order.
func (t *Tree[K, V]) Each(fn func(key K, val V)) {
t.each(t.root, t.height, fn)
}
Expand Down
4 changes: 2 additions & 2 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (t *Cache[K, V]) Capacity() int {
return t.capacity
}

// Iter returns an iterator over all key-value pairs in the cache. It iterates
// in order of most recently used to least recently used.
// Each calls 'fn' on every value in the cache, from most recently used to
// least recently used.
func (t *Cache[K, V]) Each(fn func(key K, val V)) {
t.lru.Front.Each(func(kv KV[K, V]) {
fn(kv.Key, kv.Val)
Expand Down
3 changes: 2 additions & 1 deletion hashmap/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (m *Map[K, V]) Copy() *Map[K, V] {
}
}

// Iter returns an iterator over all key-value pairs in the map.
// Each calls 'fn' on every key-value pair in the hashmap in no particular
// order.
func (m *Map[K, V]) Each(fn func(key K, val V)) {
for _, ent := range m.entries {
if ent.filled {
Expand Down
1 change: 1 addition & 0 deletions hashset/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (s *Set[K]) Size() int {
return s.m.Size()
}

// Each calls 'fn' on every item in the set in no particular order.
func (s *Set[K]) Each(fn func(key K)) {
s.m.Each(func(key K, v struct{}) {
fn(key)
Expand Down
2 changes: 2 additions & 0 deletions interval/itree.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func (t *Tree[V]) Get(pos int) (V, bool) {
return n.value, true
}

// Each calls 'fn' on every element in the tree, and its corresponding
// interval, in order sorted by starting position.
func (t *Tree[V]) Each(fn func(low, high int, val V)) {
t.root.each(fn)
}
Expand Down
2 changes: 2 additions & 0 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (l *List[V]) Remove(n *Node[V]) {
}
}

// Each calls 'fn' on every element from this node onward in the list.
func (n *Node[V]) Each(fn func(val V)) {
node := n
for node != nil {
Expand All @@ -79,6 +80,7 @@ func (n *Node[V]) Each(fn func(val V)) {
}
}

// EachReverse calls 'fn' on every element from this node backward in the list.
func (n *Node[V]) EachReverse(fn func(val V)) {
node := n
for node != nil {
Expand Down
2 changes: 2 additions & 0 deletions queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func (q *Queue[T]) Empty() bool {
return q.list.Front == nil
}

// Each calls 'fn' on every item in the queue, starting with the least
// recently pushed element.
func (q *Queue[T]) Each(fn func(t T)) {
q.list.Front.Each(fn)
}

0 comments on commit de71a42

Please sign in to comment.