Template Class Dict#

Inheritance Relationships#

Base Type#

Class Documentation#

template<typename K, typename V, typename = typename std::enable_if_t<details::storage_enabled_v<K> && details::storage_enabled_v<V>>>
class Dict : public tvm::ffi::ObjectRef#

Mutable dictionary container with shared reference semantics.

Mutations happen directly on the underlying shared DictObj. All handles sharing the same DictObj see mutations immediately.

Template Parameters:
  • K – The key type.

  • V – The value type.

Public Types

using key_type = K#

The key type of the dict.

using mapped_type = V#

The mapped type of the dict.

using ContainerType = DictObj#

specify container node

Public Functions

inline explicit Dict(UnsafeInit tag)#

Construct a Dict with UnsafeInit.

inline Dict()#

default constructor

inline Dict(Dict<K, V> &&other)#

move constructor

Parameters:

other – source

inline Dict(const Dict<K, V> &other)#

copy constructor

Parameters:

other – source

template<typename KU, typename VU, typename = std::enable_if_t<details::type_contains_v<K, KU> && details::type_contains_v<V, VU>>>
inline Dict(Dict<KU, VU> &&other)#

Move constructor.

Parameters:

other – The other dict

Template Parameters:
  • KU – The key type of the other dict

  • VU – The mapped type of the other dict

template<typename KU, typename VU, typename = std::enable_if_t<details::type_contains_v<K, KU> && details::type_contains_v<V, VU>>>
inline Dict(const Dict<KU, VU> &other)#

Copy constructor.

Parameters:

other – The other dict

Template Parameters:
  • KU – The key type of the other dict

  • VU – The mapped type of the other dict

inline explicit Dict(ObjectPtr<Object> n)#

constructor from pointer

Parameters:

n – the container pointer

template<typename IterType>
inline Dict(IterType begin, IterType end)#

constructor from iterator

Parameters:
  • begin – begin of iterator

  • end – end of iterator

Template Parameters:

IterType – The type of iterator

inline Dict(std::initializer_list<std::pair<K, V>> init)#

constructor from initializer list

Parameters:

init – The initalizer list

template<typename Hash, typename Equal>
inline Dict(const std::unordered_map<K, V, Hash, Equal> &init)#

constructor from unordered_map

Parameters:

init – The unordered_map

inline V at(const K &key) const#

Read element from dict.

Parameters:

key – The key

Returns:

the corresponding element.

inline size_t size() const#
Returns:

The size of the dict

inline size_t count(const K &key) const#
Returns:

The number of elements of the key

inline bool empty() const#
Returns:

whether dict is empty

inline void clear()#

Release reference to all the elements.

inline void Set(const K &key, const V &value)#

Set a key-value pair in the Dict (mutates in-place).

Parameters:
  • key – The index key.

  • value – The value to be set.

inline iterator begin() const#
Returns:

begin iterator

inline iterator end() const#
Returns:

end iterator

inline iterator find(const K &key) const#
Returns:

find the key and returns the associated iterator

inline std::optional<V> Get(const K &key) const#
Returns:

The value associated with the key, std::nullopt if not found

inline void erase(const K &key)#

Erase the entry associated with the key (mutates in-place)

Parameters:

key – The key