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)
| 515 | // |
| 516 | // Time complexity of this method is : O(log(N)). |
| 517 | func (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 | // |
no test coverage detected