Deprecate vtkm/BinarySearch.h, it is unused and similar to LowerBound

This commit is contained in:
nadavi 2021-04-01 16:42:09 +00:00
parent 26d9ecb398
commit 1c9ae402b0
5 changed files with 60 additions and 98 deletions

@ -11,7 +11,6 @@
#ifndef vtk_m_Algorithms_h
#define vtk_m_Algorithms_h
#include <vtkm/BinarySearch.h>
#include <vtkm/Deprecated.h>
#include <vtkm/LowerBound.h>
#include <vtkm/UpperBound.h>
@ -19,7 +18,7 @@
namespace vtkm
{
VTKM_DEPRECATED(1.6, "Use BinarySearch.h, LowerBound.h, or UpperBound.h instead of Algorithms.h.")
VTKM_DEPRECATED(1.7, "Use LowerBound.h, or UpperBound.h instead of Algorithms.h.")
inline void Algorithms_h_deprecated() {}
inline void ActivateAlgorithms_h_deprecated_warning()
@ -27,6 +26,54 @@ inline void ActivateAlgorithms_h_deprecated_warning()
Algorithms_h_deprecated();
}
template <typename IterT, typename T, typename Comp>
VTKM_DEPRECATED(1.7, "Use LowerBound or UpperBound instead of BinarySearch.")
VTKM_EXEC_CONT IterT BinarySearch(IterT first, IterT last, const T& val, Comp comp)
{
IterT found = vtkm::LowerBound(first, last, val, comp);
if ((found == last) || comp(val, *found) || comp(*found, val))
{
// Element is not actually in the array
return last;
}
else
{
return found;
}
}
VTKM_DEPRECATED_SUPPRESS_BEGIN
template <typename IterT, typename T>
VTKM_DEPRECATED(1.7, "Use LowerBound or UpperBound instead of BinarySearch.")
VTKM_EXEC_CONT IterT BinarySearch(IterT first, IterT last, const T& val)
{
return vtkm::BinarySearch(first, last, val, vtkm::SortLess{});
}
template <typename PortalT, typename T, typename Comp>
VTKM_DEPRECATED(1.7, "Use LowerBound or UpperBound instead of BinarySearch.")
VTKM_EXEC_CONT vtkm::Id BinarySearch(const PortalT& portal, const T& val, Comp comp)
{
auto first = vtkm::cont::ArrayPortalToIteratorBegin(portal);
auto last = vtkm::cont::ArrayPortalToIteratorEnd(portal);
auto result = vtkm::BinarySearch(first, last, val, comp);
return result == last ? static_cast<vtkm::Id>(-1) : static_cast<vtkm::Id>(result - first);
}
// Return -1 if not found
template <typename PortalT, typename T>
VTKM_DEPRECATED(1.7, "Use LowerBound or UpperBound instead of BinarySearch.")
VTKM_EXEC_CONT vtkm::Id BinarySearch(const PortalT& portal, const T& val)
{
auto first = vtkm::cont::ArrayPortalToIteratorBegin(portal);
auto last = vtkm::cont::ArrayPortalToIteratorEnd(portal);
auto result = vtkm::BinarySearch(first, last, val, vtkm::SortLess{});
return result == last ? static_cast<vtkm::Id>(-1) : static_cast<vtkm::Id>(result - first);
}
VTKM_DEPRECATED_SUPPRESS_END
} // end namespace vtkm
#endif // vtk_m_Algorithms_h

@ -1,87 +0,0 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_BinarySearch_h
#define vtk_m_BinarySearch_h
#include <vtkm/BinaryPredicates.h>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/internal/Configure.h>
#include <algorithm>
#include <iterator>
namespace vtkm
{
/// Similar to std::lower_bound and std::upper_bound, but returns an iterator
/// to any matching item (rather than a specific one). Returns @a last when
/// @a val is not found.
/// @{
template <typename IterT, typename T, typename Comp>
VTKM_EXEC_CONT IterT BinarySearch(IterT first, IterT last, const T& val, Comp comp)
{
auto len = last - first;
while (len != 0)
{
const auto halfLen = len / 2;
IterT mid = first + halfLen;
if (comp(*mid, val))
{
first = mid + 1;
len -= halfLen + 1;
}
else if (comp(val, *mid))
{
len = halfLen;
}
else
{
return mid; // found element
}
}
return last; // did not find element
}
template <typename IterT, typename T>
VTKM_EXEC_CONT IterT BinarySearch(IterT first, IterT last, const T& val)
{
return vtkm::BinarySearch(first, last, val, vtkm::SortLess{});
}
/// @}
/// Similar to std::lower_bound and std::upper_bound, but returns the index of
/// any matching item (rather than a specific one). Returns -1 when @a val is not
/// found.
/// @{
template <typename PortalT, typename T, typename Comp>
VTKM_EXEC_CONT vtkm::Id BinarySearch(const PortalT& portal, const T& val, Comp comp)
{
auto first = vtkm::cont::ArrayPortalToIteratorBegin(portal);
auto last = vtkm::cont::ArrayPortalToIteratorEnd(portal);
auto result = vtkm::BinarySearch(first, last, val, comp);
return result == last ? static_cast<vtkm::Id>(-1) : static_cast<vtkm::Id>(result - first);
}
// Return -1 if not found
template <typename PortalT, typename T>
VTKM_EXEC_CONT vtkm::Id BinarySearch(const PortalT& portal, const T& val)
{
auto first = vtkm::cont::ArrayPortalToIteratorBegin(portal);
auto last = vtkm::cont::ArrayPortalToIteratorEnd(portal);
auto result = vtkm::BinarySearch(first, last, val, vtkm::SortLess{});
return result == last ? static_cast<vtkm::Id>(-1) : static_cast<vtkm::Id>(result - first);
}
/// @}
} // end namespace vtkm
#endif // vtk_m_BinarySearch_h

@ -17,12 +17,11 @@ vtkm_install_headers(
vtkm ${VTKm_BINARY_INCLUDE_DIR}/${kit_dir}/Version.h)
set(headers
Algorithms.h # Deprecated, split into BinarySearch.h, LowerBound.h, UpperBound.h
Algorithms.h # Deprecated, split into LowerBound.h, UpperBound.h
Assert.h
Atomic.h
BinaryPredicates.h
BinaryOperators.h
BinarySearch.h
Bitset.h
Bounds.h
CellClassification.h

@ -49,8 +49,8 @@ set(unit_tests
# Unit tests that have device-specific code to be tested
set(unit_tests_device
UnitTestAlgorithms.cxx
UnitTestAtomic.cxx
UnitTestBinarySearch.cxx
UnitTestGeometry.cxx
UnitTestLowerBound.cxx
UnitTestMath.cxx

@ -8,15 +8,16 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/BinarySearch.h>
#include <vtkm/cont/testing/Testing.h>
VTKM_DEPRECATED_SUPPRESS_BEGIN
#include <vtkm/Algorithms.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/cont/testing/Testing.h>
#include <vector>
namespace
@ -74,7 +75,7 @@ struct TestBinarySearch
}
};
void RunBinarySearchTest()
void RunAlgorithmsTests()
{
std::cout << "Testing binary search." << std::endl;
TestBinarySearch::Run();
@ -82,7 +83,9 @@ void RunBinarySearchTest()
} // anon namespace
int UnitTestBinarySearch(int argc, char* argv[])
VTKM_DEPRECATED_SUPPRESS_END
int UnitTestAlgorithms(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(RunBinarySearchTest, argc, argv);
return vtkm::cont::testing::Testing::Run(RunAlgorithmsTests, argc, argv);
}