hashmap

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: BSD-3-Clause Imports: 10 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consistenthash

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

func NewConsistenthash

func NewConsistenthash(replicas int) (m *Consistenthash)

func (*Consistenthash) Add

func (t *Consistenthash) Add(keys ...int64)

func (*Consistenthash) Del

func (t *Consistenthash) Del(key int64)

func (*Consistenthash) Get

func (t *Consistenthash) Get(value int64) (node int64, ok bool)

func (*Consistenthash) GetNextNodeStr

func (t *Consistenthash) GetNextNodeStr(value string, step int) (nodes []int64, ok bool)

func (*Consistenthash) GetStr

func (t *Consistenthash) GetStr(value string) (node int64, ok bool)

func (*Consistenthash) Nodes

func (t *Consistenthash) Nodes() (_r []int64)

type LimitHashMap added in v0.1.2

type LimitHashMap[K int | int64 | int8 | int16 | int32 | uint | uint64 | uint8 | uint16 | uint32 | float64 | float32 | uintptr | string, V any] struct {
	// contains filtered or unexported fields
}

LimitHashMap is a capacity-limited hash map that supports different key types.

func NewLimitHashMap added in v0.1.2

func NewLimitHashMap[K int | int64 | int8 | int16 | int32 | uint | uint64 | uint8 | uint16 | uint32 | float64 | float32 | uintptr | string, V any](capacity int) *LimitHashMap[K, V]

NewLimitHashMap creates a new LimitHashMap with a specified capacity. Parameters:

capacity int - The total maximum capacity of the LimitHashMap.

Returns:

*LimitHashMap[K, V] - A new instance of a capacity-limited LimitHashMap.

func NewLimitHashMapWithSegment added in v0.1.2

func NewLimitHashMapWithSegment[K int | int64 | int8 | int16 | int32 | uint | uint64 | uint8 | uint16 | uint32 | float64 | float32 | uintptr | string, V any](capacity, segmentNumber int) *LimitHashMap[K, V]

NewLimitHashMapWithSegment creates a new LimitHashMap with a specified capacity and number of segments. Parameters:

capacity int - The total maximum capacity of the LimitHashMap.
segmentNumber int - The number of segments to divide the cache into.

Returns:

*LimitHashMap[K, V] - A new instance of a capacity-limited LimitHashMap divided into segments.

func (*LimitHashMap[K, V]) Clear added in v0.1.2

func (c *LimitHashMap[K, V]) Clear()

func (*LimitHashMap[K, V]) Contains added in v0.1.2

func (c *LimitHashMap[K, V]) Contains(key K) bool

func (*LimitHashMap[K, V]) Del added in v0.1.2

func (c *LimitHashMap[K, V]) Del(key K)

func (*LimitHashMap[K, V]) Get added in v0.1.2

func (c *LimitHashMap[K, V]) Get(key K) (r V, b bool)

func (*LimitHashMap[K, V]) Len added in v0.1.2

func (c *LimitHashMap[K, V]) Len() int

func (*LimitHashMap[K, V]) Put added in v0.1.2

func (c *LimitHashMap[K, V]) Put(key K, value V) (prev V, b bool)

type LimitMap

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

LimitMap represents a generic map with capacity limit

func NewLimitMap

func NewLimitMap[K comparable, V any](capacity int) *LimitMap[K, V]

NewLimitMap creates a new instance of LimitMap with the given capacity

func (*LimitMap[K, V]) Del added in v0.1.4

func (mc *LimitMap[K, V]) Del(key K)

Del deletes a key-value pair from the map

func (*LimitMap[K, V]) Get

func (mc *LimitMap[K, V]) Get(key K) (value V, ok bool)

Get retrieves a value from the cache by key

func (*LimitMap[K, V]) Len added in v0.1.4

func (mc *LimitMap[K, V]) Len() int

Len length of map

func (*LimitMap[K, V]) Put

func (mc *LimitMap[K, V]) Put(key K, value V) (prev V, b bool)

Put adds or updates a key-value pair in the map

func (*LimitMap[K, V]) RemoveMulti added in v0.1.2

func (mc *LimitMap[K, V]) RemoveMulti(keys []K)

RemoveMulti deletes multiple key-value pairs from the map

type LinkedHashMap added in v0.1.2

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

func NewLinkedHashMap added in v0.1.2

func NewLinkedHashMap[K, V any](limit int64) *LinkedHashMap[K, V]

func (*LinkedHashMap[K, V]) Back added in v0.1.2

func (t *LinkedHashMap[K, V]) Back() (K, V, bool)

func (*LinkedHashMap[K, V]) Clear added in v0.1.2

func (t *LinkedHashMap[K, V]) Clear()

func (*LinkedHashMap[K, V]) Delete added in v0.1.2

