LabVIEW has a somewhat hidden feature built into the variant attributes functionality that easily allows the implementation of high performance associative arrays. As discussed elsewhere, it is implemented as a red-black tree.
I wonder if this functionality could be exposed with a more intuitive set of tools that does not require dummy variants and somewhat obscure VIs hidden deeply in the variant palette (who would ever look there!).
Also, the key is currently restricted to strings (Of course we can flatten anything to strings to make a "name" for a more generalized use of all this).
I imagine a set of associative array tools:
- Create associative array (key datatype, element datatype)
- insert key/element pair (replace if key exists)
- lookup key (index key) to get element
- read all keys
- delete key/element
- delete all keys/elements
- dump associative array to disk
- restore associative array from disk
- destroy associative array
- ... (I probably forgot a few more)
I am currently writing such a tool set as a high performance cache to avoid duplicate expensive calculations during fitting (Key: flattened input parameters, element: calculated array).
However, I cannot easily write it in a truly generalized way, just as a version targeted for my specific datatype. I've done some casual testing and the variant attribute implementation is crazy fast for lookup and insertion. Somebody at NI really did a fantastic job and it would be great to get more exposure for it.
Example performance: (Key size: 1200bytes, element size 4096: bytes, 10000 elements)
insert: ~60 microseconds
random lookup: ~12 microseconds
(compare with a random lookup using linear search (search array): 10ms average. 1000x slower!)
Thanks!
Available in LabVIEW 2019 with the Collection > Map functions and VIs.