orderedmap

package module
v0.0.0-...-3da0e2f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 2 Imported by: 9

README

orderedmap

Insertion ordered map implementation in golang.

License CircleCI Status Coverage Report Go Report Card CII Best Practices GoDoc

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

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 NewOrderedMap

func NewOrderedMap() *OrderedMap

NewOrderedMap creates a new empty OrderedMap.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL