sortedmap

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JSONParserError = fmt.Errorf("parser error")

Functions

func DeepCopyValue

func DeepCopyValue(smfvalue interface{}, force bool) interface{}

force 强制合并不同子类型的 slice,map 为 []interface{},LinkedMap[interface{}]interface{} 涉及深度 map 的并发,应用需自行处理同步控制问题

func DeepMerge

func DeepMerge(smt SortedMap, smf SortedMap, force bool)

force 强制合并不同子类型的 slice,map 为 []interface{},LinkedMap[interface{}]interface{} 涉及深度 map 的并发,应用需自行处理同步控制问题

func DeepMergeValue

func DeepMergeValue(smtvalue interface{}, smfvalue interface{}, force bool) interface{}

force 强制合并不同子类型的 slice,map 为 []interface{},LinkedMap[interface{}]interface{} 涉及深度 map 的并发,应用需自行处理同步控制问题

func Int64Compare

func Int64Compare(a, b int64) int

func IntCompare

func IntCompare(a, b int) int

func KeyCompare

func KeyCompare(a, b interface{}) int

func MapItemCompare

func MapItemCompare(a, b interface{}) int

func MarshalJSON

func MarshalJSON(sm SortedMap) (rbs []byte, err error)

func Merge

func Merge(smt Map, smf Map)

func MergeMap

func MergeMap(smt Map, smfmap interface{})

func NewRedBlackTree

func NewRedBlackTree(compare Compare) *redBlackTree

func StringCompare

func StringCompare(a, b string) int

func ToMap

func ToMap(smf Map) map[interface{}]interface{}

func ToStringMap

func ToStringMap(smf Map) map[string]interface{}

func UnmarshalJSON

func UnmarshalJSON(sm SortedMap, bs []byte) (err error)

Types

type Compare

type Compare func(a, b interface{}) int

Compare returns an integer comparing the two items lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b. likly return a - b

type Element

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

func (*Element) Next

func (e *Element) Next() *Element

Next returns the next element, or nil if it finished.

func (*Element) Prev

func (e *Element) Prev() *Element

Prev returns the previous element, or nil if it finished.

type Item

type Item interface{}

Item can be anything.

type ItemVisitor

type ItemVisitor func(i Item) bool

ItemVistor callback should return true to keep going on the visitation.

type JSONFormatError

type JSONFormatError struct {
	IndexStart int
	IndexCur   int
	Runes      []rune
	Msg        string
}

func (*JSONFormatError) Error

func (jfe *JSONFormatError) Error() string

type LinkedMap

type LinkedMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLinkedMap

func NewLinkedMap() *LinkedMap

func ToLinkedMap

func ToLinkedMap(amap map[interface{}]interface{}) *LinkedMap

func (*LinkedMap) Clear

func (m *LinkedMap) Clear()

func (*LinkedMap) Copy

func (m *LinkedMap) Copy() SortedMap

func (*LinkedMap) DeepCopy

func (m *LinkedMap) DeepCopy() SortedMap

func (*LinkedMap) Delete

func (m *LinkedMap) Delete(key interface{}) (didDelete bool)

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

func (*LinkedMap) Fetch

func (m *LinkedMap) Fetch(p func(key interface{}, value interface{}) bool)

func (*LinkedMap) FetchRange

func (m *LinkedMap) FetchRange(from interface{}, to interface{}, p func(key interface{}, value interface{}) bool, reverse bool)

func (*LinkedMap) FetchReverse

func (m *LinkedMap) FetchReverse(p func(key interface{}, value interface{}) bool)

func (*LinkedMap) First

func (m *LinkedMap) First() *Element

First will return the element that is the first (oldest Set element). If there are no elements this will return nil.

func (*LinkedMap) FirstItem

func (m *LinkedMap) FirstItem() *MapItem

func (*LinkedMap) Get

func (m *LinkedMap) Get(key interface{}, defaultValue ...interface{}) (interface{}, bool)

Get returns the value for a key. If the key does not exist, the second return parameter will be false and the value will be nil or defaultValue.

func (*LinkedMap) GetElement

func (m *LinkedMap) GetElement(key interface{}) *Element

GetElement returns the element for a key. If the key does not exist, the pointer will be nil.

func (*LinkedMap) GetValue

