------------------------------------------------------------------------------
| 906 | |
| 907 | //------------------------------------------------------------------------------ |
| 908 | vtkIdType 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 | } |
nothing calls this directly
no test coverage detected