The Dict()
resembles Python's dict type, and is implemented
as a specialized associative Container()
.
For the standard S3 interface, see dict().
This class inherits from class Container()
and overwrides some
methods to account for the associative key-value pair semantic.
Internally, all key-value pairs are stored in a hash-table and the
elements are always sorted lexicographically by their keys.
container::Iterable
-> container::Container
-> Dict
Inherited methods
container::Iterable$iter()
container::Container$at()
container::Container$at2()
container::Container$clear()
container::Container$count()
container::Container$delete()
container::Container$delete_at()
container::Container$discard()
container::Container$empty()
container::Container$get_compare_fun()
container::Container$has()
container::Container$has_name()
container::Container$is_empty()
container::Container$length()
container::Container$names()
container::Container$peek_at()
container::Container$peek_at2()
container::Container$pop()
container::Container$print()
container::Container$rename()
container::Container$replace_at()
container::Container$size()
container::Container$type()
add()
If name
not yet in Dict
, insert value
at name
,
otherwise signal an error.
discard_at()
Discard value at given index. If index is not found, the operation is ignored.
replace()
Replace one element by another element.
Search for occurence of old
and, if found, replace it by new
.
If old
does not exist, an error is signaled.
set()
This function is deprecated. Use replace()
instead.
sort()
Sort elements according to their keys. This function is deprecated as keys are now always sorted.
update()
Add elements of other
to this if the name is
not in the Dict
and update elements with existing names.
clone()
The objects of this class are cloneable with this method.
d = Dict$new(o = "one", na = NA, a = 1)
d
#> {a = 1, na = NA, o = "one"}
d$keys()
#> [1] "a" "na" "o"
d$add("li", list(1, 2))
#> {a = 1, li = list(1, 2), na = NA, o = "one"}
d$discard_at("na")
#> {a = 1, li = list(1, 2), o = "one"}
d$replace(1, 9)
#> {a = 9, li = list(1, 2), o = "one"}
d2 = Dict$new(a = 0, b = 1)
d$update(d2)
#> {a = 0, b = 1, li = list(1, 2), o = "one"}