Jump to content
Sign in to follow this  
Daklu

Wildcards with Search 1D Array prim?

Recommended Posts

In my code I often have arrays of clusters in which I need to find the element that matches one piece of data in the cluster but the other pieces of data don't matter. For example, if I have an array of clusters in which each cluster contains a number and a string, I'll need to find the element in which the string matches a specific value but the number doesn't matter. (Often I won't even know the value of the number.)

I've always handled this by iterating through the array, unbundling each cluster, and comparing the strings. (Upper code line.) My benchmarking shows the search array prim to be ~20% faster than iterating for arrays that don't use clusters. Is there a way use a wildcard in place of a value in a cluster that would allow me to use the search array prim? (Lower code line.)

post-7603-1206561981.png?width=400

Share this post


Link to post
Share on other sites

Swap the order of your numeric and your string in the cluster, and I'll bet the Search 1D Array prim slows down to be a lot closer to your for loop. Currently the primitive is comparing that integer first, and if that doesn't match, it goes on to the next element. Comparing integers is always faster than comparing strings, so it's doing a lot less work than your for loop.

No, I don't know of any generic solution within LV. I'm pretty sure that various users have written various public tools to do something like this, but I'm not sure. Perhaps one of them will post here.

Share this post


Link to post
Share on other sites

QUOTE (Aristos Queue @ Mar 26 2008, 01:18 PM)

Swap the order of your numeric and your string in the cluster, and I'll bet the Search 1D Array prim slows down to be a lot closer to your for loop.

That's a good tip. Thanks! I hadn't thought about the order in which the cluster elements would get searched. Kind of a moot point in this particular case though as the search prim doesn't work for what I'm trying to do. ;) (I coded it up as an example of how I imagine it would work.)

Share this post


Link to post
Share on other sites

QUOTE (JFM @ Mar 27 2008, 07:13 AM)

1. Turn cluster array into a boolean cluster array by checking equality

2. Filter the active element by performing an AND operation

3. Search for the desired boolean cluster pattern

That is genius. Thanks! I was trying to work out some sort of masking algorithm, but wasn't successful without some serious hack. Your way is slick! :yes:

Share this post


Link to post
Share on other sites

I did some benchmarking to compare the standard unbundle method to JFM's boolean mask method.

Initially the unbundle method was faster with increased benefit if the item was near the beginning of the array. This makes sense as it will stop searching as soon as the item is found while the masking method iterates through the entire array twice before searching. However, later testing with slightly different test code had the mask method consistently faster. Odd.

Unfortunately my thumbstick appears to have digested my code. :throwpc:

Share this post


Link to post
Share on other sites

QUOTE (Daklu @ Mar 31 2008, 07:53 PM)

Initially the unbundle method was faster with increased benefit if the item was near the beginning of the array. This makes sense as it will stop searching as soon as the item is found while the masking method iterates through the entire array twice before searching. However, later testing with slightly different test code had the mask method consistently faster. Odd.

I think it is safe to say that the unbundle version should be faster for small arrays, and when only a few elements in the cluster is checked.

The main goal for me when I first started to use this, was not speed, but a way to easily update the code to include many cluster elements and to let a user select elements to search from a GUI. The search algorithm is pretty much unchanged regardless of the size of the cluster, making it easier to maintain.

/J

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.

Sign in to follow this  

×
×
  • Create New...

Important Information

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