lingo-l Sorting Challenge

2004-05-31 Thread Slava Paperno
Is there an xplat Xtra that expands Directors limited ability to sort lists?

Or, can someone please advise me on how to implement this sort?

I have a linear list where the value of each item is a property list,
[  [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
  [#Prop1: xyz, #Prop2: 02, #Prop3: 01],
  [#Prop1: abc, #Prop2: 01, #Prop3: 01],  ]

I need to sort the outer linear list on the compound values of the three properties in 
the inner lists, so I get this:

[  [#Prop1: abc, #Prop2: 01, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: xyz, #Prop2: 02, #Prop3: 01]  ]

If this were a database table with three fields and four records, I'd use a compound 
index, Prop1 + Prop2 + Prop3. How can I achieve the same result in Director MX?

The size of my lists and the number of properties in each list are quite modest, so 
peformance is not really an important factor.

Any advice will be appreciated.

Slava

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


RE: lingo-l Sorting Challenge

2004-05-31 Thread Per-Erik Bergman
Hi, I'm taking the opportunity to say Hi, I'm a new one at this list. :)

I'd create a new list with the values of the combine properties and sort
that one and in the same time making the same changes to the original list.

My code:

on sortList iList
  -- Creating the list to sort --
  tList = []
  repeat with tData in iList
-- This is similar to the 'Prop1 + Prop2 + Prop3' you used. --
tValue = tData[#Prop1]  tData[#Prop2]  tData[#Prop3]
tList.append(tValue)
  end repeat
  
  -- Tha actual sorting --
  tCount = iList.count
  repeat with i = 1 to tCount - 1
j = tCount
repeat while j  i
  -- Checking the list you just created --
  if tList[j-1]tList[j] then
-- Making the change in the list you crated --
tData  = tList[j-1]
tList[j-1] = tList[j]
tList[j]   = tData

-- Making the change in the original list --
tData  = iList[j-1]
iList[j-1] = iList[j]
iList[j]   = tData
  end if
  j=j-1
end repeat
  end repeat
  return iList  
end

on test
  tt = [  [#Prop1: abc, #Prop2: 02, #Prop3: 02],  [#Prop1: abc,
#Prop2: 02, #Prop3: 01],  [#Prop1: xyz, #Prop2: 02, #Prop3: 01],
[#Prop1: abc, #Prop2: 01, #Prop3: 01]]
  put sortList(tt)
end

-- [[#Prop1: abc, #Prop2: 01, #Prop3: 01], [#Prop1: abc, #Prop2:
02, #Prop3: 01], [#Prop1: abc, #Prop2: 02, #Prop3: 02], [#Prop1:
xyz, #Prop2: 02, #Prop3: 01]]

Hope this help.

/Per-Erik Bergman
http://www.uncle.nu/

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Slava Paperno
Sent: den 31 maj 2004 18:36
To: [EMAIL PROTECTED]
Subject: lingo-l Sorting Challenge

Is there an xplat Xtra that expands Directors limited ability to sort lists?

Or, can someone please advise me on how to implement this sort?

I have a linear list where the value of each item is a property list,
[  [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
  [#Prop1: xyz, #Prop2: 02, #Prop3: 01],
  [#Prop1: abc, #Prop2: 01, #Prop3: 01],  ]

I need to sort the outer linear list on the compound values of the three
properties in the inner lists, so I get this:

[  [#Prop1: abc, #Prop2: 01, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: xyz, #Prop2: 02, #Prop3: 01]  ]

If this were a database table with three fields and four records, I'd use a
compound index, Prop1 + Prop2 + Prop3. How can I achieve the same result in
Director MX?

The size of my lists and the number of properties in each list are quite
modest, so peformance is not really an important factor.

Any advice will be appreciated.

Slava

[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is
for learning and helping with programming Lingo.  Thanks!]



[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


Re: lingo-l Sorting Challenge

2004-05-31 Thread grimmwerks
Well, if you were using 2004 and created a global flash object, then you
could toss each of these into an associative array, then sort using the
properties quite easily.


[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


Re: lingo-l Sorting Challenge

2004-05-31 Thread Mathew Ray
Hi Slava,
Here is a simple solution using lingo only:
Create a new holder and set it to be sorted.
Loop through each of your items(that have prop1, prop2, prop3) and add 
them to a 'sortkey' property:
[
   [#sortkey:_abc_02_02, [#Prop1: abc, #Prop2: 02, #Prop3: 02]],
   [#sortkey:_abc_02_01, [#Prop1: abc, #Prop2: 02, #Prop3: 01]],
   [#sortkey:_xyz_02_01, [#Prop1: xyz, #Prop2: 02, #Prop3: 01]],
   [#sortkey:_abc_01_01, [#Prop1: abc, #Prop2: 01, #Prop3: 01]]
]

The first _ is in there cause props can't start with a number, in the 
case that you want to sort by prop 2 or 3 as the first sortitem.

The items should be sorted properly, and you can loop through the list 
to recreate the original list in a sorted format.

This works ok for medium to small lists... if you are doing anything 
huge keep in mind this solution is O(2n) complexity - it will ALWAYS 
have to traverse all the items in the list once to assign the key, and 
another time to write the new list back out.

Anyone have any other methods they use?
~Mathew
Slava Paperno wrote:
Is there an xplat Xtra that expands Directors limited ability to sort lists?
Or, can someone please advise me on how to implement this sort?
I have a linear list where the value of each item is a property list,
[  [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
  [#Prop1: xyz, #Prop2: 02, #Prop3: 01],
  [#Prop1: abc, #Prop2: 01, #Prop3: 01],  ]
I need to sort the outer linear list on the compound values of the three properties in 
the inner lists, so I get this:
[  [#Prop1: abc, #Prop2: 01, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: xyz, #Prop2: 02, #Prop3: 01]  ]

If this were a database table with three fields and four records, I'd use a compound 
index, Prop1 + Prop2 + Prop3. How can I achieve the same result in Director MX?
The size of my lists and the number of properties in each list are quite modest, so 
peformance is not really an important factor.
Any advice will be appreciated.
Slava

[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


Re: lingo-l Sorting Challenge

2004-05-31 Thread Mathew Ray
I've thought about this... it seems to be pretty fast, but I wonder how 
much faster is is than the lingo only approach... I would imagine it 
would be decent, since there is no text manipulation to create the 
keys... but ya never know... may have to experiment with that one...

grimmwerks wrote:
Well, if you were using 2004 and created a global flash object, then you
could toss each of these into an associative array, then sort using the
properties quite easily.

[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


lingo-l Sorting Challenge

2004-05-31 Thread Slava Paperno
Thanks to all for your instant solutions! You're great. S.

At 01:16 PM 5/31/04 -0400, grimmwerks wrote:
Well, if you were using 2004 and created a global flash object, then you
could toss each of these into an associative array, then sort using the
properties quite easily.

At 01:28 PM 5/31/04 -0400, Mathew wrote:
Hi Slava,

Here is a simple solution using lingo only:

Create a new holder and set it to be sorted.

Loop through each of your items(that have prop1, prop2, prop3) and add them to a 
'sortkey' property:
[
   [#sortkey:_abc_02_02, [#Prop1: abc, #Prop2: 02, #Prop3: 02]],
   [#sortkey:_abc_02_01, [#Prop1: abc, #Prop2: 02, #Prop3: 01]],
   [#sortkey:_xyz_02_01, [#Prop1: xyz, #Prop2: 02, #Prop3: 01]],
   [#sortkey:_abc_01_01, [#Prop1: abc, #Prop2: 01, #Prop3: 01]]
]

The first _ is in there cause props can't start with a number, in the case that you 
want to sort by prop 2 or 3 as the first sortitem.

The items should be sorted properly, and you can loop through the list to recreate 
the original list in a sorted format.

This works ok for medium to small lists... if you are doing anything huge keep in 
mind this solution is O(2n) complexity - it will ALWAYS have to traverse all the 
items in the list once to assign the key, and another time to write the new list back 
out.

Anyone have any other methods they use?

~Mathew

At 07:11 PM 5/31/04 +0200, Per-Erik wrote:
I'd create a new list with the values of the combine properties and sort
that one and in the same time making the same changes to the original list.

My code:

on sortList iList
  -- Creating the list to sort --
  tList = []
  repeat with tData in iList
-- This is similar to the 'Prop1 + Prop2 + Prop3' you used. --
tValue = tData[#Prop1]  tData[#Prop2]  tData[#Prop3]
tList.append(tValue)
  end repeat
  
  -- Tha actual sorting --
  tCount = iList.count
  repeat with i = 1 to tCount - 1
j = tCount
repeat while j  i
  -- Checking the list you just created --
  if tList[j-1]tList[j] then
-- Making the change in the list you crated --
tData  = tList[j-1]
tList[j-1] = tList[j]
tList[j]   = tData

-- Making the change in the original list --
tData  = iList[j-1]
iList[j-1] = iList[j]
iList[j]   = tData
  end if
  j=j-1
end repeat
  end repeat
  return iList  
end

on test
  tt = [  [#Prop1: abc, #Prop2: 02, #Prop3: 02],  [#Prop1: abc,
#Prop2: 02, #Prop3: 01],  [#Prop1: xyz, #Prop2: 02, #Prop3: 01],
[#Prop1: abc, #Prop2: 01, #Prop3: 01]]
  put sortList(tt)
end

-- [[#Prop1: abc, #Prop2: 01, #Prop3: 01], [#Prop1: abc, #Prop2:
02, #Prop3: 01], [#Prop1: abc, #Prop2: 02, #Prop3: 02], [#Prop1:
xyz, #Prop2: 02, #Prop3: 01]]

Hope this help.

/Per-Erik Bergman
http://www.uncle.nu/




Slava Paperno wrote:
Is there an xplat Xtra that expands Directors limited ability to sort lists?
Or, can someone please advise me on how to implement this sort?
I have a linear list where the value of each item is a property list,
[  [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
  [#Prop1: xyz, #Prop2: 02, #Prop3: 01],
  [#Prop1: abc, #Prop2: 01, #Prop3: 01],  ]
I need to sort the outer linear list on the compound values of the three properties 
in the inner lists, so I get this:
[  [#Prop1: abc, #Prop2: 01, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 01],
   [#Prop1: abc, #Prop2: 02, #Prop3: 02],
   [#Prop1: xyz, #Prop2: 02, #Prop3: 01]  ]
If this were a database table with three fields and four records, I'd use a compound 
index, Prop1 + Prop2 + Prop3. How can I achieve the same result in Director MX?
The size of my lists and the number of properties in each list are quite modest, so 
peformance is not really an important factor.
Any advice will be appreciated.
Slava

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]