Jump to content

Variant Hash Table for Aggregate Objects: DVRs by Name


Recommended Posts

I did a quick search of the website but I didn’t see something like this posted so I’d thought I’d post it. It’s probably been done before but I found that it pretty helpful in my current project.

I usually use DVRs whenever I want to use the aggregation pattern (zero or more relationship). Many times though I want to sort or return an object from the array based on an attribute in the object (like name). Since I am using a DVR I found I can quickly make a hash table using variant attributes. I just use the “Name” or other unique value and make the DVR the value. I can then lookup a DVR by name through the variant. It stays really fast because the DVR is just a reference to the data and I am not looping through DVR references and comparing the name or unique value to the value in the object.

Example use:

I can lookup these commands by name or opcode using the variant hash table.

I create the lookup based on name.

post-2966-0-52344000-1345597086_thumb.pn

I also create the lookup based on opcode

post-2966-0-54474700-1345597148_thumb.pn

I can then lookup the object very quickly based on name or opcode.

post-2966-0-85072300-1345597159_thumb.pn

  • Like 1
Link to comment

Instead of using the name which is possibly not unique you can flatten the dvr to string and use it as a unique identifier.

In order to prevent duplicated refs or different refs that point to the same data you can add a dup check while building your lookup:

Before adding a ref iterate over the existing dvrs and try to inset the new dvr and the current dvr from your lookup into an in place structure.

If the two dvrs refer to the same data LV will give you error 1557. Catch it and if it was caught don't add the dvr into the lookup.

Since you might have two different dvrs referring to the same data, searching for a dvr in the array might still require the 1557 error testing and thus reduce the theoretical performance.

Beside that, watch out of the dvr life span. DVRs live as long as the application that created them live. You might get a lookup table with invalid dvrs.

Moreover, you might want to add a privacy mechanism since you don't want everyone to access any dvr. It is true that a dvr can be opened only by vis from the class that it was created from yet I don't want someone to iterate over the dvrs array calling some execute.vi for example if I don't want it to (a use case might be a different operation method for advanced user and basic user).

P.S. - this lookup is not a hash table. The Variant implements the red/black tree and not a hashing algorithm.

post-18598-0-64244900-1345605475_thumb.j

Edited by 0_o
Link to comment
I usually use DVRs whenever I want to use the aggregation pattern (zero or more relationship).

If you’d like to stay by-value and avoid the DVRs, you can instead keep your objects in an array, and store the object’s array index in the variant attribute look up tables.

Link to comment

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.