Showing results for 
Search instead for 
Did you mean: 

Deficiency in Maps

When you have 2 references to the same object, under the hood, they may have different numeric values, but even so, comparison functions (e.g. paul_cardinale_0-1670247031510.png) work as you would want: They check whether the references refer to the same object, not whether they have the same numeric value.  The "Search 1D Array" function (paul_cardinale_1-1670247126696.png) also works like that.

But if you use a reference as a key in a map, the function "Look In Map" (paul_cardinale_2-1670247176950.png), doesn't work like that, it just checks the numeric value of the key.  (Drat.)




"If you weren't supposed to push it, it wouldn't be a button."
Message 1 of 3

That's interesting to know. I assume the two same-but-different reference keys can be inserted into the map at the same time too? (ie. one doesn't replace the other)


The help for the equals function states the reference comparison will return true if the object is the same, and to type cast the reference to a number if you need to compare the reference value itself. Given the equals and search 1D array functions work in this way, I'd say it's a bug that the map VIs treat reference comparisons differently. Given this behavior has presumably been there since maps/sets were added in LV2019, I don't see it being changed now. The least NI can do now is update the maps/sets documentation that reference comparison doesn't check the underlying object.

Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
0 Kudos
Message 2 of 3

That's a remarkable discovery!


I remember stepping into that trap, too. The associative array in python (i.e., a dict()) requires the key to be immutable and hashable ( I don't know, but have little doubt that LabVIEW has similar requirements. With a reference, the reference itself fulfills the requirement, but the referred object does not: The referred object can change substantially after the hash has been saved.


If you do need to have a map with your mutable objects as keys, you probably need to go a step back and implement that yourself for the object type. You might event want it to be a Multimap ( if you don't want to guarantee that the keys are unique.

0 Kudos
Message 3 of 3