ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BinarySearch.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File BinarySearch.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
54/*--------------------------------------------------------------------------*/
55/*----------------------------- DEFINITIONS --------------------------------*/
56/*--------------------------------------------------------------------------*/
57
58#ifndef __ADS_BinarySearch
59 #define __ADS_BinarySearch
60/* self-identification: #endif constant */
61
62/*--------------------------------------------------------------------------*/
63/*------------------------------ INCLUDES ----------------------------------*/
64/*--------------------------------------------------------------------------*/
65
66#include "ADS/Contract.h"
67#include "ADS/sort/Sorted.h"
68#include "ADS/tree/BinaryTree.h"
69
70#include <algorithm>
71#include <cstddef>
72#include <functional>
73#include <vector>
74
75/*--------------------------------------------------------------------------*/
76/*--------------------------- NAMESPACE ------------------------------------*/
77/*--------------------------------------------------------------------------*/
78
79namespace ADS
80{
81
102template< class T , class F >
103long binarySearch( const std::vector< T > & A , const T & v , F && trace );
104
106template< class T >
107long binarySearch( const std::vector< T > & A , const T & v );
108
130template< class T >
131BinaryTree< T > * decisionTree( const std::vector< T > & A );
132
156template< class T , class C = std::less<> >
157std::size_t lowerBound( const std::vector< T > & A , const T & v ,
158 std::size_t lo , std::size_t hi , C less = C() );
159
162template< class T , class C = std::less<> >
163std::size_t lowerBound( const std::vector< T > & A , const T & v ,
164 C less = C() );
165
185template< class T , class C = std::less<> >
186std::size_t upperBound( const std::vector< T > & A , const T & v ,
187 C less = C() );
188
212template< class T , class C = std::less<> >
213std::size_t gallopSearch( const std::vector< T > & A , const T & v ,
214 C less = C() );
215
216/*--------------------------------------------------------------------------*/
217
218} // end( namespace ADS )
219
220/*--------------------------------------------------------------------------*/
221/*-------------------------- IMPLEMENTATION --------------------------------*/
222/*--------------------------------------------------------------------------*/
223
224#include "ADS/search/impl/BinarySearch.tpp"
225
226/*--------------------------------------------------------------------------*/
227
228#endif /* BinarySearch.h included */
229
230/*--------------------------------------------------------------------------*/
231/*------------------------ End File BinarySearch.h -------------------------*/
232/*--------------------------------------------------------------------------*/
The binary TREE of the book: an ordered tree where each node has at most two children,...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
a binary tree with pointers to the parent and to the two children
Definition BinaryTree.h:104
BinaryTree< T > * decisionTree(const std::vector< T > &A)
the decision tree of binarySearch() on , nil if is empty; the caller owns it
long binarySearch(const std::vector< T > &A, const T &v, F &&trace)
the place of in the sorted , or -1; trace( i , j , m ) on each call that examines
std::size_t upperBound(const std::vector< T > &A, const T &v, C less=C())
the first place of an item larger than , if none
std::size_t gallopSearch(const std::vector< T > &A, const T &v, C less=C())
the first place of an item not smaller than , found by looking at the places and then by a binary s...
std::size_t lowerBound(const std::vector< T > &A, const T &v, std::size_t lo, std::size_t hi, C less=C())
the first place in of an item not smaller than , if none
Definition ADT.h:96