Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QMapPrivate< Key, T > Class Template Reference

#include <qmap.h>

Inheritance diagram for QMapPrivate< Key, T >:
QMapPrivateBase QShared

Public Types

typedef QMapIterator< Key, T > Iterator
 
typedef QMapConstIterator< Key, T > ConstIterator
 
typedef QMapNode< Key, T > Node
 
typedef QMapNode< Key, T > * NodePtr
 

Public Member Functions

 QMapPrivate ()
 
 QMapPrivate (const QMapPrivate< Key, T > *_map)
 
 ~QMapPrivate ()
 
NodePtr copy (NodePtr p)
 
void clear ()
 
void clear (NodePtr p)
 
Iterator begin ()
 
Iterator end ()
 
ConstIterator begin () const
 
ConstIterator end () const
 
ConstIterator find (const Key &k) const
 
void remove (Iterator it)
 
Iterator insertMulti (const Key &v)
 
Iterator insertSingle (const Key &k)
 
Iterator insert (QMapNodeBase *x, QMapNodeBase *y, const Key &k)
 
- Public Member Functions inherited from QMapPrivateBase
 QMapPrivateBase ()
 
 QMapPrivateBase (const QMapPrivateBase *_map)
 
void rotateLeft (QMapNodeBase *x, QMapNodeBase *&root)
 
void rotateRight (QMapNodeBase *x, QMapNodeBase *&root)
 
void rebalance (QMapNodeBase *x, QMapNodeBase *&root)
 
QMapNodeBaseremoveAndRebalance (QMapNodeBase *z, QMapNodeBase *&root, QMapNodeBase *&leftmost, QMapNodeBase *&rightmost)
 
- Public Member Functions inherited from QShared
 QShared ()
 
void ref ()
 
bool deref ()
 

Protected Member Functions

const Key & key (QMapNodeBase *b) const
 

Protected Attributes

NodePtr header
 

Additional Inherited Members

- Public Attributes inherited from QMapPrivateBase
int node_count
 
- Public Attributes inherited from QShared
uint count
 

Detailed Description

template<class Key, class T>
class QMapPrivate< Key, T >

Definition at line 311 of file qmap.h.

Member Typedef Documentation

template<class Key, class T>
typedef QMapConstIterator< Key, T > QMapPrivate< Key, T >::ConstIterator

Definition at line 318 of file qmap.h.

template<class Key, class T>
typedef QMapIterator< Key, T > QMapPrivate< Key, T >::Iterator

Typedefs

Definition at line 317 of file qmap.h.

template<class Key, class T>
typedef QMapNode< Key, T > QMapPrivate< Key, T >::Node

Definition at line 319 of file qmap.h.

template<class Key, class T>
typedef QMapNode< Key, T >* QMapPrivate< Key, T >::NodePtr

Definition at line 320 of file qmap.h.

Constructor & Destructor Documentation

template<class Key, class T>
QMapPrivate< Key, T >::QMapPrivate ( )
inline

Functions

Definition at line 325 of file qmap.h.

