|
Boost-Commit : |
From: chintanraoh_at_[hidden]
Date: 2008-08-13 11:41:22
Author: chintanraoh
Date: 2008-08-13 11:41:22 EDT (Wed, 13 Aug 2008)
New Revision: 48125
URL: http://svn.boost.org/trac/boost/changeset/48125
Log:
Added prefix search to example
Text files modified:
sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/example/classroom.cpp | 39 ++++++++++++++++++++++++++++++++++++---
1 files changed, 36 insertions(+), 3 deletions(-)
Modified: sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/example/classroom.cpp
==============================================================================
--- sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/example/classroom.cpp (original)
+++ sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/example/classroom.cpp 2008-08-13 11:41:22 EDT (Wed, 13 Aug 2008)
@@ -1,16 +1,27 @@
#include<boost/dsearch/patricia.hpp>
#include<boost/dsearch/pat_key_traits.hpp>
#include<iostream>
+#include<algorithm>
#include<string>
using boost::dsearch::patricia;
using boost::dsearch::pat_string_traits;
+template<class T>
+void print_range(T begin,T end)
+{
+ for(T it=begin; it!=end; ++it)
+ std::cout<<(*it).first<<" Roll No: "<<(*it).second<<std::endl;
+ std::cout<<std::endl;
+}
+
int main(int argc, char** argv)
{
typedef patricia<std::string,std::string,pat_string_traits> pat_type;
pat_type classroom;
typedef pat_type::iterator iterator;
+ std::pair<iterator,iterator> prefix_pair;
+ iterator found_it;
classroom [ "Anirudh Santhiar" ] = "05co06";
classroom [ "Anup C Shan" ] = "05co11";
@@ -18,10 +29,32 @@
classroom [ "Bharath Ravi" ] = "05co48";
classroom [ "Bala Subramanyam" ] = "05co18";
classroom [ "S Devika Nair" ] = "05co54";
- classroom [ "Mahima A S"] = "05co35";
+ classroom [ "S A Mahima"] = "05co35";
+
+ std::cout << "all of them" <<std::endl;
+ print_range ( classroom.begin() , classroom.end() );
+
+ prefix_pair=classroom.prefix_range("A");
+ std::cout << "names which begin with A" <<std::endl;
+ print_range ( prefix_pair.first , prefix_pair.second );
+
+ prefix_pair=classroom.prefix_range("B");
+ std::cout << "names which begin with B" <<std::endl;
+ print_range ( prefix_pair.first , prefix_pair.second );
+
+ prefix_pair=classroom.prefix_range("S ");
+ std::cout << "names which begin with 'S '"<<std::endl;
+ print_range ( prefix_pair.first , prefix_pair.second );
+
+ classroom.erase ( "Bala Subramanyam" );
- for(iterator it=classroom.begin(); it!=classroom.end(); ++it)
- std::cout<<(*it).first<<"-->"<<(*it).second<<std::endl;
+ classroom.insert ( std::make_pair(std::string("Chimpanzee" ),std::string("05co19" ) ) );
+ found_it=classroom.find("Chimpanzee");
+ std::cout<<(*found_it).first<<" Roll No: "<<(*found_it).second<<std::endl<<std::endl;
+
+ std::cout << "all of them" <<std::endl;
+ print_range ( classroom.begin() , classroom.end() );
+
return 0;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk