mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-25 20:11:50 +02:00
Compare commits
10 Commits
boost-1.52
...
boost-1.53
Author | SHA1 | Date | |
---|---|---|---|
351e98bfef | |||
6e098b27aa | |||
60010b4165 | |||
1660dc9d48 | |||
5ae4f848b3 | |||
fe3e0bb9c4 | |||
311e169376 | |||
3dddfa1930 | |||
be6d8f9665 | |||
bced4ed8dd |
@ -14,7 +14,7 @@ http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
[heading Overview]
|
||||
|
||||
The header file 'boyer_moore.hpp' contains an an implementation of the Boyer-Moore algorithm for searching sequences of values.
|
||||
The header file 'boyer_moore.hpp' contains an implementation of the Boyer-Moore algorithm for searching sequences of values.
|
||||
|
||||
The Boyer–Moore string search algorithm is a particularly efficient string searching algorithm, and it has been the standard benchmark for the practical string search literature. The Boyer-Moore algorithm was invented by Bob Boyer and J. Strother Moore, and published in the October 1977 issue of the Communications of the ACM , and a copy of that article is available at [@http://www.cs.utexas.edu/~moore/publications/fstrpos.pdf].
|
||||
|
||||
@ -26,7 +26,7 @@ Nomenclature: I refer to the sequence being searched for as the "pattern", and t
|
||||
|
||||
[heading Interface]
|
||||
|
||||
For flexibility, the Boyer-Moore algorithm has has two interfaces; an object-based interface and a procedural one. The object-based interface builds the tables in the constructor, and uses operator () to perform the search. The procedural interface builds the table and does the search all in one step. If you are going to be searching for the same pattern in multiple corpora, then you should use the object interface, and only build the tables once.
|
||||
For flexibility, the Boyer-Moore algorithm has two interfaces; an object-based interface and a procedural one. The object-based interface builds the tables in the constructor, and uses operator () to perform the search. The procedural interface builds the table and does the search all in one step. If you are going to be searching for the same pattern in multiple corpora, then you should use the object interface, and only build the tables once.
|
||||
|
||||
Here is the object interface:
|
||||
``
|
||||
|
@ -14,7 +14,7 @@ http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
[heading Overview]
|
||||
|
||||
The header file 'boyer_moore_horspool.hpp' contains an an implementation of the Boyer-Moore-Horspool algorithm for searching sequences of values.
|
||||
The header file 'boyer_moore_horspool.hpp' contains an implementation of the Boyer-Moore-Horspool algorithm for searching sequences of values.
|
||||
|
||||
The Boyer-Moore-Horspool search algorithm was published by Nigel Horspool in 1980. It is a refinement of the Boyer-Moore algorithm that trades space for time. It uses less space for internal tables than Boyer-Moore, and has poorer worst-case performance.
|
||||
|
||||
@ -24,7 +24,7 @@ The Boyer-Moore-Horspool algorithm cannot be used with comparison predicates lik
|
||||
|
||||
Nomenclature: I refer to the sequence being searched for as the "pattern", and the sequence being searched in as the "corpus".
|
||||
|
||||
For flexibility, the Boyer-Moore-Horspool algorithm has has two interfaces; an object-based interface and a procedural one. The object-based interface builds the tables in the constructor, and uses operator () to perform the search. The procedural interface builds the table and does the search all in one step. If you are going to be searching for the same pattern in multiple corpora, then you should use the object interface, and only build the tables once.
|
||||
For flexibility, the Boyer-Moore-Horspool algorithm has two interfaces; an object-based interface and a procedural one. The object-based interface builds the tables in the constructor, and uses operator () to perform the search. The procedural interface builds the table and does the search all in one step. If you are going to be searching for the same pattern in multiple corpora, then you should use the object interface, and only build the tables once.
|
||||
|
||||
Here is the object interface:
|
||||
``
|
||||
|
@ -14,8 +14,69 @@ http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
[heading Overview]
|
||||
|
||||
The header file 'knuth_morris_pratt.hpp' contains an an implementation of the Knuth-Morris-Pratt algorithm for searching sequences of values.
|
||||
The header file 'knuth_morris_pratt.hpp' contains an implementation of the Knuth-Morris-Pratt algorithm for searching sequences of values.
|
||||
|
||||
The basic premise of the Knuth-Morris-Pratt algorithm is that when a mismatch occurs, there is information in the pattern being searched for that can be used to determine where the next match could begin, enabling the skipping of some elements of the corpus that have already been examined.
|
||||
|
||||
It does this by building a table from the pattern being searched for, with one entry for each element in the pattern.
|
||||
|
||||
The algorithm was conceived in 1974 by Donald Knuth and Vaughan Pratt, and independently by James H. Morris. The three published it jointly in 1977 in the SIAM Journal on Computing [@http://citeseer.ist.psu.edu/context/23820/0]
|
||||
|
||||
However, the Knuth-Morris-Pratt algorithm cannot be used with comparison predicates like `std::search`.
|
||||
|
||||
[heading Interface]
|
||||
|
||||
Nomenclature: I refer to the sequence being searched for as the "pattern", and the sequence being searched in as the "corpus".
|
||||
|
||||
For flexibility, the Knuth-Morris-Pratt algorithm has two interfaces; an object-based interface and a procedural one. The object-based interface builds the table in the constructor, and uses operator () to perform the search. The procedural interface builds the table and does the search all in one step. If you are going to be searching for the same pattern in multiple corpora, then you should use the object interface, and only build the tables once.
|
||||
|
||||
Here is the object interface:
|
||||
``
|
||||
template <typename patIter>
|
||||
class knuth_morris_pratt {
|
||||
public:
|
||||
knuth_morris_pratt ( patIter first, patIter last );
|
||||
~knuth_morris_pratt ();
|
||||
|
||||
template <typename corpusIter>
|
||||
corpusIter operator () ( corpusIter corpus_first, corpusIter corpus_last );
|
||||
};
|
||||
``
|
||||
|
||||
and here is the corresponding procedural interface:
|
||||
|
||||
``
|
||||
template <typename patIter, typename corpusIter>
|
||||
corpusIter knuth_morris_pratt_search (
|
||||
corpusIter corpus_first, corpusIter corpus_last,
|
||||
patIter pat_first, patIter pat_last );
|
||||
``
|
||||
|
||||
Each of the functions is passed two pairs of iterators. The first two define the corpus and the second two define the pattern. Note that the two pairs need not be of the same type, but they do need to "point" at the same type. In other words, `patIter::value_type` and `curpusIter::value_type` need to be the same type.
|
||||
|
||||
The return value of the function is an iterator pointing to the start of the pattern in the corpus. If the pattern is not found, it returns the end of the corpus (`corpus_last`).
|
||||
|
||||
[heading Performance]
|
||||
|
||||
The execution time of the Knuth-Morris-Pratt algorithm is linear in the size of the string being searched. Generally the algorithm gets faster as the pattern being searched for becomes longer. Its efficiency derives from the fact that with each unsuccessful attempt to find a match between the search string and the text it is searching, it uses the information gained from that attempt to rule out as many positions of the text as possible where the string cannot match.
|
||||
|
||||
[heading Memory Use]
|
||||
|
||||
The algorithm an that contains one entry for each element the pattern, plus one extra. So, when searching for a 1026 byte string, the table will have 1027 entries.
|
||||
|
||||
[heading Complexity]
|
||||
|
||||
The worst-case performance is ['O(2n)], where ['n] is the length of the corpus. The average time is ['O(n)]. The best case performance is sub-linear.
|
||||
|
||||
[heading Exception Safety]
|
||||
|
||||
Both the object-oriented and procedural versions of the Knuth-Morris-Pratt algorithm take their parameters by value and do not use any information other than what is passed in. Therefore, both interfaces provide the strong exception guarantee.
|
||||
|
||||
[heading Notes]
|
||||
|
||||
* When using the object-based interface, the pattern must remain unchanged for during the searches; i.e, from the time the object is constructed until the final call to operator () returns.
|
||||
|
||||
* The Knuth-Morris-Pratt algorithm requires random-access iterators for both the pattern and the corpus. It should be possible to write this to use bidirectional iterators (or possibly even forward ones), but this implementation does not do that.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
@ -73,7 +73,7 @@ Given the sequence `{ 1, 2, 3, 4, 5, 9 }`, `is_sorted_until ( beg, end, std::l
|
||||
|
||||
There are also a set of "wrapper functions" for is_ordered which make it easy to see if an entire sequence is ordered. These functions return a boolean indicating success or failure rather than an iterator to where the out of order items were found.
|
||||
|
||||
To test if a sequence is increasing (each element at least as large as the preceeding one):
|
||||
To test if a sequence is increasing (each element at least as large as the preceding one):
|
||||
``
|
||||
namespace boost { namespace algorithm {
|
||||
template <typename Iterator>
|
||||
@ -84,7 +84,7 @@ namespace boost { namespace algorithm {
|
||||
}}
|
||||
``
|
||||
|
||||
To test if a sequence is decreasing (each element no larger than the preceeding one):
|
||||
To test if a sequence is decreasing (each element no larger than the preceding one):
|
||||
|
||||
``
|
||||
namespace boost { namespace algorithm {
|
||||
@ -96,7 +96,7 @@ namespace boost { namespace algorithm {
|
||||
}}
|
||||
``
|
||||
|
||||
To test if a sequence is strictly increasing (each element larger than the preceeding one):
|
||||
To test if a sequence is strictly increasing (each element larger than the preceding one):
|
||||
``
|
||||
namespace boost { namespace algorithm {
|
||||
template <typename Iterator>
|
||||
@ -107,7 +107,7 @@ namespace boost { namespace algorithm {
|
||||
}}
|
||||
``
|
||||
|
||||
To test if a sequence is strictly decreasing (each element smaller than the preceeding one):
|
||||
To test if a sequence is strictly decreasing (each element smaller than the preceding one):
|
||||
``
|
||||
namespace boost { namespace algorithm {
|
||||
template <typename Iterator>
|
||||
|
@ -24,11 +24,11 @@ namespace boost { namespace algorithm {
|
||||
using std::is_partitioned; // Section 25.3.13
|
||||
#else
|
||||
/// \fn is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p )
|
||||
/// \brief Tests to see if a sequence is partititioned according to a predicate
|
||||
/// \brief Tests to see if a sequence is partitioned according to a predicate
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last One past the end of the input sequence
|
||||
/// \param p The predicicate to test the values with
|
||||
/// \param p The predicate to test the values with
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
/// We will use the standard one if it is available,
|
||||
/// otherwise we have our own implementation.
|
||||
@ -51,7 +51,7 @@ bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p
|
||||
/// \brief Generates an increasing sequence of values, and stores them in the input Range.
|
||||
///
|
||||
/// \param r The input range
|
||||
/// \param p The predicicate to test the values with
|
||||
/// \param p The predicate to test the values with
|
||||
///
|
||||
template <typename Range, typename UnaryPredicate>
|
||||
bool is_partitioned ( const Range &r, UnaryPredicate p )
|
||||
|
@ -99,8 +99,10 @@ namespace boost {
|
||||
|
||||
// if odd number of elements, treat last element
|
||||
if (first != last) { // odd number of elements
|
||||
if (comp(first, min_result))
|
||||
min_result = first, potential_min_result = last;
|
||||
if (comp(first, min_result)) {
|
||||
min_result = first;
|
||||
potential_min_result = last;
|
||||
}
|
||||
else if (comp(max_result, first))
|
||||
max_result = first;
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ References:
|
||||
http://www.cs.utexas.edu/users/moore/best-ideas/string-searching/
|
||||
http://www.cs.utexas.edu/~moore/publications/fstrpos.pdf
|
||||
|
||||
Explanations: boostinspect:noascii (test tool complains)
|
||||
http://en.wikipedia.org/wiki/Boyer–Moore_string_search_algorithm
|
||||
Explanations:
|
||||
http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm
|
||||
http://www.movsd.com/bm.htm
|
||||
http://www.cs.ucdavis.edu/~gusfield/cs224f09/bnotes.pdf
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace boost {
|
||||
// Copy the beginning of the sequence
|
||||
Output = std::copy( ::boost::begin(Input), ::boost::begin(M), Output );
|
||||
// Format find result
|
||||
// Copy formated result
|
||||
// Copy formatted result
|
||||
Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
|
||||
// Copy the rest of the sequence
|
||||
Output = std::copy( M.end(), ::boost::end(Input), Output );
|
||||
@ -118,11 +118,11 @@ namespace boost {
|
||||
|
||||
InputT Output;
|
||||
// Copy the beginning of the sequence
|
||||
insert( Output, ::boost::end(Output), ::boost::begin(Input), M.begin() );
|
||||
// Copy formated result
|
||||
insert( Output, ::boost::end(Output), M.format_result() );
|
||||
boost::algorithm::detail::insert( Output, ::boost::end(Output), ::boost::begin(Input), M.begin() );
|
||||
// Copy formatted result
|
||||
boost::algorithm::detail::insert( Output, ::boost::end(Output), M.format_result() );
|
||||
// Copy the rest of the sequence
|
||||
insert( Output, ::boost::end(Output), M.end(), ::boost::end(Input) );
|
||||
boost::algorithm::detail::insert( Output, ::boost::end(Output), M.end(), ::boost::end(Input) );
|
||||
|
||||
return Output;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace boost {
|
||||
{
|
||||
// Copy the beginning of the sequence
|
||||
Output = std::copy( LastMatch, M.begin(), Output );
|
||||
// Copy formated result
|
||||
// Copy formatted result
|
||||
Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
|
||||
|
||||
// Proceed to the next match
|
||||
@ -134,9 +134,9 @@ namespace boost {
|
||||
while( M )
|
||||
{
|
||||
// Copy the beginning of the sequence
|
||||
insert( Output, ::boost::end(Output), LastMatch, M.begin() );
|
||||
// Copy formated result
|
||||
insert( Output, ::boost::end(Output), M.format_result() );
|
||||
boost::algorithm::detail::insert( Output, ::boost::end(Output), LastMatch, M.begin() );
|
||||
// Copy formatted result
|
||||
boost::algorithm::detail::insert( Output, ::boost::end(Output), M.format_result() );
|
||||
|
||||
// Proceed to the next match
|
||||
LastMatch=M.end();
|
||||
@ -218,7 +218,7 @@ namespace boost {
|
||||
// Adjust search iterator
|
||||
SearchIt=M.end();
|
||||
|
||||
// Copy formated replace to the storage
|
||||
// Copy formatted replace to the storage
|
||||
::boost::algorithm::detail::copy_to_storage( Storage, M.format_result() );
|
||||
|
||||
// Find range for a next match
|
||||
|
@ -92,7 +92,7 @@ namespace boost {
|
||||
|
||||
// find last functor -----------------------------------------------//
|
||||
|
||||
// find the last match a subseqeunce in the sequence ( functor )
|
||||
// find the last match a subsequence in the sequence ( functor )
|
||||
/*
|
||||
Returns a pair <begin,end> marking the subsequence in the sequence.
|
||||
If the find fails, returns <End,End>
|
||||
|
@ -60,14 +60,14 @@ namespace boost {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Match result retrival
|
||||
// Match result retrieval
|
||||
const match_results_type& match_results() const
|
||||
{
|
||||
return m_MatchResults;
|
||||
}
|
||||
|
||||
private:
|
||||
// Saved matchresult
|
||||
// Saved match result
|
||||
match_results_type m_MatchResults;
|
||||
};
|
||||
|
||||
|
@ -86,7 +86,7 @@ namespace boost {
|
||||
|
||||
//! Find first algorithm ( case insensitive )
|
||||
/*!
|
||||
Search for the first occurence of the substring in the input.
|
||||
Search for the first occurrence of the substring in the input.
|
||||
Searching is case insensitive.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
@ -293,7 +293,7 @@ namespace boost {
|
||||
If the "token compress mode" is enabled, adjacent tokens are considered to be one match.
|
||||
|
||||
\param Input A input string.
|
||||
\param Pred An unary predicate to identify a token
|
||||
\param Pred A unary predicate to identify a token
|
||||
\param eCompress Enable/Disable compressing of adjacent tokens
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
|
@ -132,7 +132,10 @@ namespace boost {
|
||||
// increment
|
||||
void increment()
|
||||
{
|
||||
m_Match=this->do_find(m_Match.end(),m_End);
|
||||
if(m_Match.begin() == m_Match.end())
|
||||
m_Match=this->do_find(m_Match.end(),m_End);
|
||||
else
|
||||
m_Match=this->do_find(m_Match.begin()+1,m_End);
|
||||
}
|
||||
|
||||
// comparison
|
||||
|
@ -39,7 +39,7 @@ namespace boost {
|
||||
Constructs a \c const_formatter. Const formatter always returns
|
||||
the same value, regardless of the parameter.
|
||||
|
||||
\param Format A predefined value used as a result for formating
|
||||
\param Format A predefined value used as a result for formatting
|
||||
\return An instance of the \c const_formatter object.
|
||||
*/
|
||||
template<typename RangeT>
|
||||
@ -95,7 +95,7 @@ namespace boost {
|
||||
to extract a portion of the formatted sequence. The first finder's match is returned
|
||||
as a result
|
||||
|
||||
\param Finder a finder used to select a portion of the formated sequence
|
||||
\param Finder a finder used to select a portion of the formatted sequence
|
||||
\return An instance of the \c dissect_formatter object.
|
||||
*/
|
||||
template<typename FinderT>
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
/*
|
||||
\file boost/algorith/string/predicate_facade.hpp
|
||||
This file containes predicate_facade definition. This template class is used
|
||||
This file contains predicate_facade definition. This template class is used
|
||||
to identify classification predicates, so they can be combined using
|
||||
composition operators.
|
||||
*/
|
||||
|
@ -32,7 +32,7 @@ namespace boost {
|
||||
Construct the \c regex_finder. Finder uses the regex engine to search
|
||||
for a match.
|
||||
Result is given in \c regex_search_result. This is an extension
|
||||
of the iterator_range. In addition it containes match results
|
||||
of the iterator_range. In addition it contains match results
|
||||
from the \c regex_search algorithm.
|
||||
|
||||
\param Rx A regular expression
|
||||
|
@ -50,7 +50,7 @@ namespace boost {
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input range
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
\return
|
||||
An output iterator pointing just after the last inserted character or
|
||||
a copy of the input
|
||||
@ -118,7 +118,7 @@ namespace boost {
|
||||
The input sequence is modified in-place.
|
||||
|
||||
\param Input An input sequence
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
*/
|
||||
template<typename SequenceT, typename PredicateT>
|
||||
inline void trim_left_if(SequenceT& Input, PredicateT IsSpace)
|
||||
@ -158,7 +158,7 @@ namespace boost {
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input range
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
\return
|
||||
An output iterator pointing just after the last inserted character or
|
||||
a copy of the input
|
||||
@ -228,7 +228,7 @@ namespace boost {
|
||||
The input sequence is modified in-place.
|
||||
|
||||
\param Input An input sequence
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
*/
|
||||
template<typename SequenceT, typename PredicateT>
|
||||
inline void trim_right_if(SequenceT& Input, PredicateT IsSpace)
|
||||
@ -270,7 +270,7 @@ namespace boost {
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input range
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
\return
|
||||
An output iterator pointing just after the last inserted character or
|
||||
a copy of the input
|
||||
@ -352,7 +352,7 @@ namespace boost {
|
||||
The input sequence is modified in-place.
|
||||
|
||||
\param Input An input sequence
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
*/
|
||||
template<typename SequenceT, typename PredicateT>
|
||||
inline void trim_if(SequenceT& Input, PredicateT IsSpace)
|
||||
|
@ -49,7 +49,7 @@ namespace boost {
|
||||
The result is a trimmed copy of the input
|
||||
|
||||
\param Input An input sequence
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
\return A trimmed copy of the input
|
||||
*/
|
||||
template<typename SequenceT, typename PredicateT>
|
||||
@ -70,7 +70,7 @@ namespace boost {
|
||||
The input sequence is modified in-place.
|
||||
|
||||
\param Input An input sequence
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
*/
|
||||
template<typename SequenceT, typename PredicateT>
|
||||
inline void trim_all_if(SequenceT& Input, PredicateT IsSpace)
|
||||
@ -126,7 +126,7 @@ namespace boost {
|
||||
|
||||
\param Input An input sequence
|
||||
\param Fill A string used to fill the inner spaces
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
\return A trimmed copy of the input
|
||||
*/
|
||||
template<typename SequenceT, typename RangeT, typename PredicateT>
|
||||
@ -149,7 +149,7 @@ namespace boost {
|
||||
|
||||
\param Input An input sequence
|
||||
\param Fill A string used to fill the inner spaces
|
||||
\param IsSpace An unary predicate identifying spaces
|
||||
\param IsSpace A unary predicate identifying spaces
|
||||
*/
|
||||
template<typename SequenceT, typename RangeT, typename PredicateT>
|
||||
inline void trim_fill_if(SequenceT& Input, const RangeT& Fill, PredicateT IsSpace)
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
/*! \file
|
||||
Cumulative include for string_algo library.
|
||||
In addtion to string.hpp contains also regex-related stuff.
|
||||
In addition to string.hpp contains also regex-related stuff.
|
||||
*/
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
@ -350,7 +350,7 @@ separation into two header files.</p>
|
||||
std::max.</b></h4>
|
||||
<p>I am aware of the problems with std::min and
|
||||
std::max, and all the debate that has been going on (please consult
|
||||
<a href="http://www.cuj.com/documents/s=7996/cujcexp1904alexandr/alexandr.htm">Alexandrescu's paper</a> and the links therein). But I don't see the purpose of this
|
||||
<a href="#Alexandrescu">Alexandrescu's paper</a> and the links therein). But I don't see the purpose of this
|
||||
library as fixing something that is part of the C++ standard. I humbly
|
||||
think it's beyond the scope of this library. Rather, I am
|
||||
following the way of the standard in simply providing one more function
|
||||
@ -485,7 +485,12 @@ to keep it like this.
|
||||
<a name="acks">
|
||||
<h3>
|
||||
Acknowledgements</h3>
|
||||
My students in CS903 (Polytechnic Univ., <a href="http://photon.poly.edu/~hbr/cs903/">http://photon.poly.edu/~hbr/cs903/</a>)
|
||||
|
||||
<a name="Alexandrescu">
|
||||
<a href="http://www.drdobbs.com/generic-min-and-max-redivivus/184403774">Generic: Min and Max Redivivus, by Andrei Alexandrescu</a>
|
||||
Dr. Dobbs, April 2001
|
||||
|
||||
<p>My students in CS903 (Polytechnic Univ., <a href="http://photon.poly.edu/~hbr/cs903/">http://photon.poly.edu/~hbr/cs903/</a>)
|
||||
who had <tt>minmax_element</tt> as an assignment helped clarify the issues,
|
||||
and also come up with the optimum number of comparisons for <tt>first_min_last_max_element</tt>.
|
||||
The identification of the issue surrounding <tt>max_element</tt> is solely
|
||||
@ -516,7 +521,7 @@ Comparable</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/nth_element.html">nth_element</a></tt>
|
||||
.
|
||||
<hr SIZE="6">
|
||||
<br>Last modified 2004-07-01
|
||||
<br>Last modified 2012-12-10
|
||||
<p><font face="Arial,Helvetica"><font size=-1>© Copyright Hervé
|
||||
Brönnimann, Polytechnic University, 2002--2004.
|
||||
Use, modification, and distribution is subject to the Boost Software
|
||||
|
@ -162,8 +162,8 @@ boost::iterator_range<std::string> simple_finder(
|
||||
|
||||
<para>
|
||||
Similarly to finders, formatters generalize format operations. When a finder is used to
|
||||
select a part of the input, formatter takes this selection and performs some formating
|
||||
on it. Algorithms can abstract from formating using a formatter.
|
||||
select a part of the input, formatter takes this selection and performs some formatting
|
||||
on it. Algorithms can abstract from formatting using a formatter.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis role="bold">Examples</emphasis>
|
||||
@ -171,7 +171,7 @@ boost::iterator_range<std::string> simple_finder(
|
||||
<para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
Formatter implemented as a class. This Formatter does not perform any formating and
|
||||
Formatter implemented as a class. This Formatter does not perform any formatting and
|
||||
returns the match, repackaged. <code>operator()</code>
|
||||
is templated, so that the Formatter can be used on any Finder type.
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
New comparison predicates <code>is_less</code>, <code>is_not_greater</code>
|
||||
</listitem>
|
||||
<listitem>
|
||||
Negative indexes support (like Perl) in various algorihtms
|
||||
Negative indexes support (like Perl) in various algorithms
|
||||
(<code>*_head/tail</code>, <code>*_nth</code>).
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
@ -33,7 +33,7 @@ int main()
|
||||
cout << "str1 ends with \"123\": " <<
|
||||
(ends_with( str1, string("123") )?"true":"false") << endl;
|
||||
|
||||
// Check if str1 containes 'xxx'
|
||||
// Check if str1 contains 'xxx'
|
||||
cout << "str1 contains \"xxx\": " <<
|
||||
(contains( str1, string("xxx") )?"true":"false") << endl;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <boost/algorithm/string/find.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
||||
// Include unit test framework
|
||||
#include <boost/test/included/test_exec_monitor.hpp>
|
||||
@ -248,6 +249,20 @@ void find_test()
|
||||
ostringstream osstr;
|
||||
osstr << find_first( str1, "abc" );
|
||||
BOOST_CHECK( osstr.str()=="abc" );
|
||||
|
||||
// Empty string test
|
||||
BOOST_CHECKPOINT( "overlapping" );
|
||||
|
||||
std::string overlap_target("aaaa");
|
||||
std::vector<boost::iterator_range<std::string::iterator> > overlap_results;
|
||||
boost::algorithm::find_all(overlap_results, overlap_target, string("aaa"));
|
||||
BOOST_CHECK( overlap_results.size() == 2 );
|
||||
|
||||
std::string overlap_target2("aaaabbbbaaaa");
|
||||
boost::algorithm::find_all(overlap_results, overlap_target2, string("bb"));
|
||||
BOOST_CHECK( overlap_results.size() == 3 );
|
||||
boost::algorithm::find_all(overlap_results, overlap_target2, string("aa"));
|
||||
BOOST_CHECK( overlap_results.size() == 6 );
|
||||
}
|
||||
|
||||
// test main
|
||||
|
@ -114,7 +114,7 @@ static void replace_test()
|
||||
string fmt2("_xXx_");
|
||||
vector<int> vec1( str1.begin(), str1.end() );
|
||||
|
||||
// inmutable tests
|
||||
// immutable tests
|
||||
|
||||
// basic tests
|
||||
BOOST_CHECK( replace_regex_copy( str1, rx1, fmt1 )==string("123_A1C_xxxa23cXXXa456c321") );
|
||||
|
@ -144,18 +144,35 @@ void iterator_test()
|
||||
|
||||
|
||||
find_iterator<string::iterator> fiter=make_find_iterator(str1, first_finder("xx"));
|
||||
find_iterator<string::iterator> fiter2;
|
||||
|
||||
BOOST_CHECK(equals(*fiter, "xx"));
|
||||
++fiter;
|
||||
BOOST_CHECK(equals(*fiter, "xx"));
|
||||
|
||||
fiter2 = fiter;
|
||||
BOOST_CHECK(equals(*fiter, "xx"));
|
||||
BOOST_CHECK(equals(*fiter2, "xx"));
|
||||
|
||||
++fiter;
|
||||
BOOST_CHECK(fiter==find_iterator<string::iterator>());
|
||||
BOOST_CHECK(equals(*fiter2, "xx"));
|
||||
|
||||
++fiter2;
|
||||
BOOST_CHECK(fiter2==find_iterator<string::iterator>());
|
||||
|
||||
split_iterator<string::iterator> siter=make_split_iterator(str1, token_finder(is_any_of("-"), token_compress_on));
|
||||
split_iterator<string::iterator> siter2;
|
||||
BOOST_CHECK(equals(*siter, "xx"));
|
||||
++siter;
|
||||
BOOST_CHECK(equals(*siter, "abc"));
|
||||
|
||||
siter2 = siter;
|
||||
BOOST_CHECK(equals(*siter, "abc"));
|
||||
BOOST_CHECK(equals(*siter2, "abc"));
|
||||
|
||||
++siter;
|
||||
BOOST_CHECK(equals(*siter, "xx"));
|
||||
BOOST_CHECK(equals(*siter, "xx"));
|
||||
BOOST_CHECK(equals(*siter2, "abc"));
|
||||
|
||||
++siter;
|
||||
BOOST_CHECK(equals(*siter, "abb"));
|
||||
++siter;
|
||||
|
@ -42,7 +42,7 @@ void test_sequence ( Container const &c ) {
|
||||
ba::copy_if ( c, back_inserter ( v ), is_false);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
|
||||
// All the elements
|
||||
// All the elements
|
||||
v.clear ();
|
||||
ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_true);
|
||||
BOOST_CHECK ( v.size () == c.size ());
|
||||
@ -54,7 +54,7 @@ void test_sequence ( Container const &c ) {
|
||||
BOOST_CHECK ( v.size () == c.size ());
|
||||
BOOST_CHECK ( std::equal ( c.begin (), c.end (), v.begin ()));
|
||||
|
||||
// Some of the elements
|
||||
// Some of the elements
|
||||
v.clear ();
|
||||
ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_even );
|
||||
BOOST_CHECK ( v.size () == std::count_if ( c.begin (), c.end (), is_even ));
|
||||
|
@ -129,7 +129,7 @@ void test_nonhex_input4 () {
|
||||
}
|
||||
|
||||
void test_nonhex_input () {
|
||||
// BOOST_TEST_MESSAGE ( "Non hex input tests for for boost::algorithm::unhex" );
|
||||
// BOOST_TEST_MESSAGE ( "Non hex input tests for boost::algorithm::unhex" );
|
||||
test_nonhex_input1 ();
|
||||
test_nonhex_input2 ();
|
||||
test_nonhex_input3 ();
|
||||
|
Reference in New Issue
Block a user