17 #ifndef AGX_SETVECTOR_H
18 #define AGX_SETVECTOR_H
37 template <
typename DataT,
typename HashT = HashFn<DataT> >
83 m_vector = other.m_vector;
84 m_hash = other.m_hash;
119 return m_vector.
size();
127 return m_vector.
empty();
144 template<
typename T2 >
149 typename HashType::iterator it = m_hash.
find(data);
150 if (it != m_hash.
end())
153 m_vector[it->second] = data;
154 return &m_vector[it->second];
178 template<
typename T2 >
196 template<
typename OldDataT,
typename NewDataT >
201 auto oldIt = m_hash.
find( oldData );
202 if ( oldIt == m_hash.
end() )
205 size_t index = oldIt->second;
206 m_vector[ index ] = newData;
207 m_hash.
erase( oldIt );
208 m_hash.
insert( newData, index );
210 return begin() + index;
221 template<
typename T2 >
237 template<
typename T2 >
242 typename HashType::iterator it = m_hash.
find( key );
243 if (it == m_hash.
end())
246 return &m_vector[it->second];
256 template<
typename T2 >
261 typename HashType::const_iterator it = m_hash.
find( key );
262 if (it == m_hash.
end())
266 return &m_vector[it->second];
277 return m_vector.
begin();
287 return m_vector.
begin();
317 return m_vector.
end();
326 return m_vector.
end();
336 return m_vector.
rend(); }
344 return m_vector.
rend();
371 return m_vector[m_vector.
size()-1];
377 inline const DataT&
back()
const
380 return m_vector[m_vector.
size()-1];
393 template<
typename T2 >
398 typename HashType::iterator it = m_hash.
find( key );
399 if (it == m_hash.
end())
429 typename HashType::iterator hashIt = m_hash.
find( key );
485 inline const DataT&
at(
size_t index)
const
487 return m_vector.
at(index);
496 inline DataT&
at(
size_t index)
498 return m_vector.
at(index);
547 #if 0 // Slower implementation
551 for(; it != m_vector.
end(); ++it)
570 #else // Faster implementation
585 return removeElements.
size();
593 return m_vector.
size() == m_hash.
size();
596 void erase(
typename HashType::iterator it )
598 size_t idx = it->second;
603 if (m_vector.
size() > 1 && idx != (m_vector.
size()-1))
609 m_vector[idx] = lastElement;
615 m_hash.
insert( lastElement, idx );
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements.
iterator find(const KeyT &key)
Find a key/value pair in the hash table given a key.
SetVector(const ContainerType &other)
Copy constructor.
HashTable< DataT, size_t, HashT > HashType
const_reverse_iterator rend() const
VectorType::const_iterator const_iterator
const_iterator find(const T2 &key) const
Perform a hash search for a given key.
void reserve(size_t size)
Reserve capacity in the hash table.
iterator replace(const OldDataT &oldData, const NewDataT &newData)
Replace data in set vector.
const DataT & at(size_t index) const
Access an element in the vector using an index.
bool empty() const
Return true if the container is empty.
const const agxPowerLine::Unit ** const_iterator
ClearPolicy
agxData::Values from this enumeration is passed to the subclasses' 'clear' method in order to control...
std::reverse_iterator< const_iterator > const_reverse_iterator
VectorType::iterator iterator
const DataT & const_reference
reverse_iterator rbegin()
ContainerType & operator=(const ContainerType &other)
Assignment operator.
T & at(size_t index) const
void reserve(size_t size)
Reserve capacity in the vector.
const VectorType & vector() const
Buffer is deallocated and replaced by an newly allocated empty buffer.
bool erase(const iterator &it)
Erase an element using an iterator.
reverse_iterator rbegin()
void reserve(size_t num_elems)
Make room for this many elements in the hash table.
const DataT & front() const
void clear(int=0)
Remove all elements, keeping full capacity.
const_iterator end() const
const DataT & back() const
insert_iterator insert(const KeyT &key, const ValueT value)
Insert a key/value pair into the hash table.
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements, optionally with maintained buffer allocation.
iterator end()
Iterator marking end of hash table.
DataT & operator[](size_t i)
Access an element in the vector using an index.
bool erase(const KeyT &key)
Erase an element from the hash table.
const DataT & operator[](size_t i) const
Access an element in the vector using an index.
DataT & at(size_t index)
Access an element in the vector using an index.
const_iterator begin() const
bool contains(const T2 &key) const
Hash search for the data in the container.
VectorType::reverse_iterator reverse_iterator
const HashType & table() const
VectorType::const_reverse_iterator const_reverse_iterator
Buffer is shrunk if a smoothing average (which is updated each clear call) goes below a threshold...
iterator insert(const T2 &data)
Insert a data element in to the end of the container.
SetVector< DataT, HashT > ContainerType
Inheritance with partial specialization due to bug with ref_ptr containers.
std::reverse_iterator< iterator > reverse_iterator
Vector< DataT > VectorType
Buffer is maintained (normal stl behavior).
iterator find(const T2 &key)
Perform a hash search for a given key.
void push_back(const T2 &value)
size_t purge(T purger)
Purge the hash set.
const_reverse_iterator rbegin() const
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
bool erase(const T2 &key)
Erase an element from the container.
iterator push_back(const T2 &data)
Insert a data element in to the end of the container.
size_t size() const
Return the number of inserted elements.
bool contains(const KeyT &k) const
Check if the hash table contains a key/value pair for the given key.