orderedmap

package
v0.0.86 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

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.New[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.New[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 New

func New[K comparable, V any](k K, v V) (m *OrderedMap[K, V])

func (*OrderedMap[K, V]) ApplyTo

func (m *OrderedMap[K, V]) ApplyTo(to *OrderedMap[K, V])

func (*OrderedMap[K, V]) Back

func (m *OrderedMap[K, V]) Back() (pair[K, V], bool)

func (*OrderedMap[K, V]) Contains

func (m *OrderedMap[K, V]) Contains(key K) bool

func (*OrderedMap[K, V]) CopyFrom

func (m *OrderedMap[K, V]) CopyFrom(from *OrderedMap[K, V])

func (*OrderedMap[K, V]) Delete

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

func (*OrderedMap[K, V]) Front

func (m *OrderedMap[K, V]) Front() (pair[K, V], bool)

func (*OrderedMap[K, V]) Get

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

func (*OrderedMap[K, V]) GoString

func (m *OrderedMap[K, V]) GoString() string

func (*OrderedMap[K, V]) InsertAfter

func (m *OrderedMap[K, V]) InsertAfter(key K, value V)

func (*OrderedMap[K, V]) InsertBefore

func (m *OrderedMap[K, V]) InsertBefore(key K, value V)

func (*OrderedMap[K, V]) Keys

func (m *OrderedMap[K, V]) Keys() (keys []K)

func (*OrderedMap[K, V]) Len

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

func (*OrderedMap[K, V]) List

func (m *OrderedMap[K, V]) List() []pair[K, V]

func (*OrderedMap[K, V]) Map

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

func (*OrderedMap[K, V]) MarshalJSON

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

func (*OrderedMap[K, V]) Next

func (m *OrderedMap[K, V]) Next(k K) (pair[K, V], bool)

func (*OrderedMap[K, V]) Prev

func (m *OrderedMap[K, V]) Prev(k K) (pair[K, V], bool)

func (*OrderedMap[K, V]) Reset

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

func (*OrderedMap[K, V]) Set

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

func (*OrderedMap[K, V]) String

func (m *OrderedMap[K, V]) String() string

func (*OrderedMap[K, V]) UnmarshalJSON

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

func (*OrderedMap[K, V]) Update

func (m *OrderedMap[K, V]) Update(k K, v V)

func (*OrderedMap[K, V]) Values

func (m *OrderedMap[K, V]) Values() (values []V)

Jump to

Keyboard shortcuts

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