hash

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Hash based data structures and tool set.

RWMap is map with sync.RWMutex embedded.

StrRWMap is a string based, partitioned map, internally managing multiple RWMap to furture enhance parallel performance.

Set is a HashSet data structure backed by a map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapCopy

func MapCopy[T comparable, V any](v map[T]V) map[T]V

func MapFirst

func MapFirst[K comparable, V any](m map[K]V) V

Get first from map

func MapKV added in v0.4.11

func MapKV[T comparable, V any](m map[T]V) []pair.Pair[T, V]

func MapKeys

func MapKeys[T comparable, V any](m map[T]V) []T

Get keys from map

func MapValues

func MapValues[K comparable, V any](m map[K]V) []V

Copy values of map

func StrMap

func StrMap[T any, V any](l []T, keyMapper func(T) string, valueMapper func(T) V) map[string]V

Build a map with string type key and any type of value

func StrSliceMap

func StrSliceMap[T any, V any](l []T, keyMapper func(T) string, valueMapper func(T) V) map[string][]V

Build a map with string type key and slice value of any type

Types

type RWMap

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

Map with sync.RWMutex embeded.

func NewRWMap

func NewRWMap[K comparable, V any]() *RWMap[K, V]

Create new RWMap

func (*RWMap[K, V]) Clear

func (r *RWMap[K, V]) Clear()

func (*RWMap[K, V]) Del

func (r *RWMap[K, V]) Del(k K) (prev V, hasPrev bool)

func (*RWMap[K, V]) Get

func (r *RWMap[K, V]) Get(k K) (V, bool)

func (*RWMap[K, V]) GetElse

func (r *RWMap[K, V]) GetElse(k K, elseFunc func(k K) V) (V, bool)

func (*RWMap[K, V]) GetElseErr

func (r *RWMap[K, V]) GetElseErr(k K, elseFunc func(k K) (V, error)) (V, error)

func (*RWMap[K, V]) Keys

func (r *RWMap[K, V]) Keys() []K

func (*RWMap[K, V]) Put

func (r *RWMap[K, V]) Put(k K, v V)

func (*RWMap[K, V]) PutIfAbsent

func (r *RWMap[K, V]) PutIfAbsent(k K, f func() V)

func (*RWMap[K, V]) PutIfAbsentErr

func (r *RWMap[K, V]) PutIfAbsentErr(k K, f func() (V, error)) error

type Set

type Set[T comparable] struct {
	// Keys in Set
	Keys map[T]struct{}
}

Hash Set.

It's internally backed by a Map.

To create a new Set, use NewSet.

func NewSet

func NewSet[T comparable](keys ...T) Set[T]

Create new Set

func NewSetWithCap added in v0.4.0

func NewSetWithCap[T comparable](cap int, keys ...T) Set[T]

Create new Set with capacity.

func (*Set[T]) Add

func (s *Set[T]) Add(key T) bool

Add key to set, return true if the key wasn't present previously

func (*Set[T]) AddAll

func (s *Set[T]) AddAll(keys []T)

Add keys to set

func (*Set[T]) AddThen

func (s *Set[T]) AddThen(key T) *Set[T]

Add key to set (same as Add, but used for method chaining)

func (*Set[T]) All added in v0.4.10

func (s *Set[T]) All() iter.Seq[T]

func (*Set[T]) Clear added in v0.4.3

func (s *Set[T]) Clear()

func (*Set[T]) CopyKeys

func (s *Set[T]) CopyKeys() []T

Copy keys in set

func (*Set[T]) Del

func (s *Set[T]) Del(key T)

Delete key.

func (*Set[T]) ForEach

func (s *Set[T]) ForEach(f func(v T) (stop bool))

func (*Set[T]) ForEachErr added in v0.4.0

func (s *Set[T]) ForEachErr(f func(v T) (stop bool, err error)) error

func (Set[T]) GoString added in v0.4.0

func (s Set[T]) GoString() string

To string

func (*Set[T]) Has

func (s *Set[T]) Has(key T) bool

Test whether the key is in the set

func (*Set[T]) InSet added in v0.4.3

func (s *Set[T]) InSet(b Set[T]) iter.Seq[T]

Find keys that are in s and b.

func (*Set[T]) IsEmpty

func (s *Set[T]) IsEmpty() bool

Check if the Set is empty

func (Set[T]) MarshalJSON added in v0.3.8

func (s Set[T]) MarshalJSON() ([]byte, error)

