HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
compressedIndexMapping.h
Go to the documentation of this file.
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 
19 
20 /// A mapping that relates logical blocks of indices to actual stored data
21 /// when the data is compressed by eliding unset elements.
22 /// See Vdf_CompressedIndexMapping.
23 ///
25  // The first logical index of the block of contiguous elements.
26  //
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 {
40  }
41 };
42 
43 /// This collection of IndexBlockMappings is all the info required to
44 /// take a logical index into a compressed VdfVector and obtain a
45 /// raw index into packed storage.
46 ///
47 /// An example vector with letters representing significant values:
48 /// logical vector: [ A BC DE ]
49 /// logical indices: 0123456789
50 ///
51 /// raw storage: [ABCDE]
52 ///
53 /// Block mappings: (1,1), (3,3), (7,5)
54 ///
55 /// The third block mapping (7,5) says the third contiguous block of data
56 /// (D,E) begins in the logical vector at logical index 7, and that in the
57 /// raw storage, it ends before raw index 5. To find the raw storage index
58 /// corresponding to logical index 7, just look at the previous mapping's
59 /// end index and find it's stored at raw index 3.
60 ///
61 /// Using this scheme, the total number of stored elements is available as
62 /// the end index of the last block mapping.
63 ///
65 public:
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 
124 private:
125 
126  template <class T> friend class Vdf_VectorImplCompressed;
127 
128  typedef std::vector<Vdf_IndexBlockMapping> _BlockMappings;
129  _BlockMappings _blockMappings;
130 
131 };
132 
134 
135 #endif
GLint first
Definition: glcorearb.h:405
VDF_API void Initialize(const VdfMask::Bits &bits)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
VDF_API size_t GetBlockFirstIndex(size_t blockIdx) const
#define VDF_API
Definition: api.h:25
Fast, compressed bit array which is capable of performing logical operations without first decompress...
VDF_API size_t GetBlockLength(size_t blockIdx) const
VDF_API void ComputeStoredBits(VdfMask::Bits *bits, size_t num) const
VDF_API bool ComputeDataIndex(size_t blockIndex, size_t logicalIndex, size_t *dataIndex) const
VDF_API void FindBlockRange(size_t first, size_t last, size_t *firstBlockIdx, size_t *lastBlockIdx) const
bool operator<(const Vdf_IndexBlockMapping &rhs) const
VDF_API size_t FindDataIndex(size_t logicalIdx, size_t *blockHint) const
VDF_API size_t GetBlockLastIndex(size_t blockIdx) const
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
VDF_API size_t FindBlockIndex(size_t logicalIdx) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Implements a Vdf_VectorData storage that is holds a subset of a vector. The subset is determined by a...