 |
DATAKIT API
V2025.2
|
|
Go to the documentation of this file. 1 #ifndef UTIL_STL_DTK_HPP_
2 #define UTIL_STL_DTK_HPP_
11 template <
typename T1,
typename T2>
30 int operator()(
const T& t1,
const T& t2)
const {
return t1>t2;}
44 int operator()(
const T& t1,
const T& t2)
const {
return t1<t2;}
73 T tmp = std::move( a );
86 struct allocator_from_t
88 T * operator()( std::pair<T *, Dtk_Size_t> src,
Dtk_Size_t n )
91 #if !defined( _MSC_VER ) || _MSC_VER >= 1700 // at least vs12
92 do_move_if( src.first, src.first + src.second, out, std::integral_constant<
bool, std::is_move_assignable<T>::value>() );
94 do_move_if( src.first, src.first + src.second, out, std::integral_constant<bool, false>() );
99 void do_move_if( T *
begin, T *
end, T * dst, std::true_type )
101 for( ;
begin !=
end; ( void )( ++
begin ), ( void )( ++dst ) )
102 *dst = std::move( *
begin );
104 void do_move_if( T *
begin, T *
end, T * dst, std::false_type )
106 for( ;
begin !=
end; ( void )( ++
begin ), ( void )( ++dst ) )
131 v = allocator_from_t()( std::make_pair( old, nb ), s );
186 template <
typename comp>
187 void _mergesort(T* temp,
int left,
int right,
const comp& C)
189 int i, j, k, mid = (left+right)/2;
190 if (left == right)
return;
191 _mergesort(temp, left, mid,C);
192 _mergesort(temp, mid+1, right,C);
194 for (i=left; i<=mid; i++)
196 for (j=1; j<=right-mid; j++)
197 temp[right-j+1] = v[j+mid];
199 for (i=left,j=right,k=left; k<=right; k++)
200 if (C(temp[i],temp[j]))
248 T
const *
data()
const {
return v; }
280 if (t.v!=NULL && nb > 0)
291 if (t<*
this || *
this<t)
296 #ifndef DTK_NO_CXX11_RVALUE_REFERENCES
332 for(i=0;i<
size();i++)
432 T* ex = _dtk_doublerealloc(rsv);
442 #ifndef DTK_NO_CXX11_RVALUE_REFERENCES
462 v[nb++]=std::move(x);
467 T* ex = _dtk_doublerealloc(rsv);
468 v[nb++]= std::move(x);
473 v[nb++]=std::move(x);
623 delete [] _dtk_doublerealloc(n);
651 delete [] _dtk_doublerealloc(n);
670 if ( inA >= nb || inB >= nb )
673 const T Tmp = v[ inA ];
732 template <
typename comp>
739 _mergesort(tmp,(
int)0,(
int)(nb-1),C);
751 template <
typename comp>
752 int find(
const T& e,
const comp& C)
const
755 if (!C(v[i],e) && !C(e,v[i]))
768 delete [] _dtk_doublerealloc(rsv);
783 delete[] _dtk_doublerealloc( rsv );
785 v[ i + nb ] = std::move( t.v[ i ] );
811 delete [] _dtk_doublerealloc(rsv);
864 o<<
"<Tab><Size>"<<d.
size()<<
"</Size>"<<std::endl;
866 for(i=0;i<d.
size();i++)
868 o<<
"<Elem_"<<i<<
">"<< d[i] <<
"</Elem_"<<i<<
">"<<std::endl;
870 o <<
"</Tab>"<<std::endl;
875 return 2*
sizeof(
Dtk_Size_t) +
sizeof(T*) + rsv *
sizeof(T);
884 delete [] _dtk_doublerealloc(rsv);
917 template <
typename T1,
typename T2>
926 template <
typename Arg,
typename Arg2>
Dtk_pair( Arg&& a, Arg2&& b ) :
first( std::forward<Arg>( a ) ),
second( std::forward<Arg2>( b ) )
937 o<<
"<Pair><First>" << d.
first <<
"</First><Second>" << d.
second <<
"</Second></Pair>" <<std::endl;
974 template <
typename T1,
typename T2>
990 template<
class InputIterator,
class Predicate>
991 bool all_of(InputIterator first, InputIterator last, Predicate Pred)
993 for (; first != last; ++first)
1005 template<
typename T,
class Predicate>
1019 template<
class InputIterator,
class Predicate>
1020 bool any_of(InputIterator first, InputIterator last, Predicate Pred)
1022 for(; first != last; ++first)
1034 template<
typename T,
class Predicate>
1048 template<
class InputIterator,
class Predicate>
1049 bool none_of(InputIterator first, InputIterator last, Predicate Pred)
1051 for (; first != last; ++first)
1063 template<
typename T,
class Predicate>
1075 #endif // of ifndef UTIL_STL_DTK_HPP_
Definition: util_stl_dtk.hpp:919
Functor comparison object.
Definition: util_stl_dtk.hpp:27
void reduce()
Definition: util_stl_dtk.hpp:877
Dtk_Size_t capacity() const
Returns the size of the storage space currently allocated for the array, expressed in terms of elemen...
Definition: util_stl_dtk.hpp:524
const_iterator begin() const
Definition: util_stl_dtk.hpp:893
T max_element() const
Definition: util_stl_dtk.hpp:823
bool any_of(InputIterator first, InputIterator last, Predicate Pred)
Test if any element in range fulfills condition, returns true if pred returns true for any of the ele...
Definition: util_stl_dtk.hpp:1020
Dtk_Size_t GetSize() const
Definition: util_stl_dtk.hpp:873
const T & back() const
Return the elements at the end of the array.
Definition: util_stl_dtk.hpp:554
T value_type
Definition: util_stl_dtk.hpp:207
void pop_back()
Removes the last element.
Definition: util_stl_dtk.hpp:487
Dtk_pair(Pair &&p)
Definition: util_stl_dtk.hpp:930
T * pointer
Definition: util_stl_dtk.hpp:208
iterator end()
Definition: util_stl_dtk.hpp:901
size_t Dtk_Size_t
Definition: define.h:712
~Dtk_tab()
Definition: util_stl_dtk.hpp:233
int operator<(const Dtk_tab< T > &t) const
Definition: util_stl_dtk.hpp:325
void sort()
Swap two elements.
Definition: util_stl_dtk.hpp:713
Functor comparison object.
Definition: util_stl_dtk.hpp:41
int operator==(const Dtk_tab< T > &t) const
Definition: util_stl_dtk.hpp:289
T & back()
Return the elements at the end of the array.
Definition: util_stl_dtk.hpp:539
int operator<(const Dtk_pair< T1, T2 > &t) const
Definition: util_stl_dtk.hpp:940
const_pointer const_iterator
Definition: util_stl_dtk.hpp:211
T * data()
Definition: util_stl_dtk.hpp:247
Dtk_pair(const T1 &a, const T2 &b)
Definition: util_stl_dtk.hpp:924
void remove(const T &a)
Removes the first element with the value a.
Definition: util_stl_dtk.hpp:692
T1 first
Definition: util_stl_dtk.hpp:921
T & operator[](Dtk_Size_t k)
Accesses the ith element - like a classic array -.
Definition: util_stl_dtk.hpp:382
const T & at(Dtk_Size_t k) const
Definition: util_stl_dtk.hpp:402
const T * GetArray() const
Returns array of T elements.
Definition: util_stl_dtk.hpp:243
int find(const T &e) const
Definition: util_stl_dtk.hpp:744
#define Pdtk_Assert(X)
Definition: define.h:742
Dtk_tab()
Default constructor.
Definition: util_stl_dtk.hpp:215
friend std::ostream & operator<<(std::ostream &o, const Dtk_pair &d)
Definition: util_stl_dtk.hpp:935
void sort(const comp &C)
Sorts the array with custom sorting.
Definition: util_stl_dtk.hpp:733
T const * data() const
Definition: util_stl_dtk.hpp:248
Dtk_tab(Dtk_Size_t initreservesize, int resize=0)
Definition: util_stl_dtk.hpp:221
T & front()
Return the elements at the beginning of the array.
Definition: util_stl_dtk.hpp:569
void resize(Dtk_Size_t n, const T &t)
Resizes the array.
Definition: util_stl_dtk.hpp:605
bool all_of(InputIterator first, InputIterator last, Predicate Pred)
Test condition on all elements in range, and returns true if pred returns true for all the elements i...
Definition: util_stl_dtk.hpp:991
Dtk_Size_t max_ithelement()
Definition: util_stl_dtk.hpp:847
Dtk_pair< T1, T2 > make_Dtkpair(T1 &&x, T2 &&y)
Constructs a pair object with its first element set to x and its second element set to y.
Definition: util_stl_dtk.hpp:975
Dtk_tab< T > & operator=(Dtk_tab< T > &&t) DTK_NOEXCEPT
Move assignment operator.
Definition: util_stl_dtk.hpp:308
T2 second
Definition: util_stl_dtk.hpp:922
const_iterator cend() const
Definition: util_stl_dtk.hpp:909
void reserve(Dtk_Size_t n)
Definition: util_stl_dtk.hpp:799
const_iterator end() const
Definition: util_stl_dtk.hpp:905
int find(const T &e, const comp &C) const
Definition: util_stl_dtk.hpp:752
void Dtk_ThrowOverflowException()
Dtk_Size_t min_ithelement()
Definition: util_stl_dtk.hpp:833
void reverse()
Definition: util_stl_dtk.hpp:887
T min_element() const
Definition: util_stl_dtk.hpp:813
int operator()(const T &t1, const T &t2) const
Overloaded method comparison.
Definition: util_stl_dtk.hpp:44
void resize(Dtk_Size_t n)
Definition: util_stl_dtk.hpp:628
const T & operator[](Dtk_Size_t k) const
Definition: util_stl_dtk.hpp:390
Definition: util_stl_dtk.hpp:984
Dtk_tab subtab(Dtk_Size_t a, Dtk_Size_t b)
Definition: util_stl_dtk.hpp:790
int operator()(const T &t1, const T &t2) const
Overloaded method comparison.
Definition: util_stl_dtk.hpp:30
This is a high level array class.
Definition: util_stl_dtk.hpp:85
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:504
bool none_of(InputIterator first, InputIterator last, Predicate Pred)
Test if no elements fulfill condition, returns true if pred returns false for all the elements in the...
Definition: util_stl_dtk.hpp:1049
Dtk_tab & operator+=(const Dtk_tab &t)
Definition: util_stl_dtk.hpp:760
void swap(const Dtk_Size_t inA, const Dtk_Size_t inB)
Sorts the array.
Definition: util_stl_dtk.hpp:667
void Dtk_swap(T &a, T &b)
Swap any type of data.
Definition: util_stl_dtk.hpp:71
friend std::ostream & operator<<(std::ostream &o, const Dtk_tab &d)
Definition: util_stl_dtk.hpp:862
Dtk_tab & operator+=(Dtk_tab &&t)
Definition: util_stl_dtk.hpp:775
const_iterator cbegin() const
Definition: util_stl_dtk.hpp:897
T & at(Dtk_Size_t k)
Definition: util_stl_dtk.hpp:398
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:417
void clear(int no_delete=0)
Resets the Dtk_tab content.
Definition: util_stl_dtk.hpp:353
Dtk_tab(const Dtk_tab< T > &t)
Definition: util_stl_dtk.hpp:249
pointer iterator
Definition: util_stl_dtk.hpp:210
const T & front() const
Return the elements at the beginning of the array.
Definition: util_stl_dtk.hpp:584
T const * const_pointer
Definition: util_stl_dtk.hpp:209
iterator begin()
Definition: util_stl_dtk.hpp:889
Dtk_tab & operator=(const Dtk_tab< T > &t)
Definition: util_stl_dtk.hpp:268
int operator==(const Dtk_pair< T1, T2 > &t) const
Definition: util_stl_dtk.hpp:948
Dtk_pair(Arg &&a, Arg2 &&b)
Definition: util_stl_dtk.hpp:926
Dtk_pair()
Definition: util_stl_dtk.hpp:923
#define DTK_NOEXCEPT
Definition: config.hpp:26