Results 1 to 10 of 22

Thread: Difficulties when trying to sort a custom type array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    71
    Posts
    69
    Rep Power
    13

    Difficulties when trying to sort a custom type array

    Hi,

    A you can see in enclosed file, I try to sort an array.
    This array contains members (10 in my example but more in reality) each member is
    type 
    'members
     end type
    
    defined.

    When I try to sort the array by the first member of the structure, the program crashes (see screenshots)

    This appears either with interpreted or bundled version.

    What's wrong ?

    Regards,

    Dany
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    In general Array Sort is not able to recognize array of UDT (User Defined Type) data type.
    But it should not crash, just do a binary sort based of the binary data inside UDT element
    In your example it should sort based on binary data strings composed by 10 bytes ("sName" string) + 4 bytes (binary representation of DWord "SValue") + 4 bytes (binary representation of Long "sCount")

    I have to investigate why it crash

    Thanks for reporting
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    I found the problem and solved.

    But I do not like the solution I implemented because sorting an array of UDTs would require to:
    1. make a copy of the memory allocated by the UDT
    2. splitting into dynamic strings array
    3. sorting array
    4. putting back memory into the UDT


    I'm searching a clever solution.
    I asked into Power Basic compiler forum for some help:
    https://forum.powerbasic.com/forum/u...f-unknown-size
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    71
    Posts
    69
    Rep Power
    13
    Quote Originally Posted by ErosOlmi View Post
    In general Array Sort is not able to recognize array of UDT (User Defined Type) data type.
    But it should not crash, just do a binary sort based of the binary data inside UDT element
    In your example it should sort based on binary data strings composed by 10 bytes ("sName" string) + 4 bytes (binary representation of DWord "SValue") + 4 bytes (binary representation of Long "sCount")

    I have to investigate why it crash

    Thanks for reporting
    Eros
    Hi Eros,

    This behaviour would fulfill my needs, because a previous check does not allow duplicate values in first field (string)

    Regards


    Dany

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Please find attached thinCore.dll
    Unzip it under the following folders:
    • \thinBasic\
    • \thinBasic\thinAir

    replacing your current version

    I've fixed array sort for user defined type arrays in the "slow and dirty" way I've described above

    Let me know if it works

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    71
    Posts
    69
    Rep Power
    13
    Quote Originally Posted by ErosOlmi View Post

    Let me know if it works

    Ciao
    Eros
    No more crash !

    It works, but :

    Array Sort symbol_prg() ' empty strings first ,  then chars in ASCII order     OK for ascending
    Array Sort symbol_prg() , Descend '  give the same result.  DESCEND  seems to be ignored ?
    
    I did not test asfiles option

    Non UDT array keeps sorted OK

    Regards,


    Dany

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Reality is that thinBasic was not sorting at all fixed buffers (strings, UDT, ...)
    So it is an area all to be constructed

    I will add missing part asap ad post new Core to test.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

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
  •