ordered

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ordered contains of ordered map structure and methods

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map stores data in ordered way, where key is equal to value

func NewMap

func NewMap() *Map

NewMap creates new instance of Map

Example
m := NewMap()
fmt.Println(reflect.TypeOf(m), m.Len())
Output:

*ordered.Map 0

func (*Map) Add

func (om *Map) Add(key interface{}) interface{}

Add pushes new element to a map. If element has already exists it will return ald value

Example
m := NewMap()
fmt.Println(m.Add("abc"), m.Add("bcd"), m.Add("abc"))
Output:

abc bcd abc

func (*Map) Delete

func (m *Map) Delete(key interface{}) bool

Delete will remove a key from the map. It will return true if the key was removed (the key did exist).

Example
m := NewMap()
m.Add("abc")
fmt.Println(m.Delete("abc"), m.Delete("abc"))
Output:

true false

func (*Map) Get

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

Get returns the value for a key.

Example
m := NewMap()
m.Add("abc")
fmt.Println(m.Get("abc"), m.Get("bcd"))
Output:

abc <nil>

func (*Map) Keys

func (m *Map) Keys() (keys []interface{})

Keys returns all of the keys in the order they were inserted.

Example
m := NewMap()
m.Add("abc")
m.Add("bcd")
fmt.Println(m.Keys())
Output:

[abc bcd]

func (*Map) Len

func (m *Map) Len() int

Len returns the number of elements in the map.

Example
m := NewMap()
fmt.Println(m.Len())
m.Add("abc")
fmt.Println(m.Len())
Output:

0
1

Jump to

Keyboard shortcuts

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