Hi Morgan:
Thanks for all your help with the sort algorithm. It occurred to me that in my
app I could sort my elements as I create them in my NSXMLParser delegate
methods such that I wouldn't need to use a sort algorithm. I now have:
def add_child( child )
change
Greetings,
Sorry; I neglected that aspect of your code.
If, instead of '@children = ...' you were to go:
def sort_children2
new_children = @children.sort_by.with_index { |*args| args}
set_modified if @children != new_children
@children = new_children
end
It adds an extra 'n' in doing the c
Greetings,
On Mon, Jan 31, 2011 at 11:00 AM, Charles Oliver Nutter wrote:
> FWIW, JRuby originally had a stable Array#sort, but because it was
> slower than MRI's unstable sort (and we got bug reports to that
> effect) we replaced it with an unstable hybrid sort based on
> quicksort. Shortly aft
On Sun, Jan 30, 2011 at 6:19 PM, Morgan Schweers wrote:
> Greetings,
> Ruby's sort algorithm is quicksort, last I checked, and quicksort is not
> stable (which is the property you're looking for in a sort). There are a
> bunch of ways around this, including writing your own, but one cute, quick,
Hi Morgan:
Thanks again.
I understand the concept now of adding a secondary sort key but I was
unfamiliar with the .with_index enumerator method.
My app is usually sorting a small array of XML elements that will already be
sorted but I need to know if the sequence has changed to update the fil
Greetings,
The long example didn't work quite right. You can see it here:
https://gist.github.com/803842
-- Morgan
On Mon, Jan 31, 2011 at 1:55 AM, Morgan Schweers wrote:
> Greetings,
> Ouch. That's...probably painfully expensive for large @children arrays.
> Trying to understand, it looks
Greetings,
Ouch. That's...probably painfully expensive for large @children arrays.
Trying to understand, it looks like you're sorting on child.sequence, and
keeping each child with the same sequence in the same order as they are
initially in the @children array?
You could try something like this
Hi Morgan:
Thanks for the info although I have to admit that I don't understand how your
solutions work.
I also needed my sort to return a modified flag to update the file if changed
so I wrote my own bubble sort.
I haven't test this yet:
def sort_children # Don't trust Ruby sort to ma
Greetings,
Ruby's sort algorithm is quicksort, last I checked, and quicksort is not
stable (which is the property you're looking for in a sort). There are a
bunch of ways around this, including writing your own, but one cute, quick,
but possibly performance-impairing, approach I've seen (Matz's su
Hi:
Does the Ruby Array sort algorithm maintain the relative position for children
returning the same value for the comparison? I had an instance where two
children having the compare value were interchanged.
Thanks,
Bob Rice
___
MacRuby-devel mailin
10 matches
Mail list logo