1 #ifndef _KEY_MUTABLE_SET_H_
2 #define _KEY_MUTABLE_SET_H_
26 operator T &()
const {
29 bool operator<( const MutableShell< T > &other )
const
38 template <
class T,
class _Compare = std::less< MutableShell< T > > >
39 class KeyMutableSet :
public std::multiset< MutableShell< T >, _Compare >
41 typedef std::multiset< MutableShell< T >, _Compare >SUPER;
47 if ( this->begin() != this->end() )
48 for (
typename SUPER::iterator newiter = this->begin(), iter = newiter++; newiter != this->end(); iter = newiter++)
49 assert( !comparator( *newiter, *iter ) );
58 typename SUPER::iterator &templess,
59 typename SUPER::iterator &rettempmore )
62 templess = rettempmore = iter;
64 typename SUPER::iterator tempmore = rettempmore;
65 if ( tempmore == this->end() )
67 if ( templess != this->begin() )
73 if ( comparator( newKeyShell, *templess ) ) {
74 rettempmore = templess = this->
insert( newKeyShell, templess );
76 }
else if ( comparator( *tempmore, newKeyShell ) ) {
77 rettempmore = templess = this->
insert( newKeyShell, tempmore );
79 }
else {(*iter).get() = newKey; }
if (byebye) {
83 if ( templess != this->begin() )
87 typename SUPER::iterator
insert(
const T &newKey,
typename SUPER::iterator hint )
89 return this->SUPER::insert( hint, newKey );
91 typename SUPER::iterator
insert(
const T &newKey )
93 return this->SUPER::insert( newKey );
95 typename SUPER::iterator
changeKey(
typename SUPER::iterator iter,
const T &newKey )
97 typename SUPER::iterator templess = iter, tempmore = iter;
98 changeKey( iter, newKey, templess, tempmore );
103 template <
class T,
class _Compare = std::less< T > >
106 typedef std::list< T >SUPER;
114 if ( this->begin() != this->end() )
115 for (
typename SUPER::iterator newiter = this->begin(), iter = newiter++; newiter != this->end(); iter = newiter++)
116 assert( !comparator( *newiter, *iter ) );
124 typename SUPER::iterator &templess,
125 typename SUPER::iterator &rettempmore )
128 templess = rettempmore = iter;
130 typename SUPER::iterator tempmore = rettempmore;
131 if ( tempmore == this->end() )
133 if ( templess != this->begin() )
136 if ( comparator( newKeyShell, *templess ) || comparator( *tempmore, newKeyShell ) ) {
137 rettempmore = templess = iter = this->
insert( newKeyShell, this->erase( iter ) );
139 if ( templess != this->begin() )
147 typename SUPER::iterator
changeKey(
typename SUPER::iterator iter,
const T &newKey )
149 typename SUPER::iterator templess = iter, tempmore = iter;
150 changeKey( iter, newKey, templess, tempmore );
153 typename SUPER::iterator
insert(
const T &newKey,
typename SUPER::iterator hint )
155 bool gequal =
false, lequal =
false;
158 if ( hint != this->end() ) {
159 bool tlequal = !comparator( *hint, newKey );
160 bool tgequal = !comparator( newKey, *hint );
162 if ( gequal || tgequal || hint == this->begin() ) {
163 return this->SUPER::insert( hint, newKey );
172 if (lequal || tlequal)
173 return this->SUPER::insert( hint, newKey );
175 }
else if ( hint == this->begin() ) {
176 this->SUPER::insert( hint, newKey );
179 return this->SUPER::insert( hint, newKey );
185 typename SUPER::iterator
insert(
const T &newKey )
187 return this->
insert( newKey, this->begin() );