Is there any way to get the sorting index in vl? i would like to sort a datatype´s spread against one if its elements.
It will sort based upon the first item of your datatype.
you mean something like former index? or do you want to choose the property of your data type that should be used for sorting?
For this there is Sort (Comparer) that gives you two slices it wants to compare and you have to return 1, 0 or -1 depending on how you want to sort the slices. in .NET there are default comparers for float/int and so on, but it looks like we forget to import them.
OrderBy from the DevLib could also help you, if it is a simple case like sorting by a number:
this might also be interesting:
Thanks for the tips, i have it already for simple sorting in VL,
but i don´t know how to get the same results in vl if i want to use consecutive sorting, for example:
“Sort by GroupID and then on every GroupID cluster sort by time”
this is a perfect example for the super powerful LINQ nodes in the DevLib. first group the spread by group id, sort the groups by their key and then sort the content of each group:
this can also be done in one go with the Sort (Comparer). the comparer only needs to know which element should be before another, so if the GroupID is the same, you only need to compare the time:
to switch whether you want to use the Time or ID you can use delegates to choose another operation when the value is requested for comparison this also works for the above solution with LINQ:
Super, i have the last example running,
4 times faster than the v4 version.
Just one little thing, with the last example i don´t get the elements count per group like in the first one.
Is there any other way to get it using the last example?
you can again use some LINQ magic:
to get the LINQ nodes reference the DevLib package in the node browser… if you use the other sorting option from above, you would get the groups on the fly:
AdvancedSorting.zip (10.2 KB)
Great, now it looks more elegant,
@tonfilm - could you post the simplest example of a spread sort with former index out? I get how to make a custom type and fill the index value, but not sure how to sort based on that
that would be the OrderBy node. after the OrderBy you can use a ForEach to get the Index. or maybe i did not get the question correctly… what is it you want to solve?
I’m just not sure how to use order by correctly. Patch attached
vl sort.zip (5.6 KB)
after the sorting you need to get the index back and output it to vvvv. also i’ve replace the fort ForEach loop by a Project, which in this case is much faster. still the whole thing takes about twice as much time because of all the vvvv <-> VL overhead.
in the example there is also a node that abstracts the whole index handling away using a Tuple (2 Items) which can be seen as an ad hoc data type with two arbitrary data fields, Item1 and Item2. Item1 is the original input data, Item2 is the index. the Tuple then represents the same as your myData type. in the KeySelector delegate of the OrderBy the Item1 of the Tuple is used as the input for another delegate call which selects a sort key from the original data. might be a good learning source:
but whenever you need to use the former index to sort another spread by that, you can ask yourself whether the two spreads should be joined before to stay together. the former index builds a relation between the two spreads that can be kept by a data type in a more convenient way…
vl sort 2.zip (9.9 KB)
the vl node is red however
did you use beta35.2? i’ve just downloaded the zip and it all works fine here…
35.2 fixed it. cheyas
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.