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

Method Has

tx_btree.go:260–289  ·  view source on GitHub ↗

Has returns true if the record exists. It checks without retrieving the value from disk making lookups significantly faster while keeping memory usage down as well. It does require the `HintKeyAndRAMIdxMode` option to be enabled to function as described.

(bucket string, key []byte)

Source from the content-addressed store, hash-verified

258// usage down as well. It does require the `HintKeyAndRAMIdxMode` option to be
259// enabled to function as described.
260func (tx *Tx) Has(bucket string, key []byte) (exists bool, err error) {
261 if err := tx.checkTxIsClosed(); err != nil {
262 return false, err
263 }
264
265 status, b := tx.getBucketAndItsStatus(DataStructureBTree, bucket)
266 if isBucketNotFoundStatus(status) {
267 return false, ErrNotFoundBucket
268 }
269 bucketId := b.Id
270
271 status, _ = tx.findEntryAndItsStatus(DataStructureBTree, bucket, string(key))
272 switch status {
273 case EntryDeleted:
274 return false, ErrKeyNotFound
275 case EntryUpdated:
276 return true, nil
277 }
278
279 idx, bucketExists := tx.db.Index.BTree.exist(bucketId)
280 if !bucketExists {
281 return false, ErrBucketNotExist
282 }
283
284 if _, recordExists := idx.Find(key); recordExists {
285 return true, nil
286 }
287
288 return false, nil
289}
290
291// RangeScanEntries query a range at given bucket, start and end slice. It will
292// return keys and/or values based on the includeKeys and includeValues flags.

Callers 4

txHasFunction · 0.80

Calls 6

checkTxIsClosedMethod · 0.95
getBucketAndItsStatusMethod · 0.95
findEntryAndItsStatusMethod · 0.95
isBucketNotFoundStatusFunction · 0.85
existMethod · 0.80
FindMethod · 0.65

Tested by 4

txHasFunction · 0.64