generic

package
v1.1.0-beta.0...-6a6eefe Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundedMinHeap

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

BoundedMinHeap maintains the best N items efficiently using an internal min-heap. It keeps the N best items according to the comparison function. The root of the internal heap is always the worst item, making it easy to remove when a better item arrives.

func NewBoundedMinHeap

func NewBoundedMinHeap[T any](maxSize int, cmpFunc func(T, T) int) *BoundedMinHeap[T]

NewBoundedMinHeap creates a new bounded min-heap with the specified maximum size and comparison function.

func (*BoundedMinHeap[T]) Add

func (h *BoundedMinHeap[T]) Add(item T)

Add adds an item to the bounded min-heap. If the heap is full and the new item is better than the worst item, it replaces the worst item.

func (*BoundedMinHeap[T]) Len

func (h *BoundedMinHeap[T]) Len() int

Len returns the number of items in the heap.

func (*BoundedMinHeap[T]) ToSortedSlice

func (h *BoundedMinHeap[T]) ToSortedSlice() []T

ToSortedSlice returns all items in the heap as a sorted slice (best to worst).

type SyncMap

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

SyncMap is the generic version of the sync.Map.

func NewSyncMap

func NewSyncMap[K comparable, V any](capacity int) SyncMap[K, V]

NewSyncMap returns a new SyncMap.

func (*SyncMap[K, V]) Delete

func (m *SyncMap[K, V]) Delete(key K) (val V, exist bool)

Delete deletes the value for a key, returning the previous value if any. The exist result reports whether the key was present.

func (*SyncMap[K, V]) Keys

func (m *SyncMap[K, V]) Keys() []K

Keys returns all the keys in the map.

func (*SyncMap[K, V]) Load

func (m *SyncMap[K, V]) Load(key K) (V, bool)

Load loads a key value.

func (*SyncMap[K, V]) Store

func (m *SyncMap[K, V]) Store(key K, value V)

Store stores a value.

Jump to

Keyboard shortcuts

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