Created
April 6, 2012 21:19
-
-
Save bwiklak/2323041 to your computer and use it in GitHub Desktop.
RLE encoding in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template< typename C > | |
string rle( const C& input ) | |
{ | |
stringstream out; | |
typedef C::const_iterator::value_type el_tyle; | |
pair<C::const_iterator,C::const_iterator> bounds; | |
bounds.second=input.begin(); | |
while( (bounds.first=bounds.second)!=input.end() ) | |
{ | |
bounds.second=find_if( | |
bounds.first, input.end(), | |
bind1st(not_equal_to<el_tyle>(), *bounds.first) | |
); | |
out << distance(bounds.first,bounds.second) << *bounds.first; | |
} | |
return out.str(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment