Jump to content
Götz Becker

Variant attribute list always sorted?

Recommended Posts

Is the list of names/attributes returned by "get variant attribute" without a name connected always (guaranteed) sorted?

It is sorted at all my tests but is this a feature or just a coincidence and might change if the underlying algorithms change.

Since this isn't documented, it could change without notice in a new LV version!?!

post-1037-0-35464600-1310729479_thumb.pn

Share this post


Link to post
Share on other sites

Is the list of names/attributes returned by "get variant attribute" without a name connected always (guaranteed) sorted?

It is sorted at all my tests but is this a feature or just a coincidence and might change if the underlying algorithms change.

Since this isn't documented, it could change without notice in a new LV version!?!

post-1037-0-35464600-1310729479_thumb.pn

It isn't documented, but I think the implementation is a red/black tree to allow for fast searches. This requires the list to be rebalanced (resorted) whenever an item is added, so it is stored sorted (by attribute name).

If the function returns a list of items when the name is left blank, it makes sense that the list would always be returned sorted. NI could certainly change this behavior, but I'd bet that this would break a bunch of NI code.

See the dark side:

Darren's Weekly Nugget 10/09/2006

http://forums.ni.com/t5/LabVIEW/Darren-s-Weekly-Nugget-10-09-2006/td-p/425269

Share this post


Link to post
Share on other sites

If you're worried about an undocumented feature going away, why not just add a sort after the read?

Share this post


Link to post
Share on other sites

If you're worried about an undocumented feature going away, why not just add a sort after the read?

If you are worried about performance and memory usage, why add an unneeded sort?

I don't know which sorting algorithm "Sort 1D Array" uses, but I think I've heard it's Quicksort.

This algorithm needs an especially large number of iterations, if the input array is already sorted.

We wouldn't want to waste CPU time and memory on sorting a few thousand strings that are already in the correct order, just because of incomplete documentation.

AQ:

Thank you very much for your reply!

You are really succeeding in optimizing the quotient helpfullness / number of characters in answer. :thumbup1:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.