4 #ifndef ILANG_UTIL_CONTAINER_H__
5 #define ILANG_UTIL_CONTAINER_H__
31 return lhs->result == rhs->result;
35 return lhs->result != rhs->result;
49 template <
class Key,
class T>
class KeyVec {
57 it_ = std::make_shared<KeyVecIt<Key, T>>();
66 auto idx = vec_.size();
67 auto [it, status] = map_.try_emplace(key, idx);
75 T
operator[](
const size_t& idx)
const {
return vec_.at(idx); }
78 size_t size()
const {
return vec_.size(); }
91 auto pos = map_.find(key);
92 if (pos == map_.end())
95 auto idx = pos->second;
97 it_->result = KeyVecItVal::FOUND;
112 std::map<Key, size_t> map_;
121 template <
class Key,
class T>
122 std::shared_ptr<KeyVecIt<Key, T>>
123 KeyVec<Key, T>::end_ = std::make_shared<KeyVecIt<Key, T>>();
126 template <
class Key,
class T>
class MapSet {
139 void insert(
const Key& k,
const T& t) { map_[k].insert(t); }
142 SetT get(
const Key& k)
const {
return map_.at(k); }
145 typename std::map<Key, std::set<T>>::iterator
begin() {
return map_.begin(); }
148 typename std::map<Key, std::set<T>>::iterator
end() {
return map_.end(); }
152 std::map<Key, std::set<T>> map_;
158 #endif // ILANG_UTIL_CONTAINER_H__
bool empty() const
Return whether is empty.
Definition: container.h:81
std::shared_ptr< KeyVecIt > KeyVecItPtr
Pointer type for the KeyVec iterator.
Definition: container.h:22
std::map< Key, std::set< T > >::iterator begin()
Return the iterator at the starting point.
Definition: container.h:145
The container that support key search and index access.
Definition: container.h:49
KeyVecItVal
KeyVecItVal.
Definition: container.h:16
std::set< T > SetT
Set type for data T.
Definition: container.h:129
A pseudo-iterator for the key-search vector.
Definition: container.h:19
KeyVec()
Default constructor.
Definition: container.h:56
A map for sets.
Definition: container.h:126
KeyVecIt()
Constructor.
Definition: container.h:26
friend bool operator!=(const KeyVecItPtr lhs, const KeyVecItPtr rhs)
Overload comparison != for pointer.
Definition: container.h:34
~KeyVec()
Default destructor.
Definition: container.h:61
T operator[](const size_t &idx) const
Get the data by index.
Definition: container.h:75
KeyVecItVal result
Iterator value for checking whether a data is found.
Definition: container.h:40
size_t size() const
Return the number of data stored.
Definition: container.h:78
std::shared_ptr< KeyVecIt< Key, T > > KeyVecItPtr
Iterator pointer type.
Definition: container.h:52
KeyVecItPtr find(const Key &key) const
Return whether the key has been registered.
Definition: container.h:90
void insert(const Key &k, const T &t)
Insert the pair into the mapping.
Definition: container.h:139
std::map< Key, std::set< T > >::iterator end()
Return the iterator at the ending point.
Definition: container.h:148
Key first
Key retrived.
Definition: container.h:42
bool push_back(const Key &key, const T &data)
Push back a data member. The name MUST NOT be registerd before.
Definition: container.h:65
T second
Data retrived.
Definition: container.h:44
~MapSet()
Default destructor.
Definition: container.h:135
void clear()
Clear all stored data.
Definition: container.h:84
KeyVecItPtr end() const
Return END, can be used to check whether data is found.
Definition: container.h:105
MapSet()
Default constructor.
Definition: container.h:133
friend bool operator==(const KeyVecItPtr lhs, const KeyVecItPtr rhs)
Overload comparison == for pointer.
Definition: container.h:30