OpenVDB  6.2.0
PagedArray.h
Go to the documentation of this file.
1 //
3 // Copyright (c) DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
41 
42 #ifndef OPENVDB_UTIL_PAGED_ARRAY_HAS_BEEN_INCLUDED
43 #define OPENVDB_UTIL_PAGED_ARRAY_HAS_BEEN_INCLUDED
44 
45 #include <openvdb/version.h>
46 #include <openvdb/Types.h>// SharedPtr
47 #include <deque>
48 #include <cassert>
49 #include <iostream>
50 #include <algorithm>// std::swap
51 #include <tbb/atomic.h>
52 #include <tbb/spin_mutex.h>
53 #include <tbb/parallel_for.h>
54 #include <tbb/parallel_sort.h>
55 
56 namespace openvdb {
58 namespace OPENVDB_VERSION_NAME {
59 namespace util {
60 
62 
63 
181 
182 template<typename ValueT, size_t Log2PageSize = 10UL>
184 {
185 private:
186  class Page;
187 
188  // must allow mutiple threads to call operator[] as long as only one thread calls push_back
189  using PageTableT = std::deque<Page*>;
190 
191 public:
192  using ValueType = ValueT;
194 
196  PagedArray() : mCapacity{0} { mSize = 0; }
197 
199  ~PagedArray() { this->clear(); }
200 
201  // Disallow copy construction and assignment
202  PagedArray(const PagedArray&) = delete;
203  PagedArray& operator=(const PagedArray&) = delete;
204 
206  static Ptr create() { return Ptr(new PagedArray); }
207 
216  class ValueBuffer;
217 
219  class ConstIterator;
220 
222  class Iterator;
223 
231  size_t push_back(const ValueType& value)
232  {
233  const size_t index = mSize.fetch_and_increment();
234  if (index >= mCapacity) this->grow(index);
235  (*mPageTable[index >> Log2PageSize])[index] = value;
236  return index;
237  }
238 
246  size_t push_back_unsafe(const ValueType& value)
247  {
248  const size_t index = mSize.fetch_and_increment();
249  if (index >= mCapacity) {
250  mPageTable.push_back( new Page() );
251  mCapacity += Page::Size;
252  }
253  (*mPageTable[index >> Log2PageSize])[index] = value;
254  return index;
255  }
256 
260  void shrink_to_fit();
261 
270  {
271  assert(i<mCapacity);
272  return (*mPageTable[i>>Log2PageSize])[i];
273  }
274 
282  const ValueType& operator[](size_t i) const
283  {
284  assert(i<mCapacity);
285  return (*mPageTable[i>>Log2PageSize])[i];
286  }
287 
293  void fill(const ValueType& v)
294  {
295  auto op = [&](const tbb::blocked_range<size_t>& r){
296  for(size_t i=r.begin(); i!=r.end(); ++i) mPageTable[i]->fill(v);
297  };
298  tbb::parallel_for(tbb::blocked_range<size_t>(0, this->pageCount()), op);
299  }
300 
308  bool copy(ValueType *p, size_t count) const
309  {
310  size_t last_page = count >> Log2PageSize;
311  if (last_page >= this->pageCount()) return false;
312  auto op = [&](const tbb::blocked_range<size_t>& r){
313  for (size_t i=r.begin(); i!=r.end(); ++i) {
314  mPageTable[i]->copy(p+i*Page::Size, Page::Size);
315  }
316  };
317  if (size_t m = count & Page::Mask) {//count is not divisible by page size
318  tbb::parallel_for(tbb::blocked_range<size_t>(0, last_page, 32), op);
319  mPageTable[last_page]->copy(p+last_page*Page::Size, m);
320  } else {
321  tbb::parallel_for(tbb::blocked_range<size_t>(0, last_page+1, 32), op);
322  }
323  return true;
324  }
325  void copy(ValueType *p) const { this->copy(p, mSize); }
326 
341  void resize(size_t size)
342  {
343  mSize = size;
344  if (size > mCapacity) {
345  this->grow(size-1);
346  } else {
347  this->shrink_to_fit();
348  }
349  }
350 
366  void resize(size_t size, const ValueType& v)
367  {
368  this->resize(size);
369  this->fill(v);
370  }
371 
373  size_t size() const { return mSize; }
374 
377  size_t capacity() const { return mCapacity; }
378 
381  size_t freeCount() const { return mCapacity - mSize; }
382 
384  size_t pageCount() const { return mPageTable.size(); }
385 
387  static size_t pageSize() { return Page::Size; }
388 
390  static size_t log2PageSize() { return Log2PageSize; }
391 
393  size_t memUsage() const
394  {
395  return sizeof(*this) + mPageTable.size() * Page::memUsage();
396  }
397 
399  bool isEmpty() const { return mSize == 0; }
400 
407  bool isPartiallyFull() const { return (mSize & Page::Mask) > 0; }
408 
412  void clear()
413  {
414  for (size_t i=0, n=mPageTable.size(); i<n; ++i) delete mPageTable[i];
415  PageTableT().swap(mPageTable);
416  mSize = 0;
417  mCapacity = 0;
418  }
419 
421  Iterator begin() { return Iterator(*this, 0); }
422 
428  Iterator end() { return Iterator(*this, mSize); }
429 
431  ConstIterator cbegin() const { return ConstIterator(*this, 0); }
433  ConstIterator begin() const { return ConstIterator(*this, 0); }
435 
437  ConstIterator cend() const { return ConstIterator(*this, mSize); }
443  ConstIterator end() const { return ConstIterator(*this, mSize); }
445 
447  void sort() { tbb::parallel_sort(this->begin(), this->end(), std::less<ValueT>() ); }
448 
450  void invSort() { tbb::parallel_sort(this->begin(), this->end(), std::greater<ValueT>()); }
451 
453  template <typename Functor>
458  void sort(Functor func) { tbb::parallel_sort(this->begin(), this->end(), func ); }
460 
468  void merge(PagedArray& other);
469 
471  void print(std::ostream& os = std::cout) const
472  {
473  os << "PagedArray:\n"
474  << "\tSize: " << this->size() << " elements\n"
475  << "\tPage table: " << this->pageCount() << " pages\n"
476  << "\tPage size: " << this->pageSize() << " elements\n"
477  << "\tCapacity: " << this->capacity() << " elements\n"
478  << "\tFootprint: " << this->memUsage() << " bytes\n";
479  }
480 
481 private:
482 
483  friend class ValueBuffer;
484 
485  void grow(size_t index)
486  {
487  tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
488  while(index >= mCapacity) {
489  mPageTable.push_back( new Page() );
490  mCapacity += Page::Size;
491  }
492  }
493 
494  void add_full(Page*& page, size_t size);
495 
496  void add_partially_full(Page*& page, size_t size);
497 
498  void add(Page*& page, size_t size) {
499  tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
500  if (size == Page::Size) {//page is full
501  this->add_full(page, size);
502  } else if (size>0) {//page is only partially full
503  this->add_partially_full(page, size);
504  }
505  }
506  PageTableT mPageTable;//holds points to allocated pages
507  tbb::atomic<size_t> mSize;// current number of elements in array
508  size_t mCapacity;//capacity of array given the current page count
509  tbb::spin_mutex mGrowthMutex;//Mutex-lock required to grow pages
510 }; // Public class PagedArray
511 
513 
514 template <typename ValueT, size_t Log2PageSize>
516 {
517  if (mPageTable.size() > (mSize >> Log2PageSize) + 1) {
518  tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
519  const size_t pageCount = (mSize >> Log2PageSize) + 1;
520  if (mPageTable.size() > pageCount) {
521  delete mPageTable.back();
522  mPageTable.pop_back();
523  mCapacity -= Page::Size;
524  }
525  }
526 }
527 
528 template <typename ValueT, size_t Log2PageSize>
530 {
531  if (&other != this && !other.isEmpty()) {
532  tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
533  // extract last partially full page if it exists
534  Page* page = nullptr;
535  const size_t size = mSize & Page::Mask; //number of elements in the last page
536  if ( size > 0 ) {
537  page = mPageTable.back();
538  mPageTable.pop_back();
539  mSize -= size;
540  }
541  // transfer all pages from the other page table
542  mPageTable.insert(mPageTable.end(), other.mPageTable.begin(), other.mPageTable.end());
543  mSize += other.mSize;
544  mCapacity = Page::Size*mPageTable.size();
545  other.mSize = 0;
546  other.mCapacity = 0;
547  PageTableT().swap(other.mPageTable);
548  // add back last partially full page
549  if (page) this->add_partially_full(page, size);
550  }
551 }
552 
553 template <typename ValueT, size_t Log2PageSize>
554 void PagedArray<ValueT, Log2PageSize>::add_full(Page*& page, size_t size)
555 {
556  assert(size == Page::Size);//page must be full
557  if (mSize & Page::Mask) {//page-table is partially full
558  Page*& tmp = mPageTable.back();
559  std::swap(tmp, page);//swap last table entry with page
560  }
561  mPageTable.push_back(page);
562  mCapacity += Page::Size;
563  mSize += size;
564  page = nullptr;
565 }
566 
567 template <typename ValueT, size_t Log2PageSize>
569 {
570  assert(size > 0 && size < Page::Size);//page must be partially full
571  if (size_t m = mSize & Page::Mask) {//page table is also partially full
572  ValueT *s = page->data(), *t = mPageTable.back()->data() + m;
573  for (size_t i=std::min(mSize+size, mCapacity)-mSize; i; --i) *t++ = *s++;
574  if (mSize+size > mCapacity) {//grow page table
575  mPageTable.push_back( new Page() );
576  t = mPageTable.back()->data();
577  for (size_t i=mSize+size-mCapacity; i; --i) *t++ = *s++;
578  mCapacity += Page::Size;
579  }
580  } else {//page table is full so simply append page
581  mPageTable.push_back( page );
582  mCapacity += Page::Size;
583  page = nullptr;
584  }
585  mSize += size;
586 }
587 
589 
590 // Public member-class of PagedArray
591 template <typename ValueT, size_t Log2PageSize>
592 class PagedArray<ValueT, Log2PageSize>::
594 {
595 public:
598  ValueBuffer(PagedArray& parent) : mParent(&parent), mPage(new Page()), mSize(0) {}
601  ValueBuffer(const ValueBuffer& other) : mParent(other.mParent), mPage(new Page()), mSize(0) {}
603  ~ValueBuffer() { mParent->add(mPage, mSize); delete mPage; }
604 
605  ValueBuffer& operator=(const ValueBuffer&) = delete;// disallow copy assignment
606 
611  void push_back(const ValueT& v) {
612  (*mPage)[mSize++] = v;
613  if (mSize == Page::Size) this->flush();
614  }
620  void flush() {
621  mParent->add(mPage, mSize);
622  if (mPage == nullptr) mPage = new Page();
623  mSize = 0;
624  }
626  PagedArrayType& parent() const { return *mParent; }
628  size_t size() const { return mSize; }
629 private:
630  PagedArray* mParent;
631  Page* mPage;
632  size_t mSize;
633 };// Public class PagedArray::ValueBuffer
634 
636 
637 // Const std-compliant iterator
638 // Public member-class of PagedArray
639 template <typename ValueT, size_t Log2PageSize>
640 class PagedArray<ValueT, Log2PageSize>::
641 ConstIterator : public std::iterator<std::random_access_iterator_tag, ValueT>
642 {
643 public:
644  using BaseT = std::iterator<std::random_access_iterator_tag, ValueT>;
645  using difference_type = typename BaseT::difference_type;
646  // constructors and assignment
647  ConstIterator() : mPos(0), mParent(nullptr) {}
648  ConstIterator(const PagedArray& parent, size_t pos=0) : mPos(pos), mParent(&parent) {}
649  ConstIterator(const ConstIterator& other) : mPos(other.mPos), mParent(other.mParent) {}
651  mPos=other.mPos;
652  mParent=other.mParent;
653  return *this;
654  }
655  // prefix
656  ConstIterator& operator++() { ++mPos; return *this; }
657  ConstIterator& operator--() { --mPos; return *this; }
658  // postfix
659  ConstIterator operator++(int) { ConstIterator tmp(*this); ++mPos; return tmp; }
660  ConstIterator operator--(int) { ConstIterator tmp(*this); --mPos; return tmp; }
661  // value access
662  const ValueT& operator*() const { return (*mParent)[mPos]; }
663  const ValueT* operator->() const { return &(this->operator*()); }
664  const ValueT& operator[](const difference_type& pos) const { return (*mParent)[mPos+pos]; }
665  // offset
666  ConstIterator& operator+=(const difference_type& pos) { mPos += pos; return *this; }
667  ConstIterator& operator-=(const difference_type& pos) { mPos -= pos; return *this; }
668  ConstIterator operator+(const difference_type &pos) const { return Iterator(*mParent,mPos+pos); }
669  ConstIterator operator-(const difference_type &pos) const { return Iterator(*mParent,mPos-pos); }
670  difference_type operator-(const ConstIterator& other) const { return mPos - other.pos(); }
671  // comparisons
672  bool operator==(const ConstIterator& other) const { return mPos == other.mPos; }
673  bool operator!=(const ConstIterator& other) const { return mPos != other.mPos; }
674  bool operator>=(const ConstIterator& other) const { return mPos >= other.mPos; }
675  bool operator<=(const ConstIterator& other) const { return mPos <= other.mPos; }
676  bool operator< (const ConstIterator& other) const { return mPos < other.mPos; }
677  bool operator> (const ConstIterator& other) const { return mPos > other.mPos; }
678  // non-std methods
679  bool isValid() const { return mParent != nullptr && mPos < mParent->size(); }
680  size_t pos() const { return mPos; }
681 private:
682  size_t mPos;
683  const PagedArray* mParent;
684 };// Public class PagedArray::ConstIterator
685 
687 
688 // Non-const std-compliant iterator
689 // Public member-class of PagedArray
690 template <typename ValueT, size_t Log2PageSize>
691 class PagedArray<ValueT, Log2PageSize>::
692 Iterator : public std::iterator<std::random_access_iterator_tag, ValueT>
693 {
694 public:
695  using BaseT = std::iterator<std::random_access_iterator_tag, ValueT>;
696  using difference_type = typename BaseT::difference_type;
697  // constructors and assignment
698  Iterator() : mPos(0), mParent(nullptr) {}
699  Iterator(PagedArray& parent, size_t pos=0) : mPos(pos), mParent(&parent) {}
700  Iterator(const Iterator& other) : mPos(other.mPos), mParent(other.mParent) {}
701  Iterator& operator=(const Iterator& other) {
702  mPos=other.mPos;
703  mParent=other.mParent;
704  return *this;
705  }
706  // prefix
707  Iterator& operator++() { ++mPos; return *this; }
708  Iterator& operator--() { --mPos; return *this; }
709  // postfix
710  Iterator operator++(int) { Iterator tmp(*this); ++mPos; return tmp; }
711  Iterator operator--(int) { Iterator tmp(*this); --mPos; return tmp; }
712  // value access
713  ValueT& operator*() const { return (*mParent)[mPos]; }
714  ValueT* operator->() const { return &(this->operator*()); }
715  ValueT& operator[](const difference_type& pos) const { return (*mParent)[mPos+pos]; }
716  // offset
717  Iterator& operator+=(const difference_type& pos) { mPos += pos; return *this; }
718  Iterator& operator-=(const difference_type& pos) { mPos -= pos; return *this; }
719  Iterator operator+(const difference_type &pos) const { return Iterator(*mParent, mPos+pos); }
720  Iterator operator-(const difference_type &pos) const { return Iterator(*mParent, mPos-pos); }
721  difference_type operator-(const Iterator& other) const { return mPos - other.pos(); }
722  // comparisons
723  bool operator==(const Iterator& other) const { return mPos == other.mPos; }
724  bool operator!=(const Iterator& other) const { return mPos != other.mPos; }
725  bool operator>=(const Iterator& other) const { return mPos >= other.mPos; }
726  bool operator<=(const Iterator& other) const { return mPos <= other.mPos; }
727  bool operator< (const Iterator& other) const { return mPos < other.mPos; }
728  bool operator> (const Iterator& other) const { return mPos > other.mPos; }
729  // non-std methods
730  bool isValid() const { return mParent != nullptr && mPos < mParent->size(); }
731  size_t pos() const { return mPos; }
732  private:
733  size_t mPos;
734  PagedArray* mParent;
735 };// Public class PagedArray::Iterator
736 
738 
739 // Private member-class of PagedArray implementing a memory page
740 template <typename ValueT, size_t Log2PageSize>
741 class PagedArray<ValueT, Log2PageSize>::
742 Page
743 {
744 public:
745  static const size_t Size = 1UL << Log2PageSize;
746  static const size_t Mask = Size - 1UL;
747  static size_t memUsage() { return sizeof(ValueT)*Size; }
748  // Raw memory allocation without any initialization
749  Page() : mData(reinterpret_cast<ValueT*>(new char[sizeof(ValueT)*Size])) {}
750  ~Page() { delete [] mData; }
751  Page(const Page&) = delete;//copy construction is not implemented
752  Page& operator=(const Page&) = delete;//copy assignment is not implemented
753  ValueT& operator[](const size_t i) { return mData[i & Mask]; }
754  const ValueT& operator[](const size_t i) const { return mData[i & Mask]; }
755  void fill(const ValueT& v) {
756  ValueT* dst = mData;
757  for (size_t i=Size; i; --i) *dst++ = v;
758  }
759  ValueT* data() { return mData; }
760  // Copy the first n elements of this Page to dst (which is assumed to large
761  // enough to hold the n elements).
762  void copy(ValueType *dst, size_t n) const {
763  const ValueT* src = mData;
764  for (size_t i=n; i; --i) *dst++ = *src++;
765  }
766 protected:
767  ValueT* mData;
768 };// Private class PagedArray::Page
769 
771 
772 } // namespace util
773 } // namespace OPENVDB_VERSION_NAME
774 } // namespace openvdb
775 
776 #endif // OPENVDB_UTIL_PAGED_ARRAY_HAS_BEEN_INCLUDED
777 
778 // Copyright (c) DreamWorks Animation LLC
779 // All rights reserved. This software is distributed under the
780 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Iterator end()
Return a non-const iterator pointing to the past-the-last element.
Definition: PagedArray.h:428
~Page()
Definition: PagedArray.h:750
const ValueType & operator[](size_t i) const
Return a const-reference to the value at the specified offset.
Definition: PagedArray.h:282
bool operator!=(const ConstIterator &other) const
Definition: PagedArray.h:673
void push_back(const ValueT &v)
Add a value to the buffer and increment the size.
Definition: PagedArray.h:611
ValueT * operator->() const
Definition: PagedArray.h:714
ConstIterator & operator-=(const difference_type &pos)
Definition: PagedArray.h:667
void sort()
Parallel sort of all the elements in ascending order.
Definition: PagedArray.h:447
void invSort()
Parallel sort of all the elements in descending order.
Definition: PagedArray.h:450
const ValueT & operator*() const
Definition: PagedArray.h:662
Iterator()
Definition: PagedArray.h:698
static size_t pageSize()
Return the number of elements per memory page.
Definition: PagedArray.h:387
void fill(const ValueType &v)
Set all elements in the page table to the specified value.
Definition: PagedArray.h:293
const ValueT * operator->() const
Definition: PagedArray.h:663
Iterator operator--(int)
Definition: PagedArray.h:711
static size_t memUsage()
Definition: PagedArray.h:747
Iterator & operator-=(const difference_type &pos)
Definition: PagedArray.h:718
void copy(ValueType *dst, size_t n) const
Definition: PagedArray.h:762
ConstIterator & operator--()
Definition: PagedArray.h:657
bool operator==(const ConstIterator &other) const
Definition: PagedArray.h:672
ConstIterator()
Definition: PagedArray.h:647
ValueT & operator*() const
Definition: PagedArray.h:713
size_t push_back_unsafe(const ValueType &value)
Slightly faster than the thread-safe push_back above.
Definition: PagedArray.h:246
size_t freeCount() const
Return the number of additional elements that can be added to this array without allocating more memo...
Definition: PagedArray.h:381
ValueT * data()
Definition: PagedArray.h:759
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
~PagedArray()
Destructor removed all allocated pages.
Definition: PagedArray.h:199
bool isValid() const
Definition: PagedArray.h:679
bool isPartiallyFull() const
Return true if the page table is partially full, i.e. the last non-empty page contains less than page...
Definition: PagedArray.h:407
Iterator operator-(const difference_type &pos) const
Definition: PagedArray.h:720
Concurrent, page-based, dynamically-sized linear data structure with O(1) random access and STL-compl...
Definition: PagedArray.h:183
void print(std::ostream &os=std::cout) const
Print information for debugging.
Definition: PagedArray.h:471
bool isEmpty() const
Return true if the container contains no elements.
Definition: PagedArray.h:399
size_t capacity() const
Return the maximum number of elements that this array can contain without allocating more memory page...
Definition: PagedArray.h:377
size_t pageCount() const
Return the number of allocated memory pages.
Definition: PagedArray.h:384
ConstIterator(const PagedArray &parent, size_t pos=0)
Definition: PagedArray.h:648
Iterator begin()
Return a non-const iterator pointing to the first element.
Definition: PagedArray.h:421
const ValueT & operator[](const difference_type &pos) const
Definition: PagedArray.h:664
bool operator<=(const Iterator &other) const
Definition: PagedArray.h:726
difference_type operator-(const Iterator &other) const
Definition: PagedArray.h:721
~ValueBuffer()
Destructor that transfers an buffered values to the parent PagedArray.
Definition: PagedArray.h:603
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:128
ConstIterator & operator=(const ConstIterator &other)
Definition: PagedArray.h:650
bool copy(ValueType *p, size_t count) const
Copy the first count values in this PageArray into a raw c-style array, assuming it to be at least co...
Definition: PagedArray.h:308
const ValueT & operator[](const size_t i) const
Definition: PagedArray.h:754
bool isValid() const
Definition: PagedArray.h:730
ValueT & operator[](const difference_type &pos) const
Definition: PagedArray.h:715
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition: Mat3.h:645
std::iterator< std::random_access_iterator_tag, ValueT > BaseT
Definition: PagedArray.h:644
bool operator>=(const ConstIterator &other) const
Definition: PagedArray.h:674
ConstIterator & operator+=(const difference_type &pos)
Definition: PagedArray.h:666
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:207
Page()
Definition: PagedArray.h:749
Iterator & operator++()
Definition: PagedArray.h:707
ConstIterator begin() const
Return a const iterator pointing to the first element.
Definition: PagedArray.h:433
typename BaseT::difference_type difference_type
Definition: PagedArray.h:645
bool operator<=(const ConstIterator &other) const
Definition: PagedArray.h:675
void resize(size_t size, const ValueType &v)
Resize this array to the specified size and initialize all values to v.
Definition: PagedArray.h:366
Definition: Exceptions.h:40
Iterator(PagedArray &parent, size_t pos=0)
Definition: PagedArray.h:699
void resize(size_t size)
Resize this array to the specified size.
Definition: PagedArray.h:341
Iterator & operator=(const Iterator &other)
Definition: PagedArray.h:701
static size_t log2PageSize()
Return log2 of the number of elements per memory page.
Definition: PagedArray.h:390
PagedArray()
Default constructor.
Definition: PagedArray.h:196
ValueType & operator[](size_t i)
Return a reference to the value at the specified offset.
Definition: PagedArray.h:269
size_t size() const
Return the current number of elements cached in this buffer.
Definition: PagedArray.h:628
ValueBuffer(const ValueBuffer &other)
Definition: PagedArray.h:601
void flush()
Manually transfers the values in this buffer to the parent PagedArray.
Definition: PagedArray.h:620
Definition: PagedArray.h:691
size_t push_back(const ValueType &value)
Thread safe insertion, adds a new element at the end and increases the container size by one and retu...
Definition: PagedArray.h:231
bool operator>=(const Iterator &other) const
Definition: PagedArray.h:725
Iterator operator+(const difference_type &pos) const
Definition: PagedArray.h:719
Library and file format version numbers.
static Ptr create()
Return a shared pointer to a new instance of this class.
Definition: PagedArray.h:206
PagedArrayType & parent() const
Return a reference to the parent PagedArray.
Definition: PagedArray.h:626
ValueT & operator[](const size_t i)
Definition: PagedArray.h:753
Iterator(const Iterator &other)
Definition: PagedArray.h:700
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
Iterator & operator+=(const difference_type &pos)
Definition: PagedArray.h:717
Iterator & operator--()
Definition: PagedArray.h:708
difference_type operator-(const ConstIterator &other) const
Definition: PagedArray.h:670
size_t size() const
Return the number of elements in this array.
Definition: PagedArray.h:373
size_t pos() const
Definition: PagedArray.h:731
ValueT * mData
Definition: PagedArray.h:767
size_t pos() const
Definition: PagedArray.h:680
Definition: PagedArray.h:741
ConstIterator & operator++()
Definition: PagedArray.h:656
ConstIterator operator++(int)
Definition: PagedArray.h:659
Iterator operator++(int)
Definition: PagedArray.h:710
std::iterator< std::random_access_iterator_tag, ValueT > BaseT
Definition: PagedArray.h:695
SharedPtr< PagedArray > Ptr
Definition: PagedArray.h:193
void clear()
Removes all elements from the array and delete all pages.
Definition: PagedArray.h:412
ConstIterator(const ConstIterator &other)
Definition: PagedArray.h:649
void copy(ValueType *p) const
Definition: PagedArray.h:325
ConstIterator end() const
Return a const iterator pointing to the past-the-last element.
Definition: PagedArray.h:443
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
typename BaseT::difference_type difference_type
Definition: PagedArray.h:696
ValueBuffer(PagedArray &parent)
Constructor from a PageArray.
Definition: PagedArray.h:598
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:219
bool operator==(const Iterator &other) const
Definition: PagedArray.h:723
ConstIterator operator-(const difference_type &pos) const
Definition: PagedArray.h:669
void sort(Functor func)
Parallel sort of all the elements based on a custom functor with the api:
Definition: PagedArray.h:458
ConstIterator operator+(const difference_type &pos) const
Definition: PagedArray.h:668
ValueT ValueType
Definition: PagedArray.h:192
ConstIterator operator--(int)
Definition: PagedArray.h:660
void fill(const ValueT &v)
Definition: PagedArray.h:755
size_t memUsage() const
Return the memory footprint of this array in bytes.
Definition: PagedArray.h:393
bool operator!=(const Iterator &other) const
Definition: PagedArray.h:724