Dictionary
|
A Dictionary is an Object containing an arbitrary number of bindings. A binding consists of a key and value pair. A Dictionary key can only be can any Object type such as Symbol (Unquoted or Quoted), List, Pair (Unquoted or Quoted), all Vector types, Structure, Dictionary, Repository, or Lambda.
Analytic Information Server Structure Objects and Dictionary objects share common properties: they both contain an arbitrary number of bindings, values can be referenced by key or index, or two indices, keys can only be objects. However, Dictionary Object keys are always maintained in ascending sort order. There are no sort functions for sorting keys in a Dictionary, nor can Dictionaries be sorted by value.
A Dictionary Object is analogous to a table containing exactly two columns and an arbitrary number of rows. The left column contains a key (must be an Object type: Symbol, List, Pair , any Vector type, Structure, Dictionary, Repository, or Lambda ) , and the right column contains the value associated with its key. Any given row in a table is analogous to a Dictionary binding: Key/Value pair.
Aardvark | "Animal with long snout" |
Armadillo | "Animal with a protective shell" |
Baboon | "A simian found in the jungle" |
Cheetah | "A fast running animal" |
Platypus | "A mammal with a bill" |
Or delete the key, Baboon:
Aardvark | "Animal with long snout" |
Armadillo | "Animal with a protective shell" |
Cheetah | "A fast running animal" |
Platypus | "A mammal with a bill" |
Dictionaries are like Structures, in that they are convenient for storing Key/ Value pairs. However, they have a maintenance overhead keeping the keys in sorted order. An application that requires sorted keys would best be served by using a Dictionary.
An Analytic Information Server Dictionary is similar to the user-defined type of Visual Basic. The Visual Basic user defined type is created at compile time, whereas the Analytic Information Server structure is created, expanded, or contracted dynamically at run time. The main difference is that the Visual Basic user defined type is static and the Analytic Information Server structure is dynamic, has its object keys and values available maintained in sorted order, and the object keys offer a wider range of values.
Type Employee
Name As Variant ' Name of the employee.
Salary As Variant ' Salary of the employee.
Address As Variant ' Address of the employee.
City As Variant ' City of the employee.
State As Variant ' State of the employee.
End Type
The Dictionary native data type supports a constant form. The whole Dictionary constant is enclosed in braces and preceded by the sharp symbol, brace, and the dic| symbol (#{dic|). Some Dictionary constant examples:
#{dic| Name: "John Doe" Address: "184 Anywhere Street" City: "Los Angeles" State: "California"}
The constant form for dictionaries allows using the constant prefix, #{dic|| with two bars, to specify creating "as is" in unsorted order as follows:
#{dic|| Z: 5 Y: #{Mike: "father" Sally: "mother"} X: "Hello"}
The constant form for dictionaries allows embedded Analytic Information Server objects for the values or keys as follows:
#{dic| X: 5 Y: #{Mike: "father" Sally: "mother"} Z: "Hello"}
#{dic| #Jan,1 ,1972 {Name: Joe Eyes: Blue} #Sept, 3 ,1969 {Name: Jan Eyes: Brown}}
The Dictionary is a Heap Object or an Object Data Type. The Analytic Information Server Object Types are stored in the Heap and are managed by the Heap manager. The Analytic Information Server Heap manager supports object resizing, garbage collection, and anti-fragmentation algorithms so that the user may concentrate on the analysis and modeling of data rather than on memory management. Without exception, all of the Object types are identified by an object id. The object id identifies a block of memory, managed by the Lambda Information Server memory manager, in which the Object's data is stored.
The Analytic Information Server Heap Object and Native Data types can be saved and loaded to and from persistent (disk file) storage at any time. Containers with immediate data are saved on disk in fixed length records equal to the size of the container. Containers with Heap object references are saved in fixed length records, which are automatically expanded to include the contents of the Heap object, and any objects referenced by the Heap object, etc. This feature is called Object Closure Management and is automatic with every Analytic Information Server container database save.
Analytic Information Server containers may be loaded from any database repository record at any time. If the data in the record is immediate, the database load fills the container with the immediate data. If the data in the record is an object closure, the database load fills the container with a Heap object reference, and all of the objects in the record are loaded back into the Heap with the same referential relationships they had when they were saved in the repository.
The Dictionary object can be demonstrated by the following examples.