|
Boost-Commit : |
From: chintanraoh_at_[hidden]
Date: 2008-06-02 15:22:51
Author: chintanraoh
Date: 2008-06-02 15:22:50 EDT (Mon, 02 Jun 2008)
New Revision: 46053
URL: http://svn.boost.org/trac/boost/changeset/46053
Log:
changed return type of find(const key_type &) from bool to iterator
Text files modified:
sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/trie.hpp | 50 +++++++++++++++++++++++++++++++--------
1 files changed, 39 insertions(+), 11 deletions(-)
Modified: sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/trie.hpp
==============================================================================
--- sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/trie.hpp (original)
+++ sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/trie.hpp 2008-06-02 15:22:50 EDT (Mon, 02 Jun 2008)
@@ -8,6 +8,7 @@
#include<assert.h>
#include<boost/dsearch/node_cursor.hpp>
#include<boost/dsearch/trie_iterator.hpp>
+#include<vector>
namespace boost{
namespace dsearch{
@@ -44,6 +45,8 @@
typedef trie_cursor<key_type,data_type,node_type> cursor;
typedef trie_iterator<key_type,data_type,cursor> iterator;
+// typedef trie_cursor<key_type,data_type,node_type> cursor;
+ typedef trie_iterator<key_type,const data_type,cursor> const_iterator;
trie()
{
@@ -130,26 +133,31 @@
node_allocator.deallocate(cur,1);
}
- bool find(const key_type &key) const //make this iterator instead of bool;
+ iterator find(const key_type &key) const //make this iterator instead of bool;
{
typename Key_traits::const_iterator it=Key_traits::begin(key),
end_it=Key_traits::end(key);
- typename node_type::iterator fit;
- node_type *cur=node_root;
+ std::vector<cursor> cur_st;
+ cursor cur,next;
+ cur=root();
while(!(it==end_it))
{
- fit=cur->find(*it);
- if(fit == cur->end() ) return false;
- cur=*fit;
+ cur_st.push_back(cur);
+ next=cur.find(*it);
+ if( next == cur.end() ) return end();
+ cur=next;
it++;
}
+ cur_st.push_back(cur);
if(cur->has_value())
{
- return true;
+ return iterator(cur_st.begin(),cur_st.end());
}
- return false;
+ return end();
}
+
+
void swap(const type &other)
{
std::swap(other.node_root,node_root);
@@ -184,16 +192,17 @@
new(node_root) node_type();
}
- iterator begin()
+ iterator begin() const
{
return iterator(root(),false);
}
- iterator end()
+ iterator end() const
{
return iterator(root(),true);
}
- cursor root()
+
+ cursor root() const
{
return cursor(node_root);
}
@@ -237,6 +246,25 @@
}
return cur;
}
+ bool exist(const key_type &key) const //make this iterator instead of bool;
+ {
+ typename Key_traits::const_iterator it=Key_traits::begin(key),
+ end_it=Key_traits::end(key);
+ typename node_type::iterator fit;
+ node_type *cur=node_root;
+ while(!(it==end_it))
+ {
+ fit=cur->find(*it);
+ if(fit == cur->end() ) return false;
+ cur=*fit;
+ it++;
+ }
+ if(cur->has_value())
+ {
+ return true;
+ }
+ return false;
+ }
};
}
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