Grouping Data with Collections

A collection is a container for aggregating homogeneous data. Each object in the collection is an�element�or entry of the collection. Use the collection data types to create high-performance data structures for storing and accessing data. LabVIEW includes the following collection data types: set and map.

Sets

A set groups unique elements of the same data type in sorted order. Inserting a new element modifies the set only if that element does not already exist in the set.

Element
Size�Number of elements in the set
Wires of set�Wire�color�matches�the data�type�color�of�the�element

Because a set maintains elements in sorted order, a set allows faster search, insertion, modification, and removal operations on the data than unordered data structures, such as arrays, even when the data size is large. A set has memory overhead to maintain the elements in sorted order, which arrays do not have.

Maps

A map groups�key-value�pairs in sorted order where all�the keys are�unique.�The�key and value can each be any data type. Maps are also known as dictionaries because the key is used to look up a value. Inserting a�key-value�pair into a map either adds the pair to the map or replaces the existing value of the associated key with the new value in the map, depending on whether the key already exists in the map.

Key
Value
Entry�A pair of associated key and value
Size�Number of entries in the map
Wires of map�Wire�color�matches�the�data�type�color�of�the value

While variant attributes can also be used as a dictionary to look up a value, maps are more flexible than variant attributes in that the key and value can each be any LabVIEW data type. For variant attributes, the key must be a string and the value must be a variant. Maps are also less error prone than variant attributes. For maps, LabVIEW returns wiring errors at edit time because the value accepts a specific data type. For variant attributes, LabVIEW returns wiring errors at run time because the value is a variant type that accepts any data.

Use the Collection VIs and functions and the collection controls and indicators to create or manipulate collections.

Note��You cannot modify the embedded data in a collection interactively or programmatically. You can update collection data only as a whole through operations such as writing to the collection front panel terminal or right-clicking the collection and selecting Data Operations�Copy Data or Data Operations�Paste Data.

Refer to the following VIs or projects for an example of manipulating data using collections: