|
Boost-Commit : |
From: chintanraoh_at_[hidden]
Date: 2008-06-19 13:52:06
Author: chintanraoh
Date: 2008-06-19 13:52:06 EDT (Thu, 19 Jun 2008)
New Revision: 46529
URL: http://svn.boost.org/trac/boost/changeset/46529
Log:
size(), rbegin(), rend(), erase(iterator), iterator find() for patricia.
Text files modified:
sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_pat_trie.cpp | 152 +++++++++++++++++++++++----------------
1 files changed, 88 insertions(+), 64 deletions(-)
Modified: sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_pat_trie.cpp
==============================================================================
--- sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_pat_trie.cpp (original)
+++ sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_pat_trie.cpp 2008-06-19 13:52:06 EDT (Thu, 19 Jun 2008)
@@ -6,58 +6,77 @@
#include<algorithm>
using namespace boost::dsearch;
using namespace boost::minimal_test;
+template<class T>
+void print_pat(const T &pat)
+{
+ typename T::const_iterator it;
+ for ( it=pat.begin(); it!=pat.end(); it++ )
+ {
+ std::cout<<(*it).first<<" "<<(*it).second<<std::endl;
+ }
+}
template<class T>
void insert_test_1()
{
T pat;
- //BOOST_CHECK ( pat.find("") == 0 ) ;
+ BOOST_CHECK ( pat.exists("") == 0 ) ;
pat.insert ( std::make_pair("",1) );
- BOOST_CHECK ( pat.find("") );
+ BOOST_CHECK ( pat.exists("") );
pat.insert ( std::make_pair("raining",1) );
- BOOST_CHECK ( pat.find("raining") );
+ BOOST_CHECK ( pat.exists("raining") );
- //BOOST_CHECK ( pat.find("weather") == 0 );
- //BOOST_CHECK ( pat.find("rain") == 0 );
+ BOOST_CHECK ( pat.exists("weather") == 0 );
+ BOOST_CHECK ( pat.exists("rain") == 0 );
pat.insert ( std::make_pair("rain",1) );
- BOOST_CHECK ( pat.find("rain") );
- BOOST_CHECK ( pat.find("") );
+ BOOST_CHECK ( pat.exists("rain") );
+ BOOST_CHECK ( pat.exists("") );
pat.insert ( std::make_pair("raina",1) );
- BOOST_CHECK ( pat.find("raina") );
- BOOST_CHECK ( pat.find("rain") );
+ BOOST_CHECK ( pat.exists("raina") );
+ BOOST_CHECK ( pat.exists("rain") );
pat.insert ( std::make_pair("weather",1) );
- BOOST_CHECK ( pat.find("weather") );
- BOOST_CHECK ( pat.find("rain") );
- BOOST_CHECK ( pat.find("raining") );
+ BOOST_CHECK ( pat.exists("weather") );
+ BOOST_CHECK ( pat.exists("rain") );
+ BOOST_CHECK ( pat.exists("raining") );
pat.insert ( std::make_pair("weat",1) );
- BOOST_CHECK ( pat.find("weat") );
+ BOOST_CHECK ( pat.exists("weat") );
pat.insert ( std::make_pair("weating",1) );
- BOOST_CHECK ( pat.find("weating") );
+ BOOST_CHECK ( pat.exists("weating") );
- BOOST_CHECK ( pat.find("weather") );
- BOOST_CHECK ( pat.find("rain") );
- BOOST_CHECK ( pat.find("raining") );
- BOOST_CHECK ( pat.find("raina") );
- BOOST_CHECK ( pat.find("weat") );
- BOOST_CHECK ( pat.find("") );
+ BOOST_CHECK ( pat.exists("weather") );
+ BOOST_CHECK ( pat.exists("rain") );
+ BOOST_CHECK ( pat.exists("raining") );
+ BOOST_CHECK ( pat.exists("raina") );
+ BOOST_CHECK ( pat.exists("weat") );
+ BOOST_CHECK ( pat.exists("") );
T pat1(pat);
std::cout<<"PAT 1"<<std::endl;
- typename T::iterator it;
+ typename T::iterator it,it_1;
int i=0;
for(it=pat1.begin();it!=pat1.end();it++)
{
i++;
std::cout<<(*it).first<<std::endl;
}
+ BOOST_REQUIRE ( pat1 == pat );
+ pat1["wet"]=10;
+ BOOST_REQUIRE ( !(pat1 == pat) );
+ pat1.erase("wet");
+ //std::cout<<"SIZE: "<<pat1.size()<<std::endl;
+ for(it=pat1.begin();it!=pat1.end();it++)
+ {
+ std::cout<<(*it).first<<std::endl;
+ }
+ BOOST_REQUIRE ( pat1 == pat );
std::cout<<"END PAT 1"<<std::endl;
}
@@ -140,12 +159,12 @@
BOOST_CHECK((*++it).first == "wicked" );
BOOST_CHECK( ++it == pat.end() );
- BOOST_CHECK( pat.find("") );
- BOOST_CHECK( pat.find("bad") );
- BOOST_CHECK( pat.find("hello") );
- BOOST_CHECK( pat.find("h") );
- BOOST_CHECK( pat.find("wicked") );
- BOOST_CHECK( pat.find("we") );
+ BOOST_CHECK( pat.exists("") );
+ BOOST_CHECK( pat.exists("bad") );
+ BOOST_CHECK( pat.exists("hello") );
+ BOOST_CHECK( pat.exists("h") );
+ BOOST_CHECK( pat.exists("wicked") );
+ BOOST_CHECK( pat.exists("we") );
// 4<<h 6<< hell 10<< hello 8<< bad 2<< wicked 12<< we 14
@@ -154,7 +173,7 @@
int data[]= { 4, 2 , 6, 10, 8, 14, 12 };
it=pat.begin();
- int pos=0;
+ std::size_t pos=0;
for(it=pat.begin();it!=pat.end();++it)
{
BOOST_CHECK ( (*it).first.compare( std::string((char *)key[pos]) ) == 0 );
@@ -162,6 +181,8 @@
std::cout<<(*it).first<<"==="<<(*it).second<<std::endl;
++pos;
}
+ std::cout<<pat.size()<<std::endl;
+ BOOST_REQUIRE(pat.size() == pos );
}
template<class T>
@@ -175,51 +196,54 @@
pat[""]=2;
pat["a"]=3;
- BOOST_CHECK( pat.find("") );
- BOOST_CHECK( pat.find("a") );
+ BOOST_CHECK( pat.exists("") );
+ BOOST_CHECK( pat.exists("a") );
pat.erase("a");
- BOOST_CHECK( !pat.find("a") );
- BOOST_CHECK( pat.find("") );
+ BOOST_CHECK( !pat.exists("a") );
+ BOOST_CHECK( pat.exists("") );
pat["c"]=4;
- BOOST_CHECK( pat.find("c") );
+ BOOST_CHECK( pat.exists("c") );
pat["cool"]=5;
- BOOST_CHECK( pat.find("cool") );
- BOOST_CHECK( pat.find("c") );
+ BOOST_CHECK( pat.exists("cool") );
+ BOOST_CHECK( pat.exists("c") );
pat.erase("cool");
- BOOST_CHECK( !pat.find("cool") );
- BOOST_CHECK( pat.find("c") );
- BOOST_CHECK( pat.find("") );
+ BOOST_CHECK( !pat.exists("cool") );
+ BOOST_CHECK( pat.exists("c") );
+ BOOST_CHECK( pat.exists("") );
pat["cool"]=6;
pat["chess"]=7;
pat["cheese"]=8;
- BOOST_CHECK( pat.find("c") );
- BOOST_CHECK( pat.find("chess") );
- BOOST_CHECK( pat.find("cheese") );
- BOOST_CHECK( pat.find("") );
+ BOOST_CHECK( pat.exists("c") );
+ BOOST_CHECK( pat.exists("chess") );
+ BOOST_CHECK( pat.exists("cheese") );
+ BOOST_CHECK( pat.exists("") );
pat.erase("chess");
- BOOST_CHECK( pat.find("c") );
- BOOST_CHECK( pat.find("cool") );
- BOOST_CHECK( pat.find("cheese") );
- BOOST_CHECK( pat.find("") );
+ BOOST_CHECK( pat.exists("c") );
+ BOOST_CHECK( pat.exists("cool") );
+ BOOST_CHECK( pat.exists("cheese") );
+ BOOST_CHECK( pat.exists("") );
+
+ print_pat(pat);
+ BOOST_REQUIRE( pat.size()==4 );
pat.erase("cool");
- BOOST_CHECK( pat.find("c") );
- BOOST_CHECK( pat.find("cheese") );
- BOOST_CHECK( pat.find("") );
+ BOOST_CHECK( pat.exists("c") );
+ BOOST_CHECK( pat.exists("cheese") );
+ BOOST_CHECK( pat.exists("") );
pat.erase("c");
- BOOST_CHECK( pat.find("") );
- BOOST_CHECK( pat.find("cheese") );
+ BOOST_CHECK( pat.exists("") );
+ BOOST_CHECK( pat.exists("cheese") );
pat.erase("");
- BOOST_CHECK( pat.find("cheese") );
+ BOOST_CHECK( pat.exists("cheese") );
pat.erase("cheese");
BOOST_CHECK( pat.empty() );
@@ -229,24 +253,25 @@
pat["wheat"]=11;
pat["wheats"]=12;
pat["what"]=13;
- BOOST_CHECK( pat.find("weather") );
- BOOST_CHECK( pat.find("wheat") );
- BOOST_CHECK( pat.find("wheats") );
- BOOST_CHECK( pat.find("what") );
+ BOOST_CHECK( pat.exists("weather") );
+ BOOST_CHECK( pat.exists("wheat") );
+ BOOST_CHECK( pat.exists("wheats") );
+ BOOST_CHECK( pat.exists("what") );
pat.erase("wheats");
- BOOST_CHECK( pat.find("weather") );
- BOOST_CHECK( pat.find("wheat") );
- BOOST_CHECK( pat.find("what") );
+ BOOST_CHECK( pat.exists("weather") );
+ BOOST_CHECK( pat.exists("wheat") );
+ BOOST_CHECK( pat.exists("what") );
+ //print_pat(pat);
pat.erase("wheat");
- BOOST_CHECK( pat.find("weather") );
- BOOST_CHECK( pat.find("what") );
+ BOOST_CHECK( pat.exists("weather") );
+ BOOST_CHECK( pat.exists("what") );
pat.erase("what");
- BOOST_CHECK( pat.find("weather") );
+ BOOST_CHECK( pat.exists("weather") );
BOOST_CHECK(!pat.empty());
pat.erase("weather");
@@ -307,7 +332,7 @@
fin.getline(str,999);
//std::cout<<str<<std::endl;
//pat.insert(std::make_pair( (const char *)str, value ) );
- BOOST_CHECK( pat.find( (const char *)str ) ) ;
+ BOOST_CHECK( pat.exists( (const char *)str ) ) ;
value++;
}
fin.close();
@@ -341,4 +366,3 @@
insert_test_3<pat_type>(argv[1]);
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