sortedlist - Does ruby have a list type that keeps contents sorted as adds/deletes occur? -


I need a data structure in Ruby which keeps its elements sorted because the elements are added or destroyed (at least) the ability to Pop the element before the list.

The closest thing in the Ruby docks is to get it. However, it does not provide any way to access the elements (or even close the first element) by their index.

These are specific tasks for me:

  • Add an object to the list
  • Pop the object before the list
  • Check that an object is in the list
  • Li>
  • Remove the object from the list (by object, not indexed)

Or something to Rabbi has been made, what is a library that I should take it? I can apply one without any difficulty, but if possible I want to use one already.

Currently I am using Ruby 1.8, although switching to 1.9 is probably OK.

EDIT:

Since there is some confusion, my requirement is that the sorted object is not an order to be cast. I would like to sort the & lt; = & Gt; must be on the basis of operator. Generally I'll pop the first element, processing it (which can generate new elements), adding new elements to the list, repeating Elements are being added, not only in the end, in the sorting order can end anywhere.

It may want to 1.8-compatible gem condiser for red (blue tree) (Ruby / RBTree):

Trees are always kept balanced, work on tree o (log n)

There is also a red-black tree implementation :

Container :: Ruby RTMip


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -