LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
search.hpp
1/*********************************************************************
2 *
3 * Linear Arrangement Library - A library that implements a collection
4 * algorithms for linear arrangments of graphs.
5 *
6 * Copyright (C) 2019 - 2024
7 *
8 * This file is part of Linear Arrangement Library. The full code is available
9 * at:
10 * https://github.com/LAL-project/linear-arrangement-library.git
11 *
12 * Linear Arrangement Library is free software: you can redistribute it
13 * and/or modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * Linear Arrangement Library is distributed in the hope that it will be
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with Linear Arrangement Library. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * Contact:
26 *
27 * LluĂ­s Alemany Puig (lluis.alemany.puig@upc.edu)
28 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
29 * CQL (Complexity and Quantitative Linguistics Lab)
30 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
31 * Webpage: https://cqllab.upc.edu/people/lalemany/
32 *
33 ********************************************************************/
34
35#include <algorithm>
36
37namespace lal {
38namespace detail {
39
53template <typename iterator_t, typename value_t>
54[[nodiscard]] inline iterator_t find_sorted
55(
56 const iterator_t begin,
57 const iterator_t end,
58 const std::size_t size,
59 const value_t& v,
60 const std::size_t min_size = 64
61)
62noexcept
63{
64 return size < min_size ?
65 std::find(begin, end, v) :
66 std::lower_bound(begin, end, v);
67}
68
82template <typename iterator_t, typename value_t>
83[[nodiscard]] inline bool exists_sorted
84(
85 const iterator_t begin,
86 const iterator_t end,
87 const std::size_t size,
88 const value_t& v,
89 const std::size_t min_size = 64
90)
91noexcept
92{
93 return size < min_size ?
94 std::find(begin, end, v) != end :
95 std::binary_search(begin, end, v);
96}
97
98} // -- namespace lal
99} // -- namespace detail
bool exists_sorted(const iterator_t begin, const iterator_t end, const std::size_t size, const value_t &v, const std::size_t min_size=64) noexcept
Finds an element within the sorted range [begin, end).
Definition search.hpp:84
iterator_t find_sorted(const iterator_t begin, const iterator_t end, const std::size_t size, const value_t &v, const std::size_t min_size=64) noexcept
Finds an element within the sorted range [begin, end).
Definition search.hpp:55
Main namespace of the library.
Definition basic_types.hpp:48