22#ifndef vtkGenericDataArrayLookupHelper_h
23#define vtkGenericDataArrayLookupHelper_h
29#include <unordered_map>
34template <
typename T,
bool>
40 static bool isnan(T x) {
return std::isnan(x); }
46 static bool isnan(T) {
return false; }
57template <
class ArrayTypeT>
70 if (this->AssociatedArray != array)
73 this->AssociatedArray = array;
80 auto indices = FindIndexVec(elem);
81 if (indices ==
nullptr)
85 return indices->front();
92 auto indices = FindIndexVec(elem);
96 for (
auto index : *indices)
109 this->ValueMap.clear();
110 this->NanIndices.clear();
120 if (!this->AssociatedArray || (this->AssociatedArray->GetNumberOfTuples() < 1) ||
121 (!this->ValueMap.empty() || !this->NanIndices.empty()))
126 vtkIdType num = this->AssociatedArray->GetNumberOfValues();
127 this->ValueMap.reserve(num);
130 auto value = this->AssociatedArray->GetValue(i);
133 NanIndices.push_back(i);
135 this->ValueMap[
value].push_back(i);
141 std::vector<vtkIdType>* FindIndexVec(
ValueType value)
143 std::vector<vtkIdType>* indices{
nullptr };
146 indices = &this->NanIndices;
148 const auto& pos = this->ValueMap.find(value);
149 if (pos != this->ValueMap.end())
151 indices = &pos->second;
156 ArrayTypeT* AssociatedArray{
nullptr };
157 std::unordered_map<ValueType, std::vector<vtkIdType>> ValueMap;
158 std::vector<vtkIdType> NanIndices;
internal class used by vtkGenericDataArray to support LookupValue.
~vtkGenericDataArrayLookupHelper()
void LookupValue(ValueType elem, vtkIdList *ids)
vtkGenericDataArrayLookupHelper()=default
void ClearLookup()
Release any allocated memory for internal data-structures.
void SetArray(ArrayTypeT *array)
vtkIdType LookupValue(ValueType elem)
ArrayType::ValueType ValueType
list of point or cell ids
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
int Allocate(const vtkIdType sz, const int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
void Reset()
Reset to an empty state but retain previously allocated memory.