sortedset

C# SortedSet<T> and equality

你。 提交于 2019-12-30 05:59:12
问题 I am a bit puzzled about the behaviour of SortedSet, see following example: public class Blah { public double Value { get; private set; } public Blah(double value) { Value = value; } } public class BlahComparer : Comparer<Blah> { public override int Compare(Blah x, Blah y) { return Comparer<double>.Default.Compare(x.Value, y.Value); } } public static void main() { var blahs = new List<Blah> {new Blah(1), new Blah(2), new Blah(3), new Blah(2)} //contains all 4 entries var set = new HashSet

Serialization issue with SortedSet, Arrays, an Serializable

房东的猫 提交于 2019-12-29 09:23:11
问题 I have this before the process: protected void onPostExecute(SortedSet<RatedMessage> result) { List<Object> list=Arrays.asList(result.toArray()); lancon.putExtra("results", list.toArray()); // as serializable } then in the other part I have Object o=this.getIntent().getSerializableExtra("results"); //at this point the o holds the correct value (checked by debugger) RatedMessage[] rm = (RatedMessage[]) o;// this line hangs out w ClassCastException resultSet = new TreeSet<RatedMessage>(new Comp

java TreeSet: comparing and equality

回眸只為那壹抹淺笑 提交于 2019-12-22 08:48:53
问题 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

Redis: Implement Weighted Directed Graph

笑着哭i 提交于 2019-12-22 05:41:12
问题 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

Redis: Implement Weighted Directed Graph

可紊 提交于 2019-12-22 05:41:10
问题 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

Add to SortedSet<T> and its complexity

旧城冷巷雨未停 提交于 2019-12-20 17:42:18
问题 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. 回答1: The comment is simply wrong. Yes, it is a red-black tree, O(log(n)) for inserts. Taking a look with

Add to SortedSet<T> and its complexity

白昼怎懂夜的黑 提交于 2019-12-20 17:40:06
问题 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. 回答1: The comment is simply wrong. Yes, it is a red-black tree, O(log(n)) for inserts. Taking a look with

Limited SortedSet

我们两清 提交于 2019-12-18 04:51:05
问题 i'm looking for an implementation of SortedSet with a limited number of elements. So if there are more elements added then the specified Maximum the comparator decides if to add the item and remove the last one from the Set. SortedSet<Integer> t1 = new LimitedSet<Integer>(3); t1.add(5); t1.add(3); t1.add(1); // [1,3,5] t1.add(2); // [1,2,3] t1.add(9); // [1,2,3] t1.add(0); // [0,1,2] Is there an elegant way in the standard API to accomplish this? I've wrote a JUnit Test for checking

ordering a hashset example?

╄→尐↘猪︶ㄣ 提交于 2019-12-18 02:23:32
问题 I need an example on how to use a comparable class on a HashSet to get an ascending order. Let’s say I have a HashSet like this one: HashSet<String> hs = new HashSet<String>(); How can I get hs to be in ascending order? 回答1: Use a TreeSet instead. It has a constructor taking a Comparator. It will automatically sort the Set . If you want to convert a HashSet to a TreeSet , then do so: Set<YourObject> hashSet = getItSomehow(); Set<YourObject> treeSet = new TreeSet<YourObject>(new YourComparator

Redis sorted sets and best way to store uids

扶醉桌前 提交于 2019-12-17 19:05:06
问题 I have data consisting of user_ids and tags of these user ids. The user_ids occur multiple times and have pre-specified number of tags (500) however that might change in the feature. What must be stored is the user_id, their tags and their count. I want later to easily find tags with top score.. etc. Every time a tag appears it is incremented My implementation in redis is done using sorted sets every user_id is a sorted set key is user_id and is a hex number works like this: zincrby user_id:x