sortedset

Redis Data Structure Space Requirements

半世苍凉 提交于 2019-12-06 06:31:44
问题 What is the difference in space between sorted sets and lists in redis? My guess is that sorted sets are some kind of balanced binary tree, and lists are a linked list. This means that on top of the three values that I'm encoding for each of them, key, score, value, although I'll munge together score and value for the linkedlist, the overhead is that the linkedlist needs to keep track of one other node, and the binary tree needs to keep track of two, so that the space overhead to using a

java TreeSet: comparing and equality

邮差的信 提交于 2019-12-05 13:53:54
I'd like to have list of object sorted with property 'sort_1'. But when I want to remove I'd like it to use property 'id'. The following code represents the problem. package javaapplication1; import java.util.TreeSet; public class MyObj implements Comparable<MyObj> { public long sort_1; public long id; public MyObj(long sort, long id) { this.sort_1=sort; this.id=id; } @Override public int compareTo(MyObj other) { int ret = Long.compare(sort_1, other.sort_1); return ret; } public String toString() { return id+":"+sort_1; } public static void main(String[] args) { TreeSet<MyObj> lst=new TreeSet

Redis: Implement Weighted Directed Graph

时光毁灭记忆、已成空白 提交于 2019-12-05 08:16:27
What's the best way to implement weighted graph using Redis? We will mostly search for shortest paths over the graph (probably using the Dijkstra algorithm) Currently we considered adding the edges to Redis For each node, we will have the nodeId as the key and a sortedset of keys of referenced nodes the score of each nodeId in the sortedSet is the weight of the edge. What do you think? Correct me if I am wrong but the only bummer here is that for each query for the next node in a sortedset we pay O(logn) instead of O(1)... http://redis.io/commands/zrange Getting the next item in a sorted set

Redis sorted set and solving ties

眉间皱痕 提交于 2019-12-04 10:44:59
I'm using a Redis sorted set to store a ranking for a project I'm working on. We hadn't anticipated (!) how we wanted to handle ties. Redis sorts lexicographically the entries that have the same score, but what we want to do is instead give the same rank to all the entries that have the same score, so for instance in the case of redis 127.0.0.1:6379> ZREVRANGE foo 0 -1 WITHSCORES 1) "first" 2) "3" 3) "second3" 4) "2" 5) "second2" 6) "2" 7) "second1" 8) "2" 9) "fifth" 10) "1" we want to consider second1 , second2 and second3 as both having position 2, and fifth to have position 5. Hence there

C# fastest union of 2 sets of sorted values

孤街浪徒 提交于 2019-12-04 04:21:26
What is the fastest way to union 2 sets of sorted values? Speed (big-O) is important here; not clarity - assume this is being done millions of times. Assume you do not know the type or range of the values, but have an efficent IComparer<T> and/or IEqualityComparer<T> . Given the following set of numbers: var la = new int[] { 1, 2, 4, 5, 9 }; var ra = new int[] { 3, 4, 5, 6, 6, 7, 8 }; I am expecting 1, 2, 3, 4, 5, 6, 7, 8, 9. The following stub may be used to test the code: static void Main(string[] args) { var la = new int[] { 1, 2, 4, 5, 9 }; var ra = new int[] { 3, 4, 5, 6, 6, 7, 8 };

Add to SortedSet<T> and its complexity

依然范特西╮ 提交于 2019-12-03 04:30:40
MSDN states the following SortedSet(T).Add Method : If Count is less than the capacity of the internal array, this method is an O(1) operation. Could someone please explain "how so"? I mean when adding new value we need to find a correct place to add a value (comparing it with another values) and internal implementation looks like a "Red-Black tree" with O (log N) insertion complexity. The comment is simply wrong. Yes, it is a red-black tree, O(log(n)) for inserts. Taking a look with Reflector bears this out, the private AddIfNotPresent() method contains a while() loop to find the insertion

SortedSet<>.Contains() how to implement own comparation?

微笑、不失礼 提交于 2019-12-02 10:22:10
问题 I want to check if Object with given values exists in SortedSet<> but I don't understand how custom comparation works here. In List<>.Exists() i could just use lambda, but I cannot do that there and i don't get that whole interface thing while msdn says i need to override int returning function. public class Node { public int X, Y; public int rand; public Node(int x, int y, int r) { X = x; Y = y; rand = r; } } class Program { static void Main(string[] args) { SortedSet<Node> mySet = new

SortedSet<>.Contains() how to implement own comparation?

允我心安 提交于 2019-12-02 04:03:31
I want to check if Object with given values exists in SortedSet<> but I don't understand how custom comparation works here. In List<>.Exists() i could just use lambda, but I cannot do that there and i don't get that whole interface thing while msdn says i need to override int returning function. public class Node { public int X, Y; public int rand; public Node(int x, int y, int r) { X = x; Y = y; rand = r; } } class Program { static void Main(string[] args) { SortedSet<Node> mySet = new SortedSet<Node>(); mySet.Add(new Node(1, 2, 90)); Node myNode = new Node(1, 2, 50); // I want this to check

SortedSet / SortedList with better LINQ performance?

a 夏天 提交于 2019-12-01 17:29:35
Let's say we have a sorted collection such as SortedSet or SortedList with many (10M+) elements. Lots of querying is happening, so performance matters. From runtime comparisons, I'm under the impression that LINQ to Objects doesn't take advantage of the sorting, therefore not taking advantage of potential performance gains. First example - counting the elements in a range: var mySortedSet1 = new SortedSet<int>(); // populate ... int rangeCount = (from n in mySortedSet1 where ((n >= 1000000000) && (n <= 2000000000)) select n).Count(); Not exactly sure what LINQ to Objects does here internally,

SortedSet / SortedList with better LINQ performance?

ε祈祈猫儿з 提交于 2019-12-01 15:53:24
问题 Let's say we have a sorted collection such as SortedSet or SortedList with many (10M+) elements. Lots of querying is happening, so performance matters. From runtime comparisons, I'm under the impression that LINQ to Objects doesn't take advantage of the sorting, therefore not taking advantage of potential performance gains. First example - counting the elements in a range: var mySortedSet1 = new SortedSet<int>(); // populate ... int rangeCount = (from n in mySortedSet1 where ((n >= 1000000000