MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / LRem

Method LRem

internal/data/list.go:365–377  ·  view source on GitHub ↗

LRem removes the first count occurrences of elements equal to value from the list stored at key. The count argument influences the operation in the following ways: count > 0: Remove elements equal to value moving from head to tail. count < 0: Remove elements equal to value moving from tail to head.

(key string, count int, cmp func(r *core.Record) (bool, error))

Source from the content-addressed store, hash-verified

363// count < 0: Remove elements equal to value moving from tail to head.
364// count = 0: Remove all elements equal to value.
365func (l *List) LRem(key string, count int, cmp func(r *core.Record) (bool, error)) error {
366 removeIndexes, err := l.GetRemoveIndexes(key, count, cmp)
367 if err != nil {
368 return err
369 }
370
371 list := l.Items[key]
372 for _, idx := range removeIndexes {
373 list.Delete(idx)
374 }
375
376 return nil
377}
378
379// LTrim trim an existing list so that it will contain only the specified range of elements specified.
380func (l *List) LTrim(key string, start, end int) error {

Callers 2

benchmarkListRemFunction · 0.95
TestList_LRemFunction · 0.95

Calls 2

GetRemoveIndexesMethod · 0.95
DeleteMethod · 0.65

Tested by 2

benchmarkListRemFunction · 0.76
TestList_LRemFunction · 0.76