sortedset

Why Redis SortedSet uses Skip List instead of Balanced Tree?

杀马特。学长 韩版系。学妹 提交于 2021-02-06 13:58:39
问题 The Redis document said as below : ZSETs are ordered sets using two data structures to hold the same elements in order to get O(log(N)) INSERT and REMOVE operations into a sorted data structure. The elements are added to a hash table mapping Redis objects to scores. At the same time the elements are added to a skip list mapping scores to Redis objects (so objects are sorted by scores in this "view"). I can not understand very much. Could someone give me a detailed explanation? 回答1: Antirez

Why Redis SortedSet uses Skip List instead of Balanced Tree?

醉酒当歌 提交于 2021-02-06 13:58:07
问题 The Redis document said as below : ZSETs are ordered sets using two data structures to hold the same elements in order to get O(log(N)) INSERT and REMOVE operations into a sorted data structure. The elements are added to a hash table mapping Redis objects to scores. At the same time the elements are added to a skip list mapping scores to Redis objects (so objects are sorted by scores in this "view"). I can not understand very much. Could someone give me a detailed explanation? 回答1: Antirez

Creating a new set from a range of a Sorted Set in Redis

守給你的承諾、 提交于 2020-06-28 06:06:06
问题 I have a number of sorted sets that are used as secondary indexes on my system and user queries could hit a number of them. ZADD scoreSet 1 "fred" ZADD scoreSet 5 "bob" ZADD scoreSet 2 "spodrick" ZADD ageSet 25 "fred" ZADD ageSet 29 "bob" ZADD ageSet 38 "spodrick" To use these indexes to get all users under 30 with a score >2 ZRANGEBYSCORE scoreSet (2 +inf (store these in my application code) ZRANGEBYSCORE ageSet -inf (30 (store these in my application code) (Perform Set intersection in my

c# SortedSet how to get an element out

Deadly 提交于 2020-01-14 19:03:36
问题 I am pretty new to this so forgive my noobishness here. I am trying to edit an item in a c# sortedset if I find that the item exists. So I can use list.contains(value) and find that the value does exist in the list. But how do I get that item out of the list. Here is what I have. This gets really slow as my list size gets really big, so I'm guessing there must be a better way than this. if (list.Contains(p)) { Person exists = list.First(person => person.Name.Equals(line[0])); // do something

How can Redis sort according to two different sorted sets?

二次信任 提交于 2020-01-06 11:10:28
问题 I have two different sorted sets. One is for editor ID: article_id editor_id 101 10 102 11 103 10 104 10 The other sorted set is for date sorting: article_id day 101 29 102 27 103 25 104 27 I want to merge these sets which shows first editor second day sorted state. Which commands should I use? 回答1: Assuming that article_id is your members' value and that editor_id / day are the scores in the respective Sorted Set, and assuming each article_id is present in both Sorted Sets, you can do the

How can Redis sort according to two different sorted sets?

筅森魡賤 提交于 2020-01-06 11:10:21
问题 I have two different sorted sets. One is for editor ID: article_id editor_id 101 10 102 11 103 10 104 10 The other sorted set is for date sorting: article_id day 101 29 102 27 103 25 104 27 I want to merge these sets which shows first editor second day sorted state. Which commands should I use? 回答1: Assuming that article_id is your members' value and that editor_id / day are the scores in the respective Sorted Set, and assuming each article_id is present in both Sorted Sets, you can do the

How to iterate over a SortedSet to modify items within

北战南征 提交于 2020-01-03 19:57:52
问题 lets say I have an List. There is no problem to modify list's item in for loop: for (int i = 0; i < list.size(); i++) { list.get(i).setId(i); } But I have a SortedSet instead of list. How can I do the same with it? Thank you 回答1: First of all, Set assumes that its elements are immutable (actually, mutable elements are permitted, but they must adhere to a very specific contract, which I doubt your class does). This means that generally you can't modify a set element in-place like you're doing

Reverse Pagination Through A Redis Sorted Set

大憨熊 提交于 2020-01-03 12:34:45
问题 Consider a Redis sorted set with the following members: ZADD mySortedSet 11 "A" ZADD mySortedSet 21 "B" ZADD mySortedSet 32 "C" ZADD mySortedSet 46 "D" ZADD mySortedSet 53 "E" ZADD mySortedSet 68 "F" ZADD mySortedSet 72 "G" ZADD mySortedSet 82 "H" ZADD mySortedSet 94 "I" ZADD mySortedSet 104 "J" ZADD mySortedSet 113 "K" If I want to do pagination in reverse order, starting at an arbitrary slice, I can start with this: // Returns G, F, E, as expected. ZREVRANGEBYSCORE mySortedSet 72 (46 Now,

logical inconsistence between Set and SortedSet interfaces in Java [closed]

萝らか妹 提交于 2019-12-31 00:44:16
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I noticed a logical inconsistence between Set and SortedSet interfaces in Java. SortedSet recognizes different objects (by equal()

Understanding TreeSet when compareto returns 0

不羁岁月 提交于 2019-12-30 07:18:12
问题 I have created a Student class like this: public class Student implements Comparable<Student> { private String firstName; private String lastName; public Student(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } // Getters & Setters follow here... @Override public int compareTo(Student student) { int hash = this.firstName.compareTo(student.firstName); return hash; } @Override public String toString() { return "Student [firstName=" + firstName + ",