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

Method PrefixScanEntries

tx_btree.go:352–393  ·  view source on GitHub ↗

PrefixScanEntries iterates over a key prefix at given bucket, prefix and limitNum. If reg is set a regular expression will be used to filter the found entries. LimitNum will limit the number of entries return. It will return keys and/or values based on the includeKeys and includeValues flags.

(bucket string, prefix []byte, reg string, offsetNum int, limitNum int, includeKeys, includeValues bool)

Source from the content-addressed store, hash-verified

350// found entries. LimitNum will limit the number of entries return. It will
351// return keys and/or values based on the includeKeys and includeValues flags.
352func (tx *Tx) PrefixScanEntries(bucket string, prefix []byte, reg string, offsetNum int, limitNum int, includeKeys, includeValues bool) (keys, values [][]byte, err error) {
353 // This function is a bit awkward but that is to maintain backwards
354 // compatibility while enabling the caller to pick and choose which
355 // variation to call.
356 if err := tx.checkTxIsClosed(); err != nil {
357 return nil, nil, err
358 }
359 b, err := tx.db.bucketMgr.GetBucket(DataStructureBTree, bucket)
360 if err != nil {
361 return nil, nil, err
362 }
363 bucketId := b.Id
364
365 xerr := func() error {
366 // Return expected error types based on Scan/SearchScan.
367 if reg == "" {
368 return ErrPrefixScan
369 }
370 return ErrPrefixSearchScan
371 }
372
373 if idx, ok := tx.db.Index.BTree.exist(bucketId); ok {
374 var records []*core.Record
375 if reg == "" {
376 records = idx.PrefixScan(prefix, offsetNum, limitNum)
377 } else {
378 records = idx.PrefixSearchScan(prefix, reg, offsetNum, limitNum)
379 }
380 keys, values, err = tx.getHintIdxDataItemsWrapper(records, limitNum, bucketId, includeKeys, includeValues)
381 if err != nil {
382 return nil, nil, xerr()
383 }
384 }
385
386 if includeKeys && len(keys) == 0 {
387 return nil, nil, xerr()
388 }
389 if includeValues && len(values) == 0 {
390 return nil, nil, xerr()
391 }
392 return
393}
394
395// PrefixScan iterates over a key prefix at given bucket, prefix and limitNum.
396// LimitNum will limit the number of entries return.

Callers 4

PrefixScanMethod · 0.95
PrefixSearchScanMethod · 0.95
TestTx_PrefixScanFunction · 0.80

Calls 6

checkTxIsClosedMethod · 0.95
GetBucketMethod · 0.80
existMethod · 0.80
PrefixScanMethod · 0.65
PrefixSearchScanMethod · 0.65

Tested by 2

TestTx_PrefixScanFunction · 0.64