OpenVDB 5.1.0

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