Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python equivalent to java.util.SortedSet?

Tags:

Does anybody know if Python has an equivalent to Java's SortedSet interface?

Heres what I'm looking for: lets say I have an object of type foo, and I know how to compare two objects of type foo to see whether foo1 is "greater than" or "less than" foo2. I want a way of storing many objects of type foo in a list L, so that whenever I traverse the list L, I get the objects in order, according to the comparison method I define.

Edit:

I guess I can use a dictionary or a list and sort() it every time I modify it, but is this the best way?

like image 564
benhsu Avatar asked Mar 09 '09 21:03

benhsu


1 Answers

Take a look at BTrees. It look like you need one of them. As far as I understood you need structure that will support relatively cheap insertion of element into storage structure and cheap sorting operation (or even lack of it). BTrees offers that.

I've experience with ZODB.BTrees, and they scale to thousands and millions of elements.

like image 116
myroslav Avatar answered Oct 02 '22 08:10

myroslav