LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
gnilsson

Element of Set? to also return the index in the set

Status: Declined

Sometimes it would be useful to get the index in the set. 

Could then replace Search 1D array in this :

gnilsson_0-1597300452773.png

 

4 Comments
AristosQueue (NI)
NI Employee (retired)

If you want to do this kind of search, I strongly suggest you look at

vi.lib\Array\Search Unsorted 1D Array.vim

You can pass in your comparison function that just checks the first element. An example of doing this is at

examples\Malleable VIs\Nested Malleable VIs\Malleable VIs - Nested Malleable VIs.lvproj

This malleable VI is one that my team intends to eventually add to the palettes... there just wasn't time to do it while delivering interfaces in LV 2020.

 

Regarding the idea: such a change would kill performance.

 

The time complexity of existing Search 1D Array is O(n) (it is a linear search on a presumed unsorted array). The time complexity of the picture you have shown is three parts: an O(n log n) loop, an O(n) loop, and a second O(n) loop, for a total of O(n log n + Cn), where C is a substantially large number. (Normally multiplicative constants are ignored in big-O notation, but I'm making a point comparing these two implementations.) That C includes the over head of making two complete copies of the data in the original array.

 

Sets do not have an index, deliberately. If you need a structure that you are going to index into, do not use a set. Sets do not define an index -- it isn't a linear data structure.

Christina_R
Active Participant
Status changed to: Declined
 

Christina Rogers
Principal Product Owner, LabVIEW R&D
gnilsson
Member

Hi,
Maybe I should be more clear,
I wanted Element of Set ? to return the index , since the Help text says:

Because a set maintains elements in sorted order, a set allows faster search, insertion, modification, and removal operations on the data than unordered data structures, such as arrays, even when the data size is large. A set has memory overhead to maintain the elements in sorted order, which arrays do not have.

So I don't understand "Regarding the idea: such a change would kill performance."

AristosQueue (NI)
NI Employee (retired)

> So I don't understand "Regarding the idea: such a change would kill performance."

 

The picture you posted of how to write Search 1D Array. First, it takes an array and converts it to a set... that's an O(n log n) operation with a whole lot of data movement. Then you converted that to an array. That's an O(n) operation with more data movement.

 

Sets don't maintain an internal indexed location.

 

Like I said, for efficient implementation of what you're trying to do (search an array using a limited comparison [in this case, just one element of cluster]) use the Search VIM.