README
¶
orderedmap
Insertion ordered map implementation in golang.
Install
go get github.com/goombaio/orderedmap
You can also update an already installed version:
go get -u github.com/goombaio/orderedmap
Example of use
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
}
License
Copyright (c) 2018 Goomba project Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
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.
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.