func (m *LinkedMap) GetValue(key interface{}, defaultValue ...interface{}) interface{}

func (*LinkedMap) Has

func (m *LinkedMap) Has(key interface{}) bool

func (*LinkedMap) Keys

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

Keys returns all of the keys in the order they were inserted. If a key was replaced it will retain the same position. To ensure most recently set keys are always at the end you must always Delete before Set.

func (*LinkedMap) Last

func (m *LinkedMap) Last() *Element

Last will return the element that is the last (most recent Set element). If there are no elements this will return nil.

func (*LinkedMap) LastItem

func (m *LinkedMap) LastItem() *MapItem

func (*LinkedMap) Len

func (m *LinkedMap) Len() int

Len returns the number of elements in the map.

func (*LinkedMap) MarshalJSON

func (m *LinkedMap) MarshalJSON() ([]byte, error)

func (*LinkedMap) Put

func (m *LinkedMap) Put(key, value interface{}) bool

Put will set (or replace) a value for a key. If the key was new, then true will be returned. The returned value will be false if the value was replaced (even if the value was the same).

func (*LinkedMap) PutAll

func (m *LinkedMap) PutAll(amap interface{}) SortedMap

func (*LinkedMap) String

func (m *LinkedMap) String() string

func (*LinkedMap) UnmarshalJSON

func (m *LinkedMap) UnmarshalJSON(bs []byte) (err error)

func (*LinkedMap) Values

func (m *LinkedMap) Values() (values []interface{})

Values returns all of the values in the order they were inserted.

type Map

type Map interface {
	// Put will set (or replace) a value for a key. If the key was new, then true
	// will be returned. The returned value will be false if the value was replaced
	// (even if the value was the same).
	Put(key interface{}, value interface{}) bool
	Delete(key interface{}) bool
	Get(key interface{}, defaultValue ...interface{}) (interface{}, bool)
	GetValue(key interface{}, defaultValue ...interface{}) interface{}
	Has(key interface{}) bool
	Len() int
	Keys() []interface{}
	Values() []interface{}
	Fetch(p func(key interface{}, value interface{}) bool)
}

type MapItem

type MapItem struct {
	Key   interface{}
	Value interface{}
}

type Node

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

type SortedMap

type SortedMap interface {
	Map
	//
	Copy() SortedMap
	// 深层复制,所有 slice,map,及所有实现了 DeepCopy 接口函数的数据 都将被递归复制
	DeepCopy() SortedMap
	// 参数 amap 只能是 map 或 SortedMap 类型, 为初始化使用方便返回当前对象自身
	PutAll(amap interface{}) SortedMap
	Clear()
	FirstItem() *MapItem
	LastItem() *MapItem
	FetchReverse(p func(key interface{}, value interface{}) bool)
	FetchRange(from interface{}, to interface{}, p func(key interface{}, value interface{}) bool, reverse bool)
	//
	UnmarshalJSON(bs []byte) (err error)
	MarshalJSON() ([]byte, error)
	String() string
}

type Treap

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

func NewTreap

func NewTreap(c Compare) *Treap

func (*Treap) Delete

func (t *Treap) Delete(target Item) *Treap

func (*Treap) Get

func (t *Treap) Get(target Item) Item

func (*Treap) Max

func (t *Treap) Max() Item

func (*Treap) Min

func (t *Treap) Min() Item

func (*Treap) Upsert

func (t *Treap) Upsert(item Item, itemPriority int) *Treap

Note: only the priority of the first insert of an item is used. Priorities from future updates on already existing items are ignored. To change the priority for an item, you need to do a Delete then an Upsert.

func (*Treap) VisitAscend

func (t *Treap) VisitAscend(pivot Item, visitor ItemVisitor)

Visit items greater-than-or-equal to the pivot, in ascending order.

func (*Treap) VisitDescend

func (t *Treap) VisitDescend(pivot Item, visitor ItemVisitor)

Visit items less-than-or-equal to the pivot, in descending order.

type TreapMap

type TreapMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTreapMap

func NewTreapMap() *TreapMap

func ToTreapMap

func ToTreapMap(amap map[interface{}]interface{}) *TreapMap

func (*TreapMap) Clear

func (m *TreapMap) Clear()

