Documentation ¶
Overview ¶
Package orderedmap implements an insertion-ordered associative array, also called map or dictionary. Maps are an abstract data type that can hold data in (key, value) pairs.
Associative arrays have two imporant properties. Every key can only appear once, and, every key can only have one value.
An insertion-ordered map have the extra property that when it is iterated it returns their values in order they where inserted originally.
Example
package main import ( "github.com/goombaio/orderedmap" ) func main() { m := orderedmap.NewOrderedMap() m.Put("one", "First element") m.Put("two", "Second element") m.Put("three", "Last element") for _, entry := range m.Values() { fmt.Println(entry) } // Output: // First element // Second element // Last element }
Index ¶
- type OrderedMap
- func (m *OrderedMap) Empty() bool
- func (m *OrderedMap) Get(key interface{}) (value interface{}, found bool)
- func (m *OrderedMap) Keys() []interface{}
- func (m *OrderedMap) Put(key interface{}, value interface{})
- func (m *OrderedMap) Remove(key interface{})
- func (m *OrderedMap) Size() int
- func (m *OrderedMap) String() string
- func (m *OrderedMap) Values() []interface{}
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OrderedMap ¶
type OrderedMap struct {
// contains filtered or unexported fields
}
OrderedMap represents an associative array or map abstract data type.
Example ¶
package main import ( "fmt" "github.com/goombaio/orderedmap" ) func main() { m := orderedmap.NewOrderedMap() m.Put("one", "First element") m.Put("two", "Second element") m.Put("three", "Last element") for _, entry := range m.Values() { fmt.Println(entry) } }
Output: First element Second element Last element
func (*OrderedMap) Empty ¶
func (m *OrderedMap) Empty() bool
Empty return if the map in empty or not.
func (*OrderedMap) Get ¶
func (m *OrderedMap) Get(key interface{}) (value interface{}, found bool)
Get returns the value of a key from the OrderedMap.
func (*OrderedMap) Keys ¶
func (m *OrderedMap) Keys() []interface{}
Keys return the keys in the map in insertion order.
func (*OrderedMap) Put ¶
func (m *OrderedMap) Put(key interface{}, value interface{})
Put adds items to the map.
If a key is found in the map it replaces it value.
func (*OrderedMap) Remove ¶
func (m *OrderedMap) Remove(key interface{})
Remove deletes a key-value pair from the OrderedMap.
If a key is not found in the map it doesn't fails, just does nothing.
func (*OrderedMap) Size ¶
func (m *OrderedMap) Size() int
Size return the map number of key-value pairs.
func (*OrderedMap) String ¶
func (m *OrderedMap) String() string
String implements Stringer interface.
Prints the map string representation, a concatenated string of all its string representation values in insertion order.
func (*OrderedMap) Values ¶
func (m *OrderedMap) Values() []interface{}
Values return the values in the map in insertion order.