diff --git a/src/linearmap.hpp b/src/linearmap.hpp deleted file mode 100644 index 0c8e5e8..0000000 --- a/src/linearmap.hpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - Copyright 2014 Michele "King_DuckZ" Santullo - - This file is part of CloonelJump. - - CloonelJump is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - CloonelJump is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with CloonelJump. If not, see . -*/ - -#ifndef idEA67296D7EC847B58BB3D52DBC9E51BA -#define idEA67296D7EC847B58BB3D52DBC9E51BA - -#include -#include -#include -#include -#include -#include - -namespace cloonel { - namespace implem { - template - class LinearMapIterator : public boost::iterator_facade, typename std::iterator_traits::value_type, typename std::iterator_traits::iterator_category, typename std::iterator_traits::reference, typename std::iterator_traits::difference_type> { - - typedef boost::iterator_facade, typename std::iterator_traits::value_type, typename std::iterator_traits::iterator_category, typename std::iterator_traits::reference, typename std::iterator_traits::difference_type> parent_type; - - typedef typename parent_type::reference reference; - typedef typename parent_type::value_type value_type; - typedef S size_type; - public: - LinearMapIterator ( I parItemsStart, I parItemsEnd, std::vector::const_iterator parOccupiedStart ) : - m_itStart(parItemsStart), - m_itEnd(parItemsEnd), - m_itOccupied(parOccupiedStart) - { - } - ~LinearMapIterator ( void ) noexcept = default; - - private: - friend class boost::iterator_core_access; - - void increment ( void ) { - do { - ++m_itStart; - ++m_itOccupied; - } while (m_itEnd != m_itStart and not *m_itOccupied); - } - bool equal ( const LinearMapIterator& parOther ) const { - return m_itStart == parOther.m_itStart; - } - reference dereference ( void ) const { - return *m_itStart; - } - void advance ( size_type parAdv ) { - while (parAdv and m_itEnd != m_itStart) { - increment(); - --parAdv; - } - } - - I m_itStart; - const I m_itEnd; - std::vector::const_iterator m_itOccupied; - }; - } //namespace implem - - template > - class LinearMap { - public: - typedef size_t size_type; - typedef T value_type; - typedef typename implem::LinearMapIterator iterator; - typedef typename implem::LinearMapIterator const_iterator; - - LinearMap ( void ) = default; - LinearMap ( LinearMap&& parOther ); - ~LinearMap ( void ) noexcept = default; - - size_type size ( void ) const { return m_usedCount; } - size_type max_size ( void ) const noexcept { return m_list.max_size(); } - size_type capacity ( void ) const noexcept { return m_list.capacity(); } - void shrink_to_fit ( void ); - bool empty ( void ) const noexcept { return m_list.empty(); } - void push_back ( const value_type& parNew ); - void push_back ( value_type&& parNew ); - void swap ( LinearMap& parOther ); - void clear ( void ); - iterator erase_absolute ( size_type parIndex ); - iterator at_absolute ( size_type parIndex ); - - iterator begin ( void ) { return iterator(m_list.begin(), m_list.end(), m_occupied.cbegin()); } - iterator end ( void ) { return iterator(m_list.end(), m_list.end(), m_occupied.cend()); } - const_iterator begin ( void ) const { return const_iterator(m_list.begin(), m_list.end(), m_occupied.cbegin()); } - const_iterator end ( void ) const { return const_iterator(m_list.end(), m_list.end(), m_occupied.cend()); } - const_iterator cbegin ( void ) const { return const_iterator(m_list.begin(), m_list.end(), m_occupied.cbegin()); } - const_iterator cend ( void ) const { return const_iterator(m_list.end(), m_list.end(), m_occupied.cend()); } - - private: - Container m_list; - std::vector m_occupied; - size_type m_usedCount; - }; - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - void LinearMap::shrink_to_fit() { - m_list.shrink_to_fit(); - m_occupied.shrink_to_fit(); - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - void LinearMap::push_back (const value_type& parNew) { - m_list.push_back(parNew); - m_occupied.push_back(true); - ++m_usedCount; - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - void LinearMap::push_back (value_type&& parNew) { - m_list.push_back(std::move(parNew)); - m_occupied.push_back(true); - ++m_usedCount; - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - void LinearMap::swap (LinearMap& parOther) { - m_list.swap(parOther.m_list); - m_occupied.swap(parOther.m_occupied); - std::swap(m_usedCount, parOther.m_usedCount); - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - void LinearMap::clear() { - m_list.clear(); - m_occupied.clear(); - m_usedCount = 0; - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - typename LinearMap::iterator LinearMap::erase_absolute (size_type parIndex) { - auto ret = at_absolute(parIndex); - ++ret; - - m_occupied[parIndex] = false; - --m_usedCount; - - size_type deleCount = 0; - for (auto itOcc = m_occupied.rbegin(), itOccEND = m_occupied.rend(); itOcc != itOccEND and not *itOcc; ++itOcc) { - ++deleCount; - } - - if (deleCount) { - assert(deleCount <= m_occupied.size()); - const auto newSize = m_occupied.size() - deleCount; - m_occupied.resize(newSize); - m_list.resize(newSize); - } - return ret; - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - template - typename LinearMap::iterator LinearMap::at_absolute (size_type parIndex) { - assert(m_usedCount > 0); - assert(m_list.size() == m_occupied.size()); - assert(parIndex < m_list.size()); - assert(m_occupied[parIndex]); - - return begin() + std::count_if(m_occupied.begin(), m_occupied.begin() + parIndex, [] (bool a) { return a; }); - } -} //namespace cloonel - -#endif