Caffe2 - C++ API
A deep learning, cross platform ML framework
Data Structures | Public Types | Public Member Functions
torch::OrderedDict< Key, Value > Class Template Reference

An ordered dictionary implementation, akin to Python's OrderedDict. More...

#include <ordered_dict.h>

Data Structures

class  Item
 

Public Types

using Iterator = typename std::vector< Item >::iterator
 
using ConstIterator = typename std::vector< Item >::const_iterator
 

Public Member Functions

 OrderedDict (std::string key_description="Key")
 Constructs the OrderedDict with a short description of the kinds of keys stored in the OrderedDict. More...
 
 OrderedDict (const OrderedDict &other)
 Copy constructs this OrderedDict from other.
 
OrderedDictoperator= (const OrderedDict &other)
 Assigns items from other to this OrderedDict.
 
 OrderedDict (OrderedDict &&other)=default
 
OrderedDictoperator= (OrderedDict &&other)=default
 
 OrderedDict (std::initializer_list< Item > initializer_list)
 Constructs a new OrderedDict and pre-populates it with the given Items. More...
 
const std::string & key_description () const noexcept
 Returns the key description string the OrderedDict was constructed with.
 
Itemfront ()
 Returns the very first item in the OrderedDict and throws an exception if it is empty. More...
 
const Itemfront () const
 Returns the very first item in the OrderedDict and throws an exception if it is empty. More...
 
Itemback ()
 Returns the very last item in the OrderedDict and throws an exception if it is empty. More...
 
const Itemback () const
 Returns the very last item in the OrderedDict and throws an exception if it is empty. More...
 
Itemoperator[] (size_t index)
 Returns the item at the index-th position in the OrderedDict. More...
 
const Itemoperator[] (size_t index) const
 Returns the item at the index-th position in the OrderedDict. More...
 
Value & operator[] (const Key &key)
 Returns the value associated with the given key. More...
 
const Value & operator[] (const Key &key) const
 Returns the value associated with the given key. More...
 
Value * find (const Key &key) noexcept
 Returns a pointer to the value associated with the given key, or a nullptr if no such key is stored in the OrderedDict. More...
 
const Value * find (const Key &key) const noexcept
 Returns a pointer to the value associated with the given key, or a nullptr if no such key is stored in the OrderedDict. More...
 
bool contains (const Key &key) const noexcept
 Returns true if the key is present in the OrderedDict.
 
Iterator begin ()
 Returns an iterator to the first item in the OrderedDict. More...
 
ConstIterator begin () const
 Returns an iterator to the first item in the OrderedDict. More...
 
Iterator end ()
 Returns an iterator one past the last item in the OrderedDict.
 
ConstIterator end () const
 Returns an iterator one past the last item in the OrderedDict.
 
size_t size () const noexcept
 Returns the number of items currently stored in the OrderedDict.
 
bool is_empty () const noexcept
 Returns true if the OrderedDict contains no elements.
 
void reserve (size_t requested_capacity)
 Resizes internal storage to fit at least requested_capacity items without requiring reallocation. More...
 
template<typename K , typename V >
Value & insert (K &&key, V &&value)
 Inserts a new (key, value) pair into the OrderedDict. More...
 
Value & insert (Key key, Value &&value)
 Inserts a new (key, value) pair into the OrderedDict. More...
 
void update (OrderedDict &&other)
 Inserts all items from other into this OrderedDict. More...
 
void update (const OrderedDict &other)
 Inserts all items from other into this OrderedDict. More...
 
void clear ()
 Removes all items from this OrderedDict.
 
const std::vector< Item > & items () const noexcept
 Returns the items stored in the OrderedDict.
 
::std::vector< Key > keys () const
 Returns a newly allocated vector and copies all keys from this OrderedDict into the vector. More...
 
::std::vector< Value > values () const
 Returns a newly allocated vector and copies all values from this OrderedDict into the vector. More...
 
::std::vector< std::pair< Key, Value > > pairs () const
 Returns a newly allocated vector and copies all keys and values from this OrderedDict into a vector of std::pair<Key, Value>. More...
 

Detailed Description

template<typename Key, typename Value>
class torch::OrderedDict< Key, Value >

An ordered dictionary implementation, akin to Python's OrderedDict.

Definition at line 16 of file ordered_dict.h.

Constructor & Destructor Documentation

template<typename Key , typename Value >
torch::OrderedDict< Key, Value >::OrderedDict ( std::string  key_description = "Key")
explicit

Constructs the OrderedDict with a short description of the kinds of keys stored in the OrderedDict.

This description is used in error messages thrown by the OrderedDict.

Definition at line 240 of file ordered_dict.h.

template<typename Key , typename Value >
torch::OrderedDict< Key, Value >::OrderedDict ( std::initializer_list< Item initializer_list)

Constructs a new OrderedDict and pre-populates it with the given Items.

Definition at line 266 of file ordered_dict.h.

Member Function Documentation

template<typename Key , typename Value >
OrderedDict< Key, Value >::Item & torch::OrderedDict< Key, Value >::back ( )

Returns the very last item in the OrderedDict and throws an exception if it is empty.

Definition at line 313 of file ordered_dict.h.

template<typename Key , typename Value >
const OrderedDict< Key, Value >::Item & torch::OrderedDict< Key, Value >::back ( ) const

