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

Method LRange

internal/data/list.go:284–304  ·  view source on GitHub ↗

LRange returns the specified elements of the list stored at key [start,end]

(key string, start, end int)

Source from the content-addressed store, hash-verified

282
283// LRange returns the specified elements of the list stored at key [start,end]
284func (l *List) LRange(key string, start, end int) ([]*core.Record, error) {
285 size, err := l.Size(key)
286 if err != nil || size == 0 {
287 return nil, err
288 }
289
290 start, end, err = checkBounds(start, end, size)
291 if err != nil {
292 return nil, err
293 }
294
295 var res []*core.Record
296 allRecords := l.Items[key].All()
297 for i, item := range allRecords {
298 if i >= start && i <= end {
299 res = append(res, item)
300 }
301 }
302
303 return res, nil
304}
305
306// GetRemoveIndexes returns a slice of indices to be removed from the list based on the count
307func (l *List) GetRemoveIndexes(key string, count int, cmp func(r *core.Record) (bool, error)) ([][]byte, error) {

Callers 3

benchmarkListRangeFunction · 0.95
TestList_MixedPushPopFunction · 0.95
ListCmpFunction · 0.45

Calls 4

SizeMethod · 0.95
checkBoundsFunction · 0.85
appendFunction · 0.85
AllMethod · 0.65

Tested by 3

benchmarkListRangeFunction · 0.76
TestList_MixedPushPopFunction · 0.76
ListCmpFunction · 0.36