24 #ifndef PXR_BASE_TF_SMALL_VECTOR_H
25 #define PXR_BASE_TF_SMALL_VECTOR_H
36 #include <initializer_list>
41 #include <type_traits>
67 template <
typename Iterator>
69 Iterator
first, Iterator
last, Iterator dest) {
70 return std::uninitialized_copy(
71 std::make_move_iterator(first),
72 std::make_move_iterator(last),
80 new (p) U(std::move(*src));
86 template <
typename U,
size_type M >
91 return reinterpret_cast<U *
>(_local);
95 return reinterpret_cast<const U *
>(_local);
112 alignas(U)
char _local[
sizeof(U)*M];
120 template <
typename U >
176 template <
typename T, u
int32_t N >
228 std::uninitialized_fill_n(
data(), n, v);
246 _InitStorage(rhs.
size());
255 if (rhs.size() >
N) {
256 _data.SetRemoteStorage(rhs._data.GetRemoteStorage());
276 template<
typename _ForwardIterator>
278 typename std::enable_if<
280 typename std::iterator_traits<
281 _ForwardIterator>::iterator_category,
282 std::forward_iterator_tag
288 template<
typename ForwardIterator,
293 std::uninitialized_copy(first, last,
begin());
324 assign(ilist.begin(), ilist.end());
332 if (_IsLocal() && rhs._IsLocal()) {
337 std::swap_ranges(smaller->
begin(), smaller->
end(), larger->
begin());
343 (*larger)[i].~value_type();
347 std::swap(smaller->_size, larger->_size);
352 else if (!_IsLocal() && !rhs._IsLocal()) {
354 _data.SetRemoteStorage(rhs._data.GetRemoteStorage());
355 rhs._data.SetRemoteStorage(tmp);
369 value_type *remoteStorage = remote->_GetStorage();
379 remote->_data.GetLocalStorage() + i, &(*local)[i]);
380 (*local)[i].~value_type();
385 local->_data.SetRemoteStorage(remoteStorage);
389 std::swap(remote->_capacity, local->_capacity);
397 return _Insert(it, std::move(
v));
403 return _Insert(it, v);
409 return erase(it, it + 1);
430 for (
value_type *i = (e - num); i != e; ++i) {
448 _GrowStorage(newCapacity);
457 if (newSize <
size()) {
464 else if (newSize >
size()) {
466 std::uninitialized_fill(
data() +
size(),
data() + newSize,
v);
482 template<
typename ForwardIterator,
483 typename = _EnableIfForwardIterator<ForwardIterator>>
488 std::uninitialized_copy(first, last,
begin());
494 void assign(std::initializer_list<T> ilist) {
495 assign(ilist.begin(), ilist.end());
500 template <
typename... Args >
503 _GrowStorage(_NextCapacity());
524 template <
typename ForwardIterator>
529 typename std::iterator_traits<ForwardIterator>::iterator_category,
530 std::forward_iterator_tag>::
value,
531 "Input Iterators not supported.");
536 const bool insertAtEnd = pos ==
end();
541 std::max(_NextCapacity(), neededCapacity);
553 _GrowStorage(nextCapacity);
555 std::uninitialized_copy(first, last,
end());
556 _size += numNewElems;
566 value_type *newStorage = _Allocate(nextCapacity);
569 iterator newPos = newPrefixBegin + posI;
570 iterator newSuffixBegin = newPos + numNewElems;
572 std::uninitialized_copy(first, last, newPos);
578 _data.SetRemoteStorage(newStorage);
579 _capacity = nextCapacity;
593 const long numUninitMoves =
std::min(numNewElems, numMoveElems);
594 const long numInitMoves = numMoveElems - numUninitMoves;
595 const long numUninitNews = numNewElems - numUninitMoves;
596 const long numInitNews = numNewElems - numUninitNews;
599 iterator umSrc = pos + numInitMoves;
602 std::copy_backward(pos, umSrc, umDst);
605 for (
long i=0; i<numInitNews; ++i, ++
first, ++pos) {
608 std::uninitialized_copy(first, last,
end());
611 _size += numNewElems;
617 insert(pos, ilist.begin(), ilist.end());
623 back().~value_type();
757 return *(
data() + i);
763 return *(
data() + i);
769 return _GetStorage();
775 return _GetStorage();
793 bool _IsLocal()
const {
794 return _capacity <=
N;
800 return _IsLocal() ? _data.GetLocalStorage() : _data.GetRemoteStorage();
806 return _IsLocal() ? _data.GetLocalStorage() : _data.GetRemoteStorage();
810 void _FreeStorage() {
812 free(_data.GetRemoteStorage());
833 _data.SetRemoteStorage(_Allocate(size));
841 void _GrowStorage(
const size_type newCapacity) {
842 value_type *newStorage = _Allocate(newCapacity);
846 _data.SetRemoteStorage(newStorage);
847 _capacity = newCapacity;
855 return cap + (cap / 2) + 1;
864 template <
typename U >
878 const size_type newCapacity = _NextCapacity();
879 value_type *newStorage = _Allocate(newCapacity);
892 _data.SetRemoteStorage(newStorage);
893 _capacity = newCapacity;
903 std::move_backward(newEntry, last, last + 1);
906 newEntry->~value_type();
917 _Data<value_type, N> _data;
929 template <
typename T, u
int32_t N >
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
const_reference operator[](size_type i) const
const U * GetLocalStorage() const
size_type capacity() const
const_reverse_iterator rend() const
typename std::enable_if< std::is_convertible< typename std::iterator_traits< _ForwardIterator >::iterator_category, std::forward_iterator_tag >::value >::type _EnableIfForwardIterator
void push_back(const value_type &v)
void insert(iterator pos, std::initializer_list< T > ilist)
void resize(size_type newSize, const value_type &v=value_type())
reverse_iterator rbegin()
bool operator==(const TfSmallVector &rhs) const
void SetRemoteStorage(U *p)
const_iterator cbegin() const
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
void reserve(size_type newCapacity)
static Iterator _UninitializedMove(Iterator first, Iterator last, Iterator dest)
static void _MoveConstruct(U *p, U *src)
TfSmallVector(std::initializer_list< T > values)
Construct a new vector from initializer list.
static constexpr size_type max_size()
GLboolean GLboolean GLboolean GLboolean a
TfSmallVector(size_type n, const value_type &v)
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLdouble GLdouble GLdouble q
iterator erase(const_iterator it, const_iterator last)
const_reverse_iterator crbegin() const
static constexpr size_type internal_capacity()
const_iterator begin() const
bool operator!=(const TfSmallVector &rhs) const
iterator insert(const_iterator it, const value_type &v)
TfSmallVector & operator=(std::initializer_list< T > ilist)
TfSmallVector & operator=(const TfSmallVector &rhs)
void emplace_back(Args &&...args)
TfSmallVector & operator=(TfSmallVector &&rhs)
TfSmallVector(size_type n)
const_iterator end() const
TfSmallVector(size_type n, DefaultInitTag)
const U * GetRemoteStorage() const
GLboolean GLboolean GLboolean b
void SetRemoteStorage(U *p)
void push_back(value_type &&v)
__hostdev__ uint64_t last(uint32_t i) const
iterator erase(const_iterator it)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
std::reverse_iterator< const_iterator > const_reverse_iterator
GLenum GLsizei GLsizei GLint * values
void insert(iterator pos, ForwardIterator first, ForwardIterator last)
const U * GetLocalStorage() const
std::int32_t difference_type
const_reverse_iterator crend() const
iterator insert(const_iterator it, value_type &&v)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void assign(std::initializer_list< T > ilist)
#define PXR_NAMESPACE_CLOSE_SCOPE
GA_API const UT_StringHolder N
**If you just want to fire and args
TfSmallVector(ForwardIterator first, ForwardIterator last)
const_reference front() const
const U * GetRemoteStorage() const
TfSmallVector(const TfSmallVector &rhs)
const_iterator cend() const
TfSmallVector(TfSmallVector &&rhs)
void assign(ForwardIterator first, ForwardIterator last)
const_reference back() const
SIM_API const UT_StringHolder distance
const TYPE * const_iterator
const_reverse_iterator rbegin() const
const T & const_reference
reference operator[](size_type i)
void swap(TfSmallVector &rhs)
std::reverse_iterator< iterator > reverse_iterator
const value_type * data() const
static constexpr size_type ComputeSerendipitousLocalCapacity()