search

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BubbleList

type BubbleList[Tkey comparable, Tvalue any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BubbleList contains a slice of entries that bubble up based on access frequency.

func (*BubbleList[Tkey, Tvalue]) Add

func (this *BubbleList[Tkey, Tvalue]) Add(key Tkey, value Tvalue)

Add inserts the key-value pair into this cache.

Due to chronological separation, Add is guaranteed to not interfere with any read operations.

Parameters:

  • key maps the payload value.
  • value is the payload that is mapped to key.

func (*BubbleList[Tkey, Tvalue]) All

func (this *BubbleList[Tkey, Tvalue]) All() iter.Seq2[Tkey, Tvalue]

All iterates through all key-value pairs.

All is only called during Verify, when Find calls don't reorder.

func (*BubbleList[Tkey, Tvalue]) Find

func (this *BubbleList[Tkey, Tvalue]) Find(key Tkey, reorder ReorderOption) (value Tvalue, found bool)

Find searches the cache and returns the found value (if any) and a boolean indicating success or failure.

Guaranteed to be thread-safe.

Parameters:

  • key is the search value used to find the payload value.
  • reorder indicates whether to use the reorder function or not.

Returns:

  • value is the payload value found from key.
  • found indicates if a value was found or not.

func (*BubbleList[Tkey, Tvalue]) Prepare

func (this *BubbleList[Tkey, Tvalue]) Prepare()

Prepare is called right before Verify. Any preparation before search functions is done here.

type Cache

type Cache[Tkey comparable, Tvalue any] interface {
	// Add inserts the key-value pair into this cache.
	//
	// Due to chronological separation, Add is guaranteed to not interfere with
	// any read operations.
	//
	// Parameters:
	//   - key maps the payload value.
	//   - value is the payload that is mapped to key.
	Add(key Tkey, value Tvalue)

	// All iterates through all key-value pairs.
	//
	// All is only called during Verify, when Find calls don't reorder.
	All() iter.Seq2[Tkey, Tvalue]

	// Find searches the cache and returns the found value (if any)
	// and a boolean indicating success or failure.
	//
	// Guaranteed to be thread-safe.
	//
	// Parameters:
	//   - key is the search value used to find the payload value.
	//   - reorder indicates whether to use the reorder function or not.
	//
	// Returns:
	//   - value is the payload value found from key.
	//   - found indicates if a value was found or not.
	Find(key Tkey, reorder ReorderOption) (value Tvalue, found bool)

	// Prepare is called right before Verify. Any preparation before search
	// functions is done here.
	Prepare()
}

Cache is a very basic cache implementation allowing inserts, finds, and full iterations.

type Map

type Map[Tkey comparable, Tvalue any] struct {
	// contains filtered or unexported fields
}

Map wraps a basic Go map instance.

func NewMap

func NewMap[Tkey comparable, Tvalue any]() *Map[Tkey, Tvalue]

NewMap generates a new map cache.

func (*Map[Tkey, Tvalue]) Add

func (this *Map[Tkey, Tvalue]) Add(key Tkey, value Tvalue)

Add inserts the key-value pair into this cache.

Due to chronological separation, Add is guaranteed to not interfere with any read operations.

Parameters:

  • key maps the payload value.
  • value is the payload that is mapped to key.

func (*Map[Tkey, Tvalue]) All

func (this *Map[Tkey, Tvalue]) All() iter.Seq2[Tkey, Tvalue]

All iterates through all key-value pairs.

All is only called during Verify, when Find calls don't reorder.

func (*Map[Tkey, Tvalue]) Find

func (this *Map[Tkey, Tvalue]) Find(key Tkey, reorder ReorderOption) (value Tvalue, found bool)

Find searches the cache and returns the found value (if any) and a boolean indicating success or failure.

Guaranteed to be thread-safe.

Parameters:

  • key is the search value used to find the payload value.
  • reorder indicates whether to use the reorder function or not.

Returns:

  • value is the payload value found from key.
  • found indicates if a value was found or not.

func (*Map[Tkey, Tvalue]) Prepare

func (this *Map[Tkey, Tvalue]) Prepare()

Prepare is called right before Verify. Any preparation before search functions is done here.

type PriorityList

type PriorityList[Tkey comparable, Tvalue any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PriorityList is a linked list of items that jump to the front when accessed.

func (*PriorityList[Tkey, Tvalue]) Add

func (this *PriorityList[Tkey, Tvalue]) Add(key Tkey, value Tvalue)

Add inserts the key-value pair into this cache.

Due to chronological separation, Add is guaranteed to not interfere with any read operations.

Parameters:

  • key maps the payload value.
  • value is the payload that is mapped to key.

func (*PriorityList[Tkey, Tvalue]) All

func (this *PriorityList[Tkey, Tvalue]) All() iter.Seq2[Tkey, Tvalue]

All iterates through all key-value pairs.

All is only called during Verify, when Find calls don't reorder.

func (*PriorityList[Tkey, Tvalue]) Find

func (this *PriorityList[Tkey, Tvalue]) Find(key Tkey, reorder ReorderOption) (value Tvalue, found bool)

Find searches the cache and returns the found value (if any) and a boolean indicating success or failure.

Guaranteed to be thread-safe.

Parameters:

  • key is the search value used to find the payload value.
  • reorder indicates whether to use the reorder function or not.

Returns:

  • value is the payload value found from key.
  • found indicates if a value was found or not.

func (*PriorityList[Tkey, Tvalue]) Prepare

func (this *PriorityList[Tkey, Tvalue]) Prepare()

Prepare is called right before Verify. Any preparation before search functions is done here.

type ReorderOption

type ReorderOption bool

ReorderOption defines whether to reorder during a search or not.

const (
	// NoReorder prevents the search from reordering elements.
	NoReorder ReorderOption = false

	// Reorder allows the search to reorder elements.
	Reorder ReorderOption = true
)

Jump to

Keyboard shortcuts

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