00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00045 PB_ASSOC_CLASS_T_DEC
00046 void
00047 PB_ASSOC_CLASS_C_DEC::
00048 split(const_key_reference r_key, PB_ASSOC_CLASS_C_DEC& r_other)
00049 {
00050 PB_ASSOC_DBG_ONLY(assert_valid();)
00051 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00052
00053 if (m_size == 0)
00054 {
00055 r_other.clear();
00056
00057 PB_ASSOC_DBG_ONLY(assert_valid();)
00058 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00059
00060 return;
00061 }
00062
00063 if (Cmp_Fn::operator()(r_key, PB_ASSOC_V2F(*begin())))
00064 {
00065 swap(r_other);
00066
00067 PB_ASSOC_DBG_ONLY(assert_valid();)
00068 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00069
00070 return;
00071 }
00072
00073 if (!Cmp_Fn::operator()(
00074 r_key,
00075 PB_ASSOC_V2F(*(end() - 1))))
00076 {
00077 PB_ASSOC_DBG_ONLY(assert_valid();)
00078 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00079
00080 return;
00081 }
00082
00083 if (m_size == 1)
00084 {
00085 swap(r_other);
00086
00087 PB_ASSOC_DBG_ONLY(assert_valid();)
00088 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00089
00090 return;
00091 }
00092
00093 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
00094 for (const_iterator it = begin(); it != end(); ++it)
00095 if (Cmp_Fn::operator()(
00096 r_key,
00097 PB_ASSOC_V2F(*it)))
00098 {
00099 my_map_debug_base::erase_existing(PB_ASSOC_V2F(*it));
00100 r_other.my_map_debug_base::insert_new(PB_ASSOC_V2F(*it));
00101 }
00102 #endif // PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
00103
00104 iterator it = upper_bound(r_key);
00105
00106 PB_ASSOC_CLASS_C_DEC new_other(r_other, r_other);
00107
00108 new_other.copy_from_ordered_range(it, end());
00109
00110 PB_ASSOC_CLASS_C_DEC new_this(*this, * this);
00111
00112 new_this.copy_from_ordered_range(begin(), it);
00113
00114
00115
00116 r_other.update(r_other.node_begin(), (Node_Updator* )(&r_other));
00117
00118 update(node_begin(), (Node_Updator* )this);
00119
00120 r_other.swap(new_other);
00121
00122 swap(new_this);
00123
00124 PB_ASSOC_DBG_ONLY(assert_valid();)
00125 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00126 }
00127
00128 PB_ASSOC_CLASS_T_DEC
00129 void
00130 PB_ASSOC_CLASS_C_DEC::
00131 join(PB_ASSOC_CLASS_C_DEC& r_other)
00132 {
00133 PB_ASSOC_DBG_ONLY(assert_valid();)
00134 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00135
00136 if (r_other.m_size == 0)
00137 return;
00138
00139 if (m_size == 0)
00140 {
00141 swap(r_other);
00142
00143 return;
00144 }
00145
00146 const bool greater = Cmp_Fn::operator()(
00147 PB_ASSOC_V2F(*(end() - 1)),
00148 PB_ASSOC_V2F(*r_other.begin()));
00149
00150 const bool lesser = Cmp_Fn::operator()(
00151 PB_ASSOC_V2F(*(r_other.end() - 1)),
00152 PB_ASSOC_V2F(*begin()));
00153
00154 if (!greater&& !lesser)
00155 throw cannot_join();
00156
00157 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
00158 for (const_iterator other_it = r_other.begin(); other_it != r_other.end();
00159 ++other_it)
00160 {
00161 my_map_debug_base::insert_new(PB_ASSOC_V2F(*other_it));
00162 r_other.my_map_debug_base::erase_existing(PB_ASSOC_V2F(*other_it));
00163 }
00164 #endif // PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
00165
00166 PB_ASSOC_CLASS_C_DEC new_this(*this, * this);
00167
00168 if (greater)
00169 new_this.copy_from_ordered_range(
00170 begin(),
00171 end(),
00172 r_other.begin(),
00173 r_other.end());
00174 else
00175 new_this.copy_from_ordered_range(
00176 r_other.begin(),
00177 r_other.end(),
00178 begin(),
00179 end());
00180
00181
00182
00183 swap(new_this);
00184
00185 r_other.clear();
00186
00187 PB_ASSOC_DBG_ONLY(assert_valid();)
00188 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00189 }