OpenVDB: PagedArray.h Source File

OpenVDB 5.0.0

PagedArray.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2017 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 <vector>
46 #include <cassert>
47 #include <iostream>
48 #include <algorithm>// std::swap
49 #include <tbb/atomic.h>
50 #include <tbb/spin_mutex.h>
51 #include <tbb/parallel_for.h>
52 #include <tbb/parallel_sort.h>
53
54 namespace openvdb {
55 OPENVDB_USE_VERSION_NAMESPACE
56 namespace OPENVDB_VERSION_NAME {
57 namespace util {
58
60
61
184
185 template<typename ValueT,
186 size_t Log2PageSize = 10UL,
187 template<typename ...> class TableT = std::vector>
188 class PagedArray
189 {
190 private:
191 class Page;
192
193 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1700
194 // Workaround for ICC 15/16 "too few arguments to template" bug (fixed in ICC 17)
195 using PageTableT = TableT<Page*, std::allocator<Page*>>;
196 #else
197 using PageTableT = TableT<Page*>;
198 #endif
199
200 public:
201 using ValueType = ValueT;
202
204 PagedArray() = default;
205
207 ~PagedArray() { this->clear(); }
208
209 // Disallow copy construction and assignment
210 PagedArray(const PagedArray&) = delete;
211 PagedArray& operator=(const PagedArray&) = delete;
212
221 class ValueBuffer;
222
224 class ConstIterator;
225
227 class Iterator;
228
236 size_t push_back(const ValueType& value)
237 {
238 const size_t index = mSize.fetch_and_increment();
239 if (index >= mCapacity) this->grow(index);
240 (*mPageTable[index >> Log2PageSize])[index] = value;
241 return index;
242 }
243
251 size_t push_back_unsafe(const ValueType& value)
252 {
253 const size_t index = mSize.fetch_and_increment();
254 if (index >= mCapacity) {
255 mPageTable.push_back( new Page() );
256 mCapacity += Page::Size;
257 }
258 (*mPageTable[index >> Log2PageSize])[index] = value;
259 return index;
260 }
261
265 void shrink_to_fit();
266
274 ValueType& operator[](size_t i)
275 {
276 assert(i<mCapacity);
277 return (*mPageTable[i>>Log2PageSize])[i];
278 }
279
287 const ValueType& operator[](size_t i) const
288 {
289 assert(i<mCapacity);
290 return (*mPageTable[i>>Log2PageSize])[i];
291 }
292
298 void fill(const ValueType& v)
299 {
300 auto op = [&](const tbb::blocked_range<size_t>& r){
301 for(size_t i=r.begin(); i!=r.end(); ++i) mPageTable[i]->fill(v);
302 };
303 tbb::parallel_for(tbb::blocked_range<size_t>(0, this->pageCount()), op);
304 }
305
313 bool copy(ValueType *p, size_t count) const
314 {
315 size_t last_page = count >> Log2PageSize;
316 if (last_page >= this->pageCount()) return false;
317 auto op = [&](const tbb::blocked_range<size_t>& r){
318 for (size_t i=r.begin(); i!=r.end(); ++i) {
319 mPageTable[i]->copy(p+i*Page::Size, Page::Size);
320 }
321 };
322 if (size_t m = count & Page::Mask) {//count is not divisible by page size
323 tbb::parallel_for(tbb::blocked_range<size_t>(0, last_page, 32), op);
324 mPageTable[last_page]->copy(p+last_page*Page::Size, m);
325 } else {
326 tbb::parallel_for(tbb::blocked_range<size_t>(0, last_page+1, 32), op);
327 }
328 return true;
329 }
330 void copy(ValueType *p) const { this->copy(p, mSize); }
331
346 void resize(size_t size)
347 {
348 mSize = size;
349 if (size > mCapacity) {
350 this->grow(size-1);
351 } else {
352 this->shrink_to_fit();
353 }
354 }
355
371 void resize(size_t size, const ValueType& v)
372 {
373 this->resize(size);
374 this->fill(v);
375 }
376
378 size_t size() const { return mSize; }
379
382 size_t capacity() const { return mCapacity; }
383
386 size_t freeCount() const { return mCapacity - mSize; }
387
389 size_t pageCount() const { return mPageTable.size(); }
390
392 static size_t pageSize() { return Page::Size; }
393
395 static size_t log2PageSize() { return Log2PageSize; }
396
398 size_t memUsage() const
399 {
400 return sizeof(*this) + mPageTable.size() * Page::memUsage();
401 }
402
404 bool isEmpty() const { return mSize == 0; }
405
412 bool isPartiallyFull() const { return (mSize & Page::Mask) > 0; }
413
417 void clear()
418 {
419 for (size_t i=0, n=mPageTable.size(); i<n; ++i) delete mPageTable[i];
420 PageTableT().swap(mPageTable);
421 mSize = 0;
422 mCapacity = 0;
423 }
424
426 Iterator begin() { return Iterator(*this, 0); }
427
433 Iterator end() { return Iterator(*this, mSize); }
434
436 ConstIterator cbegin() const { return ConstIterator(*this, 0); }
438 ConstIterator begin() const { return ConstIterator(*this, 0); }
440
442 ConstIterator cend() const { return ConstIterator(*this, mSize); }
448 ConstIterator end() const { return ConstIterator(*this, mSize); }
450
452 void sort() { tbb::parallel_sort(this->begin(), this->end(), std::less<ValueT>() ); }
453
455 void invSort() { tbb::parallel_sort(this->begin(), this->end(), std::greater<ValueT>()); }
456
458 template <typename Functor>
463 void sort(Functor func) { tbb::parallel_sort(this->begin(), this->end(), func ); }
465
473 void merge(PagedArray& other);
474
476 void print(std::ostream& os = std::cout) const
477 {
478 os << "PagedArray:\n"
479 << "\tSize: " << this->size() << " elements\n"
480 << "\tPage table: " << this->pageCount() << " pages\n"
481 << "\tPage size: " << this->pageSize() << " elements\n"
482 << "\tCapacity: " << this->capacity() << " elements\n"
483 << "\tFootprint: " << this->memUsage() << " bytes\n";
484 }
485
486 private:
487
488 friend class ValueBuffer;
489
490 void grow(size_t index)
491 {
492 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
493 while(index >= mCapacity) {
494 mPageTable.push_back( new Page() );
495 mCapacity += Page::Size;
496 }
497 }
498
499 void add_full(Page*& page, size_t size);
500
501 void add_partially_full(Page*& page, size_t size);
502
503 void add(Page*& page, size_t size) {
504 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
505 if (size == Page::Size) {//page is full
506 this->add_full(page, size);
507 } else if (size>0) {//page is only partially full
508 this->add_partially_full(page, size);
509 }
510 }
511 PageTableT mPageTable;//holds points to allocated pages
512 tbb::atomic<size_t> mSize{0};// current number of elements in array
513 size_t mCapacity = 0;//capacity of array given the current page count
514 tbb::spin_mutex mGrowthMutex;//Mutex-lock required to grow pages
515 }; // Public class PagedArray
516
518
519 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
520 void PagedArray<ValueT, Log2PageSize, TableT>::shrink_to_fit()
521 {
522 if (mPageTable.size() > (mSize >> Log2PageSize) + 1) {
523 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
524 const size_t pageCount = (mSize >> Log2PageSize) + 1;
525 if (mPageTable.size() > pageCount) {
526 delete mPageTable.back();
527 mPageTable.pop_back();
528 mCapacity -= Page::Size;
529 }
530 }
531 }
532
533 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
534 void PagedArray<ValueT, Log2PageSize,TableT >::merge(PagedArray& other)
535 {
536 if (&other != this && !other.isEmpty()) {
537 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
538 // extract last partially full page if it exists
539 Page* page = nullptr;
540 const size_t size = mSize & Page::Mask; //number of elements in the last page
541 if ( size > 0 ) {
542 page = mPageTable.back();
543 mPageTable.pop_back();
544 mSize -= size;
545 }
546 // transfer all pages from the other page table
547 mPageTable.insert(mPageTable.end(), other.mPageTable.begin(), other.mPageTable.end());
548 mSize += other.mSize;
549 mCapacity = Page::Size*mPageTable.size();
550 other.mSize = 0;
551 other.mCapacity = 0;
552 PageTableT().swap(other.mPageTable);
553 // add back last partially full page
554 if (page) this->add_partially_full(page, size);
555 }
556 }
557
558 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
559 void PagedArray<ValueT, Log2PageSize, TableT>::add_full(Page*& page, size_t size)
560 {
561 assert(size == Page::Size);//page must be full
562 if (mSize & Page::Mask) {//page-table is partially full
563 Page*& tmp = mPageTable.back();
564 std::swap(tmp, page);//swap last table entry with page
565 }
566 mPageTable.push_back(page);
567 mCapacity += Page::Size;
568 mSize += size;
569 page = nullptr;
570 }
571
572 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
573 void PagedArray<ValueT, Log2PageSize, TableT>::add_partially_full(Page*& page, size_t size)
574 {
575 assert(size > 0 && size < Page::Size);//page must be partially full
576 if (size_t m = mSize & Page::Mask) {//page table is also partially full
577 ValueT *s = page->data(), *t = mPageTable.back()->data() + m;
578 for (size_t i=std::min(mSize+size, mCapacity)-mSize; i; --i) *t++ = *s++;
579 if (mSize+size > mCapacity) {//grow page table
580 mPageTable.push_back( new Page() );
581 t = mPageTable.back()->data();
582 for (size_t i=mSize+size-mCapacity; i; --i) *t++ = *s++;
583 mCapacity += Page::Size;
584 }
585 } else {//page table is full so simply append page
586 mPageTable.push_back( page );
587 mCapacity += Page::Size;
588 page = nullptr;
589 }
590 mSize += size;
591 }
592
594
595 // Public member-class of PagedArray
596 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
597 class PagedArray<ValueT, Log2PageSize, TableT>::
598 ValueBuffer
599 {
600 public:
601 using PagedArrayType = PagedArray<ValueT, Log2PageSize, TableT>;
603 ValueBuffer(PagedArray& parent) : mParent(&parent), mPage(new Page()), mSize(0) {}
606 ValueBuffer(const ValueBuffer& other) : mParent(other.mParent), mPage(new Page()), mSize(0) {}
608 ~ValueBuffer() { mParent->add(mPage, mSize); delete mPage; }
609
610 ValueBuffer& operator=(const ValueBuffer&) = delete;// disallow copy assignment
611
616 void push_back(const ValueT& v) {
617 (*mPage)[mSize++] = v;
618 if (mSize == Page::Size) this->flush();
619 }
625 void flush() {
626 mParent->add(mPage, mSize);
627 if (mPage == nullptr) mPage = new Page();
628 mSize = 0;
629 }
631 PagedArrayType& parent() const { return *mParent; }
633 size_t size() const { return mSize; }
634 private:
635 PagedArray* mParent;
636 Page* mPage;
637 size_t mSize;
638 };// Public class PagedArray::ValueBuffer
639
641
642 // Const std-compliant iterator
643 // Public member-class of PagedArray
644 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
645 class PagedArray<ValueT, Log2PageSize, TableT>::
646 ConstIterator : public std::iterator<std::random_access_iterator_tag, ValueT>
647 {
648 public:
649 using BaseT = std::iterator<std::random_access_iterator_tag, ValueT>;
650 using difference_type = typename BaseT::difference_type;
651 // constructors and assignment
652 ConstIterator() : mPos(0), mParent(nullptr) {}
653 ConstIterator(const PagedArray& parent, size_t pos=0) : mPos(pos), mParent(&parent) {}
654 ConstIterator(const ConstIterator& other) : mPos(other.mPos), mParent(other.mParent) {}
655 ConstIterator& operator=(const ConstIterator& other) {
656 mPos=other.mPos;
657 mParent=other.mParent;
658 return *this;
659 }
660 // prefix
661 ConstIterator& operator++() { ++mPos; return *this; }
662 ConstIterator& operator--() { --mPos; return *this; }
663 // postfix
664 ConstIterator operator++(int) { ConstIterator tmp(*this); ++mPos; return tmp; }
665 ConstIterator operator--(int) { ConstIterator tmp(*this); --mPos; return tmp; }
666 // value access
667 const ValueT& operator*() const { return (*mParent)[mPos]; }
668 const ValueT* operator->() const { return &(this->operator*()); }
669 const ValueT& operator[](const difference_type& pos) const { return (*mParent)[mPos+pos]; }
670 // offset
671 ConstIterator& operator+=(const difference_type& pos) { mPos += pos; return *this; }
672 ConstIterator& operator-=(const difference_type& pos) { mPos -= pos; return *this; }
673 ConstIterator operator+(const difference_type &pos) const { return Iterator(*mParent,mPos+pos); }
674 ConstIterator operator-(const difference_type &pos) const { return Iterator(*mParent,mPos-pos); }
675 difference_type operator-(const ConstIterator& other) const { return mPos - other.pos(); }
676 // comparisons
677 bool operator==(const ConstIterator& other) const { return mPos == other.mPos; }
678 bool operator!=(const ConstIterator& other) const { return mPos != other.mPos; }
679 bool operator>=(const ConstIterator& other) const { return mPos >= other.mPos; }
680 bool operator<=(const ConstIterator& other) const { return mPos <= other.mPos; }
681 bool operator< (const ConstIterator& other) const { return mPos < other.mPos; }
682 bool operator> (const ConstIterator& other) const { return mPos > other.mPos; }
683 // non-std methods
684 bool isValid() const { return mParent != nullptr && mPos < mParent->size(); }
685 size_t pos() const { return mPos; }
686 private:
687 size_t mPos;
688 const PagedArray* mParent;
689 };// Public class PagedArray::ConstIterator
690
692
693 // Non-const std-compliant iterator
694 // Public member-class of PagedArray
695 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
696 class PagedArray<ValueT, Log2PageSize, TableT>::
697 Iterator : public std::iterator<std::random_access_iterator_tag, ValueT>
698 {
699 public:
700 using BaseT = std::iterator<std::random_access_iterator_tag, ValueT>;
701 using difference_type = typename BaseT::difference_type;
702 // constructors and assignment
703 Iterator() : mPos(0), mParent(nullptr) {}
704 Iterator(PagedArray& parent, size_t pos=0) : mPos(pos), mParent(&parent) {}
705 Iterator(const Iterator& other) : mPos(other.mPos), mParent(other.mParent) {}
706 Iterator& operator=(const Iterator& other) {
707 mPos=other.mPos;
708 mParent=other.mParent;
709 return *this;
710 }
711 // prefix
712 Iterator& operator++() { ++mPos; return *this; }
713 Iterator& operator--() { --mPos; return *this; }
714 // postfix
715 Iterator operator++(int) { Iterator tmp(*this); ++mPos; return tmp; }
716 Iterator operator--(int) { Iterator tmp(*this); --mPos; return tmp; }
717 // value access
718 ValueT& operator*() const { return (*mParent)[mPos]; }
719 ValueT* operator->() const { return &(this->operator*()); }
720 ValueT& operator[](const difference_type& pos) const { return (*mParent)[mPos+pos]; }
721 // offset
722 Iterator& operator+=(const difference_type& pos) { mPos += pos; return *this; }
723 Iterator& operator-=(const difference_type& pos) { mPos -= pos; return *this; }
724 Iterator operator+(const difference_type &pos) const { return Iterator(*mParent, mPos+pos); }
725 Iterator operator-(const difference_type &pos) const { return Iterator(*mParent, mPos-pos); }
726 difference_type operator-(const Iterator& other) const { return mPos - other.pos(); }
727 // comparisons
728 bool operator==(const Iterator& other) const { return mPos == other.mPos; }
729 bool operator!=(const Iterator& other) const { return mPos != other.mPos; }
730 bool operator>=(const Iterator& other) const { return mPos >= other.mPos; }
731 bool operator<=(const Iterator& other) const { return mPos <= other.mPos; }
732 bool operator< (const Iterator& other) const { return mPos < other.mPos; }
733 bool operator> (const Iterator& other) const { return mPos > other.mPos; }
734 // non-std methods
735 bool isValid() const { return mParent != nullptr && mPos < mParent->size(); }
736 size_t pos() const { return mPos; }
737 private:
738 size_t mPos;
739 PagedArray* mParent;
740 };// Public class PagedArray::Iterator
741
743
744 // Private member-class of PagedArray implementing a memory page
745 template <typename ValueT, size_t Log2PageSize, template<typename ...> class TableT>
746 class PagedArray<ValueT, Log2PageSize, TableT>::
747 Page
748 {
749 public:
750 static const size_t Size = 1UL << Log2PageSize;
751 static const size_t Mask = Size - 1UL;
752 static size_t memUsage() { return sizeof(ValueT)*Size; }
753 // Raw memory allocation without any initialization
754 Page() : mData(reinterpret_cast<ValueT*>(new char[sizeof(ValueT)*Size])) {}
755 ~Page() { delete [] mData; }
756 Page(const Page&) = delete;//copy construction is not implemented
757 Page& operator=(const Page&) = delete;//copy assignment is not implemented
758 ValueT& operator[](const size_t i) { return mData[i & Mask]; }
759 const ValueT& operator[](const size_t i) const { return mData[i & Mask]; }
760 void fill(const ValueT& v) {
761 ValueT* dst = mData;
762 for (size_t i=Size; i; --i) *dst++ = v;
763 }
764 ValueT* data() { return mData; }
765 // Copy the first n elements of this Page to dst (which is assumed to large
766 // enough to hold the n elements).
767 void copy(ValueType *dst, size_t n) const {
768 const ValueT* src = mData;
769 for (size_t i=n; i; --i) *dst++ = *src++;
770 }
771 protected:
772 ValueT* mData;
773 };// Private class PagedArray::Page
774
776
777 } // namespace util
778 } // namespace OPENVDB_VERSION_NAME
779 } // namespace openvdb
780
781 #endif // OPENVDB_UTIL_PAGED_ARRAY_HAS_BEEN_INCLUDED
782
783 // Copyright (c) 2012-2017 DreamWorks Animation LLC
784 // All rights reserved. This software is distributed under the
785 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v5_0::util::PagedArray::Iterator::operator+=
Iterator & operator+=(const difference_type &pos)
Definition: PagedArray.h:722
openvdb::v5_0::util::PagedArray::ConstIterator
Definition: PagedArray.h:645
openvdb::v5_0::util::PagedArray::freeCount
size_t freeCount() const
Return the number of additional elements that can be added to this array without allocating more memo...
Definition: PagedArray.h:386
openvdb::v5_0::util::PagedArray::Page
Definition: PagedArray.h:746
openvdb::v5_0::util::PagedArray::Page::operator[]
const ValueT & operator[](const size_t i) const
Definition: PagedArray.h:759
openvdb::v5_0::util::PagedArray::Page::fill
void fill(const ValueT &v)
Definition: PagedArray.h:760
openvdb::v5_0::util::PagedArray::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &other)
Definition: PagedArray.h:655
openvdb::v5_0::util::PagedArray::Iterator::pos
size_t pos() const
Definition: PagedArray.h:736
openvdb::v5_0::util::PagedArray::end
Iterator end()
Return a non-const iterator pointing to the past-the-last element.
Definition: PagedArray.h:433
openvdb::v5_0::util::PagedArray::end
ConstIterator end() const
Return a const iterator pointing to the past-the-last element.
Definition: PagedArray.h:448
openvdb::v5_0::util::PagedArray::ConstIterator::operator-
difference_type operator-(const ConstIterator &other) const
Definition: PagedArray.h:675
openvdb::v5_0::util::PagedArray::ConstIterator::difference_type
typename BaseT::difference_type difference_type
Definition: PagedArray.h:650
openvdb::v5_0::util::PagedArray::ConstIterator::operator<=
bool operator<=(const ConstIterator &other) const
Definition: PagedArray.h:680
openvdb::v5_0::util::PagedArray::ValueType
ValueT ValueType
Definition: PagedArray.h:201
openvdb::v5_0::util::PagedArray::Iterator::operator--
Iterator & operator--()
Definition: PagedArray.h:713
openvdb::v5_0::math::operator<
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:206
openvdb::v5_0::util::PagedArray::ConstIterator::operator-
ConstIterator operator-(const difference_type &pos) const
Definition: PagedArray.h:674
openvdb::v5_0::util::PagedArray::isEmpty
bool isEmpty() const
Return true if the container contains no elements.
Definition: PagedArray.h:404
openvdb::v5_0::util::PagedArray::ValueBuffer::push_back
void push_back(const ValueT &v)
Add a value to the buffer and increment the size.
Definition: PagedArray.h:616
openvdb::v5_0::util::PagedArray::begin
ConstIterator begin() const
Return a const iterator pointing to the first element.
Definition: PagedArray.h:438
openvdb::v5_0::util::PagedArray::invSort
void invSort()
Parallel sort of all the elements in descending order.
Definition: PagedArray.h:455
openvdb::v5_0::util::PagedArray::Iterator::operator!=
bool operator!=(const Iterator &other) const
Definition: PagedArray.h:729
openvdb::v5_0::util::PagedArray::fill
void fill(const ValueType &v)
Set all elements in the page table to the specified value.
Definition: PagedArray.h:298
openvdb::v5_0::util::PagedArray
Concurrent, page-based, dynamically-sized linear data structure with O(1) random access and STL-compl...
Definition: PagedArray.h:188
openvdb::v5_0::util::PagedArray::ValueBuffer::size
size_t size() const
Return the current number of elements cached in this buffer.
Definition: PagedArray.h:633
openvdb::v5_0::util::PagedArray::Page::operator[]
ValueT & operator[](const size_t i)
Definition: PagedArray.h:758
openvdb::v5_0::util::PagedArray::pageSize
static size_t pageSize()
Return the number of elements per memory page.
Definition: PagedArray.h:392
openvdb::v5_0::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
openvdb::v5_0::util::PagedArray::size
size_t size() const
Return the number of elements in this array.
Definition: PagedArray.h:378
openvdb::v5_0::util::PagedArray::ValueBuffer::parent
PagedArrayType & parent() const
Return a reference to the parent PagedArray.
Definition: PagedArray.h:631
openvdb::v5_0::util::PagedArray::Iterator::Iterator
Iterator(PagedArray &parent, size_t pos=0)
Definition: PagedArray.h:704
openvdb::v5_0::util::PagedArray::ConstIterator::operator->
const ValueT * operator->() const
Definition: PagedArray.h:668
openvdb::v5_0::util::PagedArray::Iterator::Iterator
Iterator(const Iterator &other)
Definition: PagedArray.h:705
openvdb::v5_0::util::PagedArray::~PagedArray
~PagedArray()
Destructor removed all allocated pages.
Definition: PagedArray.h:207
openvdb::v5_0::math::operator>
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:218
openvdb::v5_0::util::PagedArray::print
void print(std::ostream &os=std::cout) const
Print information for debugging.
Definition: PagedArray.h:476
openvdb::v5_0::util::PagedArray::ConstIterator::operator++
ConstIterator & operator++()
Definition: PagedArray.h:661
openvdb::v5_0::util::PagedArray::Iterator::operator+
Iterator operator+(const difference_type &pos) const
Definition: PagedArray.h:724
openvdb::v5_0::util::PagedArray::push_back_unsafe
size_t push_back_unsafe(const ValueType &value)
Slightly faster than the thread-safe push_back above.
Definition: PagedArray.h:251
openvdb::v5_0::util::PagedArray::begin
Iterator begin()
Return a non-const iterator pointing to the first element.
Definition: PagedArray.h:426
openvdb::v5_0::util::PagedArray::operator[]
ValueType & operator[](size_t i)
Return a reference to the value at the specified offset.
Definition: PagedArray.h:274
openvdb::v5_0::util::PagedArray::Iterator::isValid
bool isValid() const
Definition: PagedArray.h:735
openvdb::v5_0::util::PagedArray::Iterator::operator-=
Iterator & operator-=(const difference_type &pos)
Definition: PagedArray.h:723
openvdb::v5_0::util::PagedArray::Iterator::operator[]
ValueT & operator[](const difference_type &pos) const
Definition: PagedArray.h:720
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
openvdb::v5_0::util::PagedArray::Page::~Page
~Page()
Definition: PagedArray.h:755
openvdb::v5_0::util::PagedArray::Iterator::Iterator
Iterator()
Definition: PagedArray.h:703
openvdb::v5_0::util::PagedArray::Iterator::operator==
bool operator==(const Iterator &other) const
Definition: PagedArray.h:728
openvdb::v5_0::util::PagedArray::pageCount
size_t pageCount() const
Return the number of allocated memory pages.
Definition: PagedArray.h:389
openvdb::v5_0::util::PagedArray::ConstIterator::ConstIterator
ConstIterator()
Definition: PagedArray.h:652
openvdb::v5_0::util::PagedArray::Iterator::operator++
Iterator operator++(int)
Definition: PagedArray.h:715
openvdb::v5_0::util::PagedArray::ConstIterator::operator*
const ValueT & operator*() const
Definition: PagedArray.h:667
openvdb::v5_0::util::PagedArray::resize
void resize(size_t size, const ValueType &v)
Resize this array to the specified size and initialize all values to v.
Definition: PagedArray.h:371
openvdb::v5_0::util::PagedArray::ValueBuffer::~ValueBuffer
~ValueBuffer()
Destructor that transfers an buffered values to the parent PagedArray.
Definition: PagedArray.h:608
openvdb::v5_0::util::PagedArray::Iterator::operator->
ValueT * operator->() const
Definition: PagedArray.h:719
openvdb::v5_0::util::PagedArray::Iterator::operator*
ValueT & operator*() const
Definition: PagedArray.h:718
openvdb::v5_0::util::PagedArray::ValueBuffer::flush
void flush()
Manually transfers the values in this buffer to the parent PagedArray.
Definition: PagedArray.h:625
openvdb::v5_0::util::PagedArray::resize
void resize(size_t size)
Resize this array to the specified size.
Definition: PagedArray.h:346
openvdb::v5_0::util::PagedArray::ConstIterator::operator+
ConstIterator operator+(const difference_type &pos) const
Definition: PagedArray.h:673
openvdb::v5_0::util::PagedArray::operator[]
const ValueType & operator[](size_t i) const
Return a const-reference to the value at the specified offset.
Definition: PagedArray.h:287
openvdb::v5_0::util::PagedArray::Iterator::operator<=
bool operator<=(const Iterator &other) const
Definition: PagedArray.h:731
openvdb::v5_0::util::PagedArray::copy
void copy(ValueType *p) const
Definition: PagedArray.h:330
openvdb::v5_0::util::PagedArray::ConstIterator::operator[]
const ValueT & operator[](const difference_type &pos) const
Definition: PagedArray.h:669
openvdb
Definition: Exceptions.h:39
openvdb::v5_0::util::PagedArray::Iterator::BaseT
std::iterator< std::random_access_iterator_tag, ValueT > BaseT
Definition: PagedArray.h:700
openvdb::v5_0::util::PagedArray::ValueBuffer
Definition: PagedArray.h:597
openvdb::v5_0::util::PagedArray::ConstIterator::operator!=
bool operator!=(const ConstIterator &other) const
Definition: PagedArray.h:678
openvdb::v5_0::util::PagedArray::ConstIterator::operator++
ConstIterator operator++(int)
Definition: PagedArray.h:664
openvdb::v5_0::util::PagedArray::Iterator
Definition: PagedArray.h:696
openvdb::v5_0::util::PagedArray::Iterator::difference_type
typename BaseT::difference_type difference_type
Definition: PagedArray.h:701
openvdb::v5_0::util::PagedArray::ConstIterator::operator+=
ConstIterator & operator+=(const difference_type &pos)
Definition: PagedArray.h:671
openvdb::v5_0::util::PagedArray::log2PageSize
static size_t log2PageSize()
Return log2 of the number of elements per memory page.
Definition: PagedArray.h:395
openvdb::v5_0::util::PagedArray::Iterator::operator-
difference_type operator-(const Iterator &other) const
Definition: PagedArray.h:726
openvdb::v5_0::util::PagedArray::capacity
size_t capacity() const
Return the maximum number of elements that this array can contain without allocating more memory page...
Definition: PagedArray.h:382
openvdb::v5_0::util::PagedArray::ConstIterator::operator--
ConstIterator operator--(int)
Definition: PagedArray.h:665
openvdb::v5_0::util::PagedArray::isPartiallyFull
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:412
openvdb::v5_0::util::PagedArray::memUsage
size_t memUsage() const
Return the memory footprint of this array in bytes.
Definition: PagedArray.h:398
openvdb::v5_0::util::PagedArray::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &other)
Definition: PagedArray.h:654
openvdb::v5_0::util::PagedArray::ConstIterator::operator==
bool operator==(const ConstIterator &other) const
Definition: PagedArray.h:677
openvdb::v5_0::util::PagedArray::ConstIterator::BaseT
std::iterator< std::random_access_iterator_tag, ValueT > BaseT
Definition: PagedArray.h:649
openvdb::v5_0::util::PagedArray::Page::Page
Page()
Definition: PagedArray.h:754
openvdb::v5_0::util::PagedArray::Iterator::operator>=
bool operator>=(const Iterator &other) const
Definition: PagedArray.h:730
openvdb::v5_0::util::PagedArray::ConstIterator::pos
size_t pos() const
Definition: PagedArray.h:685
openvdb::v5_0::util::PagedArray::ConstIterator::operator>=
bool operator>=(const ConstIterator &other) const
Definition: PagedArray.h:679
openvdb::v5_0::util::PagedArray::Page::copy
void copy(ValueType *dst, size_t n) const
Definition: PagedArray.h:767
openvdb::v5_0::util::PagedArray::Iterator::operator++
Iterator & operator++()
Definition: PagedArray.h:712
openvdb::v5_0::util::PagedArray::clear
void clear()
Removes all elements from the array and delete all pages.
Definition: PagedArray.h:417
openvdb::v5_0::math::operator*
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
openvdb::v5_0::util::PagedArray::push_back
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:236
openvdb::v5_0::util::PagedArray::ConstIterator::operator-=
ConstIterator & operator-=(const difference_type &pos)
Definition: PagedArray.h:672
openvdb::v5_0::util::PagedArray::Iterator::operator--
Iterator operator--(int)
Definition: PagedArray.h:716
openvdb::v5_0::util::PagedArray::Iterator::operator=
Iterator & operator=(const Iterator &other)
Definition: PagedArray.h:706
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
openvdb::v5_0::util::PagedArray::sort
void sort(Functor func)
Parallel sort of all the elements based on a custom functor with the api:
Definition: PagedArray.h:463
openvdb::v5_0::util::PagedArray::ConstIterator::isValid
bool isValid() const
Definition: PagedArray.h:684
openvdb::v5_0::util::PagedArray::ValueBuffer::ValueBuffer
ValueBuffer(const ValueBuffer &other)
Definition: PagedArray.h:606
openvdb::v5_0::util::PagedArray::ConstIterator::operator--
ConstIterator & operator--()
Definition: PagedArray.h:662
openvdb::v5_0::util::PagedArray::sort
void sort()
Parallel sort of all the elements in ascending order.
Definition: PagedArray.h:452
openvdb::v5_0::util::PagedArray::Page::data
ValueT * data()
Definition: PagedArray.h:764
openvdb::v5_0::util::PagedArray::Page::mData
ValueT * mData
Definition: PagedArray.h:772
openvdb::v5_0::util::PagedArray::copy
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:313
openvdb::v5_0::util::PagedArray::Page::memUsage
static size_t memUsage()
Definition: PagedArray.h:752
openvdb::v5_0::util::PagedArray::ConstIterator::ConstIterator
ConstIterator(const PagedArray &parent, size_t pos=0)
Definition: PagedArray.h:653
openvdb::v5_0::util::PagedArray::ValueBuffer::ValueBuffer
ValueBuffer(PagedArray &parent)
Constructor from a PageArray.
Definition: PagedArray.h:603
openvdb::v5_0::util::PagedArray::Iterator::operator-
Iterator operator-(const difference_type &pos) const
Definition: PagedArray.h:725