summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-structr
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/codeberg.org/gruf/go-structr')
-rw-r--r--vendor/codeberg.org/gruf/go-structr/LICENSE9
-rw-r--r--vendor/codeberg.org/gruf/go-structr/README.md143
-rw-r--r--vendor/codeberg.org/gruf/go-structr/cache.go675
-rw-r--r--vendor/codeberg.org/gruf/go-structr/index.go433
-rw-r--r--vendor/codeberg.org/gruf/go-structr/item.go63
-rw-r--r--vendor/codeberg.org/gruf/go-structr/key.go58
-rw-r--r--vendor/codeberg.org/gruf/go-structr/list.go151
-rw-r--r--vendor/codeberg.org/gruf/go-structr/map.go58
-rw-r--r--vendor/codeberg.org/gruf/go-structr/ordered_list.bak180
-rw-r--r--vendor/codeberg.org/gruf/go-structr/queue.go342
-rw-r--r--vendor/codeberg.org/gruf/go-structr/queue_ctx.go152
-rw-r--r--vendor/codeberg.org/gruf/go-structr/runtime.go216
-rw-r--r--vendor/codeberg.org/gruf/go-structr/test.sh5
-rw-r--r--vendor/codeberg.org/gruf/go-structr/util.go13
14 files changed, 0 insertions, 2498 deletions
diff --git a/vendor/codeberg.org/gruf/go-structr/LICENSE b/vendor/codeberg.org/gruf/go-structr/LICENSE
deleted file mode 100644
index d6f08d0ab..000000000
--- a/vendor/codeberg.org/gruf/go-structr/LICENSE
+++ /dev/null
@@ -1,9 +0,0 @@
-MIT License
-
-Copyright (c) gruf
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/codeberg.org/gruf/go-structr/README.md b/vendor/codeberg.org/gruf/go-structr/README.md
deleted file mode 100644
index c8e1585b3..000000000
--- a/vendor/codeberg.org/gruf/go-structr/README.md
+++ /dev/null
@@ -1,143 +0,0 @@
-# go-structr
-
-A library with a series of performant data types with automated struct value indexing. Indexing is supported via arbitrary combinations of fields, and in the case of the cache type, negative results (errors!) are also supported.
-
-Under the hood, go-structr maintains a hashmap per index, where each hashmap is a hashmap keyed by serialized input key type. This is handled by the incredibly performant serialization library [go-mangler](https://codeberg.org/gruf/go-mangler), which at this point in time supports just about **any** arbitrary type, so feel free to index by *anything*!
-
-## Cache example
-
-```golang
-type Cached struct {
- Username string
- Domain string
- URL string
- CountryCode int
-}
-
-var c structr.Cache[*Cached]
-
-c.Init(structr.CacheConfig[*Cached]{
-
- // Fields this cached struct type
- // will be indexed and stored under.
- Indices: []structr.IndexConfig{
- {Fields: "Username,Domain", AllowZero: true},
- {Fields: "URL"},
- {Fields: "CountryCode", Multiple: true},
- },
-
- // Maximum LRU cache size before
- // new entries cause evictions.
- MaxSize: 1000,
-
- // User provided value copy function to
- // reduce need for reflection + ensure
- // concurrency safety for returned values.
- Copy: func(c *Cached) *Cached {
- c2 := new(Cached)
- *c2 = *c
- return c2
- },
-
- // User defined invalidation hook.
- Invalidate: func(c *Cached) {
- log.Println("invalidated:", c)
- },
-})
-
-// Access and store indexes ahead-of-time for perf.
-usernameDomainIndex := c.Index("Username,Domain")
-urlIndex := c.Index("URL")
-countryCodeIndex := c.Index("CountryCode")
-
-var url string
-
-// Generate URL index key.
-urlKey := urlIndex.Key(url)
-
-// Load value from cache, with callback function to hydrate
-// cache if value cannot be found under index name with key.
-// Negative (error) results are also cached, with user definable
-// errors to ignore from caching (e.g. context deadline errs).
-value, err := c.LoadOne(urlIndex, func() (*Cached, error) {
- return dbType.SelectByURL(url)
-}, urlKey)
-if err != nil {
- return nil, err
-}
-
-// Store value in cache, only if provided callback
-// function returns without error. Passes value through
-// invalidation hook regardless of error return value.
-//
-// On success value will be automatically added to and
-// accessible under all initially configured indices.
-if err := c.Store(value, func() error {
- return dbType.Insert(value)
-}); err != nil {
- return nil, err
-}
-
-// Generate country code index key.
-countryCodeKey := countryCodeIndex.Key(42)
-
-// Invalidate all cached results stored under
-// provided index name with give field value(s).
-c.Invalidate(countryCodeIndex, countryCodeKey)
-```
-
-## Queue example
-
-```golang
-
-type Queued struct{
- Username string
- Domain string
- URL string
- CountryCode int
-}
-
-var q structr.Queue[*Queued]
-
-q.Init(structr.QueueConfig[*Cached]{
-
- // Fields this queued struct type
- // will be indexed and stored under.
- Indices: []structr.IndexConfig{
- {Fields: "Username,Domain", AllowZero: true},
- {Fields: "URL"},
- {Fields: "CountryCode", Multiple: true},
- },
-
- // User defined pop hook.
- Pop: func(c *Cached) {
- log.Println("popped:", c)
- },
-})
-
-// Access and store indexes ahead-of-time for perf.
-usernameDomainIndex := q.Index("Username,Domain")
-urlIndex := q.Index("URL")
-countryCodeIndex := q.Index("CountryCode")
-
-// ...
-q.PushBack(Queued{
- Username: "billybob",
- Domain: "google.com",
- URL: "https://some.website.here",
- CountryCode: 42,
-})
-
-// ...
-queued, ok := q.PopFront()
-
-// Generate country code index key.
-countryCodeKey := countryCodeIndex.Key(42)
-
-// ...
-queuedByCountry := q.Pop(countryCodeIndex, countryCodeKey)
-```
-
-## Notes
-
-This is a core underpinning of [GoToSocial](https://github.com/superseriousbusiness/gotosocial)'s performance. \ No newline at end of file
diff --git a/vendor/codeberg.org/gruf/go-structr/cache.go b/vendor/codeberg.org/gruf/go-structr/cache.go
deleted file mode 100644
index 3705d7c7c..000000000
--- a/vendor/codeberg.org/gruf/go-structr/cache.go
+++ /dev/null
@@ -1,675 +0,0 @@
-package structr
-
-import (
- "context"
- "errors"
- "reflect"
- "sync"
- "unsafe"
-)
-
-// DefaultIgnoreErr is the default function used to
-// ignore (i.e. not cache) incoming error results during
-// Load() calls. By default ignores context pkg errors.
-func DefaultIgnoreErr(err error) bool {
- return errors.Is(err, context.Canceled) ||
- errors.Is(err, context.DeadlineExceeded)
-}
-
-// CacheConfig defines config vars
-// for initializing a struct cache.
-type CacheConfig[StructType any] struct {
-
- // IgnoreErr defines which errors to
- // ignore (i.e. not cache) returned
- // from load function callback calls.
- // This may be left as nil, on which
- // DefaultIgnoreErr will be used.
- IgnoreErr func(error) bool
-
- // Copy provides a means of copying
- // cached values, to ensure returned values
- // do not share memory with those in cache.
- Copy func(StructType) StructType
-
- // Invalidate is called when cache values
- // (NOT errors) are invalidated, either
- // as the values passed to Put() / Store(),
- // or by the keys by calls to Invalidate().
- Invalidate func(StructType)
-
- // Indices defines indices to create
- // in the Cache for the receiving
- // generic struct type parameter.
- Indices []IndexConfig
-
- // MaxSize defines the maximum number
- // of items allowed in the Cache at
- // one time, before old items start
- // getting evicted.
- MaxSize int
-}
-
-// Cache provides a structure cache with automated
-// indexing and lookups by any initialization-defined
-// combination of fields. This also supports caching
-// of negative results (errors!) returned by LoadOne().
-type Cache[StructType any] struct {
-
- // hook functions.
- ignore func(error) bool
- copy func(StructType) StructType
- invalid func(StructType)
-
- // keeps track of all indexed items,
- // in order of last recently used (LRU).
- lru list
-
- // indices used in storing passed struct
- // types by user defined sets of fields.
- indices []Index
-
- // max cache size, imposes size
- // limit on the lruList in order
- // to evict old entries.
- maxSize int
-
- // protective mutex, guards:
- // - Cache{}.lruList
- // - Index{}.data
- // - Cache{} hook fns
- mutex sync.Mutex
-}
-
-// Init initializes the cache with given configuration
-// including struct fields to index, and necessary fns.
-func (c *Cache[T]) Init(config CacheConfig[T]) {
- t := reflect.TypeOf((*T)(nil)).Elem()
-
- if len(config.Indices) == 0 {
- panic("no indices provided")
- }
-
- if config.IgnoreErr == nil {
- config.IgnoreErr = DefaultIgnoreErr
- }
-
- if config.Copy == nil {
- panic("copy function must be provided")
- }
-
- if config.MaxSize < 2 {
- panic("minimum cache size is 2 for LRU to work")
- }
-
- // Safely copy over
- // provided config.
- c.mutex.Lock()
- c.indices = make([]Index, len(config.Indices))
- for i, cfg := range config.Indices {
- c.indices[i].ptr = unsafe.Pointer(c)
- c.indices[i].init(t, cfg, config.MaxSize)
- }
- c.ignore = config.IgnoreErr
- c.copy = config.Copy
- c.invalid = config.Invalidate
- c.maxSize = config.MaxSize
- c.mutex.Unlock()
-}
-
-// Index selects index with given name from cache, else panics.
-func (c *Cache[T]) Index(name string) *Index {
- for i, idx := range c.indices {
- if idx.name == name {
- return &(c.indices[i])
- }
- }
- panic("unknown index: " + name)
-}
-
-// GetOne fetches value from cache stored under index, using precalculated index key.
-func (c *Cache[T]) GetOne(index *Index, key Key) (T, bool) {
- values := c.Get(index, key)
- if len(values) == 0 {
- var zero T
- return zero, false
- }
- return values[0], true
-}
-
-// Get fetches values from the cache stored under index, using precalculated index keys.
-func (c *Cache[T]) Get(index *Index, keys ...Key) []T {
- if index == nil {
- panic("no index given")
- } else if index.ptr != unsafe.Pointer(c) {
- panic("invalid index for cache")
- }
-
- // Preallocate expected ret slice.
- values := make([]T, 0, len(keys))
-
- // Acquire lock.
- c.mutex.Lock()
- defer c.mutex.Unlock()
-
- // Check cache init.
- if c.copy == nil {
- panic("not initialized")
- }
-
- for i := range keys {
- // Concatenate all *values* from cached items.
- index.get(keys[i].key, func(item *indexed_item) {
- if value, ok := item.data.(T); ok {
- // Append value COPY.
- value = c.copy(value)
- values = append(values, value)
-
- // Push to front of LRU list, USING
- // THE ITEM'S LRU ENTRY, NOT THE
- // INDEX KEY ENTRY. VERY IMPORTANT!!
- c.lru.move_front(&item.elem)
- }
- })
- }
-
- return values
-}
-
-// Put will insert the given values into cache,
-// calling any invalidate hook on each value.
-func (c *Cache[T]) Put(values ...T) {
- // Acquire lock.
- c.mutex.Lock()
-
- // Wrap unlock to only do once.
- unlock := once(c.mutex.Unlock)
- defer unlock()
-
- // Check cache init.
- if c.copy == nil {
- panic("not initialized")
- }
-
- // Store all passed values.
- for i := range values {
- c.store_value(
- nil, "",
- values[i],
- )
- }
-
- // Get func ptrs.
- invalid := c.invalid
-
- // Done with
- // the lock.
- unlock()
-
- if invalid != nil {
- // Pass all invalidated values
- // to given user hook (if set).
- for _, value := range values {
- invalid(value)
- }
- }
-}
-
-// LoadOneBy fetches one result from the cache stored under index, using precalculated index key.
-// In the case that no result is found, provided load callback will be used to hydrate the cache.
-func (c *Cache[T]) LoadOne(index *Index, key Key, load func() (T, error)) (T, error) {
- if index == nil {
- panic("no index given")
- } else if index.ptr != unsafe.Pointer(c) {
- panic("invalid index for cache")
- } else if !is_unique(index.flags) {
- panic("cannot get one by non-unique index")
- }
-
- var (
- // whether an item was found
- // (and so val / err are set).
- ok bool
-
- // separate value / error ptrs
- // as the item is liable to
- // change outside of lock.
- val T
- err error
- )
-
- // Acquire lock.
- c.mutex.Lock()
-
- // Wrap unlock to only do once.
- unlock := once(c.mutex.Unlock)
- defer unlock()
-
- // Check init'd.
- if c.copy == nil ||
- c.ignore == nil {
- panic("not initialized")
- }
-
- // Get item indexed at key.
- item := index.get_one(key)
-
- if ok = (item != nil); ok {
- var is bool
-
- if val, is = item.data.(T); is {
- // Set value COPY.
- val = c.copy(val)
-
- // Push to front of LRU list, USING
- // THE ITEM'S LRU ENTRY, NOT THE
- // INDEX KEY ENTRY. VERY IMPORTANT!!
- c.lru.move_front(&item.elem)
-
- } else {
-
- // Attempt to return error.
- err, _ = item.data.(error)
- }
- }
-
- // Get func ptrs.
- ignore := c.ignore
-
- // Done with
- // the lock.
- unlock()
-
- if ok {
- // item found!
- return val, err
- }
-
- // Load new result.
- val, err = load()
-
- // Check for ignored error types.
- if err != nil && ignore(err) {
- return val, err
- }
-
- // Acquire lock.
- c.mutex.Lock()
-
- // Index this new loaded item.
- // Note this handles copying of
- // the provided value, so it is
- // safe for us to return as-is.
- if err != nil {
- c.store_error(index, key.key, err)
- } else {
- c.store_value(index, key.key, val)
- }
-
- // Done with lock.
- c.mutex.Unlock()
-
- return val, err
-}
-
-// Load fetches values from the cache stored under index, using precalculated index keys. The cache will attempt to
-// results with values stored under keys, passing keys with uncached results to the provider load callback to further
-// hydrate the cache with missing results. Cached error results not included or returned by this function.
-func (c *Cache[T]) Load(index *Index, keys []Key, load func([]Key) ([]T, error)) ([]T, error) {
- if index == nil {
- panic("no index given")
- } else if index.ptr != unsafe.Pointer(c) {
- panic("invalid index for cache")
- }
-
- // Preallocate expected ret slice.
- values := make([]T, 0, len(keys))
-
- // Acquire lock.
- c.mutex.Lock()
-
- // Wrap unlock to only do once.
- unlock := once(c.mutex.Unlock)
- defer unlock()
-
- // Check init'd.
- if c.copy == nil {
- panic("not initialized")
- }
-
- // Iterate keys and catch uncached.
- toLoad := make([]Key, 0, len(keys))
- for _, key := range keys {
-
- // Value length before
- // any below appends.
- before := len(values)
-
- // Concatenate all *values* from cached items.
- index.get(key.key, func(item *indexed_item) {
- if value, ok := item.data.(T); ok {
- // Append value COPY.
- value = c.copy(value)
- values = append(values, value)
-
- // Push to front of LRU list, USING
- // THE ITEM'S LRU ENTRY, NOT THE
- // INDEX KEY ENTRY. VERY IMPORTANT!!
- c.lru.move_front(&item.elem)
- }
- })
-
- // Only if values changed did
- // we actually find anything.
- if len(values) == before {
- toLoad = append(toLoad, key)
- }
- }
-
- // Done with
- // the lock.
- unlock()
-
- if len(toLoad) == 0 {
- // We loaded everything!
- return values, nil
- }
-
- // Load uncached key values.
- uncached, err := load(toLoad)
- if err != nil {
- return nil, err
- }
-
- // Acquire lock.
- c.mutex.Lock()
-
- // Store all uncached values.
- for i := range uncached {
- c.store_value(
- nil, "",
- uncached[i],
- )
- }
-
- // Done with lock.
- c.mutex.Unlock()
-
- // Append uncached to return values.
- values = append(values, uncached...)
-
- return values, nil
-}
-
-// Store will call the given store callback, on non-error then
-// passing the provided value to the Put() function. On error
-// return the value is still passed to stored invalidate hook.
-func (c *Cache[T]) Store(value T, store func() error) error {
- // Store value.
- err := store()
- if err != nil {
-
- // Get func ptrs.
- c.mutex.Lock()
- invalid := c.invalid
- c.mutex.Unlock()
-
- // On error don't store
- // value, but still pass
- // to invalidate hook.
- if invalid != nil {
- invalid(value)
- }
-
- return err
- }
-
- // Store value.
- c.Put(value)
-
- return nil
-}
-
-// Invalidate invalidates all results stored under index keys.
-func (c *Cache[T]) Invalidate(index *Index, keys ...Key) {
- if index == nil {
- panic("no index given")
- } else if index.ptr != unsafe.Pointer(c) {
- panic("invalid index for cache")
- }
-
- // Acquire lock.
- c.mutex.Lock()
-
- // Preallocate expected ret slice.
- values := make([]T, 0, len(keys))
-
- for i := range keys {
- // Delete all items under key from index, collecting
- // value items and dropping them from all their indices.
- index.delete(keys[i].key, func(item *indexed_item) {
-
- if value, ok := item.data.(T); ok {
- // No need to copy, as item
- // being deleted from cache.
- values = append(values, value)
- }
-
- // Delete cached.
- c.delete(item)
- })
- }
-
- // Get func ptrs.
- invalid := c.invalid
-
- // Done with lock.
- c.mutex.Unlock()
-
- if invalid != nil {
- // Pass all invalidated values
- // to given user hook (if set).
- for _, value := range values {
- invalid(value)
- }
- }
-}
-
-// Trim will truncate the cache to ensure it
-// stays within given percentage of MaxSize.
-func (c *Cache[T]) Trim(perc float64) {
- // Acquire lock.
- c.mutex.Lock()
-
- // Calculate number of cache items to drop.
- max := (perc / 100) * float64(c.maxSize)
- diff := c.lru.len - int(max)
- if diff <= 0 {
-
- // Trim not needed.
- c.mutex.Unlock()
- return
- }
-
- // Iterate over 'diff' items
- // from back (oldest) of cache.
- for i := 0; i < diff; i++ {
-
- // Get oldest LRU elem.
- oldest := c.lru.tail
- if oldest == nil {
-
- // reached
- // end.
- break
- }
-
- // Drop oldest item from cache.
- item := (*indexed_item)(oldest.data)
- c.delete(item)
- }
-
- // Compact index data stores.
- for _, idx := range c.indices {
- (&idx).data.Compact()
- }
-
- // Done with lock.
- c.mutex.Unlock()
-}
-
-// Clear empties the cache by calling .Trim(0).
-func (c *Cache[T]) Clear() { c.Trim(0) }
-
-// Len returns the current length of cache.
-func (c *Cache[T]) Len() int {
- c.mutex.Lock()
- l := c.lru.len
- c.mutex.Unlock()
- return l
-}
-
-// Debug returns debug stats about cache.
-func (c *Cache[T]) Debug() map[string]any {
- m := make(map[string]any, 2)
- c.mutex.Lock()
- m["lru"] = c.lru.len
- indices := make(map[string]any, len(c.indices))
- m["indices"] = indices
- for _, idx := range c.indices {
- var n uint64
- for _, l := range idx.data.m {
- n += uint64(l.len)
- }
- indices[idx.name] = n
- }
- c.mutex.Unlock()
- return m
-}
-
-// Cap returns the maximum capacity (size) of cache.
-func (c *Cache[T]) Cap() int {
- c.mutex.Lock()
- m := c.maxSize
- c.mutex.Unlock()
- return m
-}
-
-func (c *Cache[T]) store_value(index *Index, key string, value T) {
- // Alloc new index item.
- item := new_indexed_item()
- if cap(item.indexed) < len(c.indices) {
-
- // Preallocate item indices slice to prevent Go auto
- // allocating overlying large slices we don't need.
- item.indexed = make([]*index_entry, 0, len(c.indices))
- }
-
- // Create COPY of value.
- value = c.copy(value)
- item.data = value
-
- if index != nil {
- // Append item to index a key
- // was already generated for.
- index.append(&c.lru, key, item)
- }
-
- // Get ptr to value data.
- ptr := unsafe.Pointer(&value)
-
- // Acquire key buf.
- buf := new_buffer()
-
- for i := range c.indices {
- // Get current index ptr.
- idx := (&c.indices[i])
- if idx == index {
-
- // Already stored under
- // this index, ignore.
- continue
- }
-
- // Extract fields comprising index key.
- parts := extract_fields(ptr, idx.fields)
- if parts == nil {
- continue
- }
-
- // Calculate index key.
- key := idx.key(buf, parts)
- if key == "" {
- continue
- }
-
- // Append item to this index.
- idx.append(&c.lru, key, item)
- }
-
- // Add item to main lru list.
- c.lru.push_front(&item.elem)
-
- // Done with buf.
- free_buffer(buf)
-
- if c.lru.len > c.maxSize {
- // Cache has hit max size!
- // Drop the oldest element.
- ptr := c.lru.tail.data
- item := (*indexed_item)(ptr)
- c.delete(item)
- }
-}
-
-func (c *Cache[T]) store_error(index *Index, key string, err error) {
- if index == nil {
- // nothing we
- // can do here.
- return
- }
-
- // Alloc new index item.
- item := new_indexed_item()
- if cap(item.indexed) < len(c.indices) {
-
- // Preallocate item indices slice to prevent Go auto
- // allocating overlying large slices we don't need.
- item.indexed = make([]*index_entry, 0, len(c.indices))
- }
-
- // Set error val.
- item.data = err
-
- // Append item to index a key
- // was already generated for.
- index.append(&c.lru, key, item)
-
- // Add item to main lru list.
- c.lru.push_front(&item.elem)
-
- if c.lru.len > c.maxSize {
- // Cache has hit max size!
- // Drop the oldest element.
- ptr := c.lru.tail.data
- item := (*indexed_item)(ptr)
- c.delete(item)
- }
-}
-
-func (c *Cache[T]) delete(item *indexed_item) {
- for len(item.indexed) != 0 {
- // Pop last indexed entry from list.
- entry := item.indexed[len(item.indexed)-1]
- item.indexed = item.indexed[:len(item.indexed)-1]
-
- // Drop index_entry from index.
- entry.index.delete_entry(entry)
- }
-
- // Drop entry from lru list.
- c.lru.remove(&item.elem)
-
- // Free now-unused item.
- free_indexed_item(item)
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/index.go b/vendor/codeberg.org/gruf/go-structr/index.go
deleted file mode 100644
index 558832da9..000000000
--- a/vendor/codeberg.org/gruf/go-structr/index.go
+++ /dev/null
@@ -1,433 +0,0 @@
-package structr
-
-import (
- "reflect"
- "strings"
- "sync"
- "unsafe"
-
- "codeberg.org/gruf/go-byteutil"
-)
-
-// IndexConfig defines config variables
-// for initializing a struct index.
-type IndexConfig struct {
-
- // Fields should contain a comma-separated
- // list of struct fields used when generating
- // keys for this index. Nested fields should
- // be specified using periods. An example:
- // "Username,Favorites.Color"
- //
- // Note that nested fields where the nested
- // struct field is a ptr are supported, but
- // nil ptr values in nesting will result in
- // that particular value NOT being indexed.
- // e.g. with "Favorites.Color" if *Favorites
- // is nil then it will not be indexed.
- //
- // Field types supported include any of those
- // supported by the `go-mangler` library.
- Fields string
-
- // Multiple indicates whether to accept multiple
- // possible values for any single index key. The
- // default behaviour is to only accept one value
- // and overwrite existing on any write operation.
- Multiple bool
-
- // AllowZero indicates whether to accept zero
- // value fields in index keys. i.e. whether to
- // index structs for this set of field values
- // IF any one of those field values is the zero
- // value for that type. The default behaviour
- // is to skip indexing structs for this lookup
- // when any of the indexing fields are zero.
- AllowZero bool
-}
-
-// Index is an exposed Cache internal model, used to
-// extract struct keys, generate hash checksums for them
-// and store struct results by the init defined config.
-// This model is exposed to provide faster lookups in the
-// case that you would like to manually provide the used
-// index via the Cache.___By() series of functions, or
-// access the underlying index key generator.
-type Index struct {
-
- // ptr is a pointer to
- // the source Cache/Queue
- // index is attached to.
- ptr unsafe.Pointer
-
- // name is the actual name of this
- // index, which is the unparsed
- // string value of contained fields.
- name string
-
- // backing data store of the index, containing
- // the cached results contained within wrapping
- // index_entry{} which also contains the exact
- // key each result is stored under. the hash map
- // only keys by the xxh3 hash checksum for speed.
- data hashmap
-
- // struct fields encompassed by
- // keys (+ hashes) of this index.
- fields []struct_field
-
- // index flags:
- // - 1 << 0 = unique
- // - 1 << 1 = allow zero
- flags uint8
-}
-
-// Name returns the receiving Index name.
-func (i *Index) Name() string {
- return i.name
-}
-
-// Key generates Key{} from given parts for
-// the type of lookup this Index uses in cache.
-// NOTE: panics on incorrect no. parts / types given.
-func (i *Index) Key(parts ...any) Key {
- ptrs := make([]unsafe.Pointer, len(parts))
- for x, part := range parts {
- ptrs[x] = eface_data(part)
- }
- buf := new_buffer()
- key := i.key(buf, ptrs)
- free_buffer(buf)
- return Key{
- raw: parts,
- key: key,
- }
-}
-
-// Keys generates []Key{} from given (multiple) parts
-// for the type of lookup this Index uses in the cache.
-// NOTE: panics on incorrect no. parts / types given.
-func (i *Index) Keys(parts ...[]any) []Key {
- keys := make([]Key, 0, len(parts))
- buf := new_buffer()
- for _, parts := range parts {
- ptrs := make([]unsafe.Pointer, len(parts))
- for x, part := range parts {
- ptrs[x] = eface_data(part)
- }
- key := i.key(buf, ptrs)
- if key == "" {
- continue
- }
- keys = append(keys, Key{
- raw: parts,
- key: key,
- })
- }
- free_buffer(buf)
- return keys
-}
-
-// init will initialize the cache with given type, config and capacity.
-func (i *Index) init(t reflect.Type, cfg IndexConfig, cap int) {
- switch {
- // The only 2 types we support are
- // structs, and ptrs to a struct.
- case t.Kind() == reflect.Struct:
- case t.Kind() == reflect.Pointer &&
- t.Elem().Kind() == reflect.Struct:
- default:
- panic("index only support struct{} and *struct{}")
- }
-
- // Set name from the raw
- // struct fields string.
- i.name = cfg.Fields
-
- // Set struct flags.
- if cfg.AllowZero {
- set_allow_zero(&i.flags)
- }
- if !cfg.Multiple {
- set_is_unique(&i.flags)
- }
-
- // Split to get containing struct fields.
- fields := strings.Split(cfg.Fields, ",")
-
- // Preallocate expected struct field slice.
- i.fields = make([]struct_field, len(fields))
- for x, name := range fields {
-
- // Split name to account for nesting.
- names := strings.Split(name, ".")
-
- // Look for usable struct field.
- i.fields[x] = find_field(t, names)
- }
-
- // Initialize store for
- // index_entry lists.
- i.data.init(cap)
-}
-
-// get_one will fetch one indexed item under key.
-func (i *Index) get_one(key Key) *indexed_item {
- // Get list at hash.
- l := i.data.Get(key.key)
- if l == nil {
- return nil
- }
-
- // Extract entry from first list elem.
- entry := (*index_entry)(l.head.data)
-
- return entry.item
-}
-
-// get will fetch all indexed items under key, passing each to hook.
-func (i *Index) get(key string, hook func(*indexed_item)) {
- if hook == nil {
- panic("nil hook")
- }
-
- // Get list at hash.
- l := i.data.Get(key)
- if l == nil {
- return
- }
-
- // Iterate the list.
- for elem := l.head; //
- elem != nil; //
- {
- // Get next before
- // any modification.
- next := elem.next
-
- // Extract element entry + item.
- entry := (*index_entry)(elem.data)
- item := entry.item
-
- // Pass to hook.
- hook(item)
-
- // Set next.
- elem = next
- }
-}
-
-// key uses hasher to generate Key{} from given raw parts.
-func (i *Index) key(buf *byteutil.Buffer, parts []unsafe.Pointer) string {
- buf.B = buf.B[:0]
- if len(parts) != len(i.fields) {
- panicf("incorrect number key parts: want=%d received=%d",
- len(i.fields),
- len(parts),
- )
- }
- if !allow_zero(i.flags) {
- for x, field := range i.fields {
- before := len(buf.B)
- buf.B = field.mangle(buf.B, parts[x])
- if string(buf.B[before:]) == field.zerostr {
- return ""
- }
- buf.B = append(buf.B, '.')
- }
- } else {
- for x, field := range i.fields {
- buf.B = field.mangle(buf.B, parts[x])
- buf.B = append(buf.B, '.')
- }
- }
- return string(buf.B)
-}
-
-// append will append the given index entry to appropriate
-// doubly-linked-list in index hashmap. this handles case of
-// overwriting "unique" index entries, and removes from given
-// outer linked-list in the case that it is no longer indexed.
-func (i *Index) append(ll *list, key string, item *indexed_item) {
- // Look for existing.
- l := i.data.Get(key)
-
- if l == nil {
-
- // Allocate new.
- l = new_list()
- i.data.Put(key, l)
-
- } else if is_unique(i.flags) {
-
- // Remove head.
- elem := l.head
- l.remove(elem)
-
- // Drop index from inner item,
- // catching the evicted item.
- e := (*index_entry)(elem.data)
- evicted := e.item
- evicted.drop_index(e)
-
- // Free unused entry.
- free_index_entry(e)
-
- if len(evicted.indexed) == 0 {
- // Evicted item is not indexed,
- // remove from outer linked list.
- ll.remove(&evicted.elem)
- free_indexed_item(evicted)
- }
- }
-
- // Prepare new index entry.
- entry := new_index_entry()
- entry.item = item
- entry.key = key
- entry.index = i
-
- // Add ourselves to item's index tracker.
- item.indexed = append(item.indexed, entry)
-
- // Add entry to index list.
- l.push_front(&entry.elem)
-}
-
-// delete will remove all indexed items under key, passing each to hook.
-func (i *Index) delete(key string, hook func(*indexed_item)) {
- if hook == nil {
- panic("nil hook")
- }
-
- // Get list at hash.
- l := i.data.Get(key)
- if l == nil {
- return
- }
-
- // Delete at hash.
- i.data.Delete(key)
-
- // Iterate the list.
- for elem := l.head; //
- elem != nil; //
- {
- // Get next before
- // any modification.
- next := elem.next
-
- // Remove elem.
- l.remove(elem)
-
- // Extract element entry + item.
- entry := (*index_entry)(elem.data)
- item := entry.item
-
- // Drop index from item.
- item.drop_index(entry)
-
- // Free now-unused entry.
- free_index_entry(entry)
-
- // Pass to hook.
- hook(item)
-
- // Set next.
- elem = next
- }
-
- // Release list.
- free_list(l)
-}
-
-// delete_entry deletes the given index entry.
-func (i *Index) delete_entry(entry *index_entry) {
- // Get list at hash sum.
- l := i.data.Get(entry.key)
- if l == nil {
- return
- }
-
- // Remove list entry.
- l.remove(&entry.elem)
-
- if l.len == 0 {
- // Remove entry from map.
- i.data.Delete(entry.key)
-
- // Release list.
- free_list(l)
- }
-
- // Drop this index from item.
- entry.item.drop_index(entry)
-}
-
-// index_entry represents a single entry
-// in an Index{}, where it will be accessible
-// by Key{} pointing to a containing list{}.
-type index_entry struct {
-
- // list elem that entry is stored
- // within, under containing index.
- // elem.data is ptr to index_entry.
- elem list_elem
-
- // index this is stored in.
- index *Index
-
- // underlying indexed item.
- item *indexed_item
-
- // raw cache key
- // for this entry.
- key string
-}
-
-var index_entry_pool sync.Pool
-
-// new_index_entry returns a new prepared index_entry.
-func new_index_entry() *index_entry {
- v := index_entry_pool.Get()
- if v == nil {
- e := new(index_entry)
- e.elem.data = unsafe.Pointer(e)
- v = e
- }
- entry := v.(*index_entry)
- return entry
-}
-
-// free_index_entry releases the index_entry.
-func free_index_entry(entry *index_entry) {
- if entry.elem.next != nil ||
- entry.elem.prev != nil {
- should_not_reach()
- return
- }
- entry.key = ""
- entry.index = nil
- entry.item = nil
- index_entry_pool.Put(entry)
-}
-
-func is_unique(f uint8) bool {
- const mask = uint8(1) << 0
- return f&mask != 0
-}
-
-func set_is_unique(f *uint8) {
- const mask = uint8(1) << 0
- (*f) |= mask
-}
-
-func allow_zero(f uint8) bool {
- const mask = uint8(1) << 1
- return f&mask != 0
-}
-
-func set_allow_zero(f *uint8) {
- const mask = uint8(1) << 1
- (*f) |= mask
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/item.go b/vendor/codeberg.org/gruf/go-structr/item.go
deleted file mode 100644
index 6178e18e3..000000000
--- a/vendor/codeberg.org/gruf/go-structr/item.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package structr
-
-import (
- "sync"
- "unsafe"
-)
-
-type indexed_item struct {
- // linked list elem this item
- // is stored in a main list.
- elem list_elem
-
- // cached data with type.
- data interface{}
-
- // indexed stores the indices
- // this item is stored under.
- indexed []*index_entry
-}
-
-var indexed_item_pool sync.Pool
-
-// new_indexed_item returns a new prepared indexed_item.
-func new_indexed_item() *indexed_item {
- v := indexed_item_pool.Get()
- if v == nil {
- i := new(indexed_item)
- i.elem.data = unsafe.Pointer(i)
- v = i
- }
- item := v.(*indexed_item)
- return item
-}
-
-// free_indexed_item releases the indexed_item.
-func free_indexed_item(item *indexed_item) {
- if len(item.indexed) > 0 ||
- item.elem.next != nil ||
- item.elem.prev != nil {
- should_not_reach()
- return
- }
- item.data = nil
- indexed_item_pool.Put(item)
-}
-
-// drop_index will drop the given index entry from item's indexed.
-func (i *indexed_item) drop_index(entry *index_entry) {
- for x := 0; x < len(i.indexed); x++ {
- if i.indexed[x] != entry {
- // Prof. Obiwan:
- // this is not the index
- // we are looking for.
- continue
- }
-
- // Reslice index entries minus 'x'.
- _ = copy(i.indexed[x:], i.indexed[x+1:])
- i.indexed[len(i.indexed)-1] = nil
- i.indexed = i.indexed[:len(i.indexed)-1]
- break
- }
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/key.go b/vendor/codeberg.org/gruf/go-structr/key.go
deleted file mode 100644
index 65bdba455..000000000
--- a/vendor/codeberg.org/gruf/go-structr/key.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package structr
-
-import (
- "sync"
-
- "codeberg.org/gruf/go-byteutil"
-)
-
-// Key represents one key to
-// lookup (potentially) stored
-// entries in an Index.
-type Key struct {
- key string
- raw []any
-}
-
-// Key returns the underlying cache key string.
-// NOTE: this will not be log output friendly.
-func (k Key) Key() string {
- return k.key
-}
-
-// Equal returns whether keys are equal.
-func (k Key) Equal(o Key) bool {
- return (k.key == o.key)
-}
-
-// Value returns the raw slice of
-// values that comprise this Key.
-func (k Key) Values() []any {
- return k.raw
-}
-
-// Zero indicates a zero value key.
-func (k Key) Zero() bool {
- return (k.raw == nil)
-}
-
-var buf_pool sync.Pool
-
-// new_buffer returns a new initialized byte buffer.
-func new_buffer() *byteutil.Buffer {
- v := buf_pool.Get()
- if v == nil {
- buf := new(byteutil.Buffer)
- buf.B = make([]byte, 0, 512)
- v = buf
- }
- return v.(*byteutil.Buffer)
-}
-
-// free_buffer releases the byte buffer.
-func free_buffer(buf *byteutil.Buffer) {
- if cap(buf.B) > int(^uint16(0)) {
- return // drop large bufs
- }
- buf_pool.Put(buf)
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/list.go b/vendor/codeberg.org/gruf/go-structr/list.go
deleted file mode 100644
index bf380aa26..000000000
--- a/vendor/codeberg.org/gruf/go-structr/list.go
+++ /dev/null
@@ -1,151 +0,0 @@
-package structr
-
-import (
- "sync"
- "unsafe"
-)
-
-// elem represents an elem
-// in a doubly-linked list.
-type list_elem struct {
- next *list_elem
- prev *list_elem
-
- // data is a ptr to the
- // value this linked list
- // element is embedded-in.
- data unsafe.Pointer
-}
-
-// list implements a doubly-linked list, where:
-// - head = index 0 (i.e. the front)
-// - tail = index n-1 (i.e. the back)
-type list struct {
- head *list_elem
- tail *list_elem
- len int
-}
-
-var list_pool sync.Pool
-
-// new_list returns a new prepared list.
-func new_list() *list {
- v := list_pool.Get()
- if v == nil {
- v = new(list)
- }
- list := v.(*list)
- return list
-}
-
-// free_list releases the list.
-func free_list(list *list) {
- if list.head != nil ||
- list.tail != nil ||
- list.len != 0 {
- should_not_reach()
- return
- }
- list_pool.Put(list)
-}
-
-// push_front will push the given elem to front (head) of list.
-func (l *list) push_front(elem *list_elem) {
- // Set new head.
- oldHead := l.head
- l.head = elem
-
- if oldHead != nil {
- // Link to old head
- elem.next = oldHead
- oldHead.prev = elem
- } else {
- // First in list.
- l.tail = elem
- }
-
- // Incr count
- l.len++
-}
-
-// push_back will push the given elem to back (tail) of list.
-func (l *list) push_back(elem *list_elem) {
- // Set new tail.
- oldTail := l.tail
- l.tail = elem
-
- if oldTail != nil {
- // Link to old tail
- elem.prev = oldTail
- oldTail.next = elem
- } else {
- // First in list.
- l.head = elem
- }
-
- // Incr count
- l.len++
-}
-
-// move_front will move given elem to front (head) of list.
-// if it is already at front this call is a no-op.
-func (l *list) move_front(elem *list_elem) {
- if elem == l.head {
- return
- }
- l.remove(elem)
- l.push_front(elem)
-}
-
-// move_back will move given elem to back (tail) of list,
-// if it is already at back this call is a no-op.
-func (l *list) move_back(elem *list_elem) {
- if elem == l.tail {
- return
- }
- l.remove(elem)
- l.push_back(elem)
-}
-
-// remove will remove given elem from list.
-func (l *list) remove(elem *list_elem) {
- // Get linked elems.
- next := elem.next
- prev := elem.prev
-
- // Unset elem.
- elem.next = nil
- elem.prev = nil
-
- switch {
- case next == nil:
- if prev == nil {
- // next == nil && prev == nil
- //
- // elem is ONLY one in list.
- l.head = nil
- l.tail = nil
- } else {
- // next == nil && prev != nil
- //
- // elem is last in list.
- l.tail = prev
- prev.next = nil
- }
-
- case prev == nil:
- // next != nil && prev == nil
- //
- // elem is front in list.
- l.head = next
- next.prev = nil
-
- // elem in middle of list.
- default:
- next.prev = prev
- prev.next = next
- }
-
- // Decr count
- l.len--
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/map.go b/vendor/codeberg.org/gruf/go-structr/map.go
deleted file mode 100644
index 316a8e528..000000000
--- a/vendor/codeberg.org/gruf/go-structr/map.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package structr
-
-type hashmap struct {
- m map[string]*list
- n int
-}
-
-func (m *hashmap) init(cap int) {
- m.m = make(map[string]*list, cap)
- m.n = cap
-}
-
-func (m *hashmap) Get(key string) *list {
- return m.m[key]
-}
-
-func (m *hashmap) Put(key string, list *list) {
- m.m[key] = list
- if n := len(m.m); n > m.n {
- m.n = n
- }
-}
-
-func (m *hashmap) Delete(key string) {
- delete(m.m, key)
-}
-
-func (m *hashmap) Compact() {
- // Noop when hashmap size
- // is too small to matter.
- if m.n < 2048 {
- return
- }
-
- // Difference between maximum map
- // size and the current map size.
- diff := m.n - len(m.m)
-
- // Maximum load factor before
- // runtime allocates new hmap:
- // maxLoad = 13 / 16
- //
- // So we apply the inverse/2, once
- // $maxLoad/2 % of hmap is empty we
- // compact the map to drop buckets.
- if 2*16*diff > m.n*13 {
-
- // Create new map only big as required.
- m2 := make(map[string]*list, len(m.m))
- for k, v := range m.m {
- m2[k] = v
- }
-
- // Set new.
- m.m = m2
- m.n = len(m2)
- }
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/ordered_list.bak b/vendor/codeberg.org/gruf/go-structr/ordered_list.bak
deleted file mode 100644
index 46b56853f..000000000
--- a/vendor/codeberg.org/gruf/go-structr/ordered_list.bak
+++ /dev/null
@@ -1,180 +0,0 @@
-package structr
-
-import "sync"
-
-type Timeline[StructType any, PK comparable] struct {
-
- // hook functions.
- pkey func(StructType) PK
- gte func(PK, PK) bool
- lte func(PK, PK) bool
- copy func(StructType) StructType
-
- // main underlying
- // ordered item list.
- list list
-
- // indices used in storing passed struct
- // types by user defined sets of fields.
- indices []Index
-
- // protective mutex, guards:
- // - TODO
- mutex sync.Mutex
-}
-
-func (t *Timeline[T, PK]) Init(config any) {
-
-}
-
-func (t *Timeline[T, PK]) Index(name string) *Index {
- for i := range t.indices {
- if t.indices[i].name == name {
- return &t.indices[i]
- }
- }
- panic("unknown index: " + name)
-}
-
-func (t *Timeline[T, PK]) Insert(values ...T) {
-
-}
-
-func (t *Timeline[T, PK]) LoadTop(min, max PK, length int, load func(min, max PK, length int) ([]T, error)) ([]T, error) {
- // Allocate expected no. values.
- values := make([]T, 0, length)
-
- // Acquire lock.
- t.mutex.Lock()
-
- // Wrap unlock to only do once.
- unlock := once(t.mutex.Unlock)
- defer unlock()
-
- // Check init'd.
- if t.copy == nil {
- panic("not initialized")
- }
-
- // Iterate through linked list from top (i.e. head).
- for next := t.list.head; next != nil; next = next.next {
-
- // Check if we've gathered
- // enough values from timeline.
- if len(values) >= length {
- return values, nil
- }
-
- item := (*indexed_item)(next.data)
- value := item.data.(T)
- pkey := t.pkey(value)
-
- // Check if below min.
- if t.lte(pkey, min) {
- continue
- }
-
- // Update min.
- min = pkey
-
- // Check if above max.
- if t.gte(pkey, max) {
- break
- }
-
- // Append value copy.
- value = t.copy(value)
- values = append(values, value)
- }
-}
-
-func (t *Timeline[T, PK]) LoadBottom(min, max PK, length int, load func(min, max PK, length int) ([]T, error)) ([]T, error) {
- // Allocate expected no. values.
- values := make([]T, 0, length)
-
- // Acquire lock.
- t.mutex.Lock()
-
- // Wrap unlock to only do once.
- unlock := once(t.mutex.Unlock)
- defer unlock()
-
- // Check init'd.
- if t.copy == nil {
- panic("not initialized")
- }
-
- // Iterate through linked list from bottom (i.e. tail).
- for next := t.list.tail; next != nil; next = next.prev {
-
- // Check if we've gathered
- // enough values from timeline.
- if len(values) >= length {
- return values, nil
- }
-
- item := (*indexed_item)(next.data)
- value := item.data.(T)
- pkey := t.pkey(value)
-
- // Check if above max.
- if t.gte(pkey, max) {
- continue
- }
-
- // Update max.
- max = pkey
-
- // Check if below min.
- if t.lte(pkey, min) {
- break
- }
-
- // Append value copy.
- value = t.copy(value)
- values = append(values, value)
- }
-
- // Done with
- // the lock.
- unlock()
-
- // Attempt to load values up to given length.
- next, err := load(min, max, length-len(values))
- if err != nil {
- return nil, err
- }
-
- // Acquire lock.
- t.mutex.Lock()
-
- // Store uncached values.
- for i := range next {
- t.store_value(
- nil, "",
- uncached[i],
- )
- }
-
- // Done with lock.
- t.mutex.Unlock()
-
- // Append uncached to return values.
- values = append(values, next...)
-
- return values, nil
-}
-
-func (t *Timeline[T, PK]) index(value T) *indexed_item {
- pk := t.pkey(value)
-
- switch {
- case t.list.len == 0:
-
- case pk < t.list.head.data:
- }
-}
-
-func (t *Timeline[T, PK]) delete(item *indexed_item) {
-
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/queue.go b/vendor/codeberg.org/gruf/go-structr/queue.go
deleted file mode 100644
index dab925f95..000000000
--- a/vendor/codeberg.org/gruf/go-structr/queue.go
+++ /dev/null
@@ -1,342 +0,0 @@
-package structr
-
-import (
- "reflect"
- "sync"
- "unsafe"
-)
-
-// QueueConfig defines config vars
-// for initializing a struct queue.
-type QueueConfig[StructType any] struct {
-
- // Pop is called when queue values
- // are popped, during calls to any
- // of the Pop___() series of fns.
- Pop func(StructType)
-
- // Indices defines indices to create
- // in the Queue for the receiving
- // generic struct parameter type.
- Indices []IndexConfig
-}
-
-// Queue provides a structure model queue with
-// automated indexing and popping by any init
-// defined lookups of field combinations.
-type Queue[StructType any] struct {
-
- // hook functions.
- copy func(StructType) StructType
- pop func(StructType)
-
- // main underlying
- // struct item queue.
- queue list
-
- // indices used in storing passed struct
- // types by user defined sets of fields.
- indices []Index
-
- // protective mutex, guards:
- // - Queue{}.queue
- // - Index{}.data
- // - Queue{} hook fns
- mutex sync.Mutex
-}
-
-// Init initializes the queue with given configuration
-// including struct fields to index, and necessary fns.
-func (q *Queue[T]) Init(config QueueConfig[T]) {
- t := reflect.TypeOf((*T)(nil)).Elem()
-
- if len(config.Indices) == 0 {
- panic("no indices provided")
- }
-
- // Safely copy over
- // provided config.
- q.mutex.Lock()
- q.indices = make([]Index, len(config.Indices))
- for i, cfg := range config.Indices {
- q.indices[i].ptr = unsafe.Pointer(q)
- q.indices[i].init(t, cfg, 0)
- }
- q.pop = config.Pop
- q.mutex.Unlock()
-}
-
-// Index selects index with given name from queue, else panics.
-func (q *Queue[T]) Index(name string) *Index {
- for i, idx := range q.indices {
- if idx.name == name {
- return &(q.indices[i])
- }
- }
- panic("unknown index: " + name)
-}
-
-// PopFront pops the current value at front of the queue.
-func (q *Queue[T]) PopFront() (T, bool) {
- t := q.PopFrontN(1)
- if len(t) == 0 {
- var t T
- return t, false
- }
- return t[0], true
-}
-
-// PopBack pops the current value at back of the queue.
-func (q *Queue[T]) PopBack() (T, bool) {
- t := q.PopBackN(1)
- if len(t) == 0 {
- var t T
- return t, false
- }
- return t[0], true
-}
-
-// PopFrontN attempts to pop n values from front of the queue.
-func (q *Queue[T]) PopFrontN(n int) []T {
- return q.pop_n(n, func() *list_elem {
- return q.queue.head
- })
-}
-
-// PopBackN attempts to pop n values from back of the queue.
-func (q *Queue[T]) PopBackN(n int) []T {
- return q.pop_n(n, func() *list_elem {
- return q.queue.tail
- })
-}
-
-// Pop attempts to pop values from queue indexed under any of keys.
-func (q *Queue[T]) Pop(index *Index, keys ...Key) []T {
- if index == nil {
- panic("no index given")
- } else if index.ptr != unsafe.Pointer(q) {
- panic("invalid index for queue")
- }
-
- // Acquire lock.
- q.mutex.Lock()
-
- // Preallocate expected ret slice.
- values := make([]T, 0, len(keys))
-
- for i := range keys {
- // Delete all items under key from index, collecting
- // value items and dropping them from all their indices.
- index.delete(keys[i].key, func(item *indexed_item) {
-
- // Append deleted to values.
- value := item.data.(T)
- values = append(values, value)
-
- // Delete queued.
- q.delete(item)
- })
- }
-
- // Get func ptrs.
- pop := q.pop
-
- // Done with lock.
- q.mutex.Unlock()
-
- if pop != nil {
- // Pass all popped values
- // to given user hook (if set).
- for _, value := range values {
- pop(value)
- }
- }
-
- return values
-}
-
-// PushFront pushes values to front of queue.
-func (q *Queue[T]) PushFront(values ...T) {
- q.mutex.Lock()
- for i := range values {
- item := q.index(values[i])
- q.queue.push_front(&item.elem)
- }
- q.mutex.Unlock()
-}
-
-// PushBack pushes values to back of queue.
-func (q *Queue[T]) PushBack(values ...T) {
- q.mutex.Lock()
- for i := range values {
- item := q.index(values[i])
- q.queue.push_back(&item.elem)
- }
- q.mutex.Unlock()
-}
-
-// MoveFront attempts to move values indexed under any of keys to the front of the queue.
-func (q *Queue[T]) MoveFront(index *Index, keys ...Key) {
- q.mutex.Lock()
- for i := range keys {
- index.get(keys[i].key, func(item *indexed_item) {
- q.queue.move_front(&item.elem)
- })
- }
- q.mutex.Unlock()
-}
-
-// MoveBack attempts to move values indexed under any of keys to the back of the queue.
-func (q *Queue[T]) MoveBack(index *Index, keys ...Key) {
- q.mutex.Lock()
- for i := range keys {
- index.get(keys[i].key, func(item *indexed_item) {
- q.queue.move_back(&item.elem)
- })
- }
- q.mutex.Unlock()
-}
-
-// Len returns the current length of queue.
-func (q *Queue[T]) Len() int {
- q.mutex.Lock()
- l := q.queue.len
- q.mutex.Unlock()
- return l
-}
-
-// Debug returns debug stats about queue.
-func (q *Queue[T]) Debug() map[string]any {
- m := make(map[string]any, 2)
- q.mutex.Lock()
- m["queue"] = q.queue.len
- indices := make(map[string]any, len(q.indices))
- m["indices"] = indices
- for _, idx := range q.indices {
- var n uint64
- for _, l := range idx.data.m {
- n += uint64(l.len)
- }
- indices[idx.name] = n
- }
- q.mutex.Unlock()
- return m
-}
-
-func (q *Queue[T]) pop_n(n int, next func() *list_elem) []T {
- if next == nil {
- panic("nil fn")
- }
-
- // Acquire lock.
- q.mutex.Lock()
-
- // Preallocate ret slice.
- values := make([]T, 0, n)
-
- // Iterate over 'n' items.
- for i := 0; i < n; i++ {
-
- // Get next elem.
- next := next()
- if next == nil {
-
- // reached
- // end.
- break
- }
-
- // Cast the indexed item from elem.
- item := (*indexed_item)(next.data)
-
- // Append deleted to values.
- value := item.data.(T)
- values = append(values, value)
-
- // Delete queued.
- q.delete(item)
- }
-
- // Get func ptrs.
- pop := q.pop
-
- // Done with lock.
- q.mutex.Unlock()
-
- if pop != nil {
- // Pass all popped values
- // to given user hook (if set).
- for _, value := range values {
- pop(value)
- }
- }
-
- return values
-}
-
-func (q *Queue[T]) index(value T) *indexed_item {
- item := new_indexed_item()
- if cap(item.indexed) < len(q.indices) {
-
- // Preallocate item indices slice to prevent Go auto
- // allocating overlying large slices we don't need.
- item.indexed = make([]*index_entry, 0, len(q.indices))
- }
-
- // Set item value.
- item.data = value
-
- // Get ptr to value data.
- ptr := unsafe.Pointer(&value)
-
- // Acquire key buf.
- buf := new_buffer()
-
- for i := range q.indices {
- // Get current index ptr.
- idx := &(q.indices[i])
-
- // Extract fields comprising index key.
- parts := extract_fields(ptr, idx.fields)
- if parts == nil {
- continue
- }
-
- // Calculate index key.
- key := idx.key(buf, parts)
- if key == "" {
- continue
- }
-
- // Append item to this index.
- idx.append(&q.queue, key, item)
- }
-
- // Done with buf.
- free_buffer(buf)
-
- return item
-}
-
-func (q *Queue[T]) delete(item *indexed_item) {
- for len(item.indexed) != 0 {
- // Pop last indexed entry from list.
- entry := item.indexed[len(item.indexed)-1]
- item.indexed = item.indexed[:len(item.indexed)-1]
-
- // Get entry's index.
- index := entry.index
-
- // Drop this index_entry.
- index.delete_entry(entry)
-
- // Check compact map.
- index.data.Compact()
- }
-
- // Drop entry from queue list.
- q.queue.remove(&item.elem)
-
- // Free now-unused item.
- free_indexed_item(item)
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/queue_ctx.go b/vendor/codeberg.org/gruf/go-structr/queue_ctx.go
deleted file mode 100644
index 1dac46349..000000000
--- a/vendor/codeberg.org/gruf/go-structr/queue_ctx.go
+++ /dev/null
@@ -1,152 +0,0 @@
-package structr
-
-import (
- "context"
-)
-
-// QueueCtx is a context-aware form of Queue{}.
-type QueueCtx[StructType any] struct {
- ch chan struct{}
- Queue[StructType]
-}
-
-// PopFront pops the current value at front of the queue, else blocking on ctx.
-func (q *QueueCtx[T]) PopFront(ctx context.Context) (T, bool) {
- return q.pop(ctx, func() *list_elem {
- return q.queue.head
- })
-}
-
-// PopBack pops the current value at back of the queue, else blocking on ctx.
-func (q *QueueCtx[T]) PopBack(ctx context.Context) (T, bool) {
- return q.pop(ctx, func() *list_elem {
- return q.queue.tail
- })
-}
-
-// PushFront pushes values to front of queue.
-func (q *QueueCtx[T]) PushFront(values ...T) {
- q.mutex.Lock()
- for i := range values {
- item := q.index(values[i])
- q.queue.push_front(&item.elem)
- }
- if q.ch != nil {
- close(q.ch)
- q.ch = nil
- }
- q.mutex.Unlock()
-}
-
-// PushBack pushes values to back of queue.
-func (q *QueueCtx[T]) PushBack(values ...T) {
- q.mutex.Lock()
- for i := range values {
- item := q.index(values[i])
- q.queue.push_back(&item.elem)
- }
- if q.ch != nil {
- close(q.ch)
- q.ch = nil
- }
- q.mutex.Unlock()
-}
-
-// Wait returns a ptr to the current ctx channel,
-// this will block until next push to the queue.
-func (q *QueueCtx[T]) Wait() <-chan struct{} {
- q.mutex.Lock()
- if q.ch == nil {
- q.ch = make(chan struct{})
- }
- ctx := q.ch
- q.mutex.Unlock()
- return ctx
-}
-
-// Debug returns debug stats about queue.
-func (q *QueueCtx[T]) Debug() map[string]any {
- m := make(map[string]any)
- q.mutex.Lock()
- m["queue"] = q.queue.len
- indices := make(map[string]any)
- m["indices"] = indices
- for i := range q.indices {
- var n uint64
- for _, l := range q.indices[i].data.m {
- n += uint64(l.len)
- }
- indices[q.indices[i].name] = n
- }
- q.mutex.Unlock()
- return m
-}
-
-func (q *QueueCtx[T]) pop(ctx context.Context, next func() *list_elem) (T, bool) {
- if next == nil {
- panic("nil fn")
- } else if ctx == nil {
- panic("nil ctx")
- }
-
- // Acquire lock.
- q.mutex.Lock()
-
- var elem *list_elem
-
- for {
- // Get element.
- elem = next()
- if elem != nil {
- break
- }
-
- if q.ch == nil {
- // Allocate new ctx channel.
- q.ch = make(chan struct{})
- }
-
- // Get current
- // ch pointer.
- ch := q.ch
-
- // Unlock queue.
- q.mutex.Unlock()
-
- select {
- // Ctx cancelled.
- case <-ctx.Done():
- var z T
- return z, false
-
- // Pushed!
- case <-ch:
- }
-
- // Relock queue.
- q.mutex.Lock()
- }
-
- // Cast the indexed item from elem.
- item := (*indexed_item)(elem.data)
-
- // Extract item value.
- value := item.data.(T)
-
- // Delete queued.
- q.delete(item)
-
- // Get func ptrs.
- pop := q.Queue.pop
-
- // Done with lock.
- q.mutex.Unlock()
-
- if pop != nil {
- // Pass to
- // user hook.
- pop(value)
- }
-
- return value, true
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/runtime.go b/vendor/codeberg.org/gruf/go-structr/runtime.go
deleted file mode 100644
index 6e8af83dd..000000000
--- a/vendor/codeberg.org/gruf/go-structr/runtime.go
+++ /dev/null
@@ -1,216 +0,0 @@
-package structr
-
-import (
- "fmt"
- "os"
- "reflect"
- "runtime"
- "strings"
- "unicode"
- "unicode/utf8"
- "unsafe"
-
- "codeberg.org/gruf/go-mangler"
-)
-
-// struct_field contains pre-prepared type
-// information about a struct's field member,
-// including memory offset and hash function.
-type struct_field struct {
- rtype reflect.Type
-
- // struct field type mangling
- // (i.e. fast serializing) fn.
- mangle mangler.Mangler
-
- // zero value data, used when
- // nil encountered during ptr
- // offset following.
- zero unsafe.Pointer
-
- // mangled zero value string,
- // if set this indicates zero
- // values of field not allowed
- zerostr string
-
- // offsets defines whereabouts in
- // memory this field is located.
- offsets []next_offset
-}
-
-// next_offset defines a next offset location
-// in a struct_field, first by the number of
-// derefences required, then by offset from
-// that final memory location.
-type next_offset struct {
- derefs uint
- offset uintptr
-}
-
-// find_field will search for a struct field with given set of names,
-// where names is a len > 0 slice of names account for struct nesting.
-func find_field(t reflect.Type, names []string) (sfield struct_field) {
- var (
- // is_exported returns whether name is exported
- // from a package; can be func or struct field.
- is_exported = func(name string) bool {
- r, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(r)
- }
-
- // pop_name pops the next name from
- // the provided slice of field names.
- pop_name = func() string {
- name := names[0]
- names = names[1:]
- if !is_exported(name) {
- panicf("field is not exported: %s", name)
- }
- return name
- }
-
- // field is the iteratively searched
- // struct field value in below loop.
- field reflect.StructField
- )
-
- for len(names) > 0 {
- // Pop next name.
- name := pop_name()
-
- var off next_offset
-
- // Dereference any ptrs to struct.
- for t.Kind() == reflect.Pointer {
- t = t.Elem()
- off.derefs++
- }
-
- // Check for valid struct type.
- if t.Kind() != reflect.Struct {
- panicf("field %s is not struct (or ptr-to): %s", t, name)
- }
-
- var ok bool
-
- // Look for next field by name.
- field, ok = t.FieldByName(name)
- if !ok {
- panicf("unknown field: %s", name)
- }
-
- // Set next offset value.
- off.offset = field.Offset
- sfield.offsets = append(sfield.offsets, off)
-
- // Set the next type.
- t = field.Type
- }
-
- // Set final type.
- sfield.rtype = t
-
- // Find mangler for field type.
- sfield.mangle = mangler.Get(t)
-
- // Get new zero value data ptr.
- v := reflect.New(t).Elem()
- zptr := eface_data(v.Interface())
- zstr := sfield.mangle(nil, zptr)
- sfield.zerostr = string(zstr)
- sfield.zero = zptr
-
- return
-}
-
-// extract_fields extracts given structfields from the provided value type,
-// this is done using predetermined struct field memory offset locations.
-func extract_fields(ptr unsafe.Pointer, fields []struct_field) []unsafe.Pointer {
- // Prepare slice of field value pointers.
- ptrs := make([]unsafe.Pointer, len(fields))
- for i, field := range fields {
-
- // loop scope.
- fptr := ptr
-
- for _, offset := range field.offsets {
- // Dereference any ptrs to offset.
- fptr = deref(fptr, offset.derefs)
- if fptr == nil {
- break
- }
-
- // Jump forward by offset to next ptr.
- fptr = unsafe.Pointer(uintptr(fptr) +
- offset.offset)
- }
-
- if like_ptr(field.rtype) && fptr != nil {
- // Further dereference value ptr.
- fptr = *(*unsafe.Pointer)(fptr)
- }
-
- if fptr == nil {
- // Use zero value.
- fptr = field.zero
- }
-
- // Set field ptr.
- ptrs[i] = fptr
- }
-
- return ptrs
-}
-
-// like_ptr returns whether type's kind is ptr-like.
-func like_ptr(t reflect.Type) bool {
- switch t.Kind() {
- case reflect.Pointer,
- reflect.Map,
- reflect.Chan,
- reflect.Func:
- return true
- }
- return false
-}
-
-// deref will dereference ptr 'n' times (or until nil).
-func deref(p unsafe.Pointer, n uint) unsafe.Pointer {
- for ; n > 0; n-- {
- if p == nil {
- return nil
- }
- p = *(*unsafe.Pointer)(p)
- }
- return p
-}
-
-// eface_data returns the data ptr from an empty interface.
-func eface_data(a any) unsafe.Pointer {
- type eface struct{ _, data unsafe.Pointer }
- return (*eface)(unsafe.Pointer(&a)).data
-}
-
-// panicf provides a panic with string formatting.
-func panicf(format string, args ...any) {
- panic(fmt.Sprintf(format, args...))
-}
-
-// should_not_reach can be called to indicated a
-// block of code should not be able to be reached,
-// else it prints callsite info with a BUG report.
-//
-//go:noinline
-func should_not_reach() {
- pcs := make([]uintptr, 1)
- _ = runtime.Callers(2, pcs)
- fn := runtime.FuncForPC(pcs[0])
- funcname := "go-structr" // by default use just our library name
- if fn != nil {
- funcname = fn.Name()
- if i := strings.LastIndexByte(funcname, '/'); i != -1 {
- funcname = funcname[i+1:]
- }
- }
- os.Stderr.WriteString("BUG: assertion failed in " + funcname + "\n")
-}
diff --git a/vendor/codeberg.org/gruf/go-structr/test.sh b/vendor/codeberg.org/gruf/go-structr/test.sh
deleted file mode 100644
index 554417df7..000000000
--- a/vendor/codeberg.org/gruf/go-structr/test.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-set -e
-go test -v -tags=structr_32bit_hash .
-go test -v -tags=structr_48bit_hash .
-go test -v -tags=structr_64bit_hash . \ No newline at end of file
diff --git a/vendor/codeberg.org/gruf/go-structr/util.go b/vendor/codeberg.org/gruf/go-structr/util.go
deleted file mode 100644
index 46535fcff..000000000
--- a/vendor/codeberg.org/gruf/go-structr/util.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package structr
-
-// once only executes 'fn' once.
-func once(fn func()) func() {
- var once int32
- return func() {
- if once != 0 {
- return
- }
- once = 1
- fn()
- }
-}