Questions tagged [sortedset]

Represents a collection of unique objects that is maintained in sorted order.

Starting with the .NET Framework 4, the SortedSet<T> class provides a self-balancing tree that maintains data in sorted order after insertions, deletions, and searches.

More info at MSDN.

284 questions
87
votes
6 answers

Why are there no sorted containers in Python's standard libraries?

Is there a Python design decision (PEP) that precludes a sorted container from being added to Python? (OrderedDict is not a sorted container since it is ordered by insertion order.)
Neil G
  • 28,787
  • 31
  • 143
  • 234
80
votes
7 answers

maintaining TreeSet sort as object changes value

I've got a object that defines a 'natural sort order' using Comparable<>. These are being stored in TreeSets. Other than removing and re-adding the object, is there another way to update the sort when the members that are used to define the sort…
Stevko
  • 3,969
  • 6
  • 36
  • 57
68
votes
1 answer

Why SortedSet.GetViewBetween isn't O(log N)?

In .NET 4.0+, a class SortedSet has a method called GetViewBetween(l, r), which returns an interface view on a tree part containing all the values between the two specified. Given that SortedSet is implemented as a red-black tree, I naturally…
Skiminok
  • 2,521
  • 1
  • 21
  • 29
50
votes
1 answer

Efficiency of very large collections; iteration and sort

I have a csv parser that reads in 15+ million rows (with many duplicates), and once parsed into structs, need to be added to a collection. Each struct has properties Key (int), A(datetime), and B(int) (and others that aren't relevant…
Kevin Fichter
  • 1,037
  • 1
  • 11
  • 15
32
votes
5 answers

How to find the index of an element in a TreeSet?

I'm using a TreeSet and I'd quite simply like to find the index of a number in the set. Is there a nice way to do this that actually makes use of the O(log(n)) complexity of binary trees? (If not, what should I do, and does anyone know why…
jtbandes
  • 104,858
  • 34
  • 217
  • 242
30
votes
1 answer

Add to SortedSet and its complexity

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…
Andrey Taptunov
  • 8,797
  • 4
  • 26
  • 43
23
votes
4 answers

Convert List of Ints to a SortedSet in Scala

If I have a List of Ints like: val myList = List(3,2,1,9) what is the right/preferred way to create a SortedSet from a List or Seq of Ints, where the items are sorted from least to greatest? If you held a gun to my head I would have said: val…
Andy
  • 1,410
  • 2
  • 16
  • 15
22
votes
5 answers

Difference between NavigableSet, SortedSet and TreeSet in Java

A TreeSet puts an element in natural ordering or by the provided comparator. A SortedSet is also keeps the element in natural order But what is the difference between them and NavigableSet? Where are NavigableSets useful? Some example to show its…
eagertoLearn
  • 8,372
  • 22
  • 66
  • 108
20
votes
3 answers

ordering a hashset example?

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 hs = new HashSet(); How can I get hs to be in ascending order?
Jony
  • 6,352
  • 19
  • 56
  • 69
13
votes
3 answers

C# SortedSet and equality

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 :…
NNN
  • 255
  • 1
  • 3
  • 7
13
votes
2 answers

Redis sorted set leader board ranking on same score

I'm using Redis sorted set to implement the leaderboard of my game, where I show the user ranking in descending order. I'm stuck in a case where two or more users have the same score. So in this case, I want the higher ranking of the user who gets…
ankit.vishen
  • 920
  • 10
  • 26
12
votes
3 answers

how to get a member with maximum (or minimum ) score from redis sorted set given a subset of members?

I am writing a algo for deducing the user with the least amount of work load. Based on the type/complexity of the tasks being created, i narrow down on the list of the users that are capable of performing it. Now, I need to find the user who has the…
KCore
  • 255
  • 1
  • 4
  • 12
11
votes
2 answers

How to convert a list or vector into a sorted-set in Clojure?

In Clojure, the set function automatically converts a vector or list into a set. But this is not the case for sorted-set: (set [3 2 1]) ; #{1 2 3} (set '(3 2 1)) ; #{1 2 3} (sorted-set [3 2 1]) ; #{[3 2 1]} (sorted-set '(3 2 1)) ; #{(3 2 1)} Here…
newtonapple
  • 4,053
  • 2
  • 30
  • 29
11
votes
5 answers

C# fastest intersection of 2 sets of sorted numbers

I'm calculating intersection of 2 sets of sorted numbers in a time-critical part of my application. This calculation is the biggest bottleneck of the whole application so I need to speed it up. I've tried a bunch of simple options and am currently…
gligoran
  • 3,019
  • 3
  • 28
  • 42
11
votes
7 answers

How to get the last 25 elements of a SortedSet?

In Java I have a SortedSet that may have 100,000 elements. I would like to efficiently and elegantly get the last 25 elements. I'm a bit puzzled. To get the first 25 I'd iterate and stop after 25 elements. But I don't know how to iterate in reverse…
Steve McLeod
  • 49,211
  • 44
  • 120
  • 177
1
2 3
18 19