Documentation ¶
Overview ¶
Copyright (c) 2022 0x9ef
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 0x9ef ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 0x9ef ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 0x9ef ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 0x9ef ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- type DefaultMap
- func (m DefaultMap[K, V]) Clear()
- func (m DefaultMap[K, V]) Delete(key K)
- func (m DefaultMap[K, V]) DeleteIf(key K, f func(m Map[K, V]) bool) bool
- func (m DefaultMap[K, V]) Exists(key K) bool
- func (m DefaultMap[K, V]) Filter(f func(key K, value V) bool) ([]K, []V)
- func (m DefaultMap[K, V]) Get(key K) V
- func (m DefaultMap[K, V]) GetAndDelete(key K) (V, bool)
- func (m DefaultMap[K, V]) GetOk(key K) (V, bool)
- func (m DefaultMap[K, V]) GetOrSet(key K, value V) (V, bool)
- func (m DefaultMap[K, V]) Iterate(f func(key K, value V) bool)
- func (m DefaultMap[K, V]) Keys() []K
- func (m DefaultMap[K, V]) Len() int32
- func (m DefaultMap[K, V]) Set(key K, value V)
- func (m DefaultMap[K, V]) SetIf(key K, value V, f func(m Map[K, V]) bool) bool
- func (m DefaultMap[K, V]) Values() []V
- type Map
- type Merger
- type UniqueMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultMap ¶
type DefaultMap[K comparable, V any] struct { // contains filtered or unexported fields }
DefaultMap is a thread-safe map that have additional helpers functions that give more flexibility to a user. Under the hood this map use sync.Map for rw-locks.
func NewDefaultMap ¶
func NewDefaultMap[K comparable, V any]() DefaultMap[K, V]
NewDefaultMap returns initialized map without capacity.
func (DefaultMap[K, V]) Clear ¶
func (m DefaultMap[K, V]) Clear()
Clear clears all keys from the map.
func (DefaultMap[K, V]) Delete ¶
func (m DefaultMap[K, V]) Delete(key K)
Delete deletes a key from the map.
func (DefaultMap[K, V]) DeleteIf ¶
func (m DefaultMap[K, V]) DeleteIf(key K, f func(m Map[K, V]) bool) bool
DeleteIf deletes a key from the map if the predicate function f is true.
func (DefaultMap[K, V]) Exists ¶
func (m DefaultMap[K, V]) Exists(key K) bool
Exists returns true if a key exists in the map.
func (DefaultMap[K, V]) Filter ¶
func (m DefaultMap[K, V]) Filter(f func(key K, value V) bool) ([]K, []V)
Filter returns filtered pairs of keys and values from the map, if predicate f is false filterting will be stopped.
func (DefaultMap[K, V]) Get ¶
func (m DefaultMap[K, V]) Get(key K) V
Get returns value underlined by a key from the map.
func (DefaultMap[K, V]) GetAndDelete ¶
func (m DefaultMap[K, V]) GetAndDelete(key K) (V, bool)
GetAndDelete deletes the value for a key, returning the previous value.
func (DefaultMap[K, V]) GetOk ¶
func (m DefaultMap[K, V]) GetOk(key K) (V, bool)
GetOk returns value and bool flag if a key in the map was founded.
func (DefaultMap[K, V]) GetOrSet ¶
func (m DefaultMap[K, V]) GetOrSet(key K, value V) (V, bool)
GetOrSet returns the existing value for the key if present. Otherwise, it stores and returns the given value.
func (DefaultMap[K, V]) Iterate ¶
func (m DefaultMap[K, V]) Iterate(f func(key K, value V) bool)
Iterate iterates over each map key and value with iterator f function.
func (DefaultMap[K, V]) Keys ¶
func (m DefaultMap[K, V]) Keys() []K
Keys returns all existed keys as slice in the map.
func (DefaultMap[K, V]) Set ¶
func (m DefaultMap[K, V]) Set(key K, value V)
Set sets value for a key.
func (DefaultMap[K, V]) SetIf ¶
func (m DefaultMap[K, V]) SetIf(key K, value V, f func(m Map[K, V]) bool) bool
SetIf sets value if the predicate function f is true.
func (DefaultMap[K, V]) Values ¶
func (m DefaultMap[K, V]) Values() []V
Values returns all existed values as slice in the map.
type Map ¶
type Map[K comparable, V any] interface { // Len returns length of map. Len() int32 // Exists returns true if a key exists in the map. Exists(key K) bool // Set sets value for a key. Set(key K, value V) // SetIf sets value if the predicate function f is true. SetIf(key K, value V, f func(m Map[K, V]) bool) bool // Get returns value underlined by a key from the map. Get(key K) V // GetOk returns value and bool flag if a key in the map was found. GetOk(key K) (V, bool) // GetOrSet returns the existing value for the key if present. // Otherwise, it stores and returns the given value. GetOrSet(key K, value V) (V, bool) // GetAndDelete deletes the value for a key, returning the previous value. GetAndDelete(key K) (V, bool) // Delete deletes a key from the map. Delete(key K) // DeleteIf deletes a key from the map if the predicate function f is true. DeleteIf(key K, f func(m Map[K, V]) bool) bool // Clear clears an all keys from the map. Clear() // Keys returns all existed keys as slice in the map. Keys() []K // Values returns all existed values as slice in the map. Values() []V // Filter returns filtered pairs of keys and values from the map, if // predicate f is false filterting will be stopped. Filter(f func(key K, value V) bool) ([]K, []V) // Iterate iterates over each map key and value, if predicate f is false // iterations will be stopped. // Iterate may be O(N) with the number of elements in the map even if f // returns false after a constant number of calls. Iterate(f func(key K, value V) bool) }
func Merge ¶
func Merge[K comparable, V any](collection ...Map[K, V]) Map[K, V]
Merge merges all maps to the one combined map.
func MergeUnique ¶
func MergeUnique[K comparable, V any](collection ...Map[K, V]) Map[K, V]
MergeUnique merges only unique elements to the one combined map.
type UniqueMap ¶
type UniqueMap[K comparable] struct { // contains filtered or unexported fields }
UniqueMap is a thread-safe map that operates of zero-value keys and have an additional helper functions that give more flexibility to a user.
func NewUniqueMap ¶
func NewUniqueMap[K comparable]() UniqueMap[K]
NewUniqueMap returns initialized with make map.