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

Method BinarySearchOffset

Common/DataModel/vtkCellArray.cxx:55–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53
54 template <typename IterT>
55 IterT BinarySearchOffset(const IterT& beginIter, const IterT& endIter,
56 const typename std::iterator_traits<IterT>::value_type& targetLocation) const
57 {
58 using ValueType = typename std::iterator_traits<IterT>::value_type;
59 using DifferenceType = typename std::iterator_traits<IterT>::difference_type;
60
61 DifferenceType roiSize = std::distance(beginIter, endIter);
62
63 IterT roiBegin = beginIter;
64 while (roiSize > 0)
65 {
66 IterT it = roiBegin;
67 const DifferenceType step = roiSize / 2;
68 std::advance(it, step);
69 // This differs from a generic binary search in the following line:
70 // Adding the distance from the start of the array to the current
71 // iterator will account for the cellSize entries in the old cell array
72 // format, such that curLocation would be the offset in the old style
73 // connectivity array.
74 const ValueType curLocation = *it + std::distance(beginIter, it);
75 if (curLocation < targetLocation)
76 {
77 roiBegin = ++it;
78 roiSize -= step + 1;
79 }
80 else
81 {
82 roiSize = step;
83 }
84 }
85
86 return roiBegin;
87 }
88};
89
90struct CellIdToLocationFunctor : public vtkCellArray::DispatchUtilities

Callers 1

operator()Method · 0.95

Calls 2

distanceFunction · 0.50
advanceFunction · 0.50

Tested by

no test coverage detected