summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-structr/index.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/codeberg.org/gruf/go-structr/index.go')
-rw-r--r--vendor/codeberg.org/gruf/go-structr/index.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/vendor/codeberg.org/gruf/go-structr/index.go b/vendor/codeberg.org/gruf/go-structr/index.go
index 8605cdb25..127bddb1f 100644
--- a/vendor/codeberg.org/gruf/go-structr/index.go
+++ b/vendor/codeberg.org/gruf/go-structr/index.go
@@ -174,7 +174,7 @@ func (i *Index) init(t reflect.Type, cfg IndexConfig, cap int) {
// 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)
+ l := i.data.Get(key.key)
if l == nil {
return nil
}
@@ -192,7 +192,7 @@ func (i *Index) get(key string, hook func(*indexed_item)) {
}
// Get list at hash.
- l, _ := i.data.Get(key)
+ l := i.data.Get(key)
if l == nil {
return
}
@@ -237,11 +237,12 @@ func (i *Index) key(buf *byteutil.Buffer, parts []unsafe.Pointer) string {
}
// append will append the given index entry to appropriate
-// doubly-linked-list in index hashmap. this handles case
-// of key collisions and overwriting 'unique' entries.
-func (i *Index) append(key string, item *indexed_item) {
+// 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)
+ l := i.data.Get(key)
if l == nil {
@@ -255,12 +256,21 @@ func (i *Index) append(key string, item *indexed_item) {
elem := l.head
l.remove(elem)
- // Drop index from inner item.
+ // Drop index from inner item,
+ // catching the evicted item.
e := (*index_entry)(elem.data)
- e.item.drop_index(e)
+ 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.
@@ -283,7 +293,7 @@ func (i *Index) delete(key string, hook func(*indexed_item)) {
}
// Get list at hash.
- l, _ := i.data.Get(key)
+ l := i.data.Get(key)
if l == nil {
return
}
@@ -292,10 +302,9 @@ func (i *Index) delete(key string, hook func(*indexed_item)) {
i.data.Delete(key)
// Iterate entries in list.
- for x := 0; x < l.len; x++ {
+ l.rangefn(func(elem *list_elem) {
- // Pop list head.
- elem := l.head
+ // Remove elem.
l.remove(elem)
// Extract element entry + item.
@@ -310,7 +319,7 @@ func (i *Index) delete(key string, hook func(*indexed_item)) {
// Pass to hook.
hook(item)
- }
+ })
// Release list.
free_list(l)
@@ -319,7 +328,7 @@ func (i *Index) delete(key string, hook func(*indexed_item)) {
// 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)
+ l := i.data.Get(entry.key)
if l == nil {
return
}