Template Class Map#

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 Map : public tvm::ffi::ObjectRef#

Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.

operator[] only provide const acces, use Set to mutate the content.

Template Parameters:
  • K – The key NodeRef type.

  • V – The value NodeRef type.

Public Types

using key_type = K#

The key type of the map.

using mapped_type = V#

The mapped type of the map.

using ContainerType = MapObj#

specify container node

Public Functions

inline explicit Map(UnsafeInit tag)#

Construct an Map with UnsafeInit.

inline Map()#

default constructor

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

move constructor

Parameters:

other – source

inline Map(const Map<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 Map(Map<KU, VU> &&other)#

Move constructor.

Parameters:

other – The other map

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

  • VU – The mapped type of the other map

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

Copy constructor.

Parameters:

other – The other map

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

  • VU – The mapped type of the other map

inline explicit Map(ObjectPtr<Object> n)#

constructor from pointer

Parameters:

n – the container pointer

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

constructor from iterator

Parameters:
  • begin – begin of iterator

  • end – end of iterator

Template Parameters:

IterType – The type of iterator

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

constructor from initializer list

Parameters:

init – The initalizer list

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

constructor from unordered_map

Parameters:

init – The unordered_map

inline const V at(const K &key) const#

Read element from map.

Parameters:

key – The key

Returns:

the corresonding element.

inline size_t size() const#
Returns:

The size of the array

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

The number of elements of the key

inline bool empty() const#
Returns:

whether array is empty

inline void clear()#

Release reference to all the elements.

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

set the Map.

Parameters:
  • key – The index key.

  • value – The value to be setted.

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.

Parameters:

key – The key

inline MapObj *CopyOnWrite()#

copy on write semantics Do nothing if current handle is the unique copy of the array. Otherwise make a new copy of the array to ensure the current handle hold a unique copy.

Returns:

Handle to the internal node container(which guarantees to be unique)