From ed8848010239581d0e6f5af1c5006e494b4b5b3d Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Wed, 7 Nov 2012 16:46:24 +0100 Subject: [PATCH] Remove binarySearch(). Equivalent STL call is std::binary_search(array.begin(), array.end()); --- BaseLib/binarySearch.cpp | 32 ------------------------ BaseLib/binarySearch.h | 53 ---------------------------------------- 2 files changed, 85 deletions(-) delete mode 100644 BaseLib/binarySearch.cpp delete mode 100644 BaseLib/binarySearch.h diff --git a/BaseLib/binarySearch.cpp b/BaseLib/binarySearch.cpp deleted file mode 100644 index ffef64da65e..00000000000 --- 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 c5ba2dd11de..00000000000 --- 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_ */ -- GitLab