func (t *LinkedHashMap[K, V]) Delete(k K)

func (*LinkedHashMap[K, V]) Front added in v0.1.2

func (t *LinkedHashMap[K, V]) Front() (K, V, bool)

func (*LinkedHashMap[K, V]) Get added in v0.1.2

func (t *LinkedHashMap[K, V]) Get(k K) (_r V, b bool)

func (*LinkedHashMap[K, V]) Iterator added in v0.1.2

func (t *LinkedHashMap[K, V]) Iterator(front bool) *LinkedHashMapIterator[K, V]

func (*LinkedHashMap[K, V]) Len added in v0.1.2

func (t *LinkedHashMap[K, V]) Len() int64

func (*LinkedHashMap[K, V]) LoadOrStore added in v0.1.2

func (t *LinkedHashMap[K, V]) LoadOrStore(k K, v V) (actual V, loaded bool)

func (*LinkedHashMap[K, V]) MoveToFront added in v0.1.2

func (t *LinkedHashMap[K, V]) MoveToFront(k K)

func (*LinkedHashMap[K, V]) Put added in v0.1.2

func (t *LinkedHashMap[K, V]) Put(k K, v V)

type LinkedHashMapIterator added in v0.1.2

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

func (*LinkedHashMapIterator[K, V]) Next added in v0.1.2

func (it *LinkedHashMapIterator[K, V]) Next() (K, V, bool)

type Map

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

Map Define a generic synchronized map structure using sync.Map as the underlying data structure.

func NewMap

func NewMap[K any, V any]() *Map[K, V]

NewMap Create a new instance of a generic Map and return its pointer.

func (*Map[K, V]) Del

func (t *Map[K, V]) Del(key K) (ok bool)

func (*Map[K, V]) Get

func (t *Map[K, V]) Get(key K) (v V, b bool)

func (*Map[K, V]) Has

func (t *Map[K, V]) Has(key K) (ok bool)

func (*Map[K, V]) Put

func (t *Map[K, V]) Put(key K, value V) (prev V, b bool)

func (*Map[K, V]) Range

func (t *Map[K, V]) Range(f func(k K, v V) bool)

Range Iterate over all elements in the Map. For each element, call the provided function with the key and value. The iteration stops if the function returns false.

type MapL

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

MapL Define a generic synchronized map structure that also keeps track of its length. It uses sync.Map as the underlying data structure and an int64 variable to count the number of elements.

func NewMapL

func NewMapL[K any, V any]() *MapL[K, V]

NewMapL Create a new instance of a generic MapL and return its pointer. The initial length is set to 0.

func (*MapL[K, V]) Del

func (t *MapL[K, V]) Del(key K) (ok bool)

func (*MapL[K, V]) Get

func (t *MapL[K, V]) Get(key K) (_r V, b bool)

func (*MapL[K, V]) Has

func (t *MapL[K, V]) Has(key K) (ok bool)

func (*MapL[K, V]) Len

func (t *MapL[K, V]) Len() int64

func (*MapL[K, V]) Put

func (t *MapL[K, V]) Put(key K, value V) (prev V, b bool)

func (*MapL[K, V]) Range

func (t *MapL[K, V]) Range(f func(k K, v V) bool)

Range Iterate over all elements in the MapL. For each element, call the provided function with the key and value. The iteration stops if the function returns false.

type TreeMap added in v0.1.2

type TreeMap[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

TreeMap Define the TreeMap structure which internally uses a B-tree for storing data with an RWMutex for concurrent access control.

func NewTreeMap added in v0.1.2

func NewTreeMap[K cmp.Ordered, V any](degree int) *TreeMap[K, V]

NewTreeMap Create a new instance of TreeMap with a specified degree for the underlying B-tree.

func (*TreeMap[K, V]) Ascend added in v0.1.2

func (m *TreeMap[K, V]) Ascend(iter func(K, V) bool)

Ascend Traverse all elements in ascending order based on their keys, executing the iterator function.

func (*TreeMap[K, V]) Del added in v0.1.4

func (m *TreeMap[K, V]) Del(key K)

Del Delete a key from the TreeMap.

func (*TreeMap[K, V]) Descend added in v0.1.2

func (m *TreeMap[K, V]) Descend(iter func(K, V) bool)

Descend Traverse all elements in descending order based on their keys, executing the iterator function.

func (*TreeMap[K, V]) Get added in v0.1.2

func (m *TreeMap[K, V]) Get(key K) (V, bool)

Get Retrieve a value from the TreeMap by its key, returning the value and a boolean indicating if the key was found.

func (*TreeMap[K, V]) Put added in v0.1.2

func (m *TreeMap[K, V]) Put(key K, value V) (prev V, b bool)

Put Insert or update a key-value pair in the TreeMap.

Jump to

Keyboard shortcuts

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