namespace mrpt::containers

namespace containers {

// namespaces

namespace mrpt::containers::internal;

// typedefs

typedef internal::generic_copier_ptr<T, internal::CopyCloner<T>> poly_ptr;
typedef internal::generic_copier_ptr<T, internal::CopyStatic<T>> copy_ptr;

// enums

enum CommentPosition;

// structs

template <typename STLCONTAINER>
struct ContainerReadOnlyProxyAccessor;

template <typename T>
struct ValueCommentPair;

template <typename T>
struct ValueKeyCommentPair;

struct YamlEmitOptions;
struct ci_less;
struct map_traits_map_as_vector;
struct map_traits_stdmap;

template <typename KEY, typename VALUE>
struct ts_map_entry;

// classes

template <class T>
class CDynamicGrid;

template <class T, class coord_t = double>
class CDynamicGrid3D;

template <class T>
class CThreadSafeQueue;

class MT_buffer;

template <typename KEY, typename VALUE>
class bimap;

template <typename T>
class circular_buffer;

template <typename T>
class deepcopy_poly_ptr;

template <class T>
class list_searchable;

template <
    typename KEY,
    typename VALUE,
    typename VECTOR_T = typename std::vector<std::pair<KEY, VALUE>>
    >
class map_as_vector;

template <typename VAL, size_t small_size, size_t alignment = 16>
class vector_with_small_size_optimization;

class yaml;

// global functions

ts_hash_map();
ts_hash_map(const ts_hash_map& o);
ts_hash_map(ts_hash_map&& o);
ts_hash_map& operator = (const ts_hash_map& o);
ts_hash_map& operator = (ts_hash_map&& o);
void clear();
bool empty() const;
VALUE* find_or_alloc(const KEY& key);
VALUE& operator [] (const KEY& key);
const_iterator find(const KEY& key) const;
const_iterator begin() const;
const_iterator end() const;

template <typename KEY, typename VALUE>
bool operator == (
    const bimap<KEY, VALUE>& bm1,
    const bimap<KEY, VALUE>& bm2
    );

template <typename KEY, typename VALUE>
bool operator != (
    const bimap<KEY, VALUE>& bm1,
    const bimap<KEY, VALUE>& bm2
    );

template <typename src_container, typename dst_container>
void copy_container_typecasting(
    const src_container& src,
    dst_container& trg
    );

template <typename VEC>
std::string sprintf_vector(const char* fmt, const VEC& V);

template <typename T>
void printf_vector(const char* fmt, const std::vector<T>& V);

template <class T, class CONTAINER>
size_t find_in_vector(
    const T& value,
    const CONTAINER& vect
    );

template <class T>
std::list<T>::iterator erase_return_next(
    std::list<T>& cont,
    typename std::list<T>::iterator& it
    );

template <class K, class V>
std::map<K, V>::iterator erase_return_next(
    std::map<K, V>& cont,
    typename std::map<K, V>::iterator& it
    );

template <class K, class V>
std::multimap<K, V>::iterator erase_return_next(
    std::multimap<K, V>& cont,
    typename std::multimap<K, V>::iterator& it
    );

template <class T>
std::set<T>::iterator erase_return_next(
    std::set<T>& cont,
    typename std::set<T>::iterator& it
    );

template <class T>
std::string getSTLContainerAsString(const T& t);

template <class T>
void printSTLContainer(const T& t);

template <class T>
void printSTLContainerOfContainers(const T& t);

template <class T1, class T2>
std::string getMapAsString(
    const std::map<T1, T2>& m,
    const std::string& sep = " => "
    );

template <class T1, class T2>
void printMap(const std::map<T1, T2>& m);

template <class CONTAINER>
void deep_clear(CONTAINER& c);

void reduced_hash(const std::string_view& value, uint8_t& hash);

void reduced_hash(
    const std::string_view& value,
    uint16_t& hash
    );

void reduced_hash(
    const std::string_view& value,
    uint32_t& hash
    );

void reduced_hash(
    const std::string_view& value,
    uint64_t& hash
    );

template <
    typename KEY,
    typename VALUE,
    unsigned int NUM_BYTES_HASH_TABLE = 1,
    unsigned int NUM_HAS_TABLE_COLLISIONS_ALLOWED = 5,
    typename VECTOR_T = std::array<std::array<ts_map_entry<KEY, VALUE>, NUM_HAS_TABLE_COLLISIONS_ALLOWED>,      1u<<(8* NUM_BYTES_HASH_TABLE)>>class ts_hash_map{   public:     using self_t = ts_hash_map<KEY, VALUE, NUM_BYTES_HASH_TABLE, NUM_HAS_TABLE_COLLISIONS_ALLOWED,      VECTOR_T>;  using key_type = KEY;   using value_type = ts_map_entry<KEY, VALUE>;    using vec_t = VECTOR_T; struct iterator;    struct const_iterator   {      public:      const_iterator() : m_vec(nullptr), m_parent(nullptr) {}     const_iterator(const VECTOR_T& vec, const self_t& parent, int idx_outer,            int idx_inner)          : m_vec(const_cast<VECTOR_T*>(&vec)),             m_parent(const_cast<self_t*>(&parent)),             m_idx_outer(idx_outer),             m_idx_inner(idx_inner)        {       }       const_iterator(const const_iterator& o) {*this = o; }       const_iterator& operator=(const const_iterator& o)      {           m_vec = o.m_vec;            m_idx_outer = o.m_idx_outer;            m_idx_inner = o.m_idx_inner;            return*this;        }       bool operator==(const const_iterator& o) const      {           return m_vec == o.m_vec&& m_idx_outer == o.m_idx_outer&&                m_idx_inner == o.m_idx_inner;       }       bool operator!=(const const_iterator& o) const { return !(*this == o); }        const value_type& operator*() const     {           return(*m_vec)[m_idx_outer][m_idx_inner];       }       const value_type* operator->() const { return&(*m_vec)[m_idx_outer][m_idx_inner]; } inline const_iterator operator++(int) {  const_iterator aux =*this; ++(*this); return aux; } inline const_iterator& operator++() {  incr(); return*this; } protected: VECTOR_T* m_vec; self_t* m_parent; int m_idx_outer{0}
    >
iterator operator ++ (int);

iterator& operator ++ ();

template <typename T>
struct ValueCommentPair<T> vcp(
    const T& v,
    const std::string& c,
    const CommentPosition pos = CommentPosition::RIGHT
    );

template <typename T>
struct ValueKeyCommentPair<T> vkcp(
    const std::string& keyName,
    const T& v,
    const std::string& c,
    const CommentPosition pos = CommentPosition::TOP
    );

std::ostream& operator << (std::ostream& o, const yaml& p);
bool operator < (const yaml::node_t& lhs, const yaml::node_t& rhs);

} // namespace containers

Global Functions

ts_hash_map()

< Default constructor */

void clear()

Clear the contents of this container.

VALUE* find_or_alloc(const KEY& key)

noexcept version of operator[], returns nullptr upon failure

VALUE& operator [] (const KEY& key)

Write/read via [i] operator, that creates an element if it didn’t exist already.

void reduced_hash(const std::string_view& value, uint8_t& hash)

hash function used by ts_hash_map.

Uses dbj2 method

template <
    typename KEY,
    typename VALUE,
    unsigned int NUM_BYTES_HASH_TABLE = 1,
    unsigned int NUM_HAS_TABLE_COLLISIONS_ALLOWED = 5,
    typename VECTOR_T = std::array<std::array<ts_map_entry<KEY, VALUE>, NUM_HAS_TABLE_COLLISIONS_ALLOWED>,      1u<<(8* NUM_BYTES_HASH_TABLE)>>class ts_hash_map{   public:     using self_t = ts_hash_map<KEY, VALUE, NUM_BYTES_HASH_TABLE, NUM_HAS_TABLE_COLLISIONS_ALLOWED,      VECTOR_T>;  using key_type = KEY;   using value_type = ts_map_entry<KEY, VALUE>;    using vec_t = VECTOR_T; struct iterator;    struct const_iterator   {      public:      const_iterator() : m_vec(nullptr), m_parent(nullptr) {}     const_iterator(const VECTOR_T& vec, const self_t& parent, int idx_outer,            int idx_inner)          : m_vec(const_cast<VECTOR_T*>(&vec)),             m_parent(const_cast<self_t*>(&parent)),             m_idx_outer(idx_outer),             m_idx_inner(idx_inner)        {       }       const_iterator(const const_iterator& o) {*this = o; }       const_iterator& operator=(const const_iterator& o)      {           m_vec = o.m_vec;            m_idx_outer = o.m_idx_outer;            m_idx_inner = o.m_idx_inner;            return*this;        }       bool operator==(const const_iterator& o) const      {           return m_vec == o.m_vec&& m_idx_outer == o.m_idx_outer&&                m_idx_inner == o.m_idx_inner;       }       bool operator!=(const const_iterator& o) const { return !(*this == o); }        const value_type& operator*() const     {           return(*m_vec)[m_idx_outer][m_idx_inner];       }       const value_type* operator->() const { return&(*m_vec)[m_idx_outer][m_idx_inner]; } inline const_iterator operator++(int) {  const_iterator aux =*this; ++(*this); return aux; } inline const_iterator& operator++() {  incr(); return*this; } protected: VECTOR_T* m_vec; self_t* m_parent; int m_idx_outer{0}
    >
iterator operator ++ (int)

A thread-safe (ts) container which minimally emulates a std::map<>’s [] and find() methods but which is implemented as a linear vector indexed by a hash of KEY.

Any custom hash function can be implemented, we don’t rely by default on C++11 std::hash<> due to its limitation in some implementations.

This implementation is much more efficient than std::map<> when the most common operation is accessing elements by KEY with find() or [], and is also thread-safe if different threads create entries with different hash values.

The default underlying non-associative container is a “memory-aligned std::vector<>”, but it can be changed to a standard vector<> or to a deque<> (to avoid memory reallocations) by changing the template parameter VECTOR_T.

Defined in #include <mrpt/containers/ts_hash_map.h>

std::ostream& operator << (std::ostream& o, const yaml& p)

Prints a scalar, a part of a yaml tree, or the entire structure, in YAML-like format.

This version does NOT emit neither the YAML header nor the final end line.

See also:

yaml::PrintAsYAML

bool operator < (const yaml::node_t& lhs, const yaml::node_t& rhs)

Sort operator required for std::map with node_t as key.