$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: [boost] [range] Check if one sequence is a rotation of other sequence.
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-04-27 17:51:54
Hi I want to define a function is_rotation that check if a sequence is a rotation of another using the following algorithm:
a.. First make sure s1 and s2 are of the same length.
b.. Check to see if s2 is a substring of s1 concatenated with s1.
I have started to implement this using boost range, using the join view to avoid the phisical concatenation but I'm not sure that testing 'boost::search(boost::join(s1,s1), s2) != end(boost::join(s1,s1))' is the best way to do with Boost.Range.
bool is_rotation(std::string const &s1,std::string const &s2) {
return (boost::size(s1) == boost::size(s2)) &&
boost::search(boost::join(s1,s1), s2) != end(boost::join(s1,s1)));
}
Sugestion for improvement?
Best regards,
_____________________
Vicente Juan Botet Escribá
http://viboes.blogspot.com/