func (*TreapMap) Copy

func (m *TreapMap) Copy() SortedMap

func (*TreapMap) DeepCopy

func (m *TreapMap) DeepCopy() SortedMap

func (*TreapMap) Delete

func (m *TreapMap) Delete(key interface{}) (didDeleted bool)

func (*TreapMap) Fetch

func (m *TreapMap) Fetch(p func(key interface{}, value interface{}) bool)

func (*TreapMap) FetchRange

func (m *TreapMap) FetchRange(from interface{}, to interface{}, p func(key interface{}, value interface{}) bool, reverse bool)

func (*TreapMap) FetchReverse

func (m *TreapMap) FetchReverse(p func(key interface{}, value interface{}) bool)

func (*TreapMap) FirstItem

func (m *TreapMap) FirstItem() *MapItem

func (*TreapMap) Get

func (m *TreapMap) Get(key interface{}, defaultValue ...interface{}) (interface{}, bool)

func (*TreapMap) GetValue

func (m *TreapMap) GetValue(key interface{}, defaultValue ...interface{}) interface{}

func (*TreapMap) Has

func (m *TreapMap) Has(key interface{}) bool

func (*TreapMap) Keys

func (m *TreapMap) Keys() []interface{}

func (*TreapMap) LastItem

func (m *TreapMap) LastItem() *MapItem

func (*TreapMap) Len

func (m *TreapMap) Len() int

func (*TreapMap) MarshalJSON

func (m *TreapMap) MarshalJSON() ([]byte, error)

func (*TreapMap) Put

func (m *TreapMap) Put(key interface{}, value interface{}) bool

func (*TreapMap) PutAll

func (m *TreapMap) PutAll(amap interface{}) SortedMap

func (*TreapMap) String

func (m *TreapMap) String() string

func (*TreapMap) UnmarshalJSON

func (m *TreapMap) UnmarshalJSON(bs []byte) (err error)

func (*TreapMap) Values

func (m *TreapMap) Values() []interface{}

type TreeMap

type TreeMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTreeMap

func NewTreeMap() *TreeMap

func ToTreeMap

func ToTreeMap(amap map[interface{}]interface{}) *TreeMap

func (*TreeMap) Clear

func (m *TreeMap) Clear()

func (*TreeMap) Copy

func (m *TreeMap) Copy() SortedMap

func (*TreeMap) DeepCopy

func (m *TreeMap) DeepCopy() SortedMap

func (*TreeMap) Delete

func (m *TreeMap) Delete(key interface{}) (didDeleted bool)

func (*TreeMap) Fetch

func (m *TreeMap) Fetch(p func(key interface{}, value interface{}) bool)

func (*TreeMap) FetchRange

func (m *TreeMap) FetchRange(from interface{}, to interface{}, p func(key interface{}, value interface{}) bool, reverse bool)

func (*TreeMap) FetchReverse

func (m *TreeMap) FetchReverse(p func(key interface{}, value interface{}) bool)

func (*TreeMap) FirstItem

func (m *TreeMap) FirstItem() *MapItem

func (*TreeMap) Get

func (m *TreeMap) Get(key interface{}, defaultValue ...interface{}) (interface{}, bool)

func (*TreeMap) GetValue

func (m *TreeMap) GetValue(key interface{}, defaultValue ...interface{}) interface{}

func (*TreeMap) Has

func (m *TreeMap) Has(key interface{}) bool

func (*TreeMap) Keys

func (m *TreeMap) Keys() []interface{}

func (*TreeMap) LastItem

func (m *TreeMap) LastItem() *MapItem

func (*TreeMap) Len

func (m *TreeMap) Len() int

func (*TreeMap) MarshalJSON

func (m *TreeMap) MarshalJSON() ([]byte, error)

func (*TreeMap) Put

func (m *TreeMap) Put(key interface{}, value interface{}) bool

func (*TreeMap) PutAll

func (m *TreeMap) PutAll(amap interface{}) SortedMap

func (*TreeMap) String

func (m *TreeMap) String() string

func (*TreeMap) UnmarshalJSON

func (m *TreeMap) UnmarshalJSON(bs []byte) (err error)

func (*TreeMap) Values

func (m *TreeMap) Values() []interface{}

Jump to

Keyboard shortcuts

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