Staffan
I'am not sure it fits in here but I made a kind of sort class, inspired by an 
answer by Rick.
Maybe can be useful, it should work for both integer and decimals numbers and 
alphanumerics  
Improvments welcome
/hex


-- Sort up to 5 fields ascending/descending and caseless

sortItems = .array~new

do x = 1 to 100000
   a1=random(x)  ; b=random(99999999)
   sortItems~append(.sortfields~new(a1,'D',b,'a'))
end
do s over sortItems~sortwith(.Sort~new)
    say s~field1  s~field2
end
exit

::requires mysort.cls


MySort.cls

/* use (.sortfields~new(Field1,A,Field2,A,Field3,A,Field4,A,field5,A)) */
::CLASS sortFields public
::attribute Field1
::attribute Field2
::attribute Field3
::attribute Field4
::attribute Field5
::attribute Seq1  
::attribute Seq2   
::attribute Seq3   
::attribute Seq4   
::attribute Seq5  
::attribute record
::method init
expose Field1 Field2 Field3 Field4 field5 seq1 seq2 seq3 seq4 seq5 record
use arg 
Field1='',seq1='A',Field2='',seq2='A',Field3='',seq3='A',Field4='',seq4='A',field5='',seq5='A',record=''
if seq1~translate = 'D' then seq1 = -1 
  else seq1 = 1
if seq2~translate = 'D' then seq2 = -1 
  else seq2 = 1
if seq3~translate = 'D' then seq3 = -1 
  else seq3 = 1
if seq4~translate = 'D' then seq4 = -1
  else seq4 = 1
if seq5~translate = 'D' then seq5 = -1 
  else seq5 = 1

::CLASS Sort subclass comparator public
::method compare 
use strict arg left, right
  if left~field1~datatype('N') & right~field1~datatype('N') then do 
     if (left~field1 - right~field1)~sign <> 0 then
        return  left~seq1*(left~field1 - right~field1)~sign 
   End
   else Do
     if left~field1~caselesscompareTo(right~field1) <> 0 then 
       return  left~seq1*left~field1~caselesscompareTo(right~field1) 
   End
  if left~field2~datatype('N') & right~field2~datatype('N') then do
     if (left~field2 - right~field2)~sign <> 0 then
        return  left~seq2*(left~field2 - right~field2)~sign 
  end  
   else do
     if left~field2~caselesscompareTo(right~field2) <> 0 then 
       return  left~seq2*left~field2~caselesscompareTo(right~field2) 
   end
  if left~field3~datatype('N') & right~field3~datatype('N') then do
     if (left~field3 - right~field3)~sign <> 0 then
        return  left~seq3*(left~field3 - right~field3)~sign 
  end
   else do
     if left~field3~caselesscompareTo(right~field3) <> 0 then 
       return  left~seq3*left~field3~caselesscompareTo(right~field3) 
   end
  if left~field4~datatype('N') & right~field4~datatype('N') then do
     if (left~field4 - right~field4)~sign <> 0 then
        return  left~seq4*(left~field4 - right~field4)~sign 
  end
   else do
     if left~field4~caselesscompareTo(right~field4) <> 0 then 
       return  left~seq4*left~field4~caselesscompareTo(right~field4) 
   end  

  if left~field5~datatype('N') & right~field5~datatype('N') then do
     if (left~field5 - right~field5)~sign <> 0 then
        return  left~seq5*(left~field5 - right~field5)~sign 
  end
   else do
     if left~field5~caselesscompareTo(right~field5) <> 0 then 
       return  left~seq5*left~field5~caselesscompareTo(right~field5) 
   End
return 0 





----- Ursprungligt Meddelande -----
Från: Staffan Tylen <staffan.ty...@gmail.com>
Till: Open Object Rexx Users <oorexx-users@lists.sourceforge.net>
Kopia:
Datum: torsdag, 21 februari 2013 12:03
Ämne: Re: [Oorexx-users] Oodialog: Progress indicator of undetermined duration



Hmm, that's interesting.  I had assume that it was because during the sort, the 
native code had to call back into the interpreter so often, so quickly.


Could I see your sortListView method?  Also what are you using for the user 
data items for the list-view items?





Sure. This should answer your two questions. As you can see the method is 
almost identical to yours, with the addition that a conversion of the data is 
always performed, this should "slow down" the process somewhat. On the other 
hand, your code is not a sort program but a ProgressBar example which is 
illustrated quite well. But it's not a good sorting example ;)


BTW, maybe you can suggest a more elegant way to sort a numeric column. I guess 
I could add an overriding class similar to what Rick suggested with his 
caselessIndex class, whether more elegant in this case I don't know...




::METHOD sortListView

  expose numericColumn
  use strict arg data1, data2, parms                                          
-- data1/2 are arrays, parms is a directory



  column = parms~column + 1                                                   
-- Make relative to 1


  if numericColumn[column] then
     if parms~ascending then
        return right(data1[column], digits(), 
"0")~compareTo(right(data2[column], digits(), "0"))
     else
        return right(data2[column], digits(), 
"0")~compareTo(right(data1[column], digits(), "0"))
  else
     if parms~ascending then
        return 
.Encoding~convert(data1[column])~compareTo(.Encoding~convert(data2[column]))
     else
        return 
.Encoding~convert(data2[column])~compareTo(.Encoding~convert(data1[column]))


Staffan






------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to