OpenVDB 3.2.0

PagedArray.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2016 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 //
40
41 #ifndef OPENVDB_UTIL_PAGED_ARRAY_HAS_BEEN_INCLUDED
42 #define OPENVDB_UTIL_PAGED_ARRAY_HAS_BEEN_INCLUDED
43
44
45 #include <deque>
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
190 template <typename ValueT, size_t Log2PageSize = 10UL>
191 class PagedArray {
192
193 private:
194 class Page;
195 typedef std::deque<Page*> PageTableT;
196
197 public:
198 typedef ValueT ValueType;
199
201 PagedArray() : mPageTable(), mSize(), mCapacity(0), mGrowthMutex() { mSize = 0; }
202
204 ~PagedArray() { this->clear(); }
205
214 class ValueBuffer;
215
217 class ConstIterator;
218
220 class Iterator;
221
226 size_t push_back(const ValueType& value)
227 {
228 const size_t index = mSize.fetch_and_increment();
229 if (index >= mCapacity) this->grow(index);
230 (*mPageTable[index >> Log2PageSize])[index] = value;
231 return index;
232 }
233
239 size_t push_back_unsafe(const ValueType& value)
240 {
241 const size_t index = mSize.fetch_and_increment();
242 if (index >= mCapacity) {
243 mPageTable.push_back( new Page() );
244 mCapacity += Page::Size;
245 }
246 (*mPageTable[index >> Log2PageSize])[index] = value;
247 return index;
248 }
249
263 ValueType pop_back()
264 {
265 assert(mSize>0);
266 --mSize;
267 return (*mPageTable[mSize >> Log2PageSize])[mSize];
268 }
269
273 void shrink_to_fit();
274
280 ValueType& operator[](size_t i)
281 {
282 assert(i<mCapacity);
283 return (*mPageTable[i>>Log2PageSize])[i];
284 }
285
291 const ValueType& operator[](size_t i) const
292 {
293 assert(i<mCapacity);
294 return (*mPageTable[i>>Log2PageSize])[i];
295 }
296
298 void fill(const ValueType& v)
299 {
300 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
301 Fill tmp(this, v);
302 }
303
309 void resize(size_t size)
310 {
311 mSize = size;
312 if (size > mCapacity) {
313 this->grow(size-1);
314 } else {
315 this->shrink_to_fit();
316 }
317 }
318
323 void resize(size_t size, const ValueType& v)
324 {
325 this->resize(size);
326 this->fill(v);
327 }
328
330 size_t size() const { return mSize; }
331
334 size_t capacity() const { return mCapacity; }
335
338 size_t freeCount() const { return mCapacity - mSize; }
339
341 size_t pageCount() const { return mPageTable.size(); }
342
344 static size_t pageSize() { return Page::Size; }
345
347 static size_t log2PageSize() { return Log2PageSize; }
348
350 size_t memUsage() const
351 {
352 return sizeof(*this) + mPageTable.size() * Page::memUsage();
353 }
354
356 bool isEmpty() const { return mSize == 0; }
357
364 bool isPartiallyFull() const { return (mSize & Page::Mask) > 0; }
365
369 void clear()
370 {
371 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
372 for (size_t i=0, n=mPageTable.size(); i<n; ++i) delete mPageTable[i];
373 PageTableT().swap(mPageTable);
374 mSize = 0;
375 mCapacity = 0;
376 }
377
379 Iterator begin() { return Iterator(*this, 0); }
380
386 Iterator end() { return Iterator(*this, mSize); }
387
389 ConstIterator cbegin() const { return ConstIterator(*this, 0); }
390
396 ConstIterator cend() const { return ConstIterator(*this, mSize); }
397
399 void sort() { tbb::parallel_sort(this->begin(), this->end(), std::less<ValueT>() ); }
400
402 void invSort() { tbb::parallel_sort(this->begin(), this->end(), std::greater<ValueT>()); }
403
408 template <typename Functor>
409 void sort() { tbb::parallel_sort(this->begin(), this->end(), Functor() ); }
410
416 void merge(PagedArray& other);
417
419 void print(std::ostream& os = std::cout) const
420 {
421 os << "PagedArray:\n"
422 << "\tSize: " << this->size() << " elements\n"
423 << "\tPage table: " << this->pageCount() << " pages\n"
424 << "\tPage size: " << this->pageSize() << " elements\n"
425 << "\tCapacity: " << this->capacity() << " elements\n"
426 << "\tFootrpint: " << this->memUsage() << " bytes\n";
427 }
428
429 private:
430 // Disallow copy construction and assignment
431 PagedArray(const PagedArray&);//not implemented
432 void operator=(const PagedArray&);//not implemented
433
434 friend class ValueBuffer;
435
436 // Private class for concurrent fill
437 struct Fill;
438
439 void grow(size_t index)
440 {
441 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
442 while(index >= mCapacity) {
443 mPageTable.push_back( new Page() );
444 mCapacity += Page::Size;
445 }
446 }
447
448 void add_full(Page*& page, size_t size);
449
450 void add_partially_full(Page*& page, size_t size);
451
452 void add(Page*& page, size_t size) {
453 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
454 if (size == Page::Size) {//page is full
455 this->add_full(page, size);
456 } else if (size>0) {//page is only partially full
457 this->add_partially_full(page, size);
458 }
459 }
460 PageTableT mPageTable;//holds points to allocated pages
461 tbb::atomic<size_t> mSize;// current number of elements in array
462 size_t mCapacity;//capacity of array given the current page count
463 tbb::spin_mutex mGrowthMutex;//Mutex-lock required to grow pages
464 }; // Public class PagedArray
465
467
468 template <typename ValueT, size_t Log2PageSize>
469 void PagedArray<ValueT, Log2PageSize>::shrink_to_fit()
470 {
471 if (mPageTable.size() > (mSize >> Log2PageSize) + 1) {
472 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
473 const size_t pageCount = (mSize >> Log2PageSize) + 1;
474 if (mPageTable.size() > pageCount) {
475 delete mPageTable.back();
476 mPageTable.pop_back();
477 mCapacity -= Page::Size;
478 }
479 }
480 }
481
482 template <typename ValueT, size_t Log2PageSize>
483 void PagedArray<ValueT, Log2PageSize>::merge(PagedArray& other)
484 {
485 if (!other.isEmpty()) {
486 tbb::spin_mutex::scoped_lock lock(mGrowthMutex);
487 // extract last partially full page if it exists
488 Page* page = NULL;
489 const size_t size = mSize & Page::Mask; //number of elements in the last page
490 if ( size > 0 ) {
491 page = mPageTable.back();
492 mPageTable.pop_back();
493 mSize -= size;
494 }
495 // transfer all pages from the other page table
496 mPageTable.insert(mPageTable.end(), other.mPageTable.begin(), other.mPageTable.end());
497 mSize += other.mSize;
498 mCapacity = Page::Size*mPageTable.size();
499 other.mSize = 0;
500 other.mCapacity = 0;
501 PageTableT().swap(other.mPageTable);
502 // add back last partially full page
503 if (page) this->add_partially_full(page, size);
504 }
505 }
506
507 template <typename ValueT, size_t Log2PageSize>
508 void PagedArray<ValueT, Log2PageSize>::add_full(Page*& page, size_t size)
509 {
510 assert(size == Page::Size);//page must be full
511 if (mSize & Page::Mask) {//page-table is partially full
512 Page*& tmp = mPageTable.back();
513 std::swap(tmp, page);//swap last table entry with page
514 }
515 mPageTable.push_back( page );
516 mCapacity += Page::Size;
517 mSize += size;
518 page = NULL;
519 }
520
521 template <typename ValueT, size_t Log2PageSize>
522 void PagedArray<ValueT, Log2PageSize>::add_partially_full(Page*& page, size_t size)
523 {
524 assert(size > 0 && size < Page::Size);//page must be partially full
525 if (size_t m = mSize & Page::Mask) {//page table is also partially full
526 ValueT *s = page->data(), *t = mPageTable.back()->data() + m;
527 for (size_t i=std::min(mSize+size, mCapacity)-mSize; i; --i) *t++ = *s++;
528 if (mSize+size > mCapacity) {//grow page table
529 mPageTable.push_back( new Page() );
530 t = mPageTable.back()->data();
531 for (size_t i=mSize+size-mCapacity; i; --i) *t++ = *s++;
532 mCapacity += Page::Size;
533 }
534 } else {//page table is full so simply append page
535 mPageTable.push_back( page );
536 mCapacity += Page::Size;
537 page = NULL;
538 }
539 mSize += size;
540 }
541
543
544 // Public member-class of PagedArray
545 template <typename ValueT, size_t Log2PageSize>
546 class PagedArray<ValueT, Log2PageSize>::
547 ValueBuffer
548 {
549 public:
550 typedef PagedArray<ValueT, Log2PageSize> PagedArrayType;
552 ValueBuffer(PagedArray& parent) : mParent(&parent), mPage(new Page()), mSize(0) {}
555 ValueBuffer(const ValueBuffer& other) : mParent(other.mParent), mPage(new Page()), mSize(0) {}
557 ~ValueBuffer() { this->flush(); delete mPage; }
562 void push_back(const ValueT& v) {
563 (*mPage)[mSize++] = v;
564 if (mSize == Page::Size) this->flush();
565 }
571 void flush() {
572 mParent->add(mPage, mSize);
573 if (mPage == NULL) mPage = new Page();
574 mSize = 0;
575 }
577 PagedArrayType& parent() const { return *mParent; }
579 size_t size() const { return mSize; }
580 private:
581 ValueBuffer& operator=(const ValueBuffer& other);//not implemented
582 PagedArray* mParent;
583 Page* mPage;
584 size_t mSize;
585 };// Public class PagedArray::ValueBuffer
586
588
589 // Const std-compliant iterator
590 // Public member-class of PagedArray
591 template <typename ValueT, size_t Log2PageSize>
592 class PagedArray<ValueT, Log2PageSize>::
593 ConstIterator : public std::iterator<std::random_access_iterator_tag, ValueT>
594 {
595 public:
596 typedef std::iterator<std::random_access_iterator_tag, ValueT> BaseT;
597 typedef typename BaseT::difference_type difference_type;
598 // constructors and assignment
599 ConstIterator() : mPos(0), mParent(NULL) {}
600 ConstIterator(const PagedArray& parent, size_t pos=0) : mPos(pos), mParent(&parent) {}
601 ConstIterator(const ConstIterator& other) : mPos(other.mPos), mParent(other.mParent) {}
602 ConstIterator& operator=(const ConstIterator& other) {
603 mPos=other.mPos;
604 mParent=other.mParent;
605 return *this;
606 }
607 // prefix
608 ConstIterator& operator++() { ++mPos; return *this; }
609 ConstIterator& operator--() { --mPos; return *this; }
610 // postfix
611 ConstIterator operator++(int) { ConstIterator tmp(*this); ++mPos; return tmp; }
612 ConstIterator operator--(int) { ConstIterator tmp(*this); --mPos; return tmp; }
613 // value access
614 const ValueT& operator*() const { return (*mParent)[mPos]; }
615 const ValueT* operator->() const { return &(this->operator*()); }
616 const ValueT& operator[](const difference_type& pos) const { return (*mParent)[mPos+pos]; }
617 // offset
618 ConstIterator& operator+=(const difference_type& pos) { mPos += pos; return *this; }
619 ConstIterator& operator-=(const difference_type& pos) { mPos -= pos; return *this; }
620 ConstIterator operator+(const difference_type &pos) const { return Iterator(*mParent,mPos+pos); }
621 ConstIterator operator-(const difference_type &pos) const { return Iterator(*mParent,mPos-pos); }
622 difference_type operator-(const ConstIterator& other) const { return mPos - other.pos(); }
623 // comparisons
624 bool operator==(const ConstIterator& other) const { return mPos == other.mPos; }
625 bool operator!=(const ConstIterator& other) const { return mPos != other.mPos; }
626 bool operator>=(const ConstIterator& other) const { return mPos >= other.mPos; }
627 bool operator<=(const ConstIterator& other) const { return mPos <= other.mPos; }
628 bool operator< (const ConstIterator& other) const { return mPos < other.mPos; }
629 bool operator> (const ConstIterator& other) const { return mPos > other.mPos; }
630 // non-std methods
631 bool isValid() const { return mParent != NULL && mPos < mParent->size(); }
632 size_t pos() const { return mPos; }
633 private:
634 size_t mPos;
635 const PagedArray* mParent;
636 };// Public class PagedArray::ConstIterator
637
639
640 // Public member-class of PagedArray
641 template <typename ValueT, size_t Log2PageSize>
642 class PagedArray<ValueT, Log2PageSize>::
643 Iterator : public std::iterator<std::random_access_iterator_tag, ValueT>
644 {
645 public:
646 typedef std::iterator<std::random_access_iterator_tag, ValueT> BaseT;
647 typedef typename BaseT::difference_type difference_type;
648 // constructors and assignment
649 Iterator() : mPos(0), mParent(NULL) {}
650 Iterator(PagedArray& parent, size_t pos=0) : mPos(pos), mParent(&parent) {}
651 Iterator(const Iterator& other) : mPos(other.mPos), mParent(other.mParent) {}
652 Iterator& operator=(const Iterator& other) {
653 mPos=other.mPos;
654 mParent=other.mParent;
655 return *this;
656 }
657 // prefix
658 Iterator& operator++() { ++mPos; return *this; }
659 Iterator& operator--() { --mPos; return *this; }
660 // postfix
661 Iterator operator++(int) { Iterator tmp(*this); ++mPos; return tmp; }
662 Iterator operator--(int) { Iterator tmp(*this); --mPos; return tmp; }
663 // value access
664 ValueT& operator*() const { return (*mParent)[mPos]; }
665 ValueT* operator->() const { return &(this->operator*()); }
666 ValueT& operator[](const difference_type& pos) const { return (*mParent)[mPos+pos]; }
667 // offset
668 Iterator& operator+=(const difference_type& pos) { mPos += pos; return *this; }
669 Iterator& operator-=(const difference_type& pos) { mPos -= pos; return *this; }
670 Iterator operator+(const difference_type &pos) const { return Iterator(*mParent, mPos+pos); }
671 Iterator operator-(const difference_type &pos) const { return Iterator(*mParent, mPos-pos); }
672 difference_type operator-(const Iterator& other) const { return mPos - other.pos(); }
673 // comparisons
674 bool operator==(const Iterator& other) const { return mPos == other.mPos; }
675 bool operator!=(const Iterator& other) const { return mPos != other.mPos; }
676 bool operator>=(const Iterator& other) const { return mPos >= other.mPos; }
677 bool operator<=(const Iterator& other) const { return mPos <= other.mPos; }
678 bool operator< (const Iterator& other) const { return mPos < other.mPos; }
679 bool operator> (const Iterator& other) const { return mPos > other.mPos; }
680 // non-std methods
681 bool isValid() const { return mParent != NULL && mPos < mParent->size(); }
682 size_t pos() const { return mPos; }
683 private:
684 size_t mPos;
685 PagedArray* mParent;
686 };// Public class PagedArray::Iterator
687
689
690 // Private member-class of PagedArray implementing a memory page
691 template <typename ValueT, size_t Log2PageSize>
692 class PagedArray<ValueT, Log2PageSize>::
693 Page
694 {
695 public:
696 static const size_t Size = 1UL << Log2PageSize;
697 static const size_t Mask = Size - 1UL;
698 static size_t memUsage() { return sizeof(ValueT)*Size; }
699 Page() : mData(new ValueT[Size]) {}
700 ~Page() { delete [] mData; }
701 ValueT& operator[](const size_t i) { return mData[i & Mask]; }
702 const ValueT& operator[](const size_t i) const { return mData[i & Mask]; }
703 void fill(const ValueT& v) { ValueT* p = mData; for (size_t i=Size; i; --i) *p++ = v; }
704 ValueT* data() { return mData; }
705 protected:
706 Page(const Page& other);//copy construction is not implemented
707 Page& operator=(const Page& rhs);//copy assignment is not implemented
708 ValueT* mData;
709 };// Private class PagedArray::Page
710
712
713 // Private member-class of PagedArray implementing concurrent fill of a Page
714 template <typename ValueT, size_t Log2PageSize>
715 struct PagedArray<ValueT, Log2PageSize>::
716 Fill {
717 Fill(PagedArray* _d, const ValueT& _v) : d(_d), v(_v) {
718 tbb::parallel_for(tbb::blocked_range<size_t>(0, d->pageCount()), *this);
719 }
720 void operator()(const tbb::blocked_range<size_t>& r) const {
721 for (size_t i=r.begin(); i!=r.end(); ++i) d->mPageTable[i]->fill(v);
722 }
723 PagedArray* d;
724 const ValueT& v;
725 };// Private class PagedArray::Fill
726
727 } // namespace util
728 } // namespace OPENVDB_VERSION_NAME
729 } // namespace openvdb
730
731 #endif // OPENVDB_UTIL_PAGED_ARRAY_HAS_BEEN_INCLUDED
732
733 // Copyright (c) 2012-2016 DreamWorks Animation LLC
734 // All rights reserved. This software is distributed under the
735 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v3_2_0::util::PagedArray::Iterator::operator++
Iterator operator++(int)
Definition: PagedArray.h:661
openvdb::v3_2_0::util::PagedArray::clear
void clear()
Removes all elements from the array and delete all pages.
Definition: PagedArray.h:369
openvdb::v3_2_0::util::PagedArray::Iterator
Definition: PagedArray.h:642
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator--
ConstIterator operator--(int)
Definition: PagedArray.h:612
openvdb::v3_2_0::util::PagedArray::Page::operator[]
const ValueT & operator[](const size_t i) const
Definition: PagedArray.h:702
openvdb::v3_2_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:291
openvdb::v3_2_0::util::PagedArray::cbegin
ConstIterator cbegin() const
Return a const iterator pointing to the first element.
Definition: PagedArray.h:389
openvdb::v3_2_0::util::PagedArray::Iterator::operator+=
Iterator & operator+=(const difference_type &pos)
Definition: PagedArray.h:668
openvdb::v3_2_0::util::PagedArray::resize
void resize(size_t size)
Resize this array to the specified size.
Definition: PagedArray.h:309
openvdb::v3_2_0::util::PagedArray::Iterator::Iterator
Iterator(const Iterator &other)
Definition: PagedArray.h:651
openvdb::v3_2_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:364
openvdb::v3_2_0::util::PagedArray::log2PageSize
static size_t log2PageSize()
Return log2 of the number of elements per memory page.
Definition: PagedArray.h:347
openvdb::v3_2_0::util::PagedArray::Iterator::operator-
difference_type operator-(const Iterator &other) const
Definition: PagedArray.h:672
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator++
ConstIterator & operator++()
Definition: PagedArray.h:608
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator*
const ValueT & operator*() const
Definition: PagedArray.h:614
openvdb::v3_2_0::util::PagedArray::pageCount
size_t pageCount() const
Return the number of allocated memory pages.
Definition: PagedArray.h:341
openvdb::v3_2_0::util::PagedArray::resize
void resize(size_t size, const ValueType &v)
Resize this array to the specified size and set all elements to the specified value.
Definition: PagedArray.h:323
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator++
ConstIterator operator++(int)
Definition: PagedArray.h:611
openvdb::v3_2_0::util::PagedArray::Fill::Fill
Fill(PagedArray *_d, const ValueT &_v)
Definition: PagedArray.h:717
openvdb::v3_2_0::util::PagedArray::ValueType
ValueT ValueType
Definition: PagedArray.h:198
openvdb::v3_2_0::util::PagedArray::Fill::operator()
void operator()(const tbb::blocked_range< size_t > &r) const
Definition: PagedArray.h:720
openvdb::v3_2_0::util::PagedArray::ValueBuffer::ValueBuffer
ValueBuffer(const ValueBuffer &other)
Definition: PagedArray.h:555
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator[]
const ValueT & operator[](const difference_type &pos) const
Definition: PagedArray.h:616
openvdb::v3_2_0::util::PagedArray::ValueBuffer::size
size_t size() const
Return the current number of elements cached in this buffer.
Definition: PagedArray.h:579
openvdb::v3_2_0::util::PagedArray::operator[]
ValueType & operator[](size_t i)
Return a reference to the value at the specified offset.
Definition: PagedArray.h:280
openvdb::v3_2_0::util::PagedArray::ConstIterator::isValid
bool isValid() const
Definition: PagedArray.h:631
openvdb::v3_2_0::util::PagedArray::Iterator::difference_type
BaseT::difference_type difference_type
Definition: PagedArray.h:647
openvdb::v3_2_0::math::operator*
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:658
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator--
ConstIterator & operator--()
Definition: PagedArray.h:609
openvdb::v3_2_0::util::PagedArray::Iterator::operator++
Iterator & operator++()
Definition: PagedArray.h:658
openvdb::v3_2_0::util::PagedArray::Iterator::operator-
Iterator operator-(const difference_type &pos) const
Definition: PagedArray.h:671
openvdb::v3_2_0::util::PagedArray::Iterator::operator--
Iterator & operator--()
Definition: PagedArray.h:659
openvdb::v3_2_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:334
openvdb::v3_2_0::util::PagedArray::pop_back
ValueType pop_back()
Returns the last element, decrements the size by one.
Definition: PagedArray.h:263
openvdb::v3_2_0::util::PagedArray::Iterator::isValid
bool isValid() const
Definition: PagedArray.h:681
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator-
difference_type operator-(const ConstIterator &other) const
Definition: PagedArray.h:622
openvdb::v3_2_0::util::PagedArray::Iterator::operator+
Iterator operator+(const difference_type &pos) const
Definition: PagedArray.h:670
openvdb::v3_2_0::util::PagedArray::begin
Iterator begin()
Return a non-const iterator pointing to the first element.
Definition: PagedArray.h:379
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator-
ConstIterator operator-(const difference_type &pos) const
Definition: PagedArray.h:621
openvdb::v3_2_0::util::PagedArray::ConstIterator::difference_type
BaseT::difference_type difference_type
Definition: PagedArray.h:597
openvdb::v3_2_0::util::PagedArray::Iterator::Iterator
Iterator(PagedArray &parent, size_t pos=0)
Definition: PagedArray.h:650
openvdb::v3_2_0::util::PagedArray::end
Iterator end()
Return a non-const iterator pointing to the past-the-last element.
Definition: PagedArray.h:386
openvdb::v3_2_0::util::PagedArray::Iterator::operator*
ValueT & operator*() const
Definition: PagedArray.h:664
openvdb::v3_2_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:562
openvdb::v3_2_0::math::operator<
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:158
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_2_0::util::PagedArray::size
size_t size() const
Return the number of elements in this array.
Definition: PagedArray.h:330
openvdb::v3_2_0::util::PagedArray::Fill::v
const ValueT & v
Definition: PagedArray.h:724
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator<=
bool operator<=(const ConstIterator &other) const
Definition: PagedArray.h:627
openvdb::v3_2_0::util::PagedArray::Fill::d
PagedArray * d
Definition: PagedArray.h:723
openvdb::v3_2_0::util::PagedArray::Page::data
ValueT * data()
Definition: PagedArray.h:704
openvdb::v3_2_0::util::PagedArray::ConstIterator::ConstIterator
ConstIterator()
Definition: PagedArray.h:599
openvdb::v3_2_0::util::PagedArray::invSort
void invSort()
Parallel sort of all the elements in descending order.
Definition: PagedArray.h:402
openvdb::v3_2_0::util::PagedArray::memUsage
size_t memUsage() const
Return the memory footprint of this array in bytes.
Definition: PagedArray.h:350
openvdb
Definition: Exceptions.h:39
openvdb::v3_2_0::util::PagedArray::Iterator::operator<=
bool operator<=(const Iterator &other) const
Definition: PagedArray.h:677
openvdb::v3_2_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...
Definition: PagedArray.h:226
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator->
const ValueT * operator->() const
Definition: PagedArray.h:615
openvdb::v3_2_0::util::PagedArray::Fill
Definition: PagedArray.h:715
openvdb::v3_2_0::util::PagedArray::ValueBuffer::parent
PagedArrayType & parent() const
Return a reference to the parent PagedArray.
Definition: PagedArray.h:577
openvdb::v3_2_0::util::PagedArray::Iterator::operator->
ValueT * operator->() const
Definition: PagedArray.h:665
openvdb::v3_2_0::util::PagedArray::ConstIterator::ConstIterator
ConstIterator(const PagedArray &parent, size_t pos=0)
Definition: PagedArray.h:600
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator-=
ConstIterator & operator-=(const difference_type &pos)
Definition: PagedArray.h:619
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator+
ConstIterator operator+(const difference_type &pos) const
Definition: PagedArray.h:620
openvdb::v3_2_0::util::PagedArray::Iterator::Iterator
Iterator()
Definition: PagedArray.h:649
openvdb::v3_2_0::util::PagedArray::Iterator::operator[]
ValueT & operator[](const difference_type &pos) const
Definition: PagedArray.h:666
openvdb::v3_2_0::util::PagedArray::ConstIterator::BaseT
std::iterator< std::random_access_iterator_tag, ValueT > BaseT
Definition: PagedArray.h:596
openvdb::v3_2_0::util::PagedArray::Page::~Page
~Page()
Definition: PagedArray.h:700
openvdb::v3_2_0::util::PagedArray::fill
void fill(const ValueType &v)
Set all elements to the specified value.
Definition: PagedArray.h:298
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &other)
Definition: PagedArray.h:602
openvdb::v3_2_0::util::PagedArray::Page::operator[]
ValueT & operator[](const size_t i)
Definition: PagedArray.h:701
openvdb::v3_2_0::util::PagedArray::sort
void sort()
Parallel sort of all the elements based on a custom functor with the api:
Definition: PagedArray.h:409
openvdb::v3_2_0::util::PagedArray::ValueBuffer::PagedArrayType
PagedArray< ValueT, Log2PageSize > PagedArrayType
Definition: PagedArray.h:550
openvdb::v3_2_0::util::PagedArray::Iterator::operator>=
bool operator>=(const Iterator &other) const
Definition: PagedArray.h:676
openvdb::v3_2_0::util::PagedArray::Iterator::operator!=
bool operator!=(const Iterator &other) const
Definition: PagedArray.h:675
openvdb::v3_2_0::util::PagedArray::print
void print(std::ostream &os=std::cout) const
Print information for debugging.
Definition: PagedArray.h:419
openvdb::v3_2_0::util::PagedArray::Iterator::operator=
Iterator & operator=(const Iterator &other)
Definition: PagedArray.h:652
openvdb::v3_2_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:338
openvdb::v3_2_0::util::PagedArray::Page::Page
Page()
Definition: PagedArray.h:699
openvdb::v3_2_0::util::PagedArray::PagedArray
PagedArray()
Default constructor.
Definition: PagedArray.h:201
openvdb::v3_2_0::util::PagedArray::Iterator::BaseT
std::iterator< std::random_access_iterator_tag, ValueT > BaseT
Definition: PagedArray.h:646
openvdb::v3_2_0::util::PagedArray::ValueBuffer
Definition: PagedArray.h:546
openvdb::v3_2_0::util::PagedArray::Page
Definition: PagedArray.h:692
openvdb::v3_2_0::util::PagedArray::Page::mData
ValueT * mData
Definition: PagedArray.h:708
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator==
bool operator==(const ConstIterator &other) const
Definition: PagedArray.h:624
openvdb::v3_2_0::util::PagedArray::ConstIterator
Definition: PagedArray.h:592
openvdb::v3_2_0::util::PagedArray::pageSize
static size_t pageSize()
Return the number of elements per memory page.
Definition: PagedArray.h:344
openvdb::v3_2_0::math::operator>
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:170
openvdb::v3_2_0::util::PagedArray::ConstIterator::pos
size_t pos() const
Definition: PagedArray.h:632
openvdb::v3_2_0::util::PagedArray::Page::fill
void fill(const ValueT &v)
Definition: PagedArray.h:703
openvdb::v3_2_0::util::PagedArray::isEmpty
bool isEmpty() const
Return true if the container contains no elements.
Definition: PagedArray.h:356
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_2_0::util::PagedArray::ValueBuffer::~ValueBuffer
~ValueBuffer()
Destructor that transfers an buffered values to the parent PagedArray.
Definition: PagedArray.h:557
openvdb::v3_2_0::util::PagedArray::ValueBuffer::ValueBuffer
ValueBuffer(PagedArray &parent)
Constructor from a PageArray.
Definition: PagedArray.h:552
openvdb::v3_2_0::util::PagedArray::Iterator::operator--
Iterator operator--(int)
Definition: PagedArray.h:662
openvdb::v3_2_0::util::PagedArray
Concurrent page-based linear data structure with O(1) random access and std-compliant iterators...
Definition: PagedArray.h:191
openvdb::v3_2_0::util::PagedArray::ValueBuffer::flush
void flush()
Manually transfer the values in this buffer to the parent PagedArray.
Definition: PagedArray.h:571
openvdb::v3_2_0::util::PagedArray::~PagedArray
~PagedArray()
Destructor removed all allocated pages.
Definition: PagedArray.h:204
openvdb::v3_2_0::util::PagedArray::Page::memUsage
static size_t memUsage()
Definition: PagedArray.h:698
openvdb::v3_2_0::util::PagedArray::Iterator::operator-=
Iterator & operator-=(const difference_type &pos)
Definition: PagedArray.h:669
openvdb::v3_2_0::util::PagedArray::push_back_unsafe
size_t push_back_unsafe(const ValueType &value)
Slightly faster then the thread-safe push_back above.
Definition: PagedArray.h:239
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator>=
bool operator>=(const ConstIterator &other) const
Definition: PagedArray.h:626
openvdb::v3_2_0::util::PagedArray::sort
void sort()
Parallel sort of all the elements in ascending order.
Definition: PagedArray.h:399
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator!=
bool operator!=(const ConstIterator &other) const
Definition: PagedArray.h:625
openvdb::v3_2_0::util::PagedArray::cend
ConstIterator cend() const
Return a const iterator pointing to the past-the-last element.
Definition: PagedArray.h:396
openvdb::v3_2_0::util::PagedArray::Iterator::operator==
bool operator==(const Iterator &other) const
Definition: PagedArray.h:674
openvdb::v3_2_0::util::PagedArray::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &other)
Definition: PagedArray.h:601
openvdb::v3_2_0::util::PagedArray::Iterator::pos
size_t pos() const
Definition: PagedArray.h:682
openvdb::v3_2_0::util::PagedArray::ConstIterator::operator+=
ConstIterator & operator+=(const difference_type &pos)
Definition: PagedArray.h:618
openvdb::v3_2_0::tools::composite::min
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128