1.42 class dict

A dict object (a dictionary) is a collection of dictionary items (dict_item objects), each of which is a triple (key, label, object). The key must be unique over the dict.

Dict objects can be made visible by attaching them to a browser object or list_browser object. The browser can then be used to select dict_item objects.

The access to a dict_item object from a key is implemented using a hash_table object.

Bugs:

Class dict is very old and is based on some outdated ideas. Currently its primary use is to provide the storage facilities for a browser.

Its definition might be revised some day to be more in line with the spirit of the current PCE system. Notably try not to rely on dict->format and dict<-current.

See also
- class browser
- class list_browser
- class dict_item

1.42.1 Class variables

dict.sort_ignore_blanks: bool = @off
When @on, ignore leading and trailing blanks. Map multiple blanks onto a single space. See dict->sort.
See also
- dict.sort_ignore_case
- dict->sort
dict.sort_ignore_case: bool = @off
When @on, sort the dict case-insensitive on the dict_item<-label.
See also
- dict<-find_prefix
- dict.sort_ignore_blanks
- dict->sort

1.42.2 Instance variables

dict-browser: list_browser*
When not @nil, this is the list_browser object that visualises this dictionary. The slot list_browser<-dict contains the reverse pointer.

When the dict is modified, it will send messages to the list_browser object:

[|](108, [105,115,116,95,98,114,111,119,115,101,114,32,45,62,95,100,101,108,101,116,101,95,105,116,101,109,58,32,100,105,99,116,95,105,116,101,109])
The indicated item has been deleted from the dict
[|](108, [105,115,116,95,98,114,111,119,115,101,114,32,45,62,95,105,110,115,101,114,116,95,105,116,101,109,58,32,100,105,99,116,95,105,116,101,109])
The indicated item has been inserted in the dict
[|](108, [105,115,116,95,98,114,111,119,115,101,114,32,45,62,95,99,108,101,97,114])
The dict has been cleared.
See also
- list_browser-dict
- class list_browser
dict <- members: chain
Chain with all the members. Class dict stores its members twice: once in dict<-members to maintain ordering information (see dict->sort and dict->append) and once in the hash_table object dict<-table to get fast access from a key to a dict_item object.
See also
dict-table
dict <- sort_by: [code]*
The method dict<->sort_by defines the behaviour of dict->insert as well as the default behaviour of dict->sort. If its value is @nil, no sorting is done. dict->insert and will behave as dict->append. Using @default, the arguments are sorted alphabetically on their printed representation. dict->insert will insert a new item according to this order. If the dict<-sort_by contains a code object, this will be used for comparing the pairs of dict_item objects. See also chain->sort. It dict<-sort_by is assigned another value than @nil, dict->sort will be activated to establish the desired order.

Using dict->sort_by is a good technique to insert new items at the right place in the list. It is not a good technique to build up a sorted list as this will result in quadratic behaviour for long lists, while dict->sort uses the QuickSort algorithm.

dict-table: hash_table*
The mapping from dict_item<-key to the corresponding dict_item object is maintained by this hash_table object.

1.42.3 Send methods

dict ->append: item=dict_item
Append the dict_item at the end (see dict<-members). Note that class dict_item defines a conversion function to create a dict_item from a key. See dict_item<-convert.

See also dict->insert_after and dict->insert.

Bugs: If there is already a dict_item with this dict_item<-key, the old entry is deleted from dict<-table. A subsequent dict<-member wil this return the last appended dict_item with this dict<-key.

See also
- dict->insert_after
- dict_item<-convert
dict ->clear:
Removes all dict_item objects from the dict. Informs a possibly related dict<-browser.
See also
dict->delete
dict ->delete: any|dict_item
Delete a dict_item object. The dict_item to be deleted may be specified using its dict_item<-key.

Diagnostics: Fails silently when the argument is not a member dict_item or and the key of a member dict_item.

See also
dict->clear
dict ->for_all: action=code, safe=[bool]
Invokes chain->for_all on the chain of dict<-members.
See also
dict<-find
dict ->for_some: action=code, safe=[bool]
Invokes chain->for_some on the chain of dict<-members.
See also
dict<-find
dict ->insert: item=dict_item
Insert dict_item according to dict<-sort_by. If dict<-sort_by is @nil, just dict->append. If dict<-sort_by is @default, insert the item before the first item that is alphabetically larger. It dict<-sort_by contains a code object, insert it before the first item for which executing the code (if it is a function) return larger.

See also chain->sort, dict->insert_after, dict->append, dict->sort and dict->sort_by.

dict ->insert_after: after=dict_item, item=any|dict_item*
Add a dict_item object (like dict->append) after the specified item (a dict_item or key). If the second argument is @nil, the dict_item is inserted as the first item.
See also
dict->append
dict ->member: any|dict_item
Test if the argument (a dict_item object or a dict_item<-key) is member of the is dict.

Bugs: Redundant. Use dict<-member instead.

See also
dict<-member
dict ->sort: [bool|code|function], ignore_blanks=[bool], reverse=[bool]
Sort the contents of the dict. The ordering information is kept in dict<-members. There are two possibilities:

1.42.4 Get methods

dict <-find: test=code -> dict_item
Invokes chain<-find on the chain of dict<-members.
See also
- dict<-find_all
- dict->for_some
- dict->for_all
dict <-find_all: test=code -> chain
Invokes chain<-find_all on the chain of dict<-members.
See also
- dict<-match
- dict<-find
dict <-find_prefix: for=string, from=[int], no_exact_case=[bool] -> dict_item
Return the first dict_item object from dict<-members whose dict<-label (or dict<-key if the dict<-label is @default) has the specified prefix. The search starts at the nth dict_item (0-based). The last argument requests case-insensitive (@on) or case-sensitive (@off).

Diagnostics: # Start index: 0

dict <-match: char_array -> chain
Return a new string holding all dict_item objects in this dict whose dict_item<-label (or dict_item<-key when the label is @default) match (using char_array->sub) the argument name.

Note that more complicated searches may be performed using dict<-find_all.

Bugs: Should allow for case-insensitive matching.

See also
- dict<-find_all
- dict<-find_prefix
- dict<-member
dict <-member: any|dict_item -> dict_item
When the argument is a dict_item object, return it if dict_item<-dict equals this dict. Otherwise, invoke hash_table<-member on dict<-table and return the result.

Note that many of the methods of the class that require a member dict_item argument use dict<-member to find the dict_item.

See also
dict<-match