325  {
326  header = new Node;
327  header->color = QMapNodeBase::Red; // Mark the header
328  header->parent = 0;
329  header->left = header->right = header;
330  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNode< Key, T > Node
Definition: qmap.h:319
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr header
Definition: qmap.h:496
QMapNodeBase * right
Definition: qmap.h:52
Color color
Definition: qmap.h:55
template<class Key, class T>
QMapPrivate< Key, T >::QMapPrivate ( const QMapPrivate< Key, T > *  _map)
inline

Definition at line 331 of file qmap.h.

331  : QMapPrivateBase( _map ) {
332  header = new Node;
333  header->color = QMapNodeBase::Red; // Mark the header
334  if ( _map->header->parent == 0 ) {
335  header->parent = 0;
336  header->left = header->right = header;
337  } else {
338  header->parent = copy( (NodePtr)(_map->header->parent) );
342  }
343  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNode< Key, T > Node
Definition: qmap.h:319
QMapPrivateBase()
Definition: qmap.h:286
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr copy(NodePtr p)
Definition: qmap.h:346
NodePtr header
Definition: qmap.h:496
QMapNodeBase * maximum()
Definition: qmap.h:64
QMapNodeBase * right
Definition: qmap.h:52
QMapNodeBase * minimum()
Definition: qmap.h:57
Color color
Definition: qmap.h:55
template<class Key, class T>
QMapPrivate< Key, T >::~QMapPrivate ( )
inline

Definition at line 344 of file qmap.h.

344 { clear(); delete header; }
NodePtr header
Definition: qmap.h:496
void clear()
Definition: qmap.h:366

Member Function Documentation

template<class Key, class T>
Iterator QMapPrivate< Key, T >::begin ( )
inline

Definition at line 383 of file qmap.h.

383 { return Iterator( (NodePtr)(header->left ) ); }
QMapNodeBase * left
Definition: qmap.h:51
QMapIterator< Key, T > Iterator
Definition: qmap.h:317
NodePtr header
Definition: qmap.h:496
template<class Key, class T>
ConstIterator QMapPrivate< Key, T >::begin ( ) const
inline

Definition at line 385 of file qmap.h.

385 { return ConstIterator( (NodePtr)(header->left ) ); }
QMapNodeBase * left
Definition: qmap.h:51
NodePtr header
Definition: qmap.h:496
QMapConstIterator< Key, T > ConstIterator
Definition: qmap.h:318
template<class Key, class T>
void QMapPrivate< Key, T >::clear ( )
inline

Definition at line 366 of file qmap.h.

366  {
367  clear( (NodePtr)(header->parent) );
369  header->parent = 0;
370  header->left = header->right = header;
371  node_count = 0;
372  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr header
Definition: qmap.h:496
int node_count
Definition: qmap.h:306
QMapNodeBase * right
Definition: qmap.h:52
Color color
Definition: qmap.h:55
void clear()
Definition: qmap.h:366
template<class Key, class T>
void QMapPrivate< Key, T >::clear ( NodePtr  p)
inline

Definition at line 374 of file qmap.h.

374  {
375  while ( p != 0 ) {
376  clear( (NodePtr)p->right );
377  NodePtr y = (NodePtr)p->left;
378  delete p;
379  p = y;
380  }
381  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNodeBase * right
Definition: qmap.h:52
QMapNode< Key, T > * NodePtr
Definition: qmap.h:320
void clear()
Definition: qmap.h:366
template<class Key, class T>
NodePtr QMapPrivate< Key, T >::copy ( NodePtr  p)
inline

Definition at line 346 of file qmap.h.

346  {
347  if ( !p )
348  return 0;
349  NodePtr n = new Node( *p );
350  n->color = p->color;
351  if ( p->left ) {
352  n->left = copy( (NodePtr)(p->left) );
353  n->left->parent = n;
354  } else {
355  n->left = 0;
356  }
357  if ( p->right ) {
358  n->right = copy( (NodePtr)(p->right) );
359  n->right->parent = n;
360  } else {
361  n->right = 0;
362  }
363  return n;
364  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNode< Key, T > Node
Definition: qmap.h:319
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr copy(NodePtr p)
Definition: qmap.h:346
std::void_t< T > n
QMapNodeBase * right
Definition: qmap.h:52
Color color
Definition: qmap.h:55
template<class Key, class T>
Iterator QMapPrivate< Key, T >::end ( )
inline

Definition at line 384 of file qmap.h.

384 { return Iterator( header ); }
QMapIterator< Key, T > Iterator
Definition: qmap.h:317
NodePtr header
Definition: qmap.h:496
template<class Key, class T>
ConstIterator QMapPrivate< Key, T >::end ( ) const
inline

Definition at line 386 of file qmap.h.

386 { return ConstIterator( header ); }
NodePtr header
Definition: qmap.h:496
QMapConstIterator< Key, T > ConstIterator
Definition: qmap.h:318
template<class Key, class T>
ConstIterator QMapPrivate< Key, T >::find ( const Key &  k) const
inline

Definition at line 388 of file qmap.h.

388  {
389  QMapNodeBase* y = header; // Last node
390  QMapNodeBase* x = header->parent; // Root node.
391 
392  while ( x != 0 ) {
393  // If as k <= key(x) go left
394  if ( !( key(x) < k ) ) {
395  y = x;
396  x = x->left;
397  } else {
398  x = x->right;
399  }
400  }
401 
402  // Was k bigger/smaller then the biggest/smallest
403  // element of the tree ? Return end()
404  if ( y == header || k < key(y) )
405  return ConstIterator( header );
406  return ConstIterator( (NodePtr)y );
407  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr header
Definition: qmap.h:496
QMapConstIterator< Key, T > ConstIterator
Definition: qmap.h:318
const Key & key(QMapNodeBase *b) const
Definition: qmap.h:491
list x
Definition: train.py:276
QMapNodeBase * right
Definition: qmap.h:52
template<class Key, class T>
Iterator QMapPrivate< Key, T >::insert ( QMapNodeBase x,
QMapNodeBase y,
const Key &  k 
)
inline

Definition at line 465 of file qmap.h.

465  {
466  NodePtr z = new Node( k );
467  if (y == header || x != 0 || k < key(y) ) {
468  y->left = z; // also makes leftmost = z when y == header
469  if ( y == header ) {
470  header->parent = z;
471  header->right = z;
472  } else if ( y == header->left )
473  header->left = z; // maintain leftmost pointing to min node
474  } else {
475  y->right = z;
476  if ( y == header->right )
477  header->right = z; // maintain rightmost pointing to max node
478  }
479  z->parent = y;
480  z->left = 0;
481  z->right = 0;
482  rebalance( z, header->parent );
483  ++node_count;
484  return Iterator(z);
485  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNode< Key, T > Node
Definition: qmap.h:319
QMapIterator< Key, T > Iterator
Definition: qmap.h:317
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr header
Definition: qmap.h:496
int node_count
Definition: qmap.h:306
const Key & key(QMapNodeBase *b) const
Definition: qmap.h:491
void rebalance(QMapNodeBase *x, QMapNodeBase *&root)
Definition: qmap.cpp:80
QMapNodeBase * right
Definition: qmap.h:52
template<class Key, class T>
Iterator QMapPrivate< Key, T >::insertMulti ( const Key &  v)
inline

Definition at line 427 of file qmap.h.

427  {
428  QMapNodeBase* y = header;
430  while (x != 0){
431  y = x;
432  x = ( v < key(x) ) ? x->left : x->right;
433  }
434  return insert(x, y, v);
435  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr header
Definition: qmap.h:496
Iterator insert(QMapNodeBase *x, QMapNodeBase *y, const Key &k)
Definition: qmap.h:465
const Key & key(QMapNodeBase *b) const
Definition: qmap.h:491
list x
Definition: train.py:276
QMapNodeBase * right
Definition: qmap.h:52
template<class Key, class T>
Iterator QMapPrivate< Key, T >::insertSingle ( const Key &  k)
inline

Definition at line 437 of file qmap.h.

437  {
438  // Search correct position in the tree
439  QMapNodeBase* y = header;
441  bool result = TRUE;
442  while ( x != 0 ) {
443  result = ( k < key(x) );
444  y = x;
445  x = result ? x->left : x->right;
446  }
447  // Get iterator on the last not empty one
448  Iterator j( (NodePtr)y );
449  if ( result ) {
450  // Smaller then the leftmost one ?
451  if ( j == begin() ) {
452  return insert(x, y, k );
453  } else {
454  // Perhaps daddy is the right one ?
455  --j;
456  }
457  }
458  // Really bigger ?
459  if ( (j.node->key) < k )
460  return insert(x, y, k );
461  // We are going to replace a node
462  return j;
463  }
QMapNodeBase * left
Definition: qmap.h:51
static QCString result
Iterator begin()
Definition: qmap.h:383
QMapIterator< Key, T > Iterator
Definition: qmap.h:317
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr header
Definition: qmap.h:496
Iterator insert(QMapNodeBase *x, QMapNodeBase *y, const Key &k)
Definition: qmap.h:465
const Key & key(QMapNodeBase *b) const
Definition: qmap.h:491
list x
Definition: train.py:276
QMapNodeBase * right
Definition: qmap.h:52
const bool TRUE
Definition: qglobal.h:371
template<class Key, class T>
const Key& QMapPrivate< Key, T >::key ( QMapNodeBase b) const
inlineprotected

Helpers

Definition at line 491 of file qmap.h.

491 { return ((NodePtr)b)->key; }
template<class Key, class T>
void QMapPrivate< Key, T >::remove ( Iterator  it)
inline

Definition at line 409 of file qmap.h.

409  {
411  delete del;
412  --node_count;
413  }
QMapNodeBase * left
Definition: qmap.h:51
QMapNodeBase * removeAndRebalance(QMapNodeBase *z, QMapNodeBase *&root, QMapNodeBase *&leftmost, QMapNodeBase *&rightmost)
Definition: qmap.cpp:122
QMapNodeBase * parent
Definition: qmap.h:53
NodePtr header
Definition: qmap.h:496
int node_count
Definition: qmap.h:306
QMapNodeBase * right
Definition: qmap.h:52
QMapNode< Key, T > * NodePtr
Definition: qmap.h:320

Member Data Documentation

template<class Key, class T>
NodePtr QMapPrivate< Key, T >::header
protected

Variables

Definition at line 496 of file qmap.h.


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