Loading...
Searching...
No Matches
compressedIndexMapping.h
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_VDF_COMPRESSED_INDEX_MAPPING_H
8#define PXR_EXEC_VDF_COMPRESSED_INDEX_MAPPING_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/exec/vdf/api.h"
13#include "pxr/exec/vdf/mask.h"
14
15#include <cstddef>
16#include <vector>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
25 // The first logical index of the block of contiguous elements.
26 //
27 size_t logicalStartIndex;
28
29 // The index into packed raw storage of the element AFTER
30 // the final element in this block of logically contiguous elements.
31 //
32 size_t dataEndIndex;
33
34 // A less-than operator for performing binary search on a
35 // vector of these objects. It only considers the start index
36 // becase that is sufficient to order the blocks.
37 //
38 bool operator<(const Vdf_IndexBlockMapping& rhs) const {
39 return logicalStartIndex < rhs.logicalStartIndex;
40 }
41};
42
65public:
66
67 // Computes a mapping with block layout that matches the
68 // bits set in the given VdfMask::Bits.
69 VDF_API
70 void Initialize(const VdfMask::Bits &bits);
71
72 // Finds the raw data index corresponding to the given
73 // logical element index. The block specified by blockHint
74 // is checked first as an optimization. The containing
75 // block is also returned in blockHint.
76 //
77 VDF_API
78 size_t FindDataIndex(size_t logicalIdx, size_t *blockHint) const;
79
80 // Returns the index of the block containing the given
81 // logical element index.
82 VDF_API
83 size_t FindBlockIndex(size_t logicalIdx) const;
84
85 // Returns whether logicalIndex is in the range of the given block.
86 // if so, returns the data index also.
87 VDF_API
88 bool ComputeDataIndex(size_t blockIndex, size_t logicalIndex,
89 size_t *dataIndex) const;
90
91
92 // Returns the first logical index mapped by the given block.
93 VDF_API
94 size_t GetBlockFirstIndex(size_t blockIdx) const;
95
96 // Returns the last logical index mapped by the given block.
97 VDF_API
98 size_t GetBlockLastIndex(size_t blockIdx) const;
99
100 VDF_API
101 size_t GetBlockLength(size_t blockIdx) const;
102
103 // Returns the range of blocks that intersect the given
104 // logical index range.
105 VDF_API
106 void FindBlockRange(size_t first, size_t last,
107 size_t *firstBlockIdx, size_t *lastBlockIdx) const;
108
109 // Returns the first logical index in the entire mapping
110 size_t GetFirstIndex() const {
111 return GetBlockFirstIndex(0);
112 }
113
114 // Returns the last logical index in the entire mapping
115 size_t GetLastIndex() const {
116 return GetBlockLastIndex(_blockMappings.size() - 1);
117 }
118
119 // Computes a mask with bits turned on for each index contained in the
120 // compressed index mapping
121 VDF_API
122 void ComputeStoredBits(VdfMask::Bits *bits, size_t num) const;
123
124private:
125
126 template <class T> friend class Vdf_VectorImplCompressed;
127
128 typedef std::vector<Vdf_IndexBlockMapping> _BlockMappings;
129 _BlockMappings _blockMappings;
130
131};
132
133PXR_NAMESPACE_CLOSE_SCOPE
134
135#endif
Fast, compressed bit array which is capable of performing logical operations without first decompress...
This collection of IndexBlockMappings is all the info required to take a logical index into a compres...
Implements a Vdf_VectorData storage that is holds a subset of a vector.
A mapping that relates logical blocks of indices to actual stored data when the data is compressed by...