orderedmap

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

orderedmap

ordered map in golang generics way, support json.Unmarsal, json.Marshal

example

package main

import (
	"encoding/json"
	"log"
	"time"

	"github.com/doublepu/orderedmap"
)

type Data struct {
	A int
	B int
}

func main() {
	o := orderedmap.NewOrderedMap[string, string]()
	//o.Set("a", "b")
	o.Set("c", "d")
	o.Set("a", "b")
	vv := map[string]string{
		"c": "d",
		"a": "b",
	}
	bb, _ := json.Marshal(vv)
	log.Println(string(bb))
	//o.Delete("c")
	for _, v := range o.List() {
		log.Println(v.K, v.V)
	}
	start := time.Now()
	b, err := json.Marshal(o)
	log.Println(string(b), err, time.Since(start))
	newO := orderedmap.NewOrderedMap[string, Data]()
	b = []byte(`{"c": {"A":2333}}`)
	log.Println(json.Unmarshal(b, newO))
	b, err = json.Marshal(newO)
	log.Println(string(b), err, time.Since(start))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OrderedMap

type OrderedMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewOrderedMap

func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]

func (*OrderedMap[K, V]) Back added in v1.1.0

func (me *OrderedMap[K, V]) Back() (kv[K, V], bool)

func (*OrderedMap[K, V]) Delete

func (me *OrderedMap[K, V]) Delete(k K)

func (*OrderedMap[K, V]) Front added in v1.1.0

func (me *OrderedMap[K, V]) Front() (kv[K, V], bool)

func (*OrderedMap[K, V]) Get

func (me *OrderedMap[K, V]) Get(k K) (v V, ok bool)

func (*OrderedMap[K, V]) Len added in v1.0.0

func (me *OrderedMap[K, V]) Len() int

func (*OrderedMap[K, V]) List

func (me *OrderedMap[K, V]) List() []kv[K, V]

func (*OrderedMap[K, V]) Map

func (me *OrderedMap[K, V]) Map() map[K]V

func (*OrderedMap[K, V]) MarshalJSON

func (me *OrderedMap[K, V]) MarshalJSON() ([]byte, error)

func (*OrderedMap[K, V]) Next added in v1.1.0

func (me *OrderedMap[K, V]) Next(k K) (kv[K, V], bool)

func (*OrderedMap[K, V]) Prev added in v1.1.0

func (me *OrderedMap[K, V]) Prev(k K) (kv[K, V], bool)

func (*OrderedMap[K, V]) Reset

func (me *OrderedMap[K, V]) Reset()

func (*OrderedMap[K, V]) Set

func (me *OrderedMap[K, V]) Set(k K, v V)

func (*OrderedMap[K, V]) UnmarshalJSON

func (me *OrderedMap[K, V]) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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