01-21-2021 09:24 AM
So I just upgraded to LV2020 SP1 and I'm writing some code. I went to use the trusted "Search 1D Array" native function and see that it is GONE!
It has been replaced by "Search Sorted 1D Array" and "Search Unsorted 1D Array".
But here's the catch. I want to search a 1D array of strings. And it doesn't appear that I can wire that into either of them.
Another oddity: I could certainly sort my 1D array of strings before searching it (if NI forces me). But even that doesn't help. Still can't wire it.
See below:
01-21-2021 10:15 AM
Once you wire a string into the 'element' input of the Search Unsorted 1D Array.vim, the string array wire will no longer be broken.
01-21-2021 10:23 AM
Ahhh... so easy ... and yet so confusing.
I think this is poorly implemented in the IDE. If I wire a string to the element node, it shows a broken arrow:
But if you wire strings to BOTH nodes, then the broken array to go away
Seems poorly implemented to me. I would assume that when you wire a string to the element node, the IDE should change the array node to an expected array of strings.
01-21-2021 10:25 AM
I agree completely.
01-21-2021 10:27 AM
@josborne wrote:
Ahhh... so easy ... and yet so confusing.
I think this is poorly implemented in the IDE. If I wire a string to the element node, it shows a broken arrow:
But if you wire strings to BOTH nodes, then the broken array to go away
Seems poorly implemented to me. I would assume that when you wire a string to the element node, the IDE should change the array node to an expected array of strings.
It would be too logical to think that it should behave similarly to the polymorphic VI that it is supposed to be an alternative to.
01-21-2021 10:46 AM
I made an updated Array palette file for LabVIEW 2020 SP1 that includes the Search 1D Array function. It's attached here (inside a zip file, since apparently the forums don't let me attach a .mnu file). Only use this file with LabVIEW 2020 SP1, and make sure to back up the original first. Here is the specific file you want to replace:
LabVIEW 2020\menus\Categories\Programming\array.mnu
After replacing the file, you can refresh the palettes by either restarting LabVIEW or dropping the 'Refresh Palettes' method in a VI and running it. Let me know if this works for you.
01-21-2021 10:59 AM
Dunno if this is in the online help, but I don't have 2020 SP1 to check.
Is it fair to assume that the "Search Sorted 1D Array" will use a binary search, or some other algorithm whose speed scales better than a linear search? If the item being searched for occupies 4 consecutive indices in the sorted array, which index is returned? Or will it depend on where those indices are relative to the bin boundaries of the binary search?
-Kevin P
01-21-2021 11:42 AM
@Kevin_Price wrote:
If the item being searched for occupies 4 consecutive indices in the sorted array, which index is returned? Or will it depend on where those indices are relative to the bin boundaries of the binary search?
I just tried it. Depending on the size of the array and where the duplicates lie within that range, you'll get different indices returned. I suspect this is how most binary searches work.
01-24-2021 05:06 PM
Here's a VI (attached) that will add Search 1D Array back to the Programming >>> Array palette programmatically.
It creates a backup of the original and it only adds it to the palette, if it's not already there. So, it should be pretty safe to run on even if someone accidentally runs it on something other than LabVIEW 2020 SP1.
Please take a look at the code to see if there's anything you recommend changing.
If this is helpful, I'll probably end up creating a VI Package for this and publishing it on VIPM.io.
01-25-2021 12:58 PM
@Jim_Kring wrote:
Please take a look at the code to see if there's anything you recommend changing.
Your VI looks fine to me. I assume if you build this into a VIPM package you'll have a post-uninstall VI that restores the backup .mnu file?