58 #include <pcl/Diagnostics.h>
65 #include <pcl/Memory.h>
68 #include <pcl/Rotate.h>
98 template <
class T,
class A = StandardAllocator>
156 m_data->Allocate( n );
157 m_data->Initialize( m_data->begin, m_data->end );
166 m_data->Allocate( n );
167 m_data->Initialize( m_data->begin, m_data->end, v );
179 if ( m_data->begin !=
nullptr )
180 m_data->Build( m_data->begin, i, j );
191 template <
typename T1>
192 Array( std::initializer_list<T1> l )
193 :
Array( l.begin(), l.end() )
203 if ( m_data !=
nullptr )
222 if ( m_data !=
nullptr )
234 return m_data->IsUnique();
244 return m_data == x.m_data;
258 Data* newData =
new Data;
259 newData->Allocate( Length() );
260 newData->Build( newData->begin, m_data->begin, m_data->end );
272 return m_data->Size();
280 return m_data->Length();
289 return m_data->Capacity();
300 return m_data->Available();
318 return m_data !=
nullptr;
326 return m_data->IsEmpty();
352 return m_data->alloc;
369 PCL_PRECONDITION( !IsEmpty() && i < Length() )
371 return m_data->begin + i;
379 PCL_PRECONDITION( !IsEmpty() && i < Length() )
380 return m_data->begin + i;
395 return At( i - m_data->begin );
421 PCL_PRECONDITION( m_data->begin !=
nullptr )
423 return *m_data->begin;
431 PCL_PRECONDITION( m_data->begin !=
nullptr )
432 return *m_data->begin;
441 return m_data->begin;
449 return m_data->begin;
457 return m_data->begin;
493 PCL_PRECONDITION( m_data->end !=
nullptr )
495 return m_data->end - 1;
506 PCL_PRECONDITION( m_data->end !=
nullptr )
507 return m_data->end - 1;
518 PCL_PRECONDITION( m_data->end !=
nullptr )
519 return m_data->end - 1;
531 PCL_PRECONDITION( m_data->begin !=
nullptr )
533 return m_data->begin - 1;
545 PCL_PRECONDITION( m_data->begin !=
nullptr )
546 return m_data->begin - 1;
558 PCL_PRECONDITION( m_data->begin !=
nullptr )
559 return m_data->begin - 1;
572 PCL_PRECONDITION( i >= m_data->begin && i <= m_data->end )
577 i = m_data->begin + d;
592 PCL_PRECONDITION( i >= m_data->begin && i <= m_data->end )
593 PCL_PRECONDITION( j >= m_data->begin && j <= m_data->end )
599 j = (i = m_data->begin + d) + r;
603 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
722 Data* newData =
new Data;
727 if ( Capacity() < n )
729 m_data->Deallocate();
730 m_data->Allocate( n );
734 m_data->Destroy( m_data->begin, m_data->end );
735 m_data->end = m_data->begin + n;
738 m_data->Initialize( m_data->begin, m_data->end, v );
758 Data* newData =
new Data;
763 if ( Capacity() < n )
765 m_data->Deallocate();
766 m_data->Allocate( n );
770 m_data->Destroy( m_data->begin, m_data->end );
771 m_data->end = m_data->begin + n;
774 m_data->Build( m_data->begin, i, j );
791 if ( i >= m_data->available || j <= m_data->begin )
799 m_data->end = m_data->available = j;
820 m_data->begin = m_data->end = m_data->available =
nullptr;
836 i =
pcl::Range( i, m_data->begin, m_data->end );
839 UniquifyIterator( i );
840 m_data->Initialize( i = m_data->UninitializedGrow( i, n ), n );
856 return Grow( m_data->end, n );
903 return Insert( i, x.
Begin(), x.
End() );
906 return Insert( i, t.m_data->begin, t.m_data->end );
921 i =
pcl::Range( i, m_data->begin, m_data->end );
924 UniquifyIterator( i );
925 m_data->Initialize( i = m_data->UninitializedGrow( i, n ), n, v );
945 i =
pcl::Range( i, m_data->begin, m_data->end );
949 UniquifyIterator( i );
950 m_data->Build( i = m_data->UninitializedGrow( i, n ), p, q );
960 Insert( m_data->end, x );
969 Insert( m_data->end, v, n );
981 Insert( m_data->end, p, q );
990 Insert( m_data->begin, x );
999 Insert( m_data->begin, v, n );
1011 Insert( m_data->begin, p, q );
1064 if ( i < m_data->end )
1069 if ( i > m_data->begin || j < m_data->end )
1071 UniquifyIterators( i, j );
1072 m_data->Destroy( j = pcl::Copy( i, j, m_data->end ), m_data->end );
1091 Remove( m_data->begin, m_data->begin +
pcl::Min( n, m_data->Length() ) );
1105 Remove( m_data->end -
pcl::Min( n, m_data->Length() ), m_data->end );
1120 Remove( i, m_data->end );
1130 for (
iterator i = m_data->begin, j = i; ; ++j )
1132 if ( j == m_data->end )
1134 if ( i != m_data->begin )
1159 for (
iterator i = m_data->begin, j = i; ; ++j )
1161 if ( j == m_data->end )
1163 if ( i != m_data->begin )
1195 m_data->Deallocate();
1198 Data* newData =
new Data;
1220 return Replace( i, j, x.
Begin(), x.
End() );
1241 i =
pcl::Range( i, m_data->begin, m_data->end );
1242 j =
pcl::Range( j, m_data->begin, m_data->end );
1244 if ( i < m_data->end )
1246 UniquifyIterators( i, j );
1250 m_data->Destroy( i, j );
1251 m_data->Initialize( i = m_data->UninitializedGrow( i, n-d ), n, v );
1256 pcl::Fill( i, k, v );
1258 if ( m_data->begin ==
nullptr )
1284 i =
pcl::Range( i, m_data->begin, m_data->end );
1285 j =
pcl::Range( j, m_data->begin, m_data->end );
1287 if ( i < m_data->end )
1289 UniquifyIterators( i, j );
1294 m_data->Destroy( i, j );
1295 m_data->Build( i = m_data->UninitializedGrow( i, n-d ), p, q );
1299 Remove( pcl::Move( i, p, q ), j );
1300 if ( m_data->begin ==
nullptr )
1318 if ( Capacity() < n )
1320 iterator b = m_data->alloc.Allocate( n );
1321 iterator e = m_data->Build( b, m_data->begin, m_data->end );
1322 m_data->Deallocate();
1325 m_data->available = m_data->begin + n;
1330 Data* newData =
new Data;
1331 newData->begin = newData->alloc.Allocate( n =
pcl::Max( Length(), n ) );
1332 newData->end = newData->Build( newData->begin, m_data->begin, m_data->end );
1333 newData->available = newData->begin + n;
1355 if ( Available() > 0 )
1357 iterator b = m_data->alloc.Allocate( Length() );
1358 iterator e = m_data->Build( b, m_data->begin, m_data->end );
1359 m_data->Deallocate();
1361 m_data->end = m_data->available = e;
1366 Data* newData =
new Data;
1369 newData->begin = newData->alloc.Allocate( Length() );
1370 newData->available = newData->end = newData->Build( newData->begin, m_data->begin, m_data->end );
1383 pcl::Fill( m_data->begin, m_data->end, v );
1400 pcl::Fill( m_data->begin, m_data->end, v );
1419 void Apply( F f )
const noexcept( noexcept( f ) )
1462 return pcl::Count( m_data->begin, m_data->end, v );
1470 return pcl::Count( m_data->begin, m_data->end, v, p );
1550 pcl::Reverse( m_data->begin, m_data->end );
1557 if ( Length() > 1 && n != 0 )
1560 if ( (n %= Length()) < 0 )
1562 pcl::Rotate( m_data->begin, m_data->begin+n, m_data->end );
1570 if ( !IsEmpty() && n > 0 )
1573 if ( n >= Length() )
1574 pcl::Fill( m_data->begin, m_data->end, v );
1576 pcl::ShiftLeft( m_data->begin, m_data->begin+n, m_data->end, v );
1584 if ( !IsEmpty() && n > 0 )
1587 if ( n >= Length() )
1588 pcl::Fill( m_data->begin, m_data->end, v );
1590 pcl::ShiftRight( m_data->begin, m_data->end-n, m_data->end, v );
1663 return pcl::Search( m_data->begin, m_data->end, i, j );
1672 return pcl::Search( m_data->begin, m_data->end, i, j );
1677 template <
class FI,
class BP>
1680 return pcl::Search( m_data->begin, m_data->end, i, j, p );
1685 template <
class FI,
class BP>
1689 return pcl::Search( m_data->begin, m_data->end, i, j, p );
1697 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1698 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End() );
1706 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1708 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End() );
1713 template <
class C,
class BP>
1716 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1717 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1722 template <
class C,
class BP>
1725 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1727 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1749 template <
class BI,
class BP>
1757 template <
class BI,
class BP>
1769 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1770 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End() );
1778 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1780 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End() );
1785 template <
class C,
class BP>
1788 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1789 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1794 template <
class C,
class BP>
1797 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1799 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1807 return Search( v ) != m_data->end;
1813 bool Contains(
const T& v, BP p )
const noexcept( noexcept( p ) )
1815 return Search( v, p ) != m_data->end;
1823 return SearchSubset( i, j ) != m_data->end;
1828 template <
class FI,
class BP>
1831 return SearchSubset( i, j, p ) != m_data->end;
1839 return SearchSubset( c ) != m_data->end;
1844 template <
class C,
class BP>
1847 return SearchSubset( c, p ) != m_data->end;
1891 template <
class S,
typename SP>
1892 S& ToSeparated( S& s, SP separator )
const
1895 if ( i < m_data->end )
1897 s.Append( S( *i ) );
1898 if ( ++i < m_data->end )
1901 s.Append( separator );
1902 s.Append( S( *i ) );
1904 while ( ++i < m_data->end );
1931 template <
class S,
typename SP,
class AF>
1932 S& ToSeparated( S& s, SP separator, AF append )
const
1935 if ( i < m_data->end )
1937 append( s, S( *i ) );
1938 if ( ++i < m_data->end )
1944 append( s, S( *i ) );
1946 while ( ++i < m_data->end );
1961 S& ToCommaSeparated( S& s )
const
1963 return ToSeparated( s,
',' );
1975 S& ToSpaceSeparated( S& s )
const
1977 return ToSeparated( s,
' ' );
1989 S& ToTabSeparated( S& s )
const
1991 return ToSeparated( s,
'\t' );
2003 S& ToNewLineSeparated( S& s )
const
2005 return ToSeparated( s,
'\n' );
2018 return pcl::Hash64( m_data->begin, m_data->Size(), seed );
2031 return pcl::Hash32( m_data->begin, m_data->Size(), seed );
2054 iterator begin =
nullptr;
2055 iterator end =
nullptr;
2056 iterator available =
nullptr;
2077 return Length()*
sizeof( T );
2093 return available - begin;
2101 return available - end;
2107 bool IsEmpty() const noexcept
2109 return begin == end;
2121 begin = alloc.Allocate( m );
2123 available = begin + m;
2132 PCL_CHECK( (begin ==
nullptr) ? end ==
nullptr : begin < end )
2133 if ( begin !=
nullptr )
2136 alloc.Deallocate( begin );
2137 begin = end = available =
nullptr;
2144 void Initialize( iterator __restrict__ i, iterator __restrict__ j )
2146 for ( ; i < j; ++i )
2154 void Initialize( iterator __restrict__ i,
size_type n )
2156 for ( ; n > 0; ++i, --n )
2164 void Initialize( iterator __restrict__ i, iterator __restrict__ j,
const T& v )
2166 for ( ; i < j; ++i )
2174 void Initialize( iterator __restrict__ i,
size_type n,
const T& v )
2176 for ( ; n > 0; ++i, --n )
2186 iterator Build( iterator __restrict__ i, FI p, FI q )
2188 for ( ; p != q; ++i, ++p )
2198 iterator UninitializedGrow( iterator __restrict__ i,
size_type n )
2201 if ( Available() >= n )
2205 iterator __restrict__ j1 = end;
2206 iterator __restrict__ j2 = end + n;
2217 else if ( j2 == end )
2232 size_type m = alloc.PagedLength( Length()+n );
2233 iterator b = alloc.Allocate( m );
2234 iterator r = Build( b, begin, i );
2235 iterator e = Build( r+n, i, end );
2250 static void Destroy( iterator i, iterator j )
2260 Data* m_data =
nullptr;
2266 void DetachFromData()
2268 if ( !m_data->Detach() )
2284 template <
class T,
class A>
inline
2287 return x1.Length() == x2.Length() &&
pcl::Equal( x1.Begin(), x2.Begin(), x2.End() );
2295 template <
class T,
class A>
inline
2298 return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End() ) < 0;
2312 template <
class T,
class A,
class V>
inline
2313 Array<T,A>&
operator <<( Array<T,A>& x,
const V& v )
2326 template <
class T,
class A,
class V>
inline
2327 Array<T,A>&
operator <<( Array<T,A>&& x,
const V& v )
2338 template <
class T,
class A>
inline
2339 Array<T,A>&
operator <<( Array<T,A>& x1,
const Array<T,A>& x2 )
2350 template <
class T,
class A>
inline
2351 Array<T,A>&
operator <<( Array<T,A>&& x1,
const Array<T,A>& x2 )
Provides memory allocation for PCL containers.
iterator SearchLastSubset(BI i, BI j, BP p)
const_iterator MinItem() const noexcept
iterator SearchSubset(const C &x, BP p)
iterator ContainsSubset(const C &c, BP p) const noexcept(noexcept(p))
uint64 Hash64(uint64 seed=0) const
void Shrink(size_type n=1)
iterator SearchLast(const T &v, BP p)
void Import(iterator i, iterator j)
bool IsEmpty() const noexcept
size_type LowerBound() const noexcept
void Apply(F f) const noexcept(noexcept(f))
void Remove(iterator i, iterator j)
friend void Swap(Array &x1, Array &x2) noexcept
void ShiftRight(const T &v, size_type n=1)
iterator Grow(iterator i, size_type n=1)
const_iterator SearchLastSubset(BI i, BI j) const noexcept
iterator Expand(size_type n=1)
void Prepend(const T &v, size_type n=1)
const allocator & Allocator() const noexcept
iterator SearchSubset(FI i, FI j, BP p)
const_iterator MinItem(BP p) const noexcept(noexcept(p))
void Rotate(distance_type n)
const_iterator ConstEnd() const noexcept
void UniquifyIterators(iterator &i, iterator &j)
iterator ContainsSubset(const C &c) const noexcept
iterator SearchSubset(FI i, FI j)
uint64 Hash(uint64 seed=0) const noexcept
size_type Length() const noexcept
Array(size_type n, const T &v)
const_iterator SearchLastSubset(const C &x) const noexcept
iterator Replace(iterator i, iterator j, FI p, FI q)
void Add(const T &v, size_type n=1)
bool IsValid() const noexcept
void UniquifyIterator(iterator &i)
bool IsAliasOf(const Array &x) const noexcept
const_iterator End() const noexcept
bool IsUnique() const noexcept
void Assign(const T &v, size_type n=1)
void Append(const T &v, size_type n=1)
void Append(const Array &x)
void ShiftLeft(const T &v, size_type n=1)
iterator SearchLastSubset(const C &x)
uint32 Hash32(uint32 seed=0) const noexcept
const_iterator SearchSubset(const C &x) const noexcept
bool Contains(const T &v) const noexcept
size_type Count(const T &v) const noexcept
const_reverse_iterator ReverseEnd() const noexcept
iterator Replace(iterator i, iterator j, const Array &x)
void SetAllocator(const allocator &a)
iterator SearchLast(const T &v)
void Remove(const T &v, BP p)
iterator ContainsSubset(FI i, FI j, BP p) const noexcept(noexcept(p))
const_reverse_iterator ConstReverseBegin() const noexcept
void Assign(const Array &x)
const_iterator Begin() const noexcept
Array(std::initializer_list< T1 > l)
void Prepend(const Array &x)
const_iterator SearchLastSubset(BI i, BI j, BP p) const noexcept(noexcept(p))
const_iterator MaxItem() const noexcept
const_iterator LastThat(F f) const noexcept(noexcept(f))
bool Contains(const T &v, BP p) const noexcept(noexcept(p))
void RemoveLast(size_type n=1)
typename container_type::const_item_type const_item_type
size_type UpperBound() const noexcept
const_iterator SearchSubset(FI i, FI j) const noexcept
iterator SearchSubset(const C &x)
iterator Replace(iterator i, iterator j, const T &v, size_type n=1)
const_iterator SearchSubset(const C &x, BP p) const noexcept(noexcept(p))
size_type Count(const T &v, BP p) const noexcept(noexcept(p))
const_iterator begin() const noexcept
const_reverse_iterator ConstReverseEnd() const noexcept
iterator Insert(iterator i, FI p, FI q)
iterator Search(const T &v, BP p)
reverse_iterator ReverseEnd()
const_iterator SearchSubset(FI i, FI j, BP p) const noexcept(noexcept(p))
iterator Insert(iterator i, const Array &x)
iterator Insert(iterator i, const T &v, size_type n=1)
const_iterator At(size_type i) const noexcept
iterator ContainsSubset(FI i, FI j) const noexcept
const_iterator Search(const T &v) const noexcept
reverse_iterator ReverseBegin()
size_type Capacity() const noexcept
const_iterator end() const noexcept
const_iterator FirstThat(F f) const noexcept(noexcept(f))
void Truncate(iterator i)
iterator SearchLastSubset(const C &x, BP p)
const_iterator Search(const T &v, BP p) const noexcept(noexcept(p))
void SecureFill(const T &v)
size_type Size() const noexcept
const_iterator MaxItem(BP p) const noexcept(noexcept(p))
void Reserve(size_type n)
const_iterator ConstBegin() const noexcept
size_type CountIf(UP p) const noexcept(noexcept(p))
const_iterator SearchLastSubset(const C &x, BP p) const noexcept(noexcept(p))
const_iterator SearchLast(const T &v) const noexcept
void Remove(iterator i, size_type n=1)
const_iterator SearchLast(const T &v, BP p) const noexcept(noexcept(p))
const_reverse_iterator ReverseBegin() const noexcept
iterator SearchLastSubset(BI i, BI j)
iterator Search(const T &v)
void RemoveFirst(size_type n=1)
size_type Available() const noexcept
iterator MutableIterator(const_iterator i)
typename container_type::item_type item_type
Root base class of all PCL containers of objects.
Thread-safe reference counter for copy-on-write data structures.
Reverse random access iterator.
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
uint64 Hash64(const void *data, size_type size, uint64 seed=0) noexcept
uint32 Hash32(const void *data, size_type size, uint32 seed=0) noexcept
void Rotate(T &x, T &y, T1 sa, T1 ca, T2 xc, T2 yc) noexcept
void Construct(T *p, A &a)
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
unsigned long long uint64
FI LinearSearch(FI i, FI j, const T &v) noexcept
BI1 SearchLast(BI1 i1, BI1 j1, FI2 i2, FI2 j2) noexcept
BI LinearSearchLast(BI i, BI j, const T &v) noexcept
FI1 Search(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
void QuickSort(RI i, RI j)
size_type CountIf(FI i, FI j, UP p) noexcept(noexcept(p))
constexpr const T & Min(const T &a, const T &b) noexcept
BI LastThat(BI i, BI j, UP p) noexcept(noexcept(p))
size_type Count(FI i, FI j, const T &v) noexcept
FI MinItem(FI i, FI j) noexcept
bool Equal(FI1 i1, FI2 i2, FI2 j2) noexcept
int Compare(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept
FI MaxItem(FI i, FI j) noexcept
void Apply(FI i, FI j, F f) noexcept(noexcept(f))
FI FirstThat(FI i, FI j, UP p) noexcept(noexcept(p))
distance_type Distance(FI i, FI j)