From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

BUG: 1D Array Sort is not sorting Array of Classes and Array of Clusters contain Classes

Solved!
Go to solution

function 'Sort 1D array'

 

 I wanted sort Array of Clusters [number and Class]. But to my surprise LV is not like it.

OK, I don't need sort Array of Classes. But maybe one time in future I will. 🙂

 

When 'Search 1D array' is working with classes I don't understand why 'Sort 1D array' is not working.

 

 

1DArray-Cluster-Class-Sort.png

 

 This problem is in LabVIEW 8.2, 8.5 and 2009

 

 

0 Kudos
Message 1 of 23
(4,423 Views)
Solution
Accepted by topic author JCC_(SK)

I would think that the Search 1d array function can deal with each element in the array as an agregate while to sort requires accessing the private data within the class data and carrying this even farther...

 

Say all of the elements are of class Parent and one tow children which both have private data that are uniqie from each and not present in the parents class...

 

How do handle tie-breakers when there are different fileds to sort on?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 23
(4,418 Views)

My goal is have cluster [number and class]. Number is fitness of Class.

 

I don't need sort Array of Classes.

 

You are right there could be problem with private data in class and with children's new data.

 

Why Search 1D Array is working [I didn't test it]?

 

P.S.: I could hide Class in Variant in cluster and after everything will be fine 😉

Message Edited by JCC (SK) on 04-13-2010 05:19 PM
Message Edited by JCC (SK) on 04-13-2010 05:22 PM
0 Kudos
Message 3 of 23
(4,409 Views)

JCC (SK) wrote:

 

 

Why Search 1D Array is working [I didn't test it]?


Because searching an array is defined - is this element in the array or not?

 

Sorting is not defined, because different classes are different data types and each data type needs its own definition for sorting (e.g. for strings, you need to decide whether b>C, etc.). You can implement your own sort VI for your class hierarchy, which will accept an array of these classes and use whatever logic you want to sort the array.


___________________
Try to take over the world!
Message 4 of 23
(4,389 Views)

Guys! You are not helping me!

 

🙂

0 Kudos
Message 5 of 23
(4,387 Views)

JCC (SK) wrote:

Guys! You are not helping me!

 

🙂


 

So this is not an achedemic Q? Smiley Surprised

 

In that case I'll throw out an idea to get the conversation started.

 

In the parent class create a method that returns the ranking for that object instance. Sort the rankings and then apply that sort back to the original array.

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 23
(4,384 Views)
I could program everything but I hoped that something will LV/NI do 😉
0 Kudos
Message 7 of 23
(4,379 Views)

JCC (SK) wrote:
I could program everything but I hoped that something will LV/NI do 😉

 

How can NI do anything? Sorting an array of objects is completely meaningless without an algorithm, which you have to provide. I'm not sure what the problem is, since building such a VI should be very simple once you decide how you want to sort the data.

___________________
Try to take over the world!
0 Kudos
Message 8 of 23
(4,362 Views)

I don't see any compelling reason why we should break that wire.  Putting arbitrary data in an array of clusters along with something to sort by is a really common use case.  I've filed CAR# 219940 on this issue.  Incidentally, the broken wire has been the behavior since LV Classes were introduced in LabVIEW 8.2.

Message Edited by Darren on 04-13-2010 04:12 PM
Message 9 of 23
(4,343 Views)

Darren wrote:

I don't see any compelling reason why we should break that wire.  Putting arbitrary data in an array of clusters along with something to sort by is a really common use case.  I've filed CAR# 219940 on this issue.  Incidentally, the broken wire has been the behavior since LV Classes were introduced in LabVIEW 8.2.

Message Edited by Darren on 04-13-2010 04:12 PM

 

To sort you have to get at the stuff in the private data and you aren't allowed to look a that outside the class. Beraking the wire enforces that. Seems right to me.

 

Even if we say operators are allowed, an empty parent class with two different children one with a numeric and another with just a string, how to define a sort of tht type?

 

So how is this a bug?

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 23
(4,318 Views)