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)
| 779 | // |
| 780 | // Time complexity of this method is : O(log(N)). |
| 781 | func (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. |
| 804 | func (sl *SkipList) FindRevRank(hash uint32) int { |
no test coverage detected