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

Method FindRank

sorted_set.go:781–801  ·  view source on GitHub ↗

FindRank Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. Note that the rank is 1-based integer. Rank 1 means the first node If the node is not found, 0 is returned. Otherwise rank(> 0) is returned. Time complexity of this method is : O(log(N)).

(hash uint32)

Source from the content-addressed store, hash-verified

779//
780// Time complexity of this method is : O(log(N)).
781func (sl *SkipList) FindRank(hash uint32) int {
782 rank := 0
783 targetNode := sl.dict[hash]
784 if targetNode != nil {
785 x := sl.header
786 for i := sl.level - 1; i >= 0; i-- {
787 for x.level[i].forward != nil &&
788 (x.level[i].forward.score < targetNode.score ||
789 (x.level[i].forward.score == targetNode.score &&
790 sl.cmp(x.level[i].forward.record, targetNode.record) <= 0)) {
791 rank += int(x.level[i].span)
792 x = x.level[i].forward
793 }
794
795 if x.hash == hash {
796 return rank
797 }
798 }
799 }
800 return 0
801}
802
803// FindRevRank Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low.
804func (sl *SkipList) FindRevRank(hash uint32) int {

Callers 2

FindRevRankMethod · 0.95
ZRankMethod · 0.80

Calls 1

cmpMethod · 0.95

Tested by

no test coverage detected