diff --git a/BaseLib/binarySearch.cpp b/BaseLib/binarySearch.cpp deleted file mode 100644 index ffef64da65ec57fea0e7a7c8ce88eb6d2615656c..0000000000000000000000000000000000000000 --- a/BaseLib/binarySearch.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - * - * \file binarySearch.cpp - * - * Created on 2010-09-07 by Thomas Fischer - * - */ - -#include "binarySearch.h" - -namespace BaseLib { - -size_t searchElement (double const& val, size_t beg, size_t end, const std::vector<double>& array) -{ - if (beg >= end) return std::numeric_limits<size_t>::max(); - size_t m ((end+beg)/2); - - if (array[m] - val < 0 && array[m+1] - val > 0) { - return m; - } - if (val < array[m]) { - return searchElement (val, beg, m, array); - } - return searchElement (val, m+1, end, array); -} - -} // end namespace BaseLib diff --git a/BaseLib/binarySearch.h b/BaseLib/binarySearch.h deleted file mode 100644 index c5ba2dd11de911e1d36700c9beda2a740974b619..0000000000000000000000000000000000000000 --- a/BaseLib/binarySearch.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - * - * \file binarySearch.h - * - * Created on 2010-06-07 by Thomas Fischer - * - */ - -// STL -#include <limits> -#include <vector> -#include <cstddef> - -#ifndef BINARYSEARCH_H_ -#define BINARYSEARCH_H_ - -namespace BaseLib { - -/** - * Binary search in a sorted vector of elements to get the - * id of an element according its key. - * @param key the key for the element - * @param beg beginning index in the sorted vector of elements - * @param end ending index in the sorted vector of elements - * @param array the vector of elements - * @return the id of the element in the vector or, if not found, - * the value std::numeric_limits<std::size_t>::max() - */ -template <class T> -std::size_t searchElement (const T& key, std::size_t beg, std::size_t end, const std::vector<T>& array) -{ - if (beg >= end) return std::numeric_limits<std::size_t>::max(); - std::size_t m ((end+beg)/2); - - if (key == array[m]) { - return m; - } - if (key < array[m]) { - return searchElement (key, beg, m, array); - } - return searchElement (key, m+1, end, array); -} - -std::size_t searchElement (double const& val, std::size_t beg, std::size_t end, const std::vector<double>& array); - -} // end namespace BaseLib - -#endif /* BINARYSEARCH_H_ */