github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/maps/interfaces.go (about) 1 package maps 2 3 import ( 4 "github.com/djordje200179/extendedlibrary/datastructures/iter" 5 "github.com/djordje200179/extendedlibrary/misc" 6 ) 7 8 // Iterator is an iterator over a Map. 9 type Iterator[K, V any] interface { 10 iter.Iterator[misc.Pair[K, V]] 11 12 // Key returns the key of the current entry. 13 Key() K 14 // Value returns the value of the current entry. 15 Value() V 16 // ValueRef returns a pointer to the value of the current entry. 17 ValueRef() *V 18 // SetValue sets the value of the current entry. 19 SetValue(value V) 20 21 // Remove removes the current entry. 22 Remove() 23 } 24 25 // Map is an interface that represents a map of keys to values. 26 type Map[K, V any] interface { 27 // Size returns the size of the map 28 Size() int 29 30 // Contains returns true if the map contains the given key 31 Contains(key K) bool 32 // TryGet returns the value associated with the given key, or zero value and false if the key is not present 33 TryGet(key K) (V, bool) 34 // Get returns the value associated with the given key 35 Get(key K) V 36 // GetRef returns a pointer to the value associated with the given key 37 GetRef(key K) *V 38 // Set sets the value associated with the given key to the given value 39 Set(key K, value V) 40 // Remove removes the entry associated with the given key 41 Remove(key K) 42 43 // Clear clears the map 44 Clear() 45 46 misc.Cloner[Map[K, V]] 47 48 iter.Iterable[misc.Pair[K, V]] 49 // MapIterator returns an iterator over the Map 50 MapIterator() Iterator[K, V] 51 // Stream2 streams entries of the Map 52 Stream2(yield func(K, V) bool) 53 // RefsStream2 streams keys and references to values of the Map 54 RefsStream2(yield func(K, *V) bool) 55 }