Dictionaries

Dictionaries are data structures that associate keys with values; like maps in C++ and Java, arrays in AWK, and association lists in LISP.

Declare a dictionary in a Global or Local block using the syntax:
dictionary(keyType, valueType) variable;
For instance, if you have an input stream called "input_stream", you could store an integer for distinct records as
dictionary(typeof(input_stream), integer) counter;

Only one value is stored per key. It is therefore important to understand what equality on keys means. For the simple datatypes, equality means the usual equality, for example, equality on integer or on string values. For record types, equality means that the keys match (the data fields and operation are ignored).

Dictionaries can be defined anywhere that a variable can be defined: globally or locally

While dictionaries and vectors can be defined globally, design and use global structures with care. Recall that ESP is multi-threaded. Therefore, when accessing a structure that can be modified from multiple threads, be aware that the state of the structure when you are accessing it may not actually be what you assume it to be. Also consider the impact on performance, particularly when iterating over data structures. As a CCL query or flex operator iterates over a data structure, the query or flex operator locks the structure, blocking other threads. Thus, performance degrades significantly with the number of concurrent queries iterating over the global structure.

Global use of these data structures should be limited to relatively static data (such as country codes) that will not need to be updated during processing, but will be read by multiple streams. Writing the data to the dictionary or vector must be completed before any streams read it.

When you create a dictionary, you can specify a valueType of dictionary to create a dictionary of dictionaries. This structure is useful when your logic involves separating data into two levels (for example, a dictionary of telephone area codes containing dictionaries of the exchanges within each area code). But, this structure requires a lookup at each level, and lookups are time-consuming.