Re: Using "sort!" in a C extension (1.9 problem)



On Sun, 2007-12-30 at 08:06 +0900, Andre Nathan wrote:
On Sun, 2007-12-30 at 07:34 +0900, Siep Korteling wrote:
Like this?
a=[[2],[1,2,3],[1],[1,2]]
p a.sort_by{|ar|ar.length}

Yes but in a C extension. The code I have is not working with 1.9.

Well not exactly. sort_by works but I'd prefer to use sort! with a
block, as it does the sorting in-place.

In 1.9, if I inspect "ary" below, I only see the current array element.
In 1.8, it is an array of the two elements which are being compared.

static VALUE
sort_i(VALUE ary)
{
long v1 = FIX2LONG(RARRAY_PTR(ary)[0]);
long v2 = FIX2LONG(RARRAY_PTR(ary)[1]);
return LONG2FIX(v1 - v2);
}

Andre


.



Relevant Pages

  • Re: Sorting a Hash of Arrays by an Element in the Array
    ... > but since you can always sort a hash who really cares? ... ascending sort). ... as meaningful as asking for sorting a mathematical set. ... I have no idea what "sorting a HoA on an array element" is supposed to mean. ...
    (comp.lang.perl.misc)
  • Re: sort by file extension
    ... Document" to "Log File" in the .reg file and import them again. ... I want to be able to sort by file extension. ... So when I sort by "Type", it sorts the .log and .txt files together. ... I'm sure that sorting by "Type" used to sort by file extension. ...
    (microsoft.public.windowsxp.basics)
  • Re: Completely baffled on what should be simple
    ... Depending on the version of Excel, I would have thought you'd see a warning ... asking if you want to sort everything as numbers ... Starting with the 398 row the sorting ... extension numbers. ...
    (microsoft.public.excel.misc)
  • Re: Completely baffled on what should be simple
    ... asking if you want to sort everything as numbers ... header, Ext, is in the first row. ... Starting with the 398 row the sorting ... extension numbers. ...
    (microsoft.public.excel.misc)
  • Re: Using "sort!" in a C extension (1.9 problem)
    ... For some reason I thought rb_ary_sort_bang was static while it ... I was using rb_funcallbecause this way "sort!" ... sort_by_lengthis never called, and the sub-arrays were ... given the current array element only as its argument. ...
    (comp.lang.ruby)