Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KeyMutableSet< T, _Compare > Class Template Reference

#include <key_mutable_set.h>

Inheritance diagram for KeyMutableSet< T, _Compare >:

Public Member Functions

void checkSet ()
 This just checks the order of the set for testing purposes.. More...
 
void changeKey (typename SUPER::iterator &iter, const T &newKey, typename SUPER::iterator &templess, typename SUPER::iterator &rettempmore)
 Given an iterator you can alter that iterator's key to be the one passed in. More...
 
SUPER::iterator insert (const T &newKey, typename SUPER::iterator hint)
 
SUPER::iterator insert (const T &newKey)
 
SUPER::iterator changeKey (typename SUPER::iterator iter, const T &newKey)
 

Detailed Description

template<class T, class _Compare = std::less< MutableShell< T > >>
class KeyMutableSet< T, _Compare >

This set inherits from the STL multiset, with a slight variation: The value is nonconst–that means you are allowed to change things but must not alter the key. This set inherits from the STL multiset, with a slight variation: You are allowed to update the key of a particular iterator that you have obtained. Note: T is the type that each element is pointing to.

Definition at line 39 of file key_mutable_set.h.

Member Function Documentation

template<class T , class _Compare = std::less< MutableShell< T > >>
void KeyMutableSet< T, _Compare >::changeKey ( typename SUPER::iterator &  iter,
const T &  newKey,
typename SUPER::iterator &  templess,
typename SUPER::iterator &  rettempmore 
)
inline

Given an iterator you can alter that iterator's key to be the one passed in.

The type must have a function called changeKey(const Key &newKey) that changes its key to the specified new key.

Definition at line 56 of file key_mutable_set.h.

References KeyMutableSet< T, _Compare >::insert().

Referenced by KeyMutableSet< T, _Compare >::changeKey().

60  {
61  MutableShell< T >newKeyShell( newKey );
62  templess = rettempmore = iter;
63  ++rettempmore;
64  typename SUPER::iterator tempmore = rettempmore;
65  if ( tempmore == this->end() )
66  --tempmore;
67  if ( templess != this->begin() )
68  --templess;
69  _Compare comparator;
70 
71  //O(1) amortized time on the insertion - Yippie!
72  bool byebye = false;
73  if ( comparator( newKeyShell, *templess ) ) {
74  rettempmore = templess = this->insert( newKeyShell, templess );
75  byebye = true;
76  } else if ( comparator( *tempmore, newKeyShell ) ) {
77  rettempmore = templess = this->insert( newKeyShell, tempmore );
78  byebye = true;
79  } else {(*iter).get() = newKey; } if (byebye) {
80  this->erase( iter );
81  iter = templess;
82  ++rettempmore;
83  if ( templess != this->begin() )
84  --templess;
85  }
86  }
template<class T , class _Compare = std::less< MutableShell< T > >>
SUPER::iterator KeyMutableSet< T, _Compare >::changeKey ( typename SUPER::iterator  iter,
const T &  newKey 
)
inline

Definition at line 95 of file key_mutable_set.h.

References KeyMutableSet< T, _Compare >::changeKey().

96  {
97  typename SUPER::iterator templess = iter, tempmore = iter;
98  changeKey( iter, newKey, templess, tempmore );
99  return iter;
100  }
template<class T , class _Compare = std::less< MutableShell< T > >>
void KeyMutableSet< T, _Compare >::checkSet ( )
inline

This just checks the order of the set for testing purposes..

Definition at line 44 of file key_mutable_set.h.

45  {
46  _Compare comparator;
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 ) );
50  }
template<class T , class _Compare = std::less< MutableShell< T > >>
SUPER::iterator KeyMutableSet< T, _Compare >::insert ( const T &  newKey,
typename SUPER::iterator  hint 
)
inline

Definition at line 87 of file key_mutable_set.h.

Referenced by KeyMutableSet< T, _Compare >::changeKey().

88  {
89  return this->SUPER::insert( hint, newKey );
90  }
template<class T , class _Compare = std::less< MutableShell< T > >>
SUPER::iterator KeyMutableSet< T, _Compare >::insert ( const T &  newKey)
inline

Definition at line 91 of file key_mutable_set.h.

92  {
93  return this->SUPER::insert( newKey );
94  }

The documentation for this class was generated from the following file: