libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 00026 00027 // Permission to use, copy, modify, sell, and distribute this software 00028 // is hereby granted without fee, provided that the above copyright 00029 // notice appears in all copies, and that both that copyright notice 00030 // and this permission notice appear in supporting documentation. None 00031 // of the above authors, nor IBM Haifa Research Laboratories, make any 00032 // representation about the suitability of this software for any 00033 // purpose. It is provided "as is" without express or implied 00034 // warranty. 00035 00036 /** 00037 * @file trie_policy/prefix_search_node_update_imp.hpp 00038 * Contains an implementation of prefix_search_node_update. 00039 */ 00040 00041 PB_DS_CLASS_T_DEC 00042 std::pair< 00043 typename PB_DS_CLASS_C_DEC::const_iterator, 00044 typename PB_DS_CLASS_C_DEC::const_iterator> 00045 PB_DS_CLASS_C_DEC:: 00046 prefix_range(key_const_reference r_key) const 00047 { 00048 const access_traits& r_traits = get_access_traits(); 00049 return (prefix_range(r_traits.begin(r_key), r_traits.end(r_key))); 00050 } 00051 00052 PB_DS_CLASS_T_DEC 00053 std::pair< 00054 typename PB_DS_CLASS_C_DEC::iterator, 00055 typename PB_DS_CLASS_C_DEC::iterator> 00056 PB_DS_CLASS_C_DEC:: 00057 prefix_range(key_const_reference r_key) 00058 { 00059 return (prefix_range(get_access_traits().begin(r_key), 00060 get_access_traits().end(r_key))); 00061 } 00062 00063 PB_DS_CLASS_T_DEC 00064 std::pair< 00065 typename PB_DS_CLASS_C_DEC::const_iterator, 00066 typename PB_DS_CLASS_C_DEC::const_iterator> 00067 PB_DS_CLASS_C_DEC:: 00068 prefix_range(typename access_traits::const_iterator b, 00069 typename access_traits::const_iterator e) const 00070 { 00071 const std::pair<iterator, iterator> non_const_ret = 00072 const_cast<PB_DS_CLASS_C_DEC* >(this)->prefix_range(b, e); 00073 00074 return (std::make_pair(const_iterator(non_const_ret.first), 00075 const_iterator(non_const_ret.second))); 00076 } 00077 00078 PB_DS_CLASS_T_DEC 00079 std::pair< 00080 typename PB_DS_CLASS_C_DEC::iterator, 00081 typename PB_DS_CLASS_C_DEC::iterator> 00082 PB_DS_CLASS_C_DEC:: 00083 prefix_range(typename access_traits::const_iterator b, 00084 typename access_traits::const_iterator e) 00085 { 00086 Node_Itr nd_it = node_begin(); 00087 Node_Itr end_nd_it = node_end(); 00088 00089 const access_traits& r_traits = get_access_traits(); 00090 const size_type given_range_length = std::distance(b, e); 00091 00092 while (true) 00093 { 00094 if (nd_it == end_nd_it) 00095 return (std::make_pair(end(), end())); 00096 00097 const size_type common_range_length = 00098 base_type::common_prefix_len(nd_it, b, e, r_traits); 00099 00100 if (common_range_length >= given_range_length) 00101 { 00102 iterator ret_b = this->leftmost_it(nd_it); 00103 iterator ret_e = this->rightmost_it(nd_it); 00104 return (std::make_pair(ret_b, ++ret_e)); 00105 } 00106 nd_it = next_child(nd_it, b, e, end_nd_it, r_traits); 00107 } 00108 } 00109 00110 PB_DS_CLASS_T_DEC 00111 typename PB_DS_CLASS_C_DEC::node_iterator 00112 PB_DS_CLASS_C_DEC:: 00113 next_child(node_iterator nd_it, typename access_traits::const_iterator b, 00114 typename access_traits::const_iterator e, node_iterator end_nd_it, 00115 const access_traits& r_traits) 00116 { 00117 const size_type num_children = nd_it.num_children(); 00118 node_iterator ret = end_nd_it; 00119 size_type max_length = 0; 00120 for (size_type i = 0; i < num_children; ++i) 00121 { 00122 node_iterator pot = nd_it.get_child(i); 00123 const size_type common_range_length = 00124 base_type::common_prefix_len(pot, b, e, r_traits); 00125 00126 if (common_range_length > max_length) 00127 { 00128 ret = pot; 00129 max_length = common_range_length; 00130 } 00131 } 00132 return (ret); 00133 } 00134 00135 PB_DS_CLASS_T_DEC 00136 inline void 00137 PB_DS_CLASS_C_DEC:: 00138 operator()(node_iterator /*nd_it*/, node_const_iterator /*end_nd_it*/) const 00139 { }