Documentation
¶
Overview ¶
Package orderedmap implements an ordered map, using container/list and build-in map, it remembers the original insertion order of the keys.
All operations have O(1) time complexity.
To iterate over an ordered map (where m is a *OrderedMap):
for e:= m.Front; e != nil; e = e.Next() {
key := e.Key
value:= e.Value
// do something with e.Value
}
If you want to delete element while iterating, MUST use the following pattern:
var next *orderedmap.Element
for e := m.First(); e != nil; e = next {
key := e.Key
// assign e.Next() to the next before deleting e
next = e.Next()
m.Delete(key)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ElemVal ¶
type ElemVal struct {
Key string
Value interface{}
}
ElemVal encapsulates the key-value pair which stores in the `Value` field of list element.
type Element ¶
type Element struct {
*ElemVal
// contains filtered or unexported fields
}
Element encapsulates the underlying list element and the map's key-value pair, to provide a `Next` method for iterating.
type OrderedMap ¶
type OrderedMap struct {
// contains filtered or unexported fields
}
OrderedMap holds key-value pairs and remembers the original insertion order of the keys.
`key` stores in the map, map's value is the element of the list. for the convenience of iteration, the `Value` of list element stores the aggregate data of `key` and `value`.
func (*OrderedMap) Delete ¶
func (m *OrderedMap) Delete(key string)
Delete deletes an item from the ordered map.
func (*OrderedMap) First ¶
func (m *OrderedMap) First() *Element
First returns the first element of ordered map or nil if the orded map is empty.
func (*OrderedMap) Get ¶
func (m *OrderedMap) Get(key string) (interface{}, bool)
Get retrieves an values from ordered map under given key. If no value was associated with the given key, will return false.
func (*OrderedMap) Len ¶
func (m *OrderedMap) Len() int
Len returns the number of elements of ordered map m. The complexity is O(1).
func (*OrderedMap) Set ¶
func (m *OrderedMap) Set(key string, value interface{})
Set sets the given value under the specified key.