Sorting Multi-dimensional Sparse Arrays

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Sorting Multi-dimensional Sparse Arrays

Martin Marris
How does one sort a Sparse Array (in particular, a Sparse "array of
arrays")?

I have a sparse array each of whose elements consists of a three-element
array.

Let us call those elements a, b and c.

I would like to sort the "outer element" on key "a" and within key "a" I
want to sort again on key "b".

The workaround I've come up with is to dump the sparse array. Instead of an
array of arrays, I've used a non-sparse array and combined keys "a," "b" and
"c" into a single, space-delimited string (I am lucky that all of the input
values are strings and not objects). These combined strings are the elements
in the non-sparse array. I then used the array-sorting tools in "utils" sort
the strings. Finally, I used SplitString to convert the non-sparse,
one-dimensional array into a sparse "array of arrays."

But there has to be a better way....

(At one point Bob mentioned that it's easy and fast to sort such info if you
use Dictionaries?)

Martin


_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Sorting Multi-dimensional Sparse Arrays

Bob Zawalich-3
 I tend to do all this stuff with dictionaries rather than sparse a raise. For the dictionary key you can use the index and put the other stuff in the value and then just read out for each Name name in dict.

Utils has sparse array versions of sort array but I tend to think of dictionaries as sortable arrays and that works well.

Bob (from his iPhone)

> On Oct 9, 2015, at 7:56 AM, Martin Marris <[hidden email]> wrote:
>
> How does one sort a Sparse Array (in particular, a Sparse "array of
> arrays")?
>
> I have a sparse array each of whose elements consists of a three-element
> array.
>
> Let us call those elements a, b and c.
>
> I would like to sort the "outer element" on key "a" and within key "a" I
> want to sort again on key "b".
>
> The workaround I've come up with is to dump the sparse array. Instead of an
> array of arrays, I've used a non-sparse array and combined keys "a," "b" and
> "c" into a single, space-delimited string (I am lucky that all of the input
> values are strings and not objects). These combined strings are the elements
> in the non-sparse array. I then used the array-sorting tools in "utils" sort
> the strings. Finally, I used SplitString to convert the non-sparse,
> one-dimensional array into a sparse "array of arrays."
>
> But there has to be a better way....
>
> (At one point Bob mentioned that it's easy and fast to sort such info if you
> use Dictionaries?)
>
> Martin
>
>
> _______________________________________________
> Plugin-dev mailing list
> [hidden email]
> http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev

_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Sorting Multi-dimensional Sparse Arrays

Bob Zawalich-3
Be aware that if you use user properties on a dictionary they are implemented as dictionary entries and will show up when you enumerate the entries.

Bob (from his iPhone)

> On Oct 9, 2015, at 11:40 AM, Bob Zawalich <[hidden email]> wrote:
>
> I tend to do all this stuff with dictionaries rather than sparse a raise. For the dictionary key you can use the index and put the other stuff in the value and then just read out for each Name name in dict.
>
> Utils has sparse array versions of sort array but I tend to think of dictionaries as sortable arrays and that works well.
>
> Bob (from his iPhone)
>
>> On Oct 9, 2015, at 7:56 AM, Martin Marris <[hidden email]> wrote:
>>
>> How does one sort a Sparse Array (in particular, a Sparse "array of
>> arrays")?
>>
>> I have a sparse array each of whose elements consists of a three-element
>> array.
>>
>> Let us call those elements a, b and c.
>>
>> I would like to sort the "outer element" on key "a" and within key "a" I
>> want to sort again on key "b".
>>
>> The workaround I've come up with is to dump the sparse array. Instead of an
>> array of arrays, I've used a non-sparse array and combined keys "a," "b" and
>> "c" into a single, space-delimited string (I am lucky that all of the input
>> values are strings and not objects). These combined strings are the elements
>> in the non-sparse array. I then used the array-sorting tools in "utils" sort
>> the strings. Finally, I used SplitString to convert the non-sparse,
>> one-dimensional array into a sparse "array of arrays."
>>
>> But there has to be a better way....
>>
>> (At one point Bob mentioned that it's easy and fast to sort such info if you
>> use Dictionaries?)
>>
>> Martin
>>
>>
>> _______________________________________________
>> Plugin-dev mailing list
>> [hidden email]
>> http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev

_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev