maps

package module
v0.0.0-...-fb89d6e Latest Latest
Warning

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

Go to latest
Published: May 16, 2017 License: MIT Imports: 2 Imported by: 0

README

Go List Map

GitHub license Build Status Go Report Card GoDoc

  • A ordered map implementation ordered by insertion order.
  • The ordering is done using a backing list - "container/list"
  • Why not just use a map[] ?
    • Because maps don't guarantee any order while go-list-map guarantees ordering
    • Note: Keys must be types which are allowed as the key of a standard go map.

Basic Usage

 import (
 "fmt"
 "github.com/ross-oreto/go-list-map"
 )
 
 listMap := maps.New()
 listMap.Put(1, 'Oreto').Put(2, 'Michael').Put(3, 'Ross')
 fmt.Println(listMap.Values())

Performance

go test -v -benchmem -count 1 -run none -bench .
BenchmarkListMap_Put-4                 2         529298900 ns/op        142446192 B/op   2529443 allocs/op
BenchmarkListMap_Get-4                10         114120630 ns/op               0 B/op          0 allocs/op
BenchmarkListMap_Entries-4            10         147854010 ns/op        32006144 B/op          1 allocs/op
BenchmarkListMap_DeleteAll-4         300           3884690 ns/op               0 B/op          0 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Key, Value interface{}
}

Entry represents a map key value pair entry

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is an ordered map with some extra useful methods

func New

func New() *Map

New creates a new Map and returns the Map pointer

func (*Map) Contains

func (t *Map) Contains(key interface{}) bool

Contains returns true if the map contains the key

func (*Map) ContainsAll

func (t *Map) ContainsAll(keys []interface{}) bool

ContainsAll returns true if the map contains all the keys

func (*Map) ContainsAny

func (t *Map) ContainsAny(keys []interface{}) bool

ContainsAny returns true if the map contains any of the keys

func (*Map) Delete

func (t *Map) Delete(key interface{}) *Map

Delete deletes the key from the map and returns the Map pointer

func (*Map) DeleteAll

func (t *Map) DeleteAll(keys []interface{}) *Map

DeleteAll deletes all the keys from the map and returns the Map pointer

func (*Map) Empty

func (t *Map) Empty() bool

Empty returns true if the Map is empty

func (*Map) Entries

func (t *Map) Entries() []Entry

Entries creates and returns a slice of all the map key value pair entries

func (*Map) Get

func (t *Map) Get(key interface{}) interface{}

Get gets and returns the value for the specified search key

func (*Map) Head

func (t *Map) Head() interface{}

Head returns the first value of the ordered map

func (*Map) Init

func (t *Map) Init() *Map

Init initializes/clears the Map and returns the Map pointer

func (*Map) Keys

func (t *Map) Keys() []interface{}

Keys creates and returns a slice of all the map keys

func (*Map) Len

func (t *Map) Len() int

Len returns the number of map entries

func (*Map) NotEmpty

func (t *Map) NotEmpty() bool

NotEmpty returns true if the Map is not empty

func (*Map) Pop

func (t *Map) Pop() interface{}

Pop deletes the last map entry and returns its value

func (*Map) Pull

func (t *Map) Pull() interface{}

Pull deletes the first map entry and returns its value

func (*Map) Put

func (t *Map) Put(key interface{}, value interface{}) *Map

Put enters a new key value pair into the map and returns the Map pointer

func (*Map) PutEntries

func (t *Map) PutEntries(entries []Entry) *Map

PutEntries enters all entries into the Map and returns the Map pointer

func (*Map) String

func (t *Map) String() string

String returns a string representing the map entries

func (*Map) Tail

func (t *Map) Tail() interface{}

Tail returns the last value of the ordered map

func (*Map) Values

func (t *Map) Values() []interface{}

Values creates and returns a slice of all the map values

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value represents the value of a map entry

Jump to

Keyboard shortcuts

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