Page 3 of 3 FirstFirst 123
Results 21 to 22 of 22

Thread: Difficulties when trying to sort a custom type array

  1. #21
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    Another thought:
    If the subelement to sort is an udt...
    Type tVec3d
      X as Double
      Y as Double
      Z as Double
    End Type
    
    Type t3Dpoint
      Pos as tVec3d
      Color as Long
      '... more ...
    End Type
    
    Dim myPoint(123) as t3dPoint
    

    Lets say we would sort the points from left to right ( myPoint().pos.x) it would be a little tricky to use a standard sorting routine...

    We could use the sorting-powers of dictionary-module, use the value to sort as dictionary-data, probably has to be formatted, like
    String sData = Format(myPoint(index).Pos.x, "0.000000")
    and the key for the dictionary-slot would be the actual varptr, also formatted to contain no null:
    String sKey = Hex$(Varptr(myPoint(index)))

    Fill a dictionary with myPoint().Pos.x, let it sort and then order the real array according to the dictionary-keys that hold all pointers in new order now...

    Another, very flexible approach for numeric data to sort:

    Create String-array like
    String toSort(123) ' same number of elements
    For i = 1 to CountOf(myPoint)
      toSort(i) = Format$(myPoint(i).Pos.X, "#.######") & Memory_Get(varptr(myPoint(i)), SizeOf(myPoint))
    ...
    
    • put the element-data to sort by in front, should be formatted to same length if numeric
    • sort this string-array with regular array sort
    • truncate the leading bytes of every string again
    • make the string-array to become one string containing all data
    • poke$ (memory_set) it at the varptr(myPoint(1))
    • done

    If subelement to sort by would be a String we had to fill the leading bytes with $Spc to have it all same length before we sort
    I think there are missing some Forum-sections as beta-testing and support

  2. #22
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    Ha, found it. Look there

    http://www.thinbasic.com/community/s...ll=1#post92487

    Requires a tracefile. Hmmm, what was that?
    Eros implemented a while ago some tracing-directive to test our thinbasic-scripts. It will tell us how many times a function was called and how much time was used to execute every function in order to optimize our script-code.
    I think there are missing some Forum-sections as beta-testing and support

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Array Sort - once more...
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 3
    Last Post: 20-12-2015, 13:23
  2. Array Sort- issue
    By ReneMiner in forum Core module
    Replies: 3
    Last Post: 04-11-2015, 00:41
  3. Replacing ARRAY SORT
    By MikeTrader in forum Power Basic
    Replies: 9
    Last Post: 28-08-2009, 22:57
  4. Array vs type optimization
    By MouseTrap in forum Power Basic
    Replies: 6
    Last Post: 04-03-2009, 11:05

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •