ValueMap

class dsviper.ValueMap

Bases: Value

A value of type map<key_type, element_type>. Seamless with a Python dict[object, object].

Iterates in sorted key order, not insertion order. Or use Value.create(type_map [, initial_value]).

This constructor builds a new container over the same elements, so only a mutation inside an element shows through.

at(key: _InputValues, *, encoded: Literal[True] = True) → _OutputValues

Return the value for a key.

encoded=False returns a Value rather than a native object.

static cast(value: Value | _OutputValues) → ValueMap

Return value as a map, or raise if it is not one.

clear() → None

Remove all items.

contains(key: _InputValues) → bool

Return True if the map holds an entry at key.

copy() → ValueMap

Return a deep copy.

description(*, namespace: NameSpace | None = None) → str

Return the value written out, then its type, as <value>:<type>.

namespace qualifies the type name; representation() gives the value alone.

discard(key: _InputValues) → None

Remove the key if present.

empty() → bool

Return True if the container is empty.

get(key: _InputValues, default: _InputValues | None = None, *, encoded: Literal[True] = True) → None | _OutputValues

Return the value associated with the key, or default when there is none.

Without a default, a missing key answers None. default is decoded to the map value type, which reads None: an empty optional or any, the void value, or no default for a type that cannot hold it.

encoded=False returns a Value rather than a native object.

hash() → int

Return the hash value.

items(*, encoded: Literal[True] = True) → ValueMapItemsIter[_OutputValues]

Return a ValueMapItemsIter.

It reads the map as it goes: a change of size meanwhile raises RuntimeError.

encoded=False makes it yield Values rather than native objects.

keys(*, encoded: Literal[True] = True) → ValueMapKeysIter[_OutputValues]

Return a ValueMapKeysIter.

It reads the map as it goes: a change of size meanwhile raises RuntimeError.

encoded=False makes it yield Values rather than native objects.

max(*, encoded: Literal[True] = True) → _OutputValues

Return the max key.

encoded=False returns a Value rather than a native object.

min(*, encoded: Literal[True] = True) → _OutputValues

Return the min key.

encoded=False returns a Value rather than a native object.

pop(key: _InputValues, default: _InputValues | None = None, *, encoded: Literal[True] = True) → _OutputValues

Remove the entry at key and return its value.

Return default when the map holds no such key, or raise when no default is given. default is decoded to the map value type, which reads None as get() does.

encoded=False returns a Value rather than a native object.

popitem() → ValueTuple

Remove and return the entry with the smallest key, as a 2-tuple.

Raises when the map is empty.

remove(key: _InputValues) → None

Remove the key or raises.

representation() → str

Return the value written out: the entries between braces, comma separated.

set(key: _InputValues, value: _InputValues) → None

Set the value for a key.

The KEY is stored as a copy - a map keeps its keys sorted and unique, so mutating key afterwards must not reach them - while the value is held as you give it, like every other container.

setdefault(key: _InputValues, value: _InputValues, *, encoded: Literal[True] = True) → _OutputValues

Return the value for key, inserting value first if the map has no such key.

encoded=False returns a Value rather than a native object.

size() → int

Return the number of elements.

type() → Type

Return the Type this value is an instance of.

type_code() → str

Return the code naming this kind of value, such as “int32”, “struct” or “vector”.

type_map() → TypeMap

Return the type map<key_type, element_type>.

update(value: _InputValues) → None

Write every entry of value into the map, replacing the keys already there.

values(*, encoded: Literal[True] = True) → ValueMapValuesIter[_OutputValues]

Return a ValueMapValuesIter.

It reads the map as it goes: a change of size meanwhile raises RuntimeError.

encoded=False makes it yield Values rather than native objects.