NvBlastIndexFns.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2008-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTINDEXFNS_H
30 #define NVBLASTINDEXFNS_H
31 
32 
33 #include "NvBlastTypes.h"
34 
35 #include <cstring>
36 
37 
38 namespace Nv
39 {
40 namespace Blast
41 {
42 
46 template<typename T>
48 {
49  return ~(T)0;
50 }
51 
52 
56 template<typename T>
58 {
59  return index == invalidIndex<T>();
60 }
61 
62 
95 template<typename T>
96 void createIndexStartLookup(T* lookup, T indexBase, T indexRange, T* indexSource, T indexCount, T indexByteStride)
97 {
98  ++indexBase; // Ordering invalidIndex<T>() as lowest value
99  T indexPos = 0;
100  for (T i = 0; i <= indexRange; ++i)
101  {
102  for (; indexPos < indexCount; ++indexPos, indexSource = (T*)((uintptr_t)indexSource + indexByteStride))
103  {
104  if (*indexSource + 1 >= i + indexBase) // +1 to order invalidIndex<T>() as lowest value
105  {
106  lookup[i] = indexPos;
107  break;
108  }
109  }
110  if (indexPos == indexCount)
111  {
112  lookup[i] = indexPos;
113  }
114  }
115  lookup[indexRange + 1] = indexCount;
116 }
117 
118 
127 template<typename T>
128 void invertMap(T* inverseMap, const T* map, const T size)
129 {
130  memset(inverseMap, invalidIndex<T>(), size*sizeof(T));
131 
132  for (T i = 0; i < size; i++)
133  {
134  if (!isInvalidIndex(map[i]))
135  {
136  inverseMap[map[i]] = i;
137  }
138  }
139 }
140 
141 } // end namespace Blast
142 } // end namespace Nv
143 
144 
145 #endif // #ifndef NVBLASTINDEXFNS_H
void createIndexStartLookup(T *lookup, T indexBase, T indexRange, T *indexSource, T indexCount, T indexByteStride)
Definition: NvBlastIndexFns.h:96
NV_INLINE bool isInvalidIndex(T index)
Definition: NvBlastIndexFns.h:57
NV_INLINE T invalidIndex()
Definition: NvBlastIndexFns.h:47
void invertMap(T *inverseMap, const T *map, const T size)
Definition: NvBlastIndexFns.h:128
#define NV_INLINE
Definition: NvPreprocessor.h:350
Definition: NvBlastArray.h:37