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

Method Put

sorted_set.go:517–537  ·  view source on GitHub ↗

Put puts an element into the sorted set with specific key / value / score. Time complexity of this method is : O(log(N)).

(score SCORE, value []byte, record *core.Record)

Source from the content-addressed store, hash-verified

515//
516// Time complexity of this method is : O(log(N)).
517func (sl *SkipList) Put(score SCORE, value []byte, record *core.Record) error {
518 var newNode *SkipListNode
519
520 hash, _ := utils.GetFnv32(value)
521
522 if n, ok := sl.dict[hash]; ok {
523 // score does not change, only update value
524 if n.score != score { // score changes, delete and re-insert
525 sl.delete(n.score, n.hash)
526 newNode = sl.insertNode(score, hash, record)
527 }
528 } else {
529 newNode = sl.insertNode(score, hash, record)
530 }
531
532 if newNode != nil {
533 sl.dict[hash] = newNode
534 }
535
536 return nil
537}
538
539// Remove removes element specified at given key.
540//

Callers 1

ZAddMethod · 0.45

Calls 3

deleteMethod · 0.95
insertNodeMethod · 0.95
GetFnv32Function · 0.92

Tested by

no test coverage detected