7#ifndef PXR_EXEC_VDF_VECTOR_IMPL_COMPRESSED_H
8#define PXR_EXEC_VDF_VECTOR_IMPL_COMPRESSED_H
12#include "pxr/exec/vdf/api.h"
13#include "pxr/exec/vdf/vectorDataTyped.h"
14#include "pxr/exec/vdf/boxedContainer.h"
15#include "pxr/exec/vdf/compressedIndexMapping.h"
16#include "pxr/exec/vdf/forEachCommonType.h"
18#include "pxr/exec/vdf/vectorImpl_Dispatch.h"
19#include "pxr/exec/vdf/vectorImpl_Boxed.h"
23PXR_NAMESPACE_OPEN_SCOPE
32template<
typename TYPE>
34 :
public Vdf_VectorDataTyped<TYPE>
37 !Vdf_IsBoxedContainer<TYPE>,
38 "Only Vdf_VectorImplBoxed may hold boxed values");
47 _Initialize(data, bits);
55 _Initialize(NULL, bits);
62 _data(sourceData._data),
63 _logicalSize(sourceData._logicalSize),
64 _compressedIndexMapping(sourceData._compressedIndexMapping)
66 sourceData._data = NULL;
67 sourceData._logicalSize = 0;
68 sourceData._compressedIndexMapping = NULL;
76 if (_compressedIndexMapping)
77 delete _compressedIndexMapping;
102 if (GetNumStoredElements() != mask.
GetNumSet()) {
107 _Initialize(data, mask.
GetBits());
110 void CloneSubset(
const VdfMask &mask,
119 size_t GetSize()
const override
124 size_t GetNumStoredElements()
const override
126 if (_compressedIndexMapping->_blockMappings.size() > 0) {
127 return _compressedIndexMapping->_blockMappings.back().dataEndIndex;
133 Vdf_VectorData::Info GetInfo()
override
135 return Vdf_VectorData::Info(
138 _compressedIndexMapping->GetFirstIndex(),
139 _compressedIndexMapping->GetLastIndex(),
140 _compressedIndexMapping);
155 void _Initialize(
const TYPE *data,
const VdfMask::Bits &bits);
171template<
typename TYPE>
174 _logicalSize(rhs._logicalSize),
176 *rhs._compressedIndexMapping))
179 const size_t numUsed = rhs.GetNumStoredElements();
181 _data =
new TYPE[numUsed];
183 Vdf_VectorImplDispatch<TYPE>::Copy(_data, rhs._data, numUsed);
193template<
typename TYPE>
211 size_t srcBlockHint = 0;
212 size_t destBlockHint = 0;
214 View platforms = bits.GetPlatformsView();
215 for (View::const_iterator it=platforms.begin(), e=platforms.end(); it != e;
218 const size_t index = *it;
219 const size_t srcDataIdx =
220 _compressedIndexMapping->FindDataIndex(index, &srcBlockHint);
221 const size_t destDataIdx = destImpl->
222 _compressedIndexMapping->FindDataIndex(index, &destBlockHint);
223 Vdf_VectorImplDispatch<TYPE>::Copy(
224 destImpl->_data + destDataIdx, _data + srcDataIdx,
225 it.GetPlatformSize());
230template<
typename TYPE>
242 size_t blockHint = 0;
243 for (
const uint32_t idx : bits.GetAllSetView()) {
244 const size_t dataIdx =
245 _compressedIndexMapping->FindDataIndex(idx, &blockHint);
246 v[i++] = _data[dataIdx];
253template<
typename TYPE>
259 Vdf_VectorData::Info info = destData->
Get()->GetInfo();
264 info.compressedIndexMapping == NULL &&
265 info.data,
"destData is not a Vdf_VectorImplDense.")) {
271 size_t srcBlockHint = 0;
272 TYPE *typedDest =
static_cast<TYPE*
>(info.data);
276 View platforms = bits.GetPlatformsView();
277 for (View::const_iterator it=platforms.begin(), e=platforms.end(); it != e;
280 const size_t index = *it;
281 const size_t srcDataIdx =
282 _compressedIndexMapping->FindDataIndex(index, &srcBlockHint);
283 Vdf_VectorImplDispatch<TYPE>::Copy(
284 typedDest + index - info.first, _data + srcDataIdx,
285 it.GetPlatformSize());
290template<
typename TYPE>
298 const size_t newStorageSize = bits.
GetNumSet();
301 if (newStorageSize == 0) {
311 _compressedIndexMapping->Initialize(bits);
317 size_t destDataIdx = 0;
319 View platforms = bits.GetPlatformsView();
320 for (View::const_iterator it=platforms.begin(), e=platforms.end();
323 const size_t platformSize = it.GetPlatformSize();
324 Vdf_VectorImplDispatch<TYPE>::Copy(
325 _data + destDataIdx, srcData + *it, platformSize);
326 destDataIdx += platformSize;
336#if !defined(ARCH_OS_WINDOWS)
337#define VDF_DECLARE_EXTERN_VECTOR_IMPL_COMPRESSED(type) \
338 extern template class VDF_API_TYPE Vdf_VectorImplCompressed<type>;
339VDF_FOR_EACH_COMMON_TYPE(VDF_DECLARE_EXTERN_VECTOR_IMPL_COMPRESSED)
340#undef VDF_DECLARE_EXTERN_VECTOR_IMPL_COMPRESSED
343PXR_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.
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.
size_t GetNumSet() const
Returns the number of bits currently set in this array.
View< Mode::Platforms > PlatformsView
Returns an iteratable view for the bits that steps over all platforms.
This simple container stores multiple values that flow through the network as a single data flow elem...
This collection of IndexBlockMappings is all the info required to take a logical index into a compres...
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.
Vdf_VectorImplCompressed(const VdfMask::Bits &bits)
Construct enough storage to hold as many elements as bits has set.
Vdf_VectorImplCompressed(const TYPE *data, const VdfMask::Bits &bits)
Construct storage for the elements of data indicated by bits.
void Assign(const TYPE *data, const VdfMask &mask)
Assigns the subset of data that is described by mask into this sparse vector.
A VdfMask is placed on connections to specify the data flowing through them.
size_t GetSize() const
Returns the size of the mask.
VdfMask::Bits const & GetBits() const
Get this mask's content as CtCompressedfBits.
size_t GetNumSet() const
Returns the number of set bits in the mask.
#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.