Class ADictionary

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ADictionary = class(AMapping)

Description

This class represents a dictionary, which is a list of items that are indexed by a string key. The overall functionality of the dictionary is similar to that provided by Python and other languages that implement such objects; however, the dictionary is implemented as a binary tree rather than a table of hashed objects.

As with instances of ABinaryTree, the dictionary is capable of looking up entries and streaming those entries to and from arbitrary streams. The dictionary also supports condensing itself into a delimited string and iterating over its keys and values.

Hierarchy

Overview

Methods

Public function init: boolean; override;
Public function Values: AVariantList; virtual;
Public function add(const thisKey: string; const thisValue: Variant): ADictionaryEntry; reintroduce; virtual;
Public function valueOf(const key: string): Variant; virtual;
Public function valueOf(const key: string; const defaultValue: Variant): Variant; virtual;
Public function setValueOf(const key: string; const thisValue: Variant): Variant; virtual;
Public function valueAt(const thisIndex: TNodeAbsoluteIndex): Variant; virtual;
Public function setValueAt(const thisIndex: TNodeAbsoluteIndex; const newValue: Variant): Variant; virtual;

Description

Methods

Public function init: boolean; override;

Initializer

Public function Values: AVariantList; virtual;

Construct a list of all entry values in the dictionary.

This method proceeds sequentially through all entries in the dictionary, obtaining the value of each. The values are inserted into an instance of AVariantList which is constructed for this purpose.

Returns

An instance of AVariantList that contains the values of all dictionary entries. This list should be freed by the caller when it is no longer required. If there are no entries in the dictionary, an empty variant list is returned.

Public function add(const thisKey: string; const thisValue: Variant): ADictionaryEntry; reintroduce; virtual;

Add the specified key and value to the dictionary.

As with other instances of ABinaryTree, ADictionary does not allow duplicate entries; consequently, if thisKey already exists in the dictionary, its value will be updated with thisValue. Otherwise, a new entry is created.

Returns

A reference to the dictionary entry that has been created and inserted or, if the entry already existed, the existing entry. The caller should NOT attempt to free this reference; that will be done when the dictionary is destroyed.

Public function valueOf(const key: string): Variant; virtual;

Retrieve the value of the named item.

This method retrieves the instance of ADictionaryEntry that has the specified key; it then returns the value obtained by calling ADictionaryEntry.value on that entry.

If no entry that matches key is found in the dictionary, this routine returns Variants.null.

Public function valueOf(const key: string; const defaultValue: Variant): Variant; virtual;

Retrieve the value of the named item.

This method retrieves the instance of ADictionaryEntry that has the specified key; it then returns the value obtained by calling ADictionaryEntry.value on that entry.

If no entry that matches key is found in the dictionary, this routine returns defaultValue.

Public function setValueOf(const key: string; const thisValue: Variant): Variant; virtual;

Set the value of the named item.

This method retrieves the instance of ADictionaryEntry that has the specified key; it then sets the value by calling ADictionaryEntry.setValue on that entry.

If no entry that matches key is found in the dictionary, then this method will add a new item.

Returns

The previous value of the specified item, if it was found; Variants.null otherwise.

Public function valueAt(const thisIndex: TNodeAbsoluteIndex): Variant; virtual;

Retrieves the value at the specified index in the dictionary.

Internally, this method calls ABinaryTree.LeafAtIndex on itself; if that method returns a node, then ADictionaryEntry.value is called on it.

Returns

The value of the node at the specified index, if found; Variants.null otherwise.

Public function setValueAt(const thisIndex: TNodeAbsoluteIndex; const newValue: Variant): Variant; virtual;

Set the value of the entry at the specified index in the dictionary.

Internally, this method calls ABinaryTree.LeafAtIndex on itself; if that method returns a node, then ADictionaryEntry.setValue is called on it.

Returns

The previous value of the node at the specified index, if found; Variants.null otherwise.


Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18