58 #include <pcl/Diagnostics.h>
65 #include <pcl/Memory.h>
68 #include <pcl/Rotate.h>
98 template <
class T,
class A = StandardAllocator>
144 m_data->Allocate( n );
145 m_data->Initialize( m_data->begin, m_data->end );
154 m_data->Allocate( n );
155 m_data->Initialize( m_data->begin, m_data->end, v );
167 if ( m_data->begin !=
nullptr )
168 m_data->Build( m_data->begin, i, j );
179 template <
typename T1>
180 Array( std::initializer_list<T1> l )
181 :
Array( l.begin(), l.end() )
191 if ( m_data !=
nullptr )
210 if ( m_data !=
nullptr )
222 return m_data->IsUnique();
232 return m_data == x.m_data;
246 Data* newData =
new Data;
247 newData->Allocate( Length() );
248 newData->Build( newData->begin, m_data->begin, m_data->end );
260 return m_data->Size();
268 return m_data->Length();
277 return m_data->Capacity();
288 return m_data->Available();
306 return m_data !=
nullptr;
314 return m_data->IsEmpty();
340 return m_data->alloc;
357 PCL_PRECONDITION( !IsEmpty() && i < Length() )
359 return m_data->begin + i;
367 PCL_PRECONDITION( !IsEmpty() && i < Length() )
368 return m_data->begin + i;
383 return At( i - m_data->begin );
409 PCL_PRECONDITION( m_data->begin !=
nullptr )
411 return *m_data->begin;
419 PCL_PRECONDITION( m_data->begin !=
nullptr )
420 return *m_data->begin;
429 return m_data->begin;
437 return m_data->begin;
445 return m_data->begin;
481 PCL_PRECONDITION( m_data->end !=
nullptr )
483 return m_data->end - 1;
494 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;
519 PCL_PRECONDITION( m_data->begin !=
nullptr )
521 return m_data->begin - 1;
533 PCL_PRECONDITION( m_data->begin !=
nullptr )
534 return m_data->begin - 1;
546 PCL_PRECONDITION( m_data->begin !=
nullptr )
547 return m_data->begin - 1;
560 PCL_PRECONDITION( i >= m_data->begin && i <= m_data->end )
565 i = m_data->begin + d;
580 PCL_PRECONDITION( i >= m_data->begin && i <= m_data->end )
581 PCL_PRECONDITION( j >= m_data->begin && j <= m_data->end )
587 j = (i = m_data->begin + d) + r;
591 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
704 Data* newData =
new Data;
709 if ( Capacity() < n )
711 m_data->Deallocate();
712 m_data->Allocate( n );
716 m_data->Destroy( m_data->begin, m_data->end );
717 m_data->end = m_data->begin + n;
720 m_data->Initialize( m_data->begin, m_data->end, v );
740 Data* newData =
new Data;
745 if ( Capacity() < n )
747 m_data->Deallocate();
748 m_data->Allocate( n );
752 m_data->Destroy( m_data->begin, m_data->end );
753 m_data->end = m_data->begin + n;
756 m_data->Build( m_data->begin, i, j );
773 if ( i >= m_data->available || j <= m_data->begin )
781 m_data->end = m_data->available = j;
802 m_data->begin = m_data->end = m_data->available =
nullptr;
818 i =
pcl::Range( i, m_data->begin, m_data->end );
821 UniquifyIterator( i );
822 m_data->Initialize( i = m_data->UninitializedGrow( i, n ), n );
838 return Grow( m_data->end, n );
885 return Insert( i, x.
Begin(), x.
End() );
888 return Insert( i, t.m_data->begin, t.m_data->end );
903 i =
pcl::Range( i, m_data->begin, m_data->end );
906 UniquifyIterator( i );
907 m_data->Initialize( i = m_data->UninitializedGrow( i, n ), n, v );
927 i =
pcl::Range( i, m_data->begin, m_data->end );
931 UniquifyIterator( i );
932 m_data->Build( i = m_data->UninitializedGrow( i, n ), p, q );
942 Insert( m_data->end, x );
951 Insert( m_data->end, v, n );
963 Insert( m_data->end, p, q );
972 Insert( m_data->begin, x );
981 Insert( m_data->begin, v, n );
993 Insert( m_data->begin, p, q );
1046 if ( i < m_data->end )
1051 if ( i > m_data->begin || j < m_data->end )
1053 UniquifyIterators( i, j );
1054 m_data->Destroy( j = pcl::Copy( i, j, m_data->end ), m_data->end );
1073 Remove( m_data->begin, m_data->begin +
pcl::Min( n, m_data->Length() ) );
1087 Remove( m_data->end -
pcl::Min( n, m_data->Length() ), m_data->end );
1102 Remove( i, m_data->end );
1112 for (
iterator i = m_data->begin, j = i; ; ++j )
1114 if ( j == m_data->end )
1116 if ( i != m_data->begin )
1141 for (
iterator i = m_data->begin, j = i; ; ++j )
1143 if ( j == m_data->end )
1145 if ( i != m_data->begin )
1177 m_data->Deallocate();
1180 Data* newData =
new Data;
1202 return Replace( i, j, x.
Begin(), x.
End() );
1223 i =
pcl::Range( i, m_data->begin, m_data->end );
1224 j =
pcl::Range( j, m_data->begin, m_data->end );
1226 if ( i < m_data->end )
1228 UniquifyIterators( i, j );
1232 m_data->Destroy( i, j );
1233 m_data->Initialize( i = m_data->UninitializedGrow( i, n-d ), n, v );
1238 pcl::Fill( i, k, v );
1240 if ( m_data->begin ==
nullptr )
1266 i =
pcl::Range( i, m_data->begin, m_data->end );
1267 j =
pcl::Range( j, m_data->begin, m_data->end );
1269 if ( i < m_data->end )
1271 UniquifyIterators( i, j );
1276 m_data->Destroy( i, j );
1277 m_data->Build( i = m_data->UninitializedGrow( i, n-d ), p, q );
1281 Remove( pcl::Move( i, p, q ), j );
1282 if ( m_data->begin ==
nullptr )
1300 if ( Capacity() < n )
1302 iterator b = m_data->alloc.Allocate( n );
1303 iterator e = m_data->Build( b, m_data->begin, m_data->end );
1304 m_data->Deallocate();
1307 m_data->available = m_data->begin + n;
1312 Data* newData =
new Data;
1313 newData->begin = newData->alloc.Allocate( n =
pcl::Max( Length(), n ) );
1314 newData->end = newData->Build( newData->begin, m_data->begin, m_data->end );
1315 newData->available = newData->begin + n;
1337 if ( Available() > 0 )
1339 iterator b = m_data->alloc.Allocate( Length() );
1340 iterator e = m_data->Build( b, m_data->begin, m_data->end );
1341 m_data->Deallocate();
1343 m_data->end = m_data->available = e;
1348 Data* newData =
new Data;
1351 newData->begin = newData->alloc.Allocate( Length() );
1352 newData->available = newData->end = newData->Build( newData->begin, m_data->begin, m_data->end );
1365 pcl::Fill( m_data->begin, m_data->end, v );
1382 pcl::Fill( m_data->begin, m_data->end, v );
1401 void Apply( F f )
const noexcept( noexcept( f ) )
1444 return pcl::Count( m_data->begin, m_data->end, v );
1452 return pcl::Count( m_data->begin, m_data->end, v, p );
1532 pcl::Reverse( m_data->begin, m_data->end );
1539 if ( Length() > 1 && n != 0 )
1542 if ( (n %= Length()) < 0 )
1544 pcl::Rotate( m_data->begin, m_data->begin+n, m_data->end );
1552 if ( !IsEmpty() && n > 0 )
1555 if ( n >= Length() )
1556 pcl::Fill( m_data->begin, m_data->end, v );
1558 pcl::ShiftLeft( m_data->begin, m_data->begin+n, m_data->end, v );
1566 if ( !IsEmpty() && n > 0 )
1569 if ( n >= Length() )
1570 pcl::Fill( m_data->begin, m_data->end, v );
1572 pcl::ShiftRight( m_data->begin, m_data->end-n, m_data->end, v );
1645 return pcl::Search( m_data->begin, m_data->end, i, j );
1654 return pcl::Search( m_data->begin, m_data->end, i, j );
1659 template <
class FI,
class BP>
1662 return pcl::Search( m_data->begin, m_data->end, i, j, p );
1667 template <
class FI,
class BP>
1671 return pcl::Search( m_data->begin, m_data->end, i, j, p );
1679 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1680 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End() );
1688 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1690 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End() );
1695 template <
class C,
class BP>
1698 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1699 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1704 template <
class C,
class BP>
1707 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1709 return pcl::Search( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1731 template <
class BI,
class BP>
1739 template <
class BI,
class BP>
1751 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1752 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End() );
1760 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1762 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End() );
1767 template <
class C,
class BP>
1770 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1771 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1776 template <
class C,
class BP>
1779 PCL_ASSERT_DIRECT_CONTAINER( C, T );
1781 return pcl::SearchLast( m_data->begin, m_data->end, x.Begin(), x.End(), p );
1789 return Search( v ) != m_data->end;
1795 bool Contains(
const T& v, BP p )
const noexcept( noexcept( p ) )
1797 return Search( v, p ) != m_data->end;
1805 return SearchSubset( i, j ) != m_data->end;
1810 template <
class FI,
class BP>
1813 return SearchSubset( i, j, p ) != m_data->end;
1821 return SearchSubset( c ) != m_data->end;
1826 template <
class C,
class BP>
1829 return SearchSubset( c, p ) != m_data->end;
1873 template <
class S,
typename SP>
1874 S& ToSeparated( S& s, SP separator )
const
1877 if ( i < m_data->end )
1879 s.Append( S( *i ) );
1880 if ( ++i < m_data->end )
1883 s.Append( separator );
1884 s.Append( S( *i ) );
1886 while ( ++i < m_data->end );
1913 template <
class S,
typename SP,
class AF>
1914 S& ToSeparated( S& s, SP separator, AF append )
const
1917 if ( i < m_data->end )
1919 append( s, S( *i ) );
1920 if ( ++i < m_data->end )
1926 append( s, S( *i ) );
1928 while ( ++i < m_data->end );
1943 S& ToCommaSeparated( S& s )
const
1945 return ToSeparated( s,
',' );
1957 S& ToSpaceSeparated( S& s )
const
1959 return ToSeparated( s,
' ' );
1971 S& ToTabSeparated( S& s )
const
1973 return ToSeparated( s,
'\t' );
1985 S& ToNewLineSeparated( S& s )
const
1987 return ToSeparated( s,
'\n' );
2000 return pcl::Hash64( m_data->begin, m_data->Size(), seed );
2013 return pcl::Hash32( m_data->begin, m_data->Size(), seed );
2036 iterator begin =
nullptr;
2037 iterator end =
nullptr;
2038 iterator available =
nullptr;
2059 return Length()*
sizeof( T );
2075 return available - begin;
2083 return available - end;
2089 bool IsEmpty() const noexcept
2091 return begin == end;
2103 begin = alloc.Allocate( m );
2105 available = begin + m;
2114 PCL_CHECK( (begin ==
nullptr) ? end ==
nullptr : begin < end )
2115 if ( begin !=
nullptr )
2118 alloc.Deallocate( begin );
2119 begin = end = available =
nullptr;
2126 void Initialize( iterator __restrict__ i, iterator __restrict__ j )
2128 for ( ; i < j; ++i )
2136 void Initialize( iterator __restrict__ i,
size_type n )
2138 for ( ; n > 0; ++i, --n )
2146 void Initialize( iterator __restrict__ i, iterator __restrict__ j,
const T& v )
2148 for ( ; i < j; ++i )
2156 void Initialize( iterator __restrict__ i,
size_type n,
const T& v )
2158 for ( ; n > 0; ++i, --n )
2168 iterator Build( iterator __restrict__ i, FI p, FI q )
2170 for ( ; p != q; ++i, ++p )
2180 iterator UninitializedGrow( iterator __restrict__ i,
size_type n )
2183 if ( Available() >= n )
2187 iterator __restrict__ j1 = end;
2188 iterator __restrict__ j2 = end + n;
2199 else if ( j2 == end )
2214 size_type m = alloc.PagedLength( Length()+n );
2215 iterator b = alloc.Allocate( m );
2216 iterator r = Build( b, begin, i );
2217 iterator e = Build( r+n, i, end );
2232 static void Destroy( iterator i, iterator j )
2242 Data* m_data =
nullptr;
2248 void DetachFromData()
2250 if ( !m_data->Detach() )
2266 template <
class T,
class A>
inline
2269 return x1.Length() == x2.Length() &&
pcl::Equal( x1.Begin(), x2.Begin(), x2.End() );
2277 template <
class T,
class A>
inline
2280 return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End() ) < 0;
2294 template <
class T,
class A,
class V>
inline
2295 Array<T,A>&
operator <<( Array<T,A>& x,
const V& v )
2308 template <
class T,
class A,
class V>
inline
2309 Array<T,A>&
operator <<( Array<T,A>&& x,
const V& v )
2320 template <
class T,
class A>
inline
2321 Array<T,A>&
operator <<( Array<T,A>& x1,
const Array<T,A>& x2 )
2332 template <
class T,
class A>
inline
2333 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)
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)
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)