Add to SortedSet and its 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 point, using normal red-black node traversal. This doc bug has already been submitted by you-know-who.

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

There’s also a python sortedcontainers module that implements sorted list, dict, and set types. It’s very similar to blist but implemented in pure-Python and in most cases faster. >>> from sortedcontainers import SortedSet >>> ss = SortedSet([3, 7, 2, 2]) >>> ss SortedSet([2, 3, 7]) It also has functionality uncommon to other packages: >>> from … Read more

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

about the version field UPDATE1: In my memory, a lot of (maybe all?) collections in BCL have the field version. First, about foreach: according to this msdn link The foreach statement repeats a group of embedded statements for each element in an array or an object collection. The foreach statement is used to iterate through the collection to get … Read more

maintaining TreeSet sort as object changes value

As others have noted, there is no in-built way. But you can always subclass that TreeSet, with your constructor(s) of choice, and add in the required functionality: public class UpdateableTreeSet<T extends Updateable> extends TreeSet<T> { // definition of updateable interface Updateable{ void update(Object value); } // constructors here … // ‘update’ method; returns false if … Read more

tech