xsync

package
v0.1.36 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package xsync provides a data structure that allows for concurrent access and modification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiMap

type MultiMap[T any] struct {
	// contains filtered or unexported fields
}

MultiMap is a map that allows multiple keys to point to the same value. It is thread-safe and can be used in concurrent environments. It is not serializable.

func NewMultiMap

func NewMultiMap[T any]() *MultiMap[T]

NewMultiMap creates a new instance of MultiMap.

func (*MultiMap[T]) AddIndex

func (m *MultiMap[T]) AddIndex(key string, indexName string, indexValue string)

AddIndex adds an index to the map for the given key. It allows multiple indexes to be associated with the same key.

func (*MultiMap[T]) AddIndexByAnotherIndex

func (m *MultiMap[T]) AddIndexByAnotherIndex(
	indexName string, indexValue string,
	anotherIndexName string, anotherIndexValue string,
)

AddIndexByAnotherIndex adds an index to the map for the given index.

func (*MultiMap[T]) Delete

func (m *MultiMap[T]) Delete(key string)

Delete removes the value from the map with the given key.

func (*MultiMap[T]) DeleteByIndex

func (m *MultiMap[T]) DeleteByIndex(indexName string, indexValue string)

DeleteByIndex removes the value from the map with the given index key.

func (*MultiMap[T]) Indexes

func (m *MultiMap[T]) Indexes(indexName string) []string

Indexes returns all indexes in the map.

func (*MultiMap[T]) KeyByIndex

func (m *MultiMap[T]) KeyByIndex(indexName string, indexValue string) (string, bool)

KeyByIndex retrieves the key from the map with the given index key.

func (*MultiMap[T]) KeyValues added in v0.1.9

func (m *MultiMap[T]) KeyValues() map[string]T

KeyValues returns all key-value pairs in the map.

func (*MultiMap[T]) Keys

func (m *MultiMap[T]) Keys() []string

Keys returns all keys in the map.

func (*MultiMap[T]) Len

func (m *MultiMap[T]) Len() int

Len returns the number of items in the map.

func (*MultiMap[T]) Load

func (m *MultiMap[T]) Load(key string) (T, bool)

Load retrieves the value from the map with the given key. It returns the value and a boolean indicating whether the value was found.

func (*MultiMap[T]) LoadByIndex

func (m *MultiMap[T]) LoadByIndex(indexName string, indexValue string) (T, bool)

LoadByIndex retrieves the value from the map with the given index key. It returns the value and a boolean indicating whether the value was found.

func (*MultiMap[T]) Store

func (m *MultiMap[T]) Store(key string, value T, opts ...StoreOption)

Store stores the value in the map with the given key. It overwrites the existing value if the key already exists.

func (*MultiMap[T]) Values

func (m *MultiMap[T]) Values() []T

Values returns all values in the map.

type StoreOption

type StoreOption interface {
	// contains filtered or unexported methods
}

StoreOption is an interface for options that can be passed to the Store method.

type WithIndexImpl

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

WithIndexImpl is an implementation of StoreOption for index options.

func WithIndex

func WithIndex(indexName, indexValue string) *WithIndexImpl

WithIndex creates a index option for the Store method.

Jump to

Keyboard shortcuts

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