7#ifndef PXR_EXEC_VDF_VECTOR_IMPL_CONTIGUOUS_H
8#define PXR_EXEC_VDF_VECTOR_IMPL_CONTIGUOUS_H
12#include "pxr/exec/vdf/api.h"
13#include "pxr/exec/vdf/boxedContainer.h"
14#include "pxr/exec/vdf/forEachCommonType.h"
16#include "pxr/exec/vdf/vectorDataTyped.h"
17#include "pxr/exec/vdf/vectorImpl_Boxed.h"
18#include "pxr/exec/vdf/vectorImpl_Compressed.h"
19#include "pxr/exec/vdf/vectorImpl_Dispatch.h"
23PXR_NAMESPACE_OPEN_SCOPE
28template <
typename TYPE>
30 :
public Vdf_VectorDataTyped<TYPE>
33 !Vdf_IsBoxedContainer<TYPE>,
34 "Only Vdf_VectorImplBoxed may hold boxed values");
44 : _data(size ? new TYPE[size] : nullptr)
47 , _last(size ? size-1 : 0)
58 _AllocateSpace(size, first, last);
89 Vdf_VectorImplDispatch<TYPE>::Copy(_data - firstSet, data, bits);
99 const size_t numUsed = _last - _first + 1;
100 _data =
new TYPE[numUsed];
103 Vdf_VectorImplDispatch<TYPE>::Copy(_data, rhs._data, numUsed);
110 _data(sourceData._data),
111 _size(sourceData._size),
112 _first(sourceData._first),
113 _last(sourceData._last)
115 sourceData._data = NULL;
116 sourceData._size = 0;
117 sourceData._first = 0;
118 sourceData._last = 0;
140 void CloneSubset(
const VdfMask &mask,
154 }
else if (Vdf_VectorData::ShouldStoreCompressed(
155 mask.
GetBits(),
sizeof(TYPE)) ) {
163 if (destCompressed) {
164 destCompressed->
Assign(&(_data[-_first]), mask);
168 &(_data[-_first]), mask.
GetBits() );
177 if (firstSet == _first && lastSet == _last) {
188 _data - _first, mask.
GetBits());
203 for (
size_t i = 0; i < v.size(); ++i) {
204 v[i] = _data[offset + i];
208 for (
const uint32_t idx : bits.GetAllSetView()) {
209 v[i++] = _data[idx - _first];
221 Vdf_VectorData::Info info = destData->
Get()->GetInfo();
226 info.compressedIndexMapping == NULL &&
227 info.data,
"destData is not a Vdf_VectorImplContiguous.")) {
232 TYPE *typedDest =
static_cast<TYPE*
>(info.data);
233 Vdf_VectorImplDispatch<TYPE>::Copy(
234 typedDest - info.first, _data - _first, bits);
237 void Expand(
size_t first,
size_t last)
override
241 const size_t newFirst = _data ? std::min(_first, first) : first;
242 const size_t newLast = _data ? std::max(_last, last) : last;
246 if (_first == newFirst && _last == newLast) {
251 TYPE *oldData = _data;
254 const size_t newSize = newLast - newFirst + 1;
255 _data =
new TYPE[newSize];
260 Vdf_VectorImplDispatch<TYPE>::Copy(
261 _data + _first - newFirst, oldData, _last - _first + 1);
270 size_t GetSize()
const override
275 size_t GetNumStoredElements()
const override
280 return _last - _first + 1;
283 bool IsSharable()
const override
285 return _size >= Vdf_VectorData::_VectorSharingSize;
288 Vdf_VectorData::Info GetInfo()
override
290 return Vdf_VectorData::Info(
313 void _AllocateSpace(
size_t size,
size_t firstIndex,
size_t lastIndex)
323 const size_t numUsed = _last - _first + 1;
324 _data =
new TYPE[numUsed];
336#define VDF_DECLARE_EXTERN_VECTOR_IMPL_CONTIGUOUS(type) \
337 extern template class VDF_API_TYPE Vdf_VectorImplContiguous<type>;
338VDF_FOR_EACH_COMMON_TYPE(VDF_DECLARE_EXTERN_VECTOR_IMPL_CONTIGUOUS)
339#undef VDF_DECLARE_EXTERN_VECTOR_IMPL_CONTIGUOUS
341PXR_NAMESPACE_CLOSE_SCOPE
Fast, compressed bit array which is capable of performing logical operations without first decompress...
size_t GetSize() const
Returns the size of the bit array, ie.
bool AreContiguouslySet() const
Returns true if the set bits in this bit array are contiguous.
size_t GetLastSet() const
Returns the index of the last bit set in the bit array.
size_t GetFirstSet() const
Returns the index of the first bit set in the bit array.
bool AreAllUnset() const
Returns true, if all the bits in this bit array are unset.
size_t GetNumSet() const
Returns the number of bits currently set in this array.
This simple container stores multiple values that flow through the network as a single data flow elem...
void New(Args &&... args)
Creates an instance.
void Destroy()
Destroys a held instance.
Base const * Get() const
Returns a Base pointer to the held instance.
Implements a Vdf_VectorData storage that holds a boxed element.
Implements a Vdf_VectorData storage that is holds a subset of a vector.
void Assign(const TYPE *data, const VdfMask &mask)
Assigns the subset of data that is described by mask into this sparse vector.
Implements Vdf_VectorData storage that holds a contiguous range of elements, which may be a subrange ...
Vdf_VectorImplContiguous(const VdfMask::Bits &bits)
Sparse vector constructor.
Vdf_VectorImplContiguous(size_t size)
Dense vector constructor.
Vdf_VectorImplContiguous(const TYPE *data, const VdfMask::Bits &bits)
Sparse vector constructor.
Vdf_VectorImplContiguous(size_t size, size_t first, size_t last)
Sparse vector constructor.
Implements a Vdf_VectorData storage that is always empty.
A VdfMask is placed on connections to specify the data flowing through them.
size_t GetSize() const
Returns the size of the mask.
bool IsAllZeros() const
Returns true if this mask has all entries unset.
size_t GetLastSet() const
Returns the last set bit in the mask.
size_t GetFirstSet() const
Returns the first set bit in the mask.
VdfMask::Bits const & GetBits() const
Get this mask's content as CtCompressedfBits.
#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.