MCPcopy Create free account
hub / github.com/Kitware/VTK / LookupValue

Method LookupValue

Common/Core/vtkVariantArray.cxx:908–976  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

906
907//------------------------------------------------------------------------------
908vtkIdType vtkVariantArray::LookupValue(ValueType value)
909{
910 this->UpdateLookup();
911
912 // First look into the cached updates, to see if there were any
913 // cached changes. Find an equivalent element in the set of cached
914 // indices for this value. Some of the indices may have changed
915 // values since the cache was built, so we need to do this equality
916 // check.
917 typedef vtkVariantCachedUpdates::iterator CacheIterator;
918 CacheIterator cached = this->Lookup->CachedUpdates.lower_bound(value),
919 cachedEnd = this->Lookup->CachedUpdates.end();
920 while (cached != cachedEnd)
921 {
922 // Check that we are still in the same equivalence class as the
923 // value.
924 if (value == (*cached).first)
925 {
926 // Check that the value in the original array hasn't changed.
927 ValueType currentValue = this->GetValue(cached->second);
928 if (value == currentValue)
929 {
930 return (*cached).second;
931 }
932 }
933 else
934 {
935 break;
936 }
937
938 ++cached;
939 }
940
941 // Perform a binary search of the sorted array using STL equal_range.
942 int numComps = this->Lookup->SortedArray->GetNumberOfComponents();
943 vtkIdType numTuples = this->Lookup->SortedArray->GetNumberOfTuples();
944 ValueType* ptr = this->Lookup->SortedArray->GetPointer(0);
945 ValueType* ptrEnd = ptr + numComps * numTuples;
946 ValueType* found = std::lower_bound(ptr, ptrEnd, value, vtkVariantLessThan());
947
948 // Find an index with a matching value. Non-matching values might
949 // show up here when the underlying value at that index has been
950 // changed (so the sorted array is out-of-date).
951 vtkIdType offset = static_cast<vtkIdType>(found - ptr);
952 while (found != ptrEnd)
953 {
954 // Check whether we still have a value equivalent to what we're
955 // looking for.
956 if (value == *found)
957 {
958 // Check that the value in the original array hasn't changed.
959 vtkIdType index = this->Lookup->IndexArray->GetId(offset);
960 ValueType currentValue = this->GetValue(index);
961 if (value == currentValue)
962 {
963 return index;
964 }
965 }

Callers

nothing calls this directly

Calls 12

UpdateLookupMethod · 0.95
lower_boundMethod · 0.80
InsertNextIdMethod · 0.80
vtkVariantLessThanClass · 0.70
endMethod · 0.45
GetValueMethod · 0.45
GetNumberOfComponentsMethod · 0.45
GetNumberOfTuplesMethod · 0.45
GetPointerMethod · 0.45
GetIdMethod · 0.45
ResetMethod · 0.45
equal_rangeMethod · 0.45

Tested by

no test coverage detected