Documentation
¶
Index ¶
- type ConcurrentOrderedMap
- func (m *ConcurrentOrderedMap[K, V]) Clear()
- func (m *ConcurrentOrderedMap[K, V]) Delete(key K)
- func (m *ConcurrentOrderedMap[K, V]) Exists(key K) bool
- func (m *ConcurrentOrderedMap[K, V]) Get(key K) (V, bool)
- func (m *ConcurrentOrderedMap[K, V]) GetOrdered() []struct{ ... }
- func (m *ConcurrentOrderedMap[K, V]) GetOrderedByField(orderBy OrderBy) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) GetOrderedByMultiField(orderBy []OrderBy) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) GetOrderedV2() []OrderedPair[K, V]
- func (m *ConcurrentOrderedMap[K, V]) Keys() []K
- func (m *ConcurrentOrderedMap[K, V]) Len() int
- func (m *ConcurrentOrderedMap[K, V]) OrderedByCombinedSimilarity(target string, caseInsensitive bool) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByCombinedSimilarityFiltered(target string, caseInsensitive bool, filter string) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByCosineTFIDF(target string, caseInsensitive bool) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByCosineTFIDFFiltered(target string, caseInsensitive bool, filter string) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByDamerauLevenshteinDistance(target string, caseInsensitive bool) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByDamerauLevenshteinDistanceFiltered(target string, caseInsensitive bool, filter string) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByJaccardNGrams(target string, caseInsensitive bool) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByJaccardNGramsFiltered(target string, caseInsensitive bool, filter string) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByJaroWinklerSimilarity(target string, caseInsensitive bool) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByJaroWinklerSimilarityFiltered(target string, caseInsensitive bool, filter string) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByLevenshteinDistance(target string, caseInsensitive bool) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByLevenshteinDistanceFiltered(target string, caseInsensitive bool, filter string) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedBySoundex(target string, caseInsensitive bool) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedBySoundexFiltered(target string, caseInsensitive bool, filter string) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByVectorCombinedSimilarity(target string, caseInsensitive bool, queryVec []float64, dims int, ...) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByVectorCombinedSimilarityFiltered(target string, caseInsensitive bool, filter string, queryVec []float64, ...) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) OrderedByVectorOnlyFiltered(caseInsensitive bool, filter string, queryVec []float64, dims int, ...) ([]OrderedPair[K, V], error)
- func (m *ConcurrentOrderedMap[K, V]) Set(key K, value V)
- func (m *ConcurrentOrderedMap[K, V]) SetOrUpdate(key K, value V, updateIfExists func(*V) V)
- func (m *ConcurrentOrderedMap[K, V]) Update(key K, updateFunc func(*V) error) error
- func (m *ConcurrentOrderedMap[K, V]) UpdateGeneric(key K, operation UpdateOperation[V]) error
- func (m *ConcurrentOrderedMap[K, V]) UpdateWithPointer(key K, updatePointerFunc func(*V) error) error
- func (m *ConcurrentOrderedMap[K, V]) Values() []V
- type DirectUpdate
- type FieldUpdate
- type FunctionUpdate
- type OrderBy
- type OrderDirection
- type OrderedPair
- type UpdateOperation
- type VectorBlendWeights
- type VectorTextExtractor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentOrderedMap ¶
type ConcurrentOrderedMap[K comparable, V any] struct { sync.RWMutex // contains filtered or unexported fields }
func NewConcurrentOrderedMap ¶
func NewConcurrentOrderedMap[K comparable, V any]() *ConcurrentOrderedMap[K, V]
NewConcurrentOrderedMap creates a new ConcurrentOrderedMap with the given key and value types It initializes the map with empty data and ensures thread-safety for concurrent operations
Returns:
- A pointer to a new ConcurrentOrderedMap[K, V] instance
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
pairs := map.GetOrderedV2()
fmt.Println(pairs) // Output: [{a 1} {b 2} {c 3}]
func NewConcurrentOrderedMapWithCapacity ¶
func NewConcurrentOrderedMapWithCapacity[K comparable, V any](initialCapacity ...int) *ConcurrentOrderedMap[K, V]
NewConcurrentOrderedMapWithCapacity creates a new ConcurrentOrderedMap with the given key and value types It initializes the map with empty data and ensures thread-safety for concurrent operations
Returns:
- A pointer to a new ConcurrentOrderedMap[K, V] instance
Example:
map := NewConcurrentOrderedMapWithCapacity[string, int](10)
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
pairs := map.GetOrderedV2()
fmt.Println(pairs) // Output: [{a 1} {b 2} {c 3}]
func (*ConcurrentOrderedMap[K, V]) Clear ¶
func (m *ConcurrentOrderedMap[K, V]) Clear()
Clear removes all key-value pairs from the map
Returns:
- The map itself
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
map.Clear()
fmt.Println(map) // Output: {}
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) Delete ¶
func (m *ConcurrentOrderedMap[K, V]) Delete(key K)
Delete removes a key-value pair from the map
Returns:
- The map itself
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
map.Delete("b")
fmt.Println(map) // Output: {a: 1, c: 3}
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) Exists ¶
func (m *ConcurrentOrderedMap[K, V]) Exists(key K) bool
Exists checks if a key exists in the map
Returns:
- true if the key exists, false otherwise
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
exists := map.Exists("a")
fmt.Println(exists) // Output: true
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) Get ¶
func (m *ConcurrentOrderedMap[K, V]) Get(key K) (V, bool)
Get retrieves a value from the map by key
Returns:
- The value associated with the key, and a boolean indicating if the key exists
- The boolean is true if the key exists, false otherwise
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
value, exists := map.Get("a")
fmt.Println(value, exists) // Output: 1 true
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) GetOrdered ¶
func (m *ConcurrentOrderedMap[K, V]) GetOrdered() []struct { Key K Value V }
GetOrdered returns a slice of key-value pairs in the order of insertion
Returns:
- A slice of key-value pairs in the order of insertion
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
pairs := map.GetOrdered()
fmt.Println(pairs) // Output: [{a 1} {b 2} {c 3}]
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) GetOrderedByField ¶
func (m *ConcurrentOrderedMap[K, V]) GetOrderedByField(orderBy OrderBy) ([]OrderedPair[K, V], error)
GetOrderedByField returns a slice of key-value pairs in the order of insertion
Returns:
- A slice of key-value pairs in the order of insertion
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
pairs := map.GetOrderedByField(OrderBy{Field: "a", Direction: ASC})
fmt.Println(pairs) // Output: [{a 1} {b 2} {c 3}]
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) GetOrderedByMultiField ¶
func (m *ConcurrentOrderedMap[K, V]) GetOrderedByMultiField(orderBy []OrderBy) ([]OrderedPair[K, V], error)
GetOrderedByMultiField returns a slice of key-value pairs in the order of insertion
Returns:
- A slice of key-value pairs in the order of insertion
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
pairs := map.GetOrderedByMultiField([]OrderBy{OrderBy{Field: "a", Direction: ASC}, OrderBy{Field: "b", Direction: DESC}})
fmt.Println(pairs) // Output: [{a 1} {b 2} {c 3}]
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) GetOrderedV2 ¶
func (m *ConcurrentOrderedMap[K, V]) GetOrderedV2() []OrderedPair[K, V]
GetOrderedV2 is a method that returns a slice of OrderedPair[K, V] It locks the map for reading and returns a copy of the map's data in the order of insertion.
Returns:
- A slice of OrderedPair[K, V] containing the key-value pairs in insertion order
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
pairs := map.GetOrderedV2()
fmt.Println(pairs) // Output: [{a 1} {b 2} {c 3}]
Note:
- The returned slice is a copy of the map's data and is safe for concurrent use
- The map is locked for reading during the operation, ensuring thread-safety
- The order of the pairs is guaranteed to be the same as the order of insertion
func (*ConcurrentOrderedMap[K, V]) Keys ¶
func (m *ConcurrentOrderedMap[K, V]) Keys() []K
Keys returns a copy of the keys in the map
Returns:
- A slice of keys in the map
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
keys := map.Keys()
fmt.Println(keys) // Output: [a b c]
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) Len ¶
func (m *ConcurrentOrderedMap[K, V]) Len() int
Len returns the number of key-value pairs in the map
Returns:
- The number of key-value pairs in the map
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
fmt.Println(map.Len()) // Output: 3
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) OrderedByCombinedSimilarity ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByCombinedSimilarity( target string, caseInsensitive bool, ) ([]OrderedPair[K, V], error)
OrderedByCombinedSimilarity orders by a weighted blend of multiple similarity metrics:
- Levenshtein (normalized as similarity)
- Damerau–Levenshtein OSA (normalized as similarity)
- Jaro–Winkler
- Cosine TF–IDF (computed over target + filtered documents)
- Soundex (phonetic)
- Jaccard N-grams (trigrams)
Higher combined score is better. Stable on ties. Requires V == string.
func (*ConcurrentOrderedMap[K, V]) OrderedByCombinedSimilarityFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByCombinedSimilarityFiltered( target string, caseInsensitive bool, filter string, ) ([]OrderedPair[K, V], error)
OrderedByCombinedSimilarityFiltered: same as above but keeps only values that contain `filter` (respects caseInsensitive) before scoring.
func (*ConcurrentOrderedMap[K, V]) OrderedByCosineTFIDF ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByCosineTFIDF( target string, caseInsensitive bool, ) ([]OrderedPair[K, V], error)
Public: Cosine TF-IDF
func (*ConcurrentOrderedMap[K, V]) OrderedByCosineTFIDFFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByCosineTFIDFFiltered( target string, caseInsensitive bool, filter string, ) ([]OrderedPair[K, V], error)
func (*ConcurrentOrderedMap[K, V]) OrderedByDamerauLevenshteinDistance ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByDamerauLevenshteinDistance( target string, caseInsensitive bool, ) ([]OrderedPair[K, V], error)
Public: Damerau–Levenshtein (OSA; adjacent transpositions)
func (*ConcurrentOrderedMap[K, V]) OrderedByDamerauLevenshteinDistanceFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByDamerauLevenshteinDistanceFiltered( target string, caseInsensitive bool, filter string, ) ([]OrderedPair[K, V], error)
Public: Damerau–Levenshtein with substring filter
func (*ConcurrentOrderedMap[K, V]) OrderedByJaccardNGrams ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByJaccardNGrams( target string, caseInsensitive bool, ) ([]OrderedPair[K, V], error)
Public: Jaccard on character trigrams (n=3). Higher is better in [0,1].
func (*ConcurrentOrderedMap[K, V]) OrderedByJaccardNGramsFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByJaccardNGramsFiltered( target string, caseInsensitive bool, filter string, ) ([]OrderedPair[K, V], error)
func (*ConcurrentOrderedMap[K, V]) OrderedByJaroWinklerSimilarity ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByJaroWinklerSimilarity( target string, caseInsensitive bool, ) ([]OrderedPair[K, V], error)
Public: Jaro–Winkler (higher is better)
func (*ConcurrentOrderedMap[K, V]) OrderedByJaroWinklerSimilarityFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByJaroWinklerSimilarityFiltered( target string, caseInsensitive bool, filter string, ) ([]OrderedPair[K, V], error)
func (*ConcurrentOrderedMap[K, V]) OrderedByLevenshteinDistance ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByLevenshteinDistance( target string, caseInsensitive bool, ) ([]OrderedPair[K, V], error)
Public: Levenshtein (no filter)
func (*ConcurrentOrderedMap[K, V]) OrderedByLevenshteinDistanceFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByLevenshteinDistanceFiltered( target string, caseInsensitive bool, filter string, ) ([]OrderedPair[K, V], error)
Public: Levenshtein with substring filter
func (*ConcurrentOrderedMap[K, V]) OrderedBySoundex ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedBySoundex( target string, caseInsensitive bool, ) ([]OrderedPair[K, V], error)
Public: Soundex-based ordering (higher is better). Score = 1.0 if Soundex codes equal, else common-prefix(codeA, codeB)/4.0.
func (*ConcurrentOrderedMap[K, V]) OrderedBySoundexFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedBySoundexFiltered( target string, caseInsensitive bool, filter string, ) ([]OrderedPair[K, V], error)
func (*ConcurrentOrderedMap[K, V]) OrderedByVectorCombinedSimilarity ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByVectorCombinedSimilarity( target string, caseInsensitive bool, queryVec []float64, dims int, extract VectorTextExtractor[V], weights *VectorBlendWeights, ) ([]OrderedPair[K, V], error)
OrderedByVectorCombinedSimilarity ranks by a weighted blend of:
- cosine(queryVec, itemVec)
- Levenshtein (norm), Damerau–Levenshtein (norm), Jaro–Winkler,
- Cosine TF–IDF (over text), Jaccard n-grams, Soundex.
No substring filter.
func (*ConcurrentOrderedMap[K, V]) OrderedByVectorCombinedSimilarityFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByVectorCombinedSimilarityFiltered( target string, caseInsensitive bool, filter string, queryVec []float64, dims int, extract VectorTextExtractor[V], weights *VectorBlendWeights, ) ([]OrderedPair[K, V], error)
OrderedByVectorCombinedSimilarityFiltered same as above but keeps only items whose TEXT contains 'filter' (respects caseInsensitive) before scoring.
func (*ConcurrentOrderedMap[K, V]) OrderedByVectorOnlyFiltered ¶ added in v1.1.0
func (m *ConcurrentOrderedMap[K, V]) OrderedByVectorOnlyFiltered( caseInsensitive bool, filter string, queryVec []float64, dims int, extract VectorTextExtractor[V], ) ([]OrderedPair[K, V], error)
Pure vector-only ordering (handy for benchmarks/comparison). Filtered.
func (*ConcurrentOrderedMap[K, V]) Set ¶
func (m *ConcurrentOrderedMap[K, V]) Set(key K, value V)
Set adds a new key-value pair to the map
Returns:
- The map itself
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
fmt.Println(map) // Output: {a: 1, b: 2, c: 3}
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) SetOrUpdate ¶
func (m *ConcurrentOrderedMap[K, V]) SetOrUpdate(key K, value V, updateIfExists func(*V) V)
SetOrUpdate sets a value in the map if the key does not exist, otherwise it updates the value
Returns:
- The map itself
Example:
map := NewConcurrentOrderedMap[string, int]()
map.SetOrUpdate("a", 1, func(current *int) *int {
*current = 2
return current
})
fmt.Println(map) // Output: {a: 2}
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) Update ¶
func (m *ConcurrentOrderedMap[K, V]) Update(key K, updateFunc func(*V) error) error
Update updates a value in the map by key using a function
Returns:
- An error if the update fails
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
err := map.Update("a", func(v *int) error {
*v = 2
return nil
})
fmt.Println(err) // Output: nil
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) UpdateGeneric ¶
func (m *ConcurrentOrderedMap[K, V]) UpdateGeneric(key K, operation UpdateOperation[V]) error
UpdateGeneric updates a value in the map by key using a generic operation
Returns:
- An error if the update fails
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
err := map.UpdateGeneric("a", DirectUpdate{NewValue: 2})
fmt.Println(err) // Output: nil
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) UpdateWithPointer ¶
func (m *ConcurrentOrderedMap[K, V]) UpdateWithPointer(key K, updatePointerFunc func(*V) error) error
UpdateWithPointer updates a value in the map by key using a pointer function
Returns:
- An error if the update fails
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
err := map.UpdateWithPointer("a", func(v *int) error {
*v = 2
return nil
})
fmt.Println(err) // Output: nil
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (*ConcurrentOrderedMap[K, V]) Values ¶
func (m *ConcurrentOrderedMap[K, V]) Values() []V
Values returns a copy of the values in the map
Returns:
- A slice of values in the map
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
map.Set("b", 2)
map.Set("c", 3)
values := map.Values()
fmt.Println(values) // Output: [1 2 3]
Note:
- The map is locked for reading during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
type DirectUpdate ¶
type DirectUpdate[V any] struct { NewValue V }
func (DirectUpdate[V]) Apply ¶
func (u DirectUpdate[V]) Apply(current V) (V, error)
type FieldUpdate ¶
FieldUpdate is a struct that contains a map of fields to update in the map
Returns:
- An error if the update fails
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
err := map.UpdateGeneric("a", FieldUpdate{Fields: map[string]interface{}{"a": 2}})
fmt.Println(err) // Output: nil
Note:
- The map is locked for writing during the operation, ensuring thread-safety
func (FieldUpdate[V]) Apply ¶
func (u FieldUpdate[V]) Apply(current V) (V, error)
Apply is a method that applies the update function to the current value
Returns:
- The updated value and an error if the update fails
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
updated, err := map.UpdateGeneric("a", FieldUpdate{Fields: map[string]interface{}{"a": 2}})
fmt.Println(updated, err) // Output: 2 nil
Note:
- The map is locked for writing during the operation, ensuring thread-safety
type FunctionUpdate ¶
FunctionUpdate is a struct that contains a function to update a value in the map
Returns:
- An error if the update fails
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
err := map.UpdateGeneric("a", FunctionUpdate{UpdateFunc: func(current *int) error {
*current = 2
return nil
}})
fmt.Println(err) // Output: nil
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
func (FunctionUpdate[V]) Apply ¶
func (u FunctionUpdate[V]) Apply(current V) (V, error)
Apply is a method that applies the update function to the current value
Returns:
- The updated value and an error if the update fails
Example:
map := NewConcurrentOrderedMap[string, int]()
map.Set("a", 1)
updated, err := map.UpdateGeneric("a", FunctionUpdate{UpdateFunc: func(current *int) error {
*current = 2
return nil
}})
fmt.Println(updated, err) // Output: 2 nil
Note:
- The map is locked for writing during the operation, ensuring thread-safety
- The operation is thread-safe and can be used concurrently by multiple goroutines
type OrderBy ¶
type OrderBy struct {
Field string
Direction OrderDirection
}
type OrderedPair ¶
type OrderedPair[K comparable, V any] struct { Key K Value V }
type UpdateOperation ¶
type VectorBlendWeights ¶ added in v1.1.0
type VectorBlendWeights struct {
WVec float64 // vector cosine similarity
WLev float64 // Levenshtein (normalized)
WDL float64 // Damerau–Levenshtein (OSA; normalized)
WJW float64 // Jaro–Winkler
WCos float64 // Cosine TF-IDF (over text)
WJac float64 // Jaccard n-grams (char)
WSdx float64 // Soundex score
NGramN int // default 3
}
func DefaultVectorBlendWeights ¶ added in v1.1.0
func DefaultVectorBlendWeights() VectorBlendWeights
Defaults tuned to give vectors strong influence while keeping textual checks meaningful.