summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-structr/item.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-04-02 11:03:40 +0100
committerLibravatar GitHub <noreply@github.com>2024-04-02 12:03:40 +0200
commitadf345f1ec0cb76a0df94a4505143d891659cba9 (patch)
treee0cca289c0a50f30191d4b65a2c336704570e470 /vendor/codeberg.org/gruf/go-structr/item.go
parent[feature] Option to hide followers/following (#2788) (diff)
downloadgotosocial-adf345f1ec0cb76a0df94a4505143d891659cba9.tar.xz
[chore] bump go structr cache version -> v0.6.0 (#2773)
* update go-structr library -> v0.6.0, add necessary wrapping types + code changes to support these changes * update readme with go-structr package changes * improved wrapping of the SliceCache type * add code comments for the cache wrapper types * remove test.out :innocent: --------- Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-structr/item.go')
-rw-r--r--vendor/codeberg.org/gruf/go-structr/item.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-structr/item.go b/vendor/codeberg.org/gruf/go-structr/item.go
new file mode 100644
index 000000000..602c5b84a
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-structr/item.go
@@ -0,0 +1,59 @@
+package structr
+
+import (
+ "sync"
+ "unsafe"
+)
+
+type indexed_item struct {
+ // linked list elem this item
+ // is stored in a main list.
+ elem list_elem
+
+ // indexed stores the indices
+ // this item is stored under.
+ indexed []*index_entry
+
+ // cached data with type.
+ data interface{}
+}
+
+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 {
+ v = new(indexed_item)
+ }
+ item := v.(*indexed_item)
+ ptr := unsafe.Pointer(item)
+ item.elem.data = ptr
+ return item
+}
+
+// free_indexed_item releases the indexed_item.
+func free_indexed_item(item *indexed_item) {
+ item.elem.data = nil
+ item.indexed = item.indexed[:0]
+ item.data = nil
+ indexed_item_pool.Put(item)
+}
+
+// drop_index will drop the given index entry from item's indexed.
+// note this also handles freeing the index_entry memory (e.g. to pool)
+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
+ }
+
+ // Move all index entries down + reslice.
+ copy(i.indexed[x:], i.indexed[x+1:])
+ i.indexed = i.indexed[:len(i.indexed)-1]
+ break
+ }
+}