Documentation
¶
Index ¶
- type Element
- type OrderedMap
- func (m *OrderedMap) Back() *Element
- func (m *OrderedMap) Delete(key interface{}) (didDelete bool)
- func (m *OrderedMap) Front() *Element
- func (m *OrderedMap) Get(key interface{}) (interface{}, bool)
- func (m *OrderedMap) GetOrDefault(key, defaultValue interface{}) interface{}
- func (m *OrderedMap) Keys() (keys []interface{})
- func (m *OrderedMap) Len() int
- func (m *OrderedMap) MarshalJSON() ([]byte, error)
- func (m *OrderedMap) Set(key, value interface{}) bool
- func (m *OrderedMap) UnmarshalJSON(data []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element struct {
Key, Value interface{}
// contains filtered or unexported fields
}
type OrderedMap ¶
func NewOrderedMap ¶
func NewOrderedMap() *OrderedMap
Example ¶
package main
import (
"fmt"
"github.com/abusizhishen/orderedmap"
)
func main() {
m := orderedmap.NewOrderedMap()
m.Set("foo", "bar")
m.Set("qux", 1.23)
m.Set(123, true)
m.Delete("qux")
for _, key := range m.Keys() {
value, _ := m.Get(key)
fmt.Println(key, value)
}
}
func (*OrderedMap) Back ¶
func (m *OrderedMap) Back() *Element
Back will return the element that is the last (most recent Set element). If there are no elements this will return nil.
func (*OrderedMap) Delete ¶
func (m *OrderedMap) Delete(key interface{}) (didDelete bool)
Delete will remove a key from the map. It will return true if the key was removed (the key did exist).
func (*OrderedMap) Front ¶
func (m *OrderedMap) Front() *Element
Front will return the element that is the first (oldest Set element). If there are no elements this will return nil.
Example ¶
package main
import (
"fmt"
"github.com/abusizhishen/orderedmap"
)
func main() {
m := orderedmap.NewOrderedMap()
m.Set(1, true)
m.Set(2, true)
for el := m.Front(); el != nil; el = el.Next() {
fmt.Println(el)
}
}
func (*OrderedMap) Get ¶
func (m *OrderedMap) Get(key interface{}) (interface{}, bool)
Get returns the value for a key. If the key does not exist, the second return parameter will be false and the value will be nil.
func (*OrderedMap) GetOrDefault ¶
func (m *OrderedMap) GetOrDefault(key, defaultValue interface{}) interface{}
GetOrDefault returns the value for a key. If the key does not exist, returns the default value instead.
func (*OrderedMap) Keys ¶
func (m *OrderedMap) Keys() (keys []interface{})
Keys returns all of the keys in the order they were inserted. If a key was replaced it will retain the same position. To ensure most recently set keys are always at the end you must always Delete before Set.
func (*OrderedMap) Len ¶
func (m *OrderedMap) Len() int
Len returns the number of elements in the map.
func (*OrderedMap) MarshalJSON ¶
func (m *OrderedMap) MarshalJSON() ([]byte, error)
marshal json to save
func (*OrderedMap) Set ¶
func (m *OrderedMap) Set(key, value interface{}) bool
Set will set (or replace) a value for a key. If the key was new, then true will be returned. The returned value will be false if the value was replaced (even if the value was the same).
func (*OrderedMap) UnmarshalJSON ¶
func (m *OrderedMap) UnmarshalJSON(data []byte) error
unmarshal json to load byte