Documentation ¶
Index ¶
- type Filter
- type Item
- type OrderedMap
- func (m *OrderedMap[K, V]) Back() *Item[K, V]
- func (m *OrderedMap[K, V]) Clear() *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Delete(k K) *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Front() *Item[K, V]
- func (m *OrderedMap[K, V]) Has(k K) bool
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) Load(k K) (V, bool)
- func (m *OrderedMap[K, V]) LoadOrStore(k K, v V) (actual V, loaded bool)
- func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
- func (m *OrderedMap[K, V]) Range(f func(key K, val V) bool)
- func (m *OrderedMap[K, V]) Reverse(filters ...Filter[K, V]) []V
- func (m *OrderedMap[K, V]) Slice(filters ...Filter[K, V]) []V
- func (m *OrderedMap[K, V]) Store(k K, v V) *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Travel(mode TravelMode, f Visitor[K, V], filters ...Filter[K, V])
- func (m *OrderedMap[K, V]) TravelForward(f Visitor[K, V], filters ...Filter[K, V])
- func (m *OrderedMap[K, V]) TravelReverse(f Visitor[K, V], filters ...Filter[K, V])
- type TravelMode
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter[K comparable, V any] func(idx int, key K, val V) (want bool)
Filter Used to filter elements during traversal this method receives the position index of the element in OrderedMap, and the key-value. Only when the method returns true will the element be passed to the subsequent Filter and Visitor. The relationship between multiple Filter is 'and'.
type Item ¶
type Item[K comparable, V any] struct { // contains filtered or unexported fields }
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap use List[T] to ensure order The actual key-value pair exists in the basic map All operations lock objects and use read-write mutex to reduce lock competition.
func New ¶
func New[K comparable, V any]() *OrderedMap[K, V]
New returns a pointer of *OrderedMap[K, V]
func (*OrderedMap[K, V]) Back ¶
func (m *OrderedMap[K, V]) Back() *Item[K, V]
Back returns the last Item of list l or nil if the list is empty.
func (*OrderedMap[K, V]) Clear ¶
func (m *OrderedMap[K, V]) Clear() *OrderedMap[K, V]
Clear empty saved elements
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(k K) *OrderedMap[K, V]
Delete removes key-value pair
func (*OrderedMap[K, V]) Front ¶
func (m *OrderedMap[K, V]) Front() *Item[K, V]
Front returns the first Item of list l or nil if the list is empty.
func (*OrderedMap[K, V]) Load ¶
func (m *OrderedMap[K, V]) Load(k K) (V, bool)
Load returns the value stored in the map for a key, or zero-value if no value is present, It depends on the data type. The ok result indicates whether value was found in the map.
func (*OrderedMap[K, V]) LoadOrStore ¶
func (m *OrderedMap[K, V]) LoadOrStore(k K, v V) (actual V, loaded bool)
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*OrderedMap[K, V]) MarshalJSON ¶
func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON implement the json.Marshaler interface. the interface implemented by types that can marshal themselves into valid JSON.
func (*OrderedMap[K, V]) Range ¶
func (m *OrderedMap[K, V]) Range(f func(key K, val V) bool)
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration. Deprecated: Please replace it with the TravelForward.
func (*OrderedMap[K, V]) Reverse ¶
func (m *OrderedMap[K, V]) Reverse(filters ...Filter[K, V]) []V
Reverse the elements in the array.
func (*OrderedMap[K, V]) Slice ¶
func (m *OrderedMap[K, V]) Slice(filters ...Filter[K, V]) []V
Slice returns the elements slice
func (*OrderedMap[K, V]) Store ¶
func (m *OrderedMap[K, V]) Store(k K, v V) *OrderedMap[K, V]
Store key-value pair
func (*OrderedMap[K, V]) Travel ¶
func (m *OrderedMap[K, V]) Travel(mode TravelMode, f Visitor[K, V], filters ...Filter[K, V])
Travel items with custom travel mode
func (*OrderedMap[K, V]) TravelForward ¶
func (m *OrderedMap[K, V]) TravelForward(f Visitor[K, V], filters ...Filter[K, V])
TravelForward all items with visitor and filters
func (*OrderedMap[K, V]) TravelReverse ¶
func (m *OrderedMap[K, V]) TravelReverse(f Visitor[K, V], filters ...Filter[K, V])
TravelReverse all items with visitor and filters
type TravelMode ¶
type TravelMode uint
TravelMode used to specify the direction of traversal
const ( Forward TravelMode = iota Reverse )