7#ifndef PXR_EXEC_VDF_MASK_H
8#define PXR_EXEC_VDF_MASK_H
14#include "pxr/exec/vdf/api.h"
16#include "pxr/base/tf/compressedBits.h"
17#include "pxr/base/tf/delegatedCountPtr.h"
27PXR_NAMESPACE_OPEN_SCOPE
68 *
this = _GetAllOnes1();
76 _bits = _FindOrInsert(bits);
86 if (bits.GetSize() != 0) {
87 _bits = _FindOrEmplace(std::move(bits));
94 _bits.
swap(rhs._bits);
112 _bits = _FindOrInsert(bits);
126 _bits = _FindOrEmplace(std::move(copy));
136 return _bits->Get().IsSet(index);
150 _bits = _FindOrEmplace(std::move(copy));
163 return _bits->Get().GetSize();
176 if (_bits == mask._bits) {
187 if (_bits == mask._bits) {
201 return _bits->Get().AreAllSet();
211 return _bits->Get().AreAllUnset();
221 return _bits->Get().IsAnySet();
231 return _bits->Get().GetFirstSet();
241 return _bits->Get().GetLastSet();
251 return _bits->Get().GetNumSet();
263 return _bits->Get().AreContiguouslySet();
272 return _bits == rhs._bits;
275 bool operator!=(
const VdfMask &rhs)
const {
276 return !(*
this == rhs);
286 return lhs._bits < rhs._bits;
295 if (_bits == rhs._bits) {
314 if (_bits == rhs._bits) {
360 _bits = _FindOrEmplace(std::move(copy));
377 _bits = _FindOrEmplace(
400 using _BaseIterator = VdfMask::Bits::AllSetView::const_iterator;
403 using value_type = _BaseIterator::value_type;
412 return _it == rhs._it;
437 return _it.IsAtEnd();
443 _it = _BaseIterator();
459 while (!_it.IsAtEnd() && *_it < index) {
469 _it(bits->GetAllSetView().
begin())
498 }
else if (size == 1) {
499 return _GetAllOnes1();
530 return std::string();
533 return _bits->Get().GetAsRLEString();
544 return _bits->Get().GetAllocatedSize();
566 return std::hash<_BitsImpl*>()(_bits.
get());
572 size_t operator()(
const VdfMask &mask)
const {
581 struct _AllOnes1Factory
585 return new VdfMask(_AllOnes1Factory());
589 explicit VdfMask(
const _AllOnes1Factory &) {
590 Bits allOnes1Bits(1);
591 allOnes1Bits.SetAll();
592 _bits = _FindOrInsert(allOnes1Bits);
595 static VdfMask _GetAllOnes1() {
600 friend VDF_API std::ostream & operator<<(
601 std::ostream &os,
const VdfMask &mask);
609 _BitsImpl(
const _BitsImpl &) =
delete;
610 _BitsImpl& operator=(
const _BitsImpl &) =
delete;
613 _BitsImpl(_BitsImpl &&) =
delete;
614 _BitsImpl& operator=(_BitsImpl &&) =
delete;
625 size_t GetHash()
const;
631 _BitsImpl(_BitsImpl *next,
size_t hash,
VdfMask::Bits &&bits);
633 friend inline void TfDelegatedCountIncrement(_BitsImpl *p)
noexcept;
634 friend inline void TfDelegatedCountDecrement(_BitsImpl *p)
noexcept;
636 friend class Vdf_MaskRegistry;
641 std::atomic<int> _refCount;
644 std::atomic<uint16_t> _resurrectionCount;
648 friend inline void TfDelegatedCountIncrement(_BitsImpl *p)
noexcept;
649 friend inline void TfDelegatedCountDecrement(_BitsImpl *p)
noexcept;
651 friend class Vdf_MaskRegistry;
669 static _BitsImplRefPtr _FindOrInsert(
const VdfMask::Bits &bits);
674 static void _EraseBits(_BitsImpl *bits);
679 _BitsImplRefPtr _bits;
686inline void TfDelegatedCountIncrement(VdfMask::_BitsImpl *p)
noexcept
689 if (p->_isImmortal) {
701 p->_refCount.fetch_add(1, std::memory_order_relaxed);
703inline void TfDelegatedCountDecrement(VdfMask::_BitsImpl *p)
noexcept
706 if (p->_isImmortal) {
715 const int prevRC = p->_refCount.fetch_sub(1, std::memory_order_release);
719 std::atomic_thread_fence(std::memory_order_acquire);
720 VdfMask::_EraseBits(p);
729PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Fast, compressed bit array which is capable of performing logical operations without first decompress...
void SetAll()
Sets all bits to one.
size_t GetSize() const
Returns the size of the bit array, ie.
bool AreAllSet() const
Returns true, if all the bits in this bit array are set.
void Clear(size_t index)
Clears bit # index to zero.
void Set(size_t index)
Sets bit # index to zero.
TfCompressedBits & Complement()
Flips all bits.
bool HasNonEmptyDifference(const TfCompressedBits &rhs) const
Returns true if the result of an asymmetric set different is non-zero.
static const TfCompressedBits & GetEmpty()
Returns an empty TfBits.
bool HasNonEmptyIntersection(const TfCompressedBits &rhs) const
Returns true if the result of the intersection with rhs would be non-zero.
Stores a pointer to a ValueType which uses TfDelegatedCountIncrement and TfDelegatedCountDecrement to...
void swap(TfDelegatedCountPtr &other) noexcept
Swap this object's held pointer with other's.
RawPtrType get() const noexcept
Return the underlying pointer.
Create or return a previously created object instance of global data.
Iterator class used to iterate through the elements of the mask.
bool IsAtEnd() const
Returns true if the iteration is finished.
void AdvanceToEnd()
Advance the iterator to the end.
bool operator!=(const iterator &rhs) const
Returns true if this iterator and rhs do not compare equal.
iterator()
Constructs an null iterator that is already at end.
bool operator==(const iterator &rhs) const
Returns true if this iterator and rhs compare equal.
iterator & operator++()
Increment the iterator to the next element.
value_type operator*() const
Returns the index of the current element.
int AdvanceTo(value_type index)
Advance the iterator to the first index that is set in the mask located at or after index.
A VdfMask is placed on connections to specify the data flowing through them.
void SetAll()
Enables all the bits in the mask.
size_t GetSize() const
Returns the size of the mask.
VdfMask(VdfMask::Bits &&bits)
Constructs a mask by moving the contents of bits into the mask.
iterator begin() const
Returns an iterator that can be used to iterate through the elements of the mask.
static VdfMask AllZeros(size_t size)
Returns a mask of the requested size where no element is set.
VdfMask & operator-=(const VdfMask &rhs)
Performs an asymmetric set difference.
void SetIndex(size_t index)
Adds the given index to the mask.
bool IsAnySet() const
Returns true, if there is at least a single set entry.
bool IsContiguous() const
Returns true if the set bits in the mask are contiguous.
VdfMask & SetOrAppend(const VdfMask &rhs)
Sets this mask to rhs if this mask is of zero size.
TfCompressedBits Bits
Typedef on the internal bitset implementation used.
VdfMask & operator^=(const VdfMask &rhs)
Xors two masks together.
void ClearIndex(size_t index)
Removes the given index from the mask.
bool IsAllZeros() const
Returns true if this mask has all entries unset.
bool operator==(const VdfMask &rhs) const
Returns true if this and rhs are equal, false otherwise.
VdfMask(VdfMask::Bits const &bits)
Constructs a mask from VdfMask::Bits.
bool IsAllOnes() const
Returns true if this mask has all entries set.
size_t GetLastSet() const
Returns the last set bit in the mask.
std::string GetRLEString() const
Returns the mask in an RLE format.
bool IsSet(size_t index) const
Returns true if mask at index is set.
bool IsEmpty() const
Returns true if this mask is empty, i.e.
bool Overlaps(const VdfMask &mask) const
Returns true if this mask and mask have any set entries in common, and false otherwise.
size_t GetFirstSet() const
Returns the first set bit in the mask.
VdfMask & operator|=(const VdfMask &rhs)
Ors two masks together.
VdfMask & operator&=(const VdfMask &rhs)
Ands two masks together.
static VdfMask AllOnes(size_t size)
Returns a mask of the requested size that will iterate over all elements.
size_t GetHash() const
Returns a hash for the mask.
size_t GetMemoryUsage() const
Returns the amount of memory in bytes used by this mask.
VdfMask & Complement()
Complement.
VdfMask(size_t size)
Constructs a mask of size size.
VdfMask::Bits const & GetBits() const
Get this mask's content as CtCompressedfBits.
VdfMask()
Constructs an empty mask.
bool Contains(const VdfMask &mask) const
Returns true if mask is a subset-of or equal to this mask, false otherwise.
friend void swap(VdfMask &lhs, VdfMask &rhs) noexcept
Swap lhs's bits with rhs.
size_t GetNumSet() const
Returns the number of set bits in the mask.
void Swap(VdfMask &rhs) noexcept
Swap this mask's bits with rhs.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Arbitrary total ordering of masks.