Returns the very last item in the OrderedDict and throws an exception if it is empty.

Definition at line 319 of file ordered_dict.h.

template<typename Key , typename Value >
OrderedDict< Key, Value >::Iterator torch::OrderedDict< Key, Value >::begin ( )

Returns an iterator to the first item in the OrderedDict.

Iteration is ordered.

Definition at line 278 of file ordered_dict.h.

template<typename Key , typename Value >
OrderedDict< Key, Value >::ConstIterator torch::OrderedDict< Key, Value >::begin ( ) const

Returns an iterator to the first item in the OrderedDict.

Iteration is ordered.

Definition at line 283 of file ordered_dict.h.

template<typename Key, typename Value >
Value * torch::OrderedDict< Key, Value >::find ( const Key &  key)
noexcept

Returns a pointer to the value associated with the given key, or a nullptr if no such key is stored in the OrderedDict.

Definition at line 390 of file ordered_dict.h.

template<typename Key, typename Value >
const Value * torch::OrderedDict< Key, Value >::find ( const Key &  key) const
noexcept

Returns a pointer to the value associated with the given key, or a nullptr if no such key is stored in the OrderedDict.

Definition at line 399 of file ordered_dict.h.

template<typename Key , typename Value >
OrderedDict< Key, Value >::Item & torch::OrderedDict< Key, Value >::front ( )

Returns the very first item in the OrderedDict and throws an exception if it is empty.

Definition at line 300 of file ordered_dict.h.

template<typename Key , typename Value >
const OrderedDict< Key, Value >::Item & torch::OrderedDict< Key, Value >::front ( ) const

Returns the very first item in the OrderedDict and throws an exception if it is empty.

Definition at line 306 of file ordered_dict.h.

template<typename Key , typename Value >
template<typename K , typename V >
Value & torch::OrderedDict< Key, Value >::insert ( K &&  key,
V &&  value 
)

Inserts a new (key, value) pair into the OrderedDict.

Throws an exception if the key is already present. If insertion is succesful, immediately returns a reference to the inserted value.

Definition at line 357 of file ordered_dict.h.

template<typename Key, typename Value>
Value & torch::OrderedDict< Key, Value >::insert ( Key  key,
Value &&  value 
)

Inserts a new (key, value) pair into the OrderedDict.

Throws an exception if the key is already present. If insertion is succesful, immediately returns a reference to the inserted value.

Definition at line 367 of file ordered_dict.h.

template<typename Key , typename Value >
std::vector< Key > torch::OrderedDict< Key, Value >::keys ( ) const

Returns a newly allocated vector and copies all keys from this OrderedDict into the vector.

Definition at line 441 of file ordered_dict.h.

template<typename Key , typename Value >
OrderedDict< Key, Value >::Item & torch::OrderedDict< Key, Value >::operator[] ( size_t  index)

Returns the item at the index-th position in the OrderedDict.

Throws an exception if the index is out of bounds.

Definition at line 326 of file ordered_dict.h.

template<typename Key , typename Value >
const OrderedDict< Key, Value >::Item & torch::OrderedDict< Key, Value >::operator[] ( size_t  index) const

Returns the item at the index-th position in the OrderedDict.

Throws an exception if the index is out of bounds.

Definition at line 334 of file ordered_dict.h.

template<typename Key, typename Value >
Value & torch::OrderedDict< Key, Value >::operator[] ( const Key &  key)

Returns the value associated with the given key.

Throws an exception if no such key is stored in the OrderedDict. Use find() for a non-throwing way of accessing a value if it is present.

Definition at line 340 of file ordered_dict.h.

template<typename Key, typename Value >
const Value & torch::OrderedDict< Key, Value >::operator[] ( const Key &  key) const

Returns the value associated with the given key.

Throws an exception if no such key is stored in the OrderedDict. Use find() for a non-throwing way of accessing a value if it is present.

Definition at line 348 of file ordered_dict.h.

template<typename Key , typename Value >
std::vector< std::pair< Key, Value > > torch::OrderedDict< Key, Value >::pairs ( ) const

Returns a newly allocated vector and copies all keys and values from this OrderedDict into a vector of std::pair<Key, Value>.

Definition at line 461 of file ordered_dict.h.

template<typename Key , typename Value >
void torch::OrderedDict< Key, Value >::reserve ( size_t  requested_capacity)

Resizes internal storage to fit at least requested_capacity items without requiring reallocation.

Definition at line 471 of file ordered_dict.h.

template<typename Key , typename Value >
void torch::OrderedDict< Key, Value >::update ( OrderedDict< Key, Value > &&  other)

Inserts all items from other into this OrderedDict.

If any key from other is already present in this OrderedDict, an exception is thrown.

Definition at line 372 of file ordered_dict.h.

template<typename Key , typename Value >
void torch::OrderedDict< Key, Value >::update ( const OrderedDict< Key, Value > &  other)

Inserts all items from other into this OrderedDict.

If any key from other is already present in this OrderedDict, an exception is thrown.

Definition at line 381 of file ordered_dict.h.

template<typename Key , typename Value >
std::vector< Value > torch::OrderedDict< Key, Value >::values ( ) const

Returns a newly allocated vector and copies all values from this OrderedDict into the vector.

Definition at line 451 of file ordered_dict.h.


The documentation for this class was generated from the following file: