Skip to content

Commit

Permalink
Add comments about the performance of some methods. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobg authored Aug 1, 2024
1 parent 5318b5a commit c47090b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iter/gomap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (*goMapIter[K, V]) Err() error {

// FromMap produces an iterator of key-value pairs from a Go map.
// The resulting iterator never returns an error.
// Note that this is implemented in terms of [FromMapKeys],
// which makes copies the keys of the map to a new slice.
func FromMap[M ~map[K]V, K comparable, V any](m M) Of[Pair[K, V]] {
return &goMapIter[K, V]{
m: m,
Expand All @@ -33,6 +35,8 @@ func FromMap[M ~map[K]V, K comparable, V any](m M) Of[Pair[K, V]] {
}

// FromMapKeys produces an iterator over the keys of a Go map.
// Note that this is implemented in terms of [FromSlice],
// after first copying the keys of the map to a new slice.
func FromMapKeys[M ~map[K]V, K comparable, V any](m M) Of[K] {
keys := make([]K, 0, len(m))
for k := range m {
Expand Down
1 change: 1 addition & 0 deletions set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s Of[T]) Eachx(f func(T) error) error {
// Iter produces an iterator over the members of the set,
// in an indeterminate order.
// The set may be nil.
// Note that this makes a copy of the elements in the set.
func (s Of[T]) Iter() iter.Of[T] {
return iter.FromMapKeys(s)
}
Expand Down

0 comments on commit c47090b

Please sign in to comment.