7#ifndef PXR_EXEC_VDF_INDEXED_DATA_H
8#define PXR_EXEC_VDF_INDEXED_DATA_H
26PXR_NAMESPACE_OPEN_SCOPE
43 if (!_indices.empty() && index <= _indices.back()) {
47 _indices.push_back(index);
48 _data.push_back(data);
53 size_t GetSize()
const {
54 return _indices.size();
60 void Reserve(
size_t size) {
61 _indices.reserve(size);
67 bool IsEmpty()
const {
68 return _indices.empty();
73 int GetIndex(
size_t i)
const {
85 T &operator[](
size_t i) {
96 size_t GetFirstDataIndex(
size_t currentIndex)
const;
104 size_t GetFirstDataIndex(
size_t currentIndex,
size_t startIndex)
const {
105 const size_t size = _indices.size();
106 for (
size_t i = startIndex; i < size; ++i) {
107 if (_indices[i] >= 0 &&
108 static_cast<unsigned int>(_indices[i]) >= currentIndex) {
128 static void Compose(VdfIndexedData *result,
129 const VdfIndexedData &weak,
130 const VdfIndexedData &strong);
135 size_t GetMemoryUsage()
const {
136 return sizeof(*this) +
137 sizeof(int)*_indices.capacity() +
138 sizeof(T)*_data.capacity();
145 template <
class HashState>
146 friend void TfHashAppend(HashState &h,
const VdfIndexedData &d) {
147 h.Append(d._indices, d._data);
152 bool operator==(
const VdfIndexedData &rhs)
const {
153 return _indices == rhs._indices &&
159 bool operator!=(
const VdfIndexedData &rhs)
const {
160 return !(*
this == rhs);
165 friend void swap(VdfIndexedData &lhs, VdfIndexedData &rhs) {
166 lhs._indices.swap(rhs._indices);
167 lhs._data.swap(rhs._data);
180 typedef std::pair<IndexIterator, IndexIterator> IndexIteratorRange;
181 typedef std::pair<DataIterator, DataIterator> DataIteratorRange;
190 IndexIteratorRange GetIndexIterators()
const {
191 return std::make_pair(IndexIterator(_indices.begin()),
192 IndexIterator(_indices.end()));
201 DataIteratorRange GetDataIterators()
const {
202 return std::make_pair(DataIterator(_data.begin()),
203 DataIterator(_data.end()));
208 std::vector<int> &_GetWriteIndices() {
213 const std::vector<int> &_GetReadIndices()
const {
218 std::vector<T> &_GetWriteData() {
223 const std::vector<T> &_GetReadData()
const {
229 static std::vector<int> &_GetWriteIndices(
230 VdfIndexedData<T> *o) {
231 return o->_GetWriteIndices();
234 static const std::vector<int> &_GetReadIndices(
235 const VdfIndexedData<T> *o) {
236 return o->_GetReadIndices();
239 static std::vector<T> &_GetWriteData(
240 VdfIndexedData<T> *o) {
241 return o->_GetWriteData();
244 static const std::vector<T> &_GetReadData(
245 const VdfIndexedData<T> *o) {
246 return o->_GetReadData();
252 std::vector<int> _indices;
255 std::vector<T> _data;
261operator<<(std::ostream &os,
const VdfIndexedData<T> &data)
263 size_t sz = data.GetSize();
268 for(
size_t i=0; i<sz; i++) {
269 os <<
'(' << data.GetIndex(i) <<
", " << data.GetData(i) <<
')';
279VdfIndexedData<T>::GetFirstDataIndex(
size_t currentIndex)
const
281 std::vector<int>::const_iterator it = std::lower_bound(
282 _indices.begin(), _indices.end(), currentIndex);
283 return std::distance(_indices.begin(), it);
288VdfIndexedData<T>::Compose(VdfIndexedData<T> *result,
289 const VdfIndexedData<T> &weak,
290 const VdfIndexedData<T> &strong)
293 if ((&weak == result) ||
294 (&strong == result)) {
295 TF_CODING_ERROR(
"Result indexData must be different than strong or weak.");
301 if (strong._indices.empty()) {
302 result->_indices = weak._indices;
303 result->_data = weak._data;
307 if (weak._indices.empty()) {
308 result->_indices = strong._indices;
309 result->_data = strong._data;
313 std::vector<int> &resultIndices = result->_indices;
314 std::vector<T> &resultData = result->_data;
318 resultIndices.clear();
323 size_t strongIndex = 0;
324 bool strongDone =
false;
326 size_t weakIndex = 0;
327 bool weakDone =
false;
330 const std::vector<int> &strongIndices = strong._indices;
331 const std::vector<int> &weakIndices = weak._indices;
333 size_t numStrongIndices = strongIndices.size();
334 size_t numWeakIndices = weakIndices.size();
338 while ( (weakDone ==
false) || (strongDone ==
false)) {
342 bool useStrongValue =
true;
344 int strongIndexValue = -1;
345 int weakIndexValue = -1;
350 useStrongValue =
false;
351 weakIndexValue = weakIndices[weakIndex];
353 }
else if (weakDone) {
356 strongIndexValue = strongIndices[strongIndex];
363 strongIndexValue = strongIndices[strongIndex];
364 weakIndexValue = weakIndices[weakIndex];
366 if (weakIndexValue < strongIndexValue) {
378 useStrongValue =
false;
389 if (useStrongValue) {
393 resultIndices.push_back(strongIndexValue);
394 resultData.push_back(strong._data[strongIndex]);
396 if (weakIndexValue == strongIndexValue) {
405 resultIndices.push_back(weakIndexValue);
406 resultData.push_back(weak._data[weakIndex]);
411 if (strongIndex >= numStrongIndices) {
414 if (weakIndex >= numWeakIndices) {
422constexpr bool VdfIsEqualityComparable<VdfIndexedData<T>> =
423 VdfIsEqualityComparable<T>;
425PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
This is a simple "iterator filter" that erases the type and traits of the container used by VdfIndexe...
typename std::conditional_t< std::is_pointer_v< T >||Vdf_AndTypeIsSmall< T, std::is_arithmetic_v< T > >||Vdf_AndTypeIsSmall< T, std::is_enum_v< T > >, T, const T & > VdfByValueOrConstRef
Template that evaluates to either T or const T & depending on whether T best be passed as value or co...
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_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
A file containing basic constants and definitions.