Implements encoding/json Marshaler

func (*Set[T]) NotInSet added in v0.4.3

func (s *Set[T]) NotInSet(b Set[T]) iter.Seq[T]

Find keys that are in s but not in b.

func (*Set[T]) Scan added in v0.3.8

func (s *Set[T]) Scan(value interface{}) error

Implements sql.Scanner in database/sql.

func (*Set[T]) Size

func (s *Set[T]) Size() int

Get the size of the Set

func (Set[T]) String

func (s Set[T]) String() string

To string

func (*Set[T]) UnmarshalJSON added in v0.3.8

func (s *Set[T]) UnmarshalJSON(b []byte) error

Implements encoding/json Unmarshaler.

func (Set[T]) Value added in v0.3.8

func (s Set[T]) Value() (driver.Value, error)

Implements driver.Valuer in database/sql.

type StrRWMap

type StrRWMap[V any] struct {
	// contains filtered or unexported fields
}

func NewStrRWMap

func NewStrRWMap[V any]() *StrRWMap[V]

Create new sharded, concurrent access StrRWMap.

func (*StrRWMap[V]) Del

func (r *StrRWMap[V]) Del(k string) (V, bool)

func (*StrRWMap[V]) Get

func (r *StrRWMap[V]) Get(k string) (V, bool)

func (*StrRWMap[V]) GetElse

func (r *StrRWMap[V]) GetElse(k string, elseFunc func(k string) V) (V, bool)

func (*StrRWMap[V]) GetElseErr

func (r *StrRWMap[V]) GetElseErr(k string, elseFunc func(k string) (V, error)) (V, error)

func (*StrRWMap[V]) Keys

func (r *StrRWMap[V]) Keys() []string

func (*StrRWMap[V]) Put

func (r *StrRWMap[V]) Put(k string, v V)

func (*StrRWMap[V]) PutIfAbsent

func (r *StrRWMap[V]) PutIfAbsent(k string, f func() V)

func (*StrRWMap[V]) PutIfAbsentErr

func (r *StrRWMap[V]) PutIfAbsentErr(k string, f func() (V, error))

type SyncSet added in v0.4.10

type SyncSet[T comparable] struct {
	// contains filtered or unexported fields
}

Hash Set.

It's internally backed by a Map.

To create a new Set, use NewSet.

func NewSyncSet added in v0.4.10

func NewSyncSet[T comparable](keys ...T) *SyncSet[T]

Create new SyncSet

func (*SyncSet[T]) Add added in v0.4.10

func (s *SyncSet[T]) Add(key T) bool

Add key to set, return true if the key wasn't present previously

func (*SyncSet[T]) AddAll added in v0.4.10

func (s *SyncSet[T]) AddAll(keys []T)

Add keys to set

func (*SyncSet[T]) All added in v0.4.10

func (s *SyncSet[T]) All() iter.Seq[T]

func (*SyncSet[T]) Clear added in v0.4.10

func (s *SyncSet[T]) Clear()

func (*SyncSet[T]) CopyKeys added in v0.4.10

func (s *SyncSet[T]) CopyKeys() []T

Copy keys in set

func (*SyncSet[T]) Del added in v0.4.10

func (s *SyncSet[T]) Del(key T)

Delete key.

func (*SyncSet[T]) GoString added in v0.4.10

func (s *SyncSet[T]) GoString() string

To string

func (*SyncSet[T]) Has added in v0.4.10

func (s *SyncSet[T]) Has(key T) bool

Test whether the key is in the set

func (*SyncSet[T]) MarshalJSON added in v0.4.10

func (s *SyncSet[T]) MarshalJSON() ([]byte, error)

Implements encoding/json Marshaler

func (*SyncSet[T]) Scan added in v0.4.10

func (s *SyncSet[T]) Scan(value interface{}) error

Implements sql.Scanner in database/sql.

func (*SyncSet[T]) Size added in v0.4.10

func (s *SyncSet[T]) Size() int

Get the size of the Set

func (*SyncSet[T]) String added in v0.4.10

func (s *SyncSet[T]) String() string

To string

func (*SyncSet[T]) UnmarshalJSON added in v0.4.10

func (s *SyncSet[T]) UnmarshalJSON(b []byte) error

Implements encoding/json Unmarshaler.

func (*SyncSet[T]) Value added in v0.4.10

func (s *SyncSet[T]) Value() (driver.Value, error)

Implements driver.Valuer in database/sql.

Jump to

Keyboard shortcuts

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