dictionary
datatypes: dictionary
Map of unique keys to values.
A dictionary object holds entries, each a key and the value it
maps to. Every key is of one type and every value of one type, the key
type and the value type of the dictionary; two keys are the same key when
keyMatch says so.
A dictionary with no entries may have no key and value types yet, when
it is unconfigured; the first entries added configure it, and
configureDictionary creates one configured with no entries.
dictionary is a value class, and a dictionary is always a scalar
object: numel, size and isempty describe the object,
not its entries, which numEntries counts. Dictionaries cannot be
concatenated.
Entries are reached by indexing with keys, converted to the key type as
dictionary converts them:
d(keys) returns the values of keys, an
array of keys, in an array of the same shape; a key not in d is an
error.
d(keys) = values adds entries, or replaces
the values of keys already present, which keep their positions;
values has the size of keys, or is one value for all. An
unconfigured dictionary takes its types from the first entries.
d(keys) = [] removes the entries of
keys, ignoring keys not in d. A key removed and added
again goes after the others.
d{keys}, for a dictionary of 'cell'
values, returns the contents of their cells as a comma-separated list,
and d{key} = value stores value in a
cell under the single key key, [] included.
d.method (…) calls a method, as
d.keys ().
Indexing can continue into a value, as in d(key).x
or d{key}(2) = 5; assigning into the contents of
a new key starts from empty. end is not supported. Octave
cannot tell d(:) from d(':'), so ':'
is the key ":", as it is in MATLAB in an assignment; use
keys or values for every entry.
jsonencode refuses a dictionary, as in MATLAB, and
writedictionary writes one to a JSON file.
See also: configureDictionary, isdictionary, keyHash, keyMatch
Source Code: dictionary
The dictionary class offers the following public methods:
dictionary |
Create a ‘dictionary’ object. |
types |
Return the key and value types. |
isConfigured |
True for a dictionary with key and value types. |
numEntries |
Return the number of entries. |
numel |
Return 1, the number of elements of a scalar object. |
length |
Return 1, the length of a scalar object. |
size |
Return the size of a scalar object. |
ndims |
Return 2, the number of dimensions of a scalar object. |
isempty |
Return ‘false’: a dictionary is never an empty array. |
dispstrings |
Return the line that describes a dictionary. |
writedictionary |
Write a dictionary to a JSON or an OpenDocument spreadsheet file. |