mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-08 13:49:47 +00:00
Optimization - replace inner vector with static mem container in dbsource.
This commit is contained in:
parent
8cbd9560ec
commit
394ae7672a
7 changed files with 1018 additions and 5 deletions
140
src/navigate/AutomemBase.hpp
Normal file
140
src/navigate/AutomemBase.hpp
Normal file
|
@ -0,0 +1,140 @@
|
|||
/* Copyright 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" 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.
|
||||
*
|
||||
* "dindexer" 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 "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idDB299AE3079F4830BB1D543C07F7B594
|
||||
#define idDB299AE3079F4830BB1D543C07F7B594
|
||||
|
||||
//Classes in this file are low level and only intended to be used by library
|
||||
//code. They don't do much by themselves and shoud never be used from outside.
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
# define ASSERTIONSENABLED
|
||||
#endif
|
||||
|
||||
namespace din {
|
||||
const size_t MAX_STACK_ALLOC_SIZE = 128;
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Heap-based allocation, constructs everything
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A=std::allocator<T> >
|
||||
class AutomemBase_heap {
|
||||
protected:
|
||||
AutomemBase_heap ( void );
|
||||
AutomemBase_heap ( const AutomemBase_heap& parOther );
|
||||
AutomemBase_heap ( AutomemBase_heap&& parOther );
|
||||
~AutomemBase_heap ( void ) = default;
|
||||
|
||||
T* GetMemPtr ( void ) { return m_localMem; }
|
||||
const T* GetMemPtr ( void ) const { return m_localMem; }
|
||||
void AllocMemory ( void );
|
||||
void FreeMemory ( void ) noexcept;
|
||||
void swap ( AutomemBase_heap& parOther ) noexcept { std::swap(m_localMem, parOther.m_localMem); }
|
||||
private:
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
typedef uintptr_t PTR_INT_TYPE;
|
||||
static_assert(sizeof(PTR_INT_TYPE) == sizeof(T*), "Wrong uintptr_t size");
|
||||
#endif
|
||||
void operator= (const AutomemBase_heap&);
|
||||
T* m_localMem;
|
||||
};
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Stack-based allocation, constructs everything
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
class AutomemBase_stack {
|
||||
protected:
|
||||
AutomemBase_stack ( void );
|
||||
AutomemBase_stack ( const AutomemBase_stack& parOther );
|
||||
AutomemBase_stack ( AutomemBase_stack&& parOther );
|
||||
~AutomemBase_stack ( void ) = default;
|
||||
|
||||
T* GetMemPtr ( void ) { return m_localMem; }
|
||||
const T* GetMemPtr ( void ) const { return m_localMem; }
|
||||
void AllocMemory ( void ) { return; }
|
||||
void FreeMemory ( void ) noexcept { return; }
|
||||
private:
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
typedef uintptr_t PTR_INT_TYPE;
|
||||
static_assert(sizeof(PTR_INT_TYPE) == sizeof(T*), "Wrong uintptr_t size");
|
||||
#endif
|
||||
T m_localMem[S];
|
||||
};
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Heap-based allocation, only gets raw memory
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A=std::allocator<T> >
|
||||
class AutomemRawBase_heap {
|
||||
protected:
|
||||
AutomemRawBase_heap ( void );
|
||||
AutomemRawBase_heap ( const AutomemRawBase_heap& ) = delete; //Copy ctor can't be implemented at this level
|
||||
|
||||
T* GetMemPtr ( void ) { return m_localMem; }
|
||||
const T* GetMemPtr ( void ) const { return m_localMem; }
|
||||
char* GetMemPtrAtIndex ( size_t parIndex );
|
||||
void AllocMemory ( void );
|
||||
void FreeMemory ( void ) noexcept;
|
||||
void swap ( AutomemRawBase_heap& parOther ) noexcept { std::swap(m_localMem, parOther.m_localMem); }
|
||||
private:
|
||||
void operator= (const AutomemRawBase_heap&);
|
||||
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
typedef uintptr_t PTR_INT_TYPE;
|
||||
static_assert(sizeof(PTR_INT_TYPE) == sizeof(char*), "Wrong uintptr_t size");
|
||||
#endif
|
||||
T* m_localMem;
|
||||
};
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Stack-based allocation, only gets raw memory
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
class AutomemRawBase_stack {
|
||||
protected:
|
||||
AutomemRawBase_stack ( void ) = default;
|
||||
AutomemRawBase_stack ( const AutomemRawBase_stack& ) = delete; //Copy ctor can't be implemented at this level
|
||||
AutomemRawBase_stack ( AutomemRawBase_stack&& ) = delete;
|
||||
~AutomemRawBase_stack ( void ) = default;
|
||||
|
||||
T* GetMemPtr ( void ) { return reinterpret_cast<T*>(&m_localMem[0]); }
|
||||
const T* GetMemPtr ( void ) const { return reinterpret_cast<const T*>(&m_localMem[0]); }
|
||||
char* GetMemPtrAtIndex ( size_t parIndex );
|
||||
void AllocMemory ( void );
|
||||
void FreeMemory ( void ) noexcept { return; }
|
||||
private:
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
typedef uintptr_t PTR_INT_TYPE;
|
||||
static_assert(sizeof(PTR_INT_TYPE) == sizeof(char*), "Wrong uintptr_t size");
|
||||
#endif
|
||||
void operator= (const AutomemRawBase_stack&);
|
||||
typename std::aligned_storage<sizeof(T), alignof(T)>::type m_localMem[S];
|
||||
};
|
||||
} //namespace din
|
||||
|
||||
#include "AutomemBase.inl"
|
||||
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
# undef ASSERTIONSENABLED
|
||||
#endif
|
||||
#endif
|
159
src/navigate/AutomemBase.inl
Normal file
159
src/navigate/AutomemBase.inl
Normal file
|
@ -0,0 +1,159 @@
|
|||
/* Copyright 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" 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.
|
||||
*
|
||||
* "dindexer" 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 "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace din {
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
AutomemBase_heap<T, S, A>::AutomemBase_heap() {
|
||||
#if !defined(NDEBUG)
|
||||
m_localMem = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
AutomemBase_heap<T, S, A>::AutomemBase_heap (const AutomemBase_heap& parOther) {
|
||||
#if !defined(NDEBUG)
|
||||
m_localMem = NULL;
|
||||
#endif
|
||||
AllocMemory();
|
||||
std::copy(parOther.GetMemPtr(), parOther.GetMemPtr() + S, this->GetMemPtr());
|
||||
}
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
AutomemBase_heap<T, S, A>::AutomemBase_heap (AutomemBase_heap&& parOther) {
|
||||
std::swap(parOther.m_localMem, this->m_localMem);
|
||||
}
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void AutomemBase_heap<T, S, A>::AllocMemory() {
|
||||
#if !defined(NDEBUG)
|
||||
Assert(NULL == m_localMem);
|
||||
#endif
|
||||
m_localMem = A().allocate(S);
|
||||
for (size_t z = 0; z < S; ++z) {
|
||||
new(m_localMem + z) T;
|
||||
}
|
||||
}
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void AutomemBase_heap<T, S, A>::FreeMemory() noexcept {
|
||||
#if !defined(NDEBUG)
|
||||
Assert(NULL != m_localMem);
|
||||
#endif
|
||||
for (size_t z = 0; z < S; ++z) {
|
||||
m_localMem->~T();
|
||||
}
|
||||
A().deallocate(m_localMem, S);
|
||||
#if !defined(NDEBUG)
|
||||
m_localMem = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
AutomemBase_stack<T, S>::AutomemBase_stack() {
|
||||
}
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
AutomemBase_stack<T, S>::AutomemBase_stack (const AutomemBase_stack& parOther) {
|
||||
std::copy(parOther.GetMemPtr(), parOther.GetMemPtr() + S, this->GetMemPtr());
|
||||
}
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
AutomemBase_stack<T, S>::AutomemBase_stack (AutomemBase_stack&& parOther) {
|
||||
for (size_t z = 0; z < S; ++z) {
|
||||
std::swap(m_localMem[z], parOther.m_localMem[z]);
|
||||
}
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
AutomemRawBase_heap<T, S, A>::AutomemRawBase_heap() {
|
||||
#if !defined(NDEBUG)
|
||||
m_localMem = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void AutomemRawBase_heap<T, S, A>::AllocMemory() {
|
||||
#if !defined(NDEBUG)
|
||||
Assert(NULL == m_localMem);
|
||||
#endif
|
||||
m_localMem = A().allocate(S);
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
assert(reinterpret_cast<PTR_INT_TYPE>(m_localMem) % alignof(T) == 0); //Make sure alignment is correct
|
||||
#endif
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void AutomemRawBase_heap<T, S, A>::FreeMemory() noexcept {
|
||||
#if !defined(NDEBUG)
|
||||
Assert(NULL != m_localMem);
|
||||
#endif
|
||||
A().deallocate(m_localMem, S);
|
||||
#if !defined(NDEBUG)
|
||||
m_localMem = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
char* AutomemRawBase_heap<T, S, A>::GetMemPtrAtIndex (size_t parIndex) {
|
||||
T* const retVal = GetMemPtr() + parIndex;
|
||||
return reinterpret_cast<char*>(retVal);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
void AutomemRawBase_stack<T, S>::AllocMemory() {
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
assert(reinterpret_cast<PTR_INT_TYPE>(m_localMem) % alignof(T) == 0); //Make sure alignment is correct
|
||||
#endif
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
char* AutomemRawBase_stack<T, S>::GetMemPtrAtIndex (size_t parIndex) {
|
||||
T* const retVal = GetMemPtr() + parIndex;
|
||||
#if defined(ASSERTIONSENABLED)
|
||||
assert(reinterpret_cast<PTR_INT_TYPE>(retVal) % alignof(T) == 0);
|
||||
#endif
|
||||
return reinterpret_cast<char*>(retVal);
|
||||
}
|
||||
} //namespace din
|
314
src/navigate/IteratorOnPtr.hpp
Normal file
314
src/navigate/IteratorOnPtr.hpp
Normal file
|
@ -0,0 +1,314 @@
|
|||
/* Copyright 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" 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.
|
||||
*
|
||||
* "dindexer" 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 "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef id1B822B1775424D879AA6AD1739B5BC91
|
||||
#define id1B822B1775424D879AA6AD1739B5BC91
|
||||
|
||||
#include <iterator>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
namespace din {
|
||||
namespace implem_iop {
|
||||
template <typename P, typename T, int32_t I>
|
||||
class IteratorOnPtr_base : public std::iterator<std::random_access_iterator_tag, T> {
|
||||
typedef std::iterator<std::random_access_iterator_tag, T> parent_type;
|
||||
public:
|
||||
//Typedefs to be STL-compliant
|
||||
typedef typename parent_type::iterator_category iterator_category;
|
||||
typedef typename parent_type::value_type value_type;
|
||||
typedef typename parent_type::difference_type difference_type;
|
||||
typedef typename parent_type::pointer pointer;
|
||||
typedef typename std::remove_reference<T>::type& reference;
|
||||
|
||||
IteratorOnPtr_base ( P parPointer, difference_type parSize );
|
||||
IteratorOnPtr_base ( const IteratorOnPtr_base& parOther );
|
||||
template <typename P1, typename T1>
|
||||
explicit IteratorOnPtr_base ( const IteratorOnPtr_base<P1, T1, I>& parOther );
|
||||
~IteratorOnPtr_base ( void );
|
||||
|
||||
difference_type operator- ( const IteratorOnPtr_base& parOther ) const;
|
||||
|
||||
bool operator== ( const IteratorOnPtr_base& parOther ) const { return m_pointer == parOther.m_pointer; }
|
||||
bool operator!= ( const IteratorOnPtr_base& parOther ) const { return not operator==(parOther); }
|
||||
bool operator< ( const IteratorOnPtr_base& parOther ) const { return m_pointer < parOther.m_pointer; }
|
||||
bool operator>= ( const IteratorOnPtr_base& parOther ) const { return not operator<(parOther); }
|
||||
bool operator> ( const IteratorOnPtr_base& parOther ) const { return parOther < *this; }
|
||||
bool operator<= ( const IteratorOnPtr_base& parOther ) const { return not operator>(parOther); }
|
||||
|
||||
P GetPointer ( void ) { return m_pointer; }
|
||||
const P GetPointer ( void ) const { return m_pointer; }
|
||||
#if !defined(NDEBUG)
|
||||
difference_type GetSize ( void ) const { return GetSize(0); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
enum {
|
||||
STEP = (I < 0 ? -I : I)
|
||||
};
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
difference_type GetSize ( difference_type parAdvance ) const;
|
||||
bool CanAdvance ( difference_type parAdvance ) const;
|
||||
void AlterSize ( difference_type parAdvance );
|
||||
#endif
|
||||
void MoveIterator ( difference_type parAdvance );
|
||||
|
||||
P m_pointer;
|
||||
|
||||
private:
|
||||
#if !defined(NDEBUG)
|
||||
difference_type m_size;
|
||||
#endif
|
||||
};
|
||||
} //namespace implem_iop
|
||||
|
||||
template <typename P, typename T, bool R>
|
||||
class IteratorOnPtr : public implem_iop::IteratorOnPtr_base<P, T, (R ? -1 : 1)> {
|
||||
typedef implem_iop::IteratorOnPtr_base<P, T, (R ? -1 : 1)> parent_type;
|
||||
enum {
|
||||
STEP = parent_type::STEP
|
||||
};
|
||||
public:
|
||||
typedef typename parent_type::iterator_category iterator_category;
|
||||
typedef typename parent_type::value_type value_type;
|
||||
typedef typename parent_type::difference_type difference_type;
|
||||
typedef typename parent_type::pointer pointer;
|
||||
typedef typename parent_type::reference reference;
|
||||
|
||||
IteratorOnPtr ( void );
|
||||
IteratorOnPtr ( P parPointer, difference_type parSize );
|
||||
IteratorOnPtr ( const IteratorOnPtr& parOther ) : parent_type(parOther) { return; }
|
||||
template <typename P1, typename T1>
|
||||
IteratorOnPtr ( const IteratorOnPtr<P1, T1, R>& parOther ) : parent_type(parOther) {}
|
||||
~IteratorOnPtr ( void );
|
||||
|
||||
IteratorOnPtr& operator++ ( void ); //pre
|
||||
IteratorOnPtr operator++ ( int ); //post
|
||||
IteratorOnPtr& operator-- ( void );
|
||||
IteratorOnPtr operator-- ( int );
|
||||
reference operator* ( void );
|
||||
pointer operator-> ( void );
|
||||
|
||||
using parent_type::operator-;
|
||||
IteratorOnPtr operator+ ( difference_type parOther ) const;
|
||||
IteratorOnPtr operator- ( difference_type parOther ) const;
|
||||
IteratorOnPtr& operator+= ( difference_type parOther );
|
||||
IteratorOnPtr& operator-= ( difference_type parOther );
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
namespace implem_iop {
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
#if !defined(NDEBUG)
|
||||
IteratorOnPtr_base<P, T, I>::IteratorOnPtr_base (P parPointer, difference_type parSize) :
|
||||
m_pointer(parPointer),
|
||||
m_size(parSize)
|
||||
#else
|
||||
IteratorOnPtr_base<P, T, I>::IteratorOnPtr_base (P parPointer, difference_type) :
|
||||
m_pointer(parPointer)
|
||||
#endif
|
||||
{
|
||||
static_assert(I != 0, "Step must be non-zero");
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
template <typename P1, typename T1>
|
||||
IteratorOnPtr_base<P, T, I>::IteratorOnPtr_base (const IteratorOnPtr_base<P1, T1, I>& parOther) {
|
||||
m_pointer = parOther.GetPointer();
|
||||
#if !defined(NDEBUG)
|
||||
m_size = parOther.GetSize();
|
||||
#endif
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
IteratorOnPtr_base<P, T, I>::IteratorOnPtr_base (const IteratorOnPtr_base& parOther) {
|
||||
m_pointer = parOther.m_pointer;
|
||||
#if !defined(NDEBUG)
|
||||
m_size = parOther.m_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
IteratorOnPtr_base<P, T, I>::~IteratorOnPtr_base() {
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
typename IteratorOnPtr_base<P, T, I>::difference_type IteratorOnPtr_base<P, T, I>::operator- (const IteratorOnPtr_base& parOther) const {
|
||||
if (I > 0)
|
||||
return m_pointer - parOther.m_pointer;
|
||||
else
|
||||
return parOther.m_pointer - m_pointer;
|
||||
}
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
typename IteratorOnPtr_base<P, T, I>::difference_type IteratorOnPtr_base<P, T, I>::GetSize (difference_type parAdvance) const {
|
||||
return m_size - STEP * parAdvance;
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
bool IteratorOnPtr_base<P, T, I>::CanAdvance (difference_type parAdvance) const {
|
||||
return (m_size >= STEP * parAdvance);
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
void IteratorOnPtr_base<P, T, I>::AlterSize (difference_type parAdvance) {
|
||||
m_size = GetSize(parAdvance);
|
||||
}
|
||||
#endif
|
||||
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
template <typename P, typename T, int32_t I>
|
||||
void IteratorOnPtr_base<P, T, I>::MoveIterator (difference_type parAdvance) {
|
||||
#if !defined(NDEBUG)
|
||||
assert(CanAdvance(parAdvance));
|
||||
AlterSize(parAdvance);
|
||||
#endif
|
||||
m_pointer += I * parAdvance;
|
||||
}
|
||||
} //namespace implem_iop
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R>::IteratorOnPtr() :
|
||||
parent_type(NULL, 0)
|
||||
{
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R>::IteratorOnPtr (P parPointer, difference_type parSize) :
|
||||
parent_type(parPointer, parSize)
|
||||
{
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R>::~IteratorOnPtr() {
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Pre-increment.
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R>& IteratorOnPtr<P, T, R>::operator++() {
|
||||
this->MoveIterator(1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Post-increment.
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R> IteratorOnPtr<P, T, R>::operator++ (int) {
|
||||
IteratorOnPtr<P, T, R> retVal(*this);
|
||||
this->MoveIterator(1);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Pre-decrement.
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R>& IteratorOnPtr<P, T, R>::operator--() {
|
||||
this->MoveIterator(-1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///Post-decrement.
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R> IteratorOnPtr<P, T, R>::operator-- (int) {
|
||||
IteratorOnPtr<P, T, R> retVal(*this);
|
||||
this->MoveIterator(-1);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
typename IteratorOnPtr<P, T, R>::reference IteratorOnPtr<P, T, R>::operator*() {
|
||||
return *(this->m_pointer);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
typename IteratorOnPtr<P, T, R>::pointer IteratorOnPtr<P, T, R>::operator->() {
|
||||
return this->m_pointer;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R> IteratorOnPtr<P, T, R>::operator+ (difference_type parOther) const {
|
||||
IteratorOnPtr<P, T, R> retVal(*this);
|
||||
retVal += parOther;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R> IteratorOnPtr<P, T, R>::operator- (difference_type parOther) const {
|
||||
IteratorOnPtr<P, T, R> retVal(*this);
|
||||
retVal -= parOther;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R>& IteratorOnPtr<P, T, R>::operator+= (difference_type parOther) {
|
||||
this->MoveIterator(parOther);
|
||||
return *this;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename P, typename T, bool R>
|
||||
IteratorOnPtr<P, T, R>& IteratorOnPtr<P, T, R>::operator-= (difference_type parOther) {
|
||||
this->MoveIterator(-parOther);
|
||||
return *this;
|
||||
}
|
||||
} //namespace din
|
||||
|
||||
#endif
|
112
src/navigate/MaxSizedArray.hpp
Normal file
112
src/navigate/MaxSizedArray.hpp
Normal file
|
@ -0,0 +1,112 @@
|
|||
/* Copyright 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" 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.
|
||||
*
|
||||
* "dindexer" 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 "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idBC9F804ADD33468A9C7657E823FFC706
|
||||
#define idBC9F804ADD33468A9C7657E823FFC706
|
||||
|
||||
#include "AutomemBase.hpp"
|
||||
#include "IteratorOnPtr.hpp"
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
namespace din {
|
||||
const size_t MAXSZARR_MAX_STACK_ALLOC_SIZE = MAX_STACK_ALLOC_SIZE;
|
||||
|
||||
template <typename T, size_t S, typename A=std::allocator<T> >
|
||||
class MaxSizedArray :
|
||||
private std::conditional<
|
||||
(sizeof(T) * S > (MAXSZARR_MAX_STACK_ALLOC_SIZE > 4 * sizeof(T*) ? MAXSZARR_MAX_STACK_ALLOC_SIZE - sizeof(T*) : MAXSZARR_MAX_STACK_ALLOC_SIZE)),
|
||||
AutomemRawBase_heap<T, S, A>,
|
||||
AutomemRawBase_stack<T, S>
|
||||
>::type
|
||||
{
|
||||
typedef typename std::conditional<
|
||||
(sizeof(T) * S > (MAXSZARR_MAX_STACK_ALLOC_SIZE > 4 * sizeof(T*) ? MAXSZARR_MAX_STACK_ALLOC_SIZE - sizeof(T*) : MAXSZARR_MAX_STACK_ALLOC_SIZE)),
|
||||
AutomemRawBase_heap<T, S, A>,
|
||||
AutomemRawBase_stack<T, S>
|
||||
>::type parent_type;
|
||||
|
||||
public:
|
||||
typedef IteratorOnPtr<T*, T, false> iterator;
|
||||
typedef IteratorOnPtr<const T*, const T, false> const_iterator;
|
||||
typedef IteratorOnPtr<T*, T, true> reverse_iterator;
|
||||
typedef IteratorOnPtr<const T*, const T, true> const_reverse_iterator;
|
||||
typedef T& reference;
|
||||
typedef T&& mov_reference;
|
||||
typedef const T& const_reference;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
|
||||
enum MAX_SIZE_ENUM {
|
||||
MAX_SIZE = S
|
||||
};
|
||||
|
||||
MaxSizedArray ( void );
|
||||
MaxSizedArray ( const MaxSizedArray& parOther );
|
||||
MaxSizedArray ( MaxSizedArray&& parOther );
|
||||
~MaxSizedArray ( void );
|
||||
|
||||
bool empty ( void ) const;
|
||||
size_type size ( void ) const;
|
||||
size_type capacity ( void ) const { return S; }
|
||||
size_type max_size ( void ) const { return S; }
|
||||
void push_back ( const value_type& parNewItem );
|
||||
void push_back ( value_type&& parNewItem );
|
||||
void pop_back ( void );
|
||||
iterator erase ( const iterator& parDele );
|
||||
iterator erase ( const iterator& parFrom, const iterator& parToExcl );
|
||||
void clear ( void );
|
||||
mov_reference operator[] ( size_type parIndex );
|
||||
const_reference operator[] ( size_type parIndex ) const;
|
||||
MaxSizedArray& operator= ( const MaxSizedArray& parOther );
|
||||
bool operator== ( const MaxSizedArray& parOther ) const;
|
||||
bool operator!= ( const MaxSizedArray& parOther ) const;
|
||||
pointer GetPointer ( void );
|
||||
const_pointer GetPointer ( void ) const;
|
||||
void reserve ( size_type parReserve );
|
||||
|
||||
iterator begin ( void );
|
||||
const_iterator begin ( void ) const;
|
||||
iterator end ( void );
|
||||
const_iterator end ( void ) const;
|
||||
reverse_iterator rbegin ( void );
|
||||
const_reverse_iterator rbegin ( void ) const;
|
||||
reverse_iterator rend ( void );
|
||||
const_reverse_iterator rend ( void ) const;
|
||||
reference front ( void ) { return (*this)[0]; }
|
||||
reference back ( void ) { return (*this)[size() - 1]; }
|
||||
const_reference front ( void ) const { return (*this)[0]; }
|
||||
const_reference back ( void ) const { return (*this)[size() - 1]; }
|
||||
|
||||
private:
|
||||
pointer GetPointer_NoAssert ( void ) { return m_localMem; }
|
||||
const_pointer GetPointer_NoAssert ( void ) const { return m_localMem; }
|
||||
|
||||
T* m_localMem; //A copy of memory pointer is required
|
||||
size_type m_used;
|
||||
};
|
||||
} //namespace din
|
||||
|
||||
#include "MaxSizedArray.inl"
|
||||
|
||||
#endif
|
287
src/navigate/MaxSizedArray.inl
Normal file
287
src/navigate/MaxSizedArray.inl
Normal file
|
@ -0,0 +1,287 @@
|
|||
/* Copyright 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" 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.
|
||||
*
|
||||
* "dindexer" 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 "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace din {
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
MaxSizedArray<T, S, A>::MaxSizedArray() {
|
||||
this->AllocMemory();
|
||||
//Careful here, I'm not sure this is valid c++
|
||||
m_localMem = reinterpret_cast<T*>(this->GetMemPtrAtIndex(0));
|
||||
m_used = 0;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
MaxSizedArray<T, S, A>::MaxSizedArray (const MaxSizedArray& parOther) :
|
||||
parent_type(),
|
||||
m_used(0)
|
||||
{
|
||||
this->AllocMemory();
|
||||
m_localMem = reinterpret_cast<T*>(this->GetMemPtrAtIndex(0));
|
||||
const size_type count = parOther.size();
|
||||
for (size_type z = 0; z < count; ++z) {
|
||||
this->push_back(parOther[z]);
|
||||
}
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
MaxSizedArray<T, S, A>::MaxSizedArray (MaxSizedArray&& parOther) :
|
||||
parent_type(),
|
||||
m_used(0)
|
||||
{
|
||||
this->AllocMemory();
|
||||
m_localMem = reinterpret_cast<T*>(this->GetMemPtrAtIndex(0));
|
||||
const size_type count = parOther.size();
|
||||
for (size_type z = 0; z < count; ++z) {
|
||||
this->push_back(std::move(parOther[z]));
|
||||
}
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
MaxSizedArray<T, S, A>::~MaxSizedArray() {
|
||||
this->clear();
|
||||
this->FreeMemory();
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
bool MaxSizedArray<T, S, A>::empty() const {
|
||||
return 0 == m_used;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::size_type MaxSizedArray<T, S, A>::size() const {
|
||||
return m_used;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void MaxSizedArray<T, S, A>::push_back (value_type&& parNewItem) {
|
||||
assert(size() < capacity());
|
||||
char* buffer = this->GetMemPtrAtIndex(m_used);
|
||||
new(buffer) T(std::move(parNewItem));
|
||||
++m_used;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void MaxSizedArray<T, S, A>::push_back (const value_type& parNewItem) {
|
||||
assert(size() < capacity());
|
||||
char* buffer = this->GetMemPtrAtIndex(m_used);
|
||||
new(buffer) T(parNewItem);
|
||||
++m_used;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void MaxSizedArray<T, S, A>::pop_back() {
|
||||
assert(not empty());
|
||||
m_localMem[m_used - 1].~T();
|
||||
--m_used;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::mov_reference MaxSizedArray<T, S, A>::operator[] (size_type parIndex) {
|
||||
assert(parIndex < size());
|
||||
return std::move(m_localMem[parIndex]);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::const_reference MaxSizedArray<T, S, A>::operator[] (size_type parIndex) const {
|
||||
assert(parIndex < size());
|
||||
return m_localMem[parIndex];
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
MaxSizedArray<T, S, A>& MaxSizedArray<T, S, A>::operator= (const MaxSizedArray& parOther) {
|
||||
m_used = parOther.m_used;
|
||||
std::copy(parOther.GetMemPtr(), parOther.GetMemPtr() + parOther.size(), this->GetMemPtr());
|
||||
return *this;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
bool MaxSizedArray<T, S, A>::operator== (const MaxSizedArray& parOther) const {
|
||||
if (size() != parOther.size())
|
||||
return false;
|
||||
for (size_type z = 0; z < size(); ++z) {
|
||||
if ((*this)[z] != parOther[z])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
bool MaxSizedArray<T, S, A>::operator!= (const MaxSizedArray& parOther) const {
|
||||
return not (*this == parOther);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::pointer MaxSizedArray<T, S, A>::GetPointer() {
|
||||
assert(size() > 0);
|
||||
return GetPointer_NoAssert();
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::const_pointer MaxSizedArray<T, S, A>::GetPointer() const {
|
||||
assert(size() > 0);
|
||||
return GetPointer_NoAssert();
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void MaxSizedArray<T, S, A>::clear() {
|
||||
const size_type count = this->size();
|
||||
for (size_type z = 0; z < count; ++z) {
|
||||
(*this)[z].~T();
|
||||
}
|
||||
m_used = 0;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::iterator MaxSizedArray<T, S, A>::begin() {
|
||||
return iterator(GetPointer_NoAssert(), size());
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::const_iterator MaxSizedArray<T, S, A>::begin() const {
|
||||
return const_iterator(GetPointer_NoAssert(), size());
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::iterator MaxSizedArray<T, S, A>::end() {
|
||||
return iterator(GetPointer_NoAssert() + size(), 0);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::const_iterator MaxSizedArray<T, S, A>::end() const {
|
||||
return const_iterator(GetPointer_NoAssert() + size(), 0);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::reverse_iterator MaxSizedArray<T, S, A>::rbegin() {
|
||||
return reverse_iterator(GetPointer_NoAssert() + size() - 1, size());
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::const_reverse_iterator MaxSizedArray<T, S, A>::rbegin() const {
|
||||
return const_reverse_iterator(GetPointer_NoAssert() + size() - 1, size());
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::reverse_iterator MaxSizedArray<T, S, A>::rend() {
|
||||
return reverse_iterator(GetPointer_NoAssert() - 1, 0);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::const_reverse_iterator MaxSizedArray<T, S, A>::rend() const {
|
||||
return const_reverse_iterator(GetPointer_NoAssert() - 1, 0);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::iterator MaxSizedArray<T, S, A>::erase (const iterator& parDele) {
|
||||
assert(end() != parDele);
|
||||
return erase(parDele, parDele + 1);
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
typename MaxSizedArray<T, S, A>::iterator MaxSizedArray<T, S, A>::erase (const iterator& parFrom, const iterator& parToExcl) {
|
||||
assert(parFrom >= begin());
|
||||
assert(parToExcl <= end());
|
||||
assert(parToExcl >= parFrom);
|
||||
|
||||
//I'm doing this in two passes: first, I'm deleting as many elements as
|
||||
//the ones that would be left at the end (that is, delete and move),
|
||||
//then delete everything to the end of the buffer, if necessary.
|
||||
const size_type deleCount = static_cast<size_type>(parToExcl - parFrom);
|
||||
const size_type firstIndexToDele = static_cast<size_type>(parFrom - begin());
|
||||
const size_type& sz = m_used;
|
||||
assert(firstIndexToDele + deleCount <= sz);
|
||||
const size_type deleAndCopyCount = sz - (firstIndexToDele + deleCount);
|
||||
|
||||
//As said, make room and copy from the cut tail
|
||||
for (size_type z = firstIndexToDele; z < firstIndexToDele + deleAndCopyCount; z++) {
|
||||
(*this)[z].~T();
|
||||
new(&(*this)[z]) T((*this)[z + deleCount]);
|
||||
}
|
||||
|
||||
//Any leftover is rubbish
|
||||
for (size_type z = firstIndexToDele + deleAndCopyCount; z < sz; z++) {
|
||||
(*this)[z].~T();
|
||||
}
|
||||
|
||||
m_used -= deleCount;
|
||||
return begin() + firstIndexToDele;
|
||||
}
|
||||
|
||||
///-------------------------------------------------------------------------
|
||||
///-------------------------------------------------------------------------
|
||||
template <typename T, size_t S, typename A>
|
||||
void MaxSizedArray<T, S, A>::reserve (size_type parReserve) {
|
||||
assert(parReserve <= S);
|
||||
if (parReserve > S) {
|
||||
throw std::length_error("Unable to reserve more memory than the build-time size for MaxSizedArray");
|
||||
}
|
||||
}
|
||||
} //namespace din
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include "flatinsertin2dlist.hpp"
|
||||
#include "MaxSizedArray.hpp"
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
@ -56,7 +57,7 @@ namespace din {
|
|||
std::vector<uint32_t> sets ( void );
|
||||
|
||||
template <SetDetails... D>
|
||||
std::vector<std::vector<std::string>> set_details ( const std::vector<uint32_t>& parIDs );
|
||||
auto set_details ( const std::vector<uint32_t>& parIDs ) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>>;
|
||||
//TODO: replace return value with vector of maxsizedarray
|
||||
//auto set_details ( const std::vector<uint32_t>& parIDs ) -> std::array<std::string, sizeof...(D)>;
|
||||
|
||||
|
@ -70,12 +71,12 @@ namespace din {
|
|||
};
|
||||
|
||||
template <SetDetails... D>
|
||||
std::vector<std::vector<std::string>> DBSource::set_details (const std::vector<uint32_t>& parIDs) {
|
||||
auto DBSource::set_details (const std::vector<uint32_t>& parIDs) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>> {
|
||||
//auto DBSource::set_details (const std::vector<uint32_t>& parIDs) -> std::array<std::string, sizeof...(D)> {
|
||||
typedef std::vector<std::vector<std::string>> ReturnType;
|
||||
typedef std::vector<MaxSizedArray<std::string, sizeof...(D)>> ReturnType;
|
||||
typedef std::map<SetDetails, std::string> DetailsMap;
|
||||
typedef const std::string&(DetailsMap::*AtFunc)(const SetDetails&) const;
|
||||
typedef void(din::FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(const std::string&);
|
||||
typedef void(din::FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(std::string&&);
|
||||
|
||||
const std::array<SetDetails, sizeof...(D)> details { D... };
|
||||
const DetailsMap details_dic {
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace din {
|
|||
auto& list = *m_list;
|
||||
const auto inner_size = (list.empty() ? m_inner_count : list[list.size() - 1].size());
|
||||
if (inner_size == m_inner_count) {
|
||||
if (not m_outer_count or m_outer_count < list.size()) {
|
||||
if (not m_outer_count or list.size() < m_outer_count) {
|
||||
list.push_back(inner_list_type());
|
||||
list[list.size() - 1].reserve(m_inner_count);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue