#pragma once
#include <iterator>
#include "../../common/specialized.hpp"
namespace sprawl
{
template<typename ValueType, typename AccessorType>
class MapIterator : public std::iterator<std::forward_iterator_tag, ValueType, std::ptrdiff_t, ValueType*, ValueType&>
{
public:
typedef AccessorType* accessor_type;
MapIterator(AccessorType* item)
: m_currentItem(item)
{
//
}
ValueType& operator*()
{
return m_currentItem->m_value;
}
ValueType& operator->()
{
return m_currentItem->m_value;
}
ValueType const& operator*() const
{
return m_currentItem->m_value;
}
ValueType const& operator->() const
{
return m_currentItem->m_value;
}
template<int i>
auto Key() const -> decltype(accessor_type(nullptr)->Accessor(Specialized<i>()).GetKey())
{
return m_currentItem->Accessor(Specialized<i>()).GetKey();
}
auto Key() const -> decltype(accessor_type(nullptr)->Accessor(Specialized<0>()).GetKey())
{
return m_currentItem->Accessor(Specialized<0>()).GetKey();
}
ValueType& Value()
{
return m_currentItem->m_value;
}
ValueType const& Value() const
{
return m_currentItem->m_value;
}
MapIterator<ValueType, AccessorType>& operator++()
{
m_currentItem = m_currentItem ? m_currentItem->next : nullptr;
return *this;
}
MapIterator<ValueType, AccessorType> operator++(int)
{
MapIterator<ValueType, AccessorType> tmp(*this);
++(*this);
return tmp;
}
MapIterator<ValueType, AccessorType> const& operator++() const
{
m_currentItem = m_currentItem ? m_currentItem->next : nullptr;
return *this;
}
MapIterator<ValueType, AccessorType> const operator++(int) const
{
MapIterator<ValueType, AccessorType> tmp(*this);
++(*this);
return tmp;
}
MapIterator<ValueType, AccessorType> operator+(int steps)
{
AccessorType* item = m_currentItem;
for(int i = 0; i < steps; ++i)
{
if(!item)
{
break;
}
item = item->next;
}
return MapIterator<ValueType, AccessorType>(item);
}
MapIterator<ValueType, AccessorType> const operator+(int steps) const
{
AccessorType* item = m_currentItem;
for(int i = 0; i < steps; ++i)
{
if(!item)
{
break;
}
item = item->next;
}
return MapIterator<ValueType, AccessorType>(item);
}
bool operator==(MapIterator<ValueType, AccessorType> const& rhs) const
{
return m_currentItem == rhs.m_currentItem;
}
bool operator!=(MapIterator<ValueType, AccessorType> const& rhs) const
{
return !this->operator==(rhs);
}
operator bool() const
{
return m_currentItem != nullptr;
}
bool operator!() const
{
return m_currentItem != nullptr;
}
bool Valid() const
{
return m_currentItem != nullptr;
}
bool More() const
{
return m_currentItem != nullptr && m_currentItem->next != nullptr;
}
MapIterator<ValueType, AccessorType> Next()
{
return MapIterator<ValueType, AccessorType>(m_currentItem ? m_currentItem->next : nullptr);
}
MapIterator<ValueType, AccessorType> const Next() const
{
return MapIterator<ValueType, AccessorType>(m_currentItem ? m_currentItem->next : nullptr);
}
operator bool()
{
return m_currentItem != nullptr;
}
protected:
mutable AccessorType* m_currentItem;
};
}
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #3 | 14220 | ShadauxCat |
-Added binary tree implementation (red/black tree) with same multi-key interface as hashmap -Renamed AccessorGroup to MapAccessorGroup to make room for TreeAccessorGroup, which is a lot of duplicated code but had to meet some specific requirements that couldn't be easily fit into the existing AccessorGroup -Fixed HashMap::Clear() not resetting size to 0 -Fixed HashMap::Erase() neither decrementing size nor freeing memory -Changed HashMap to grow before insert instead of after (delaying needed growth until the next insert instead of growing when it detects the next insert will need it) -Fixed a style issue for private function HashMap_Impl::insertHere_() -Fully removed support for Visual Studio 2012 as I have neither the need nor the desire to continue supporting it. The doubled maintenance cost is too high. -Included array unit test that got missed before #review-14221 |
||
| #2 | 14066 | ShadauxCat |
-Improved iterating in hashmap - range-based for now gives the ability to access both key and value instead of just value -Slightly improved some of the template aliases -Mega-deprecated VC11 support. Probably doesn't compile anymore. Maintaining it is too much of a headache. #review-14067 |
||
| #1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |