PPL  1.2
Parma_Polyhedra_Library::CO_Tree::iterator Class Reference

An iterator on the tree elements, ordered by key. More...

#include <CO_Tree_defs.hh>

Public Types

typedef std::bidirectional_iterator_tag iterator_category
 
typedef data_type value_type
 
typedef std::ptrdiff_t difference_type
 
typedef value_typepointer
 
typedef value_typereference
 

Public Member Functions

 iterator ()
 Constructs an invalid iterator. More...
 
 iterator (CO_Tree &tree)
 Constructs an iterator pointing to first element of the tree. More...
 
 iterator (CO_Tree &tree, dimension_type i)
 Constructs an iterator pointing to the i-th node. More...
 
 iterator (const tree_iterator &itr)
 The constructor from a tree_iterator. More...
 
 iterator (const iterator &itr)
 The copy constructor. More...
 
void m_swap (iterator &itr)
 Swaps itr with *this. More...
 
iteratoroperator= (const iterator &itr)
 Assigns itr to *this . More...
 
iteratoroperator= (const tree_iterator &itr)
 Assigns itr to *this . More...
 
iteratoroperator++ ()
 Navigates to the next element in the tree. More...
 
iteratoroperator-- ()
 Navigates to the previous element in the tree. More...
 
iterator operator++ (int)
 Navigates to the next element in the tree. More...
 
iterator operator-- (int)
 Navigates to the previous element in the tree. More...
 
data_typeoperator* ()
 Returns the current element. More...
 
data_type_const_reference operator* () const
 Returns the current element. More...
 
dimension_type index () const
 Returns the index of the element pointed to by *this. More...
 
bool operator== (const iterator &x) const
 Compares *this with x . More...
 
bool operator!= (const iterator &x) const
 Compares *this with x . More...
 

Private Member Functions

bool OK () const
 Checks the internal invariants, in debug mode only. More...
 

Private Attributes

const dimension_typecurrent_index
 A pointer to the corresponding element of the tree's indexes[] array. More...
 
data_typecurrent_data
 A pointer to the corresponding element of the tree's data[] array. More...
 

Friends

const_iteratorconst_iterator::operator= (const iterator &)
 
dimension_type CO_Tree::dfs_index (iterator itr) const
 

Related Functions

(Note that these are not member functions.)

void swap (CO_Tree::iterator &x, CO_Tree::iterator &y)
 Swaps x with y. More...
 

Detailed Description

An iterator on the tree elements, ordered by key.

Iterator increment and decrement operations are $O(1)$ time. These iterators are invalidated by operations that add or remove elements from the tree.

Definition at line 313 of file CO_Tree_defs.hh.

Member Typedef Documentation

Definition at line 318 of file CO_Tree_defs.hh.

typedef std::bidirectional_iterator_tag Parma_Polyhedra_Library::CO_Tree::iterator::iterator_category

Definition at line 316 of file CO_Tree_defs.hh.

Constructor & Destructor Documentation

Parma_Polyhedra_Library::CO_Tree::iterator::iterator ( )
inline

Constructs an invalid iterator.

This constructor takes $O(1)$ time.

Definition at line 523 of file CO_Tree_inlines.hh.

References OK().

524  : current_index(0), current_data(0) {
525 #if PPL_CO_TREE_EXTRA_DEBUG
526  tree = 0;
527 #endif
528  PPL_ASSERT(OK());
529 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
Parma_Polyhedra_Library::CO_Tree::iterator::iterator ( CO_Tree tree)
inlineexplicit

Constructs an iterator pointing to first element of the tree.

Parameters
treeThe tree to which the new iterator will point to.

This constructor takes $O(1)$ time.

Definition at line 532 of file CO_Tree_inlines.hh.

References current_data, current_index, Parma_Polyhedra_Library::CO_Tree::empty(), OK(), and Parma_Polyhedra_Library::CO_Tree::unused_index.

533  : current_index(&(tree1.indexes[1])), current_data(&(tree1.data[1])) {
534 #if PPL_CO_TREE_EXTRA_DEBUG
535  tree = &tree1;
536 #endif
537  if (!tree1.empty()) {
538  while (*current_index == unused_index) {
539  ++current_index;
540  ++current_data;
541  }
542  }
543  PPL_ASSERT(OK());
544 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
static const dimension_type unused_index
An index used as a marker for unused nodes in the tree.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
Parma_Polyhedra_Library::CO_Tree::iterator::iterator ( CO_Tree tree,
dimension_type  i 
)
inline

Constructs an iterator pointing to the i-th node.

Parameters
treeThe tree to which the new iterator will point to.
iThe index of the element in tree to which the new iterator will point to.

The i-th node must be a node with a value or end().

This constructor takes $O(1)$ time.

Definition at line 547 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::empty(), Parma_Polyhedra_Library::CO_Tree::indexes, OK(), Parma_Polyhedra_Library::CO_Tree::reserved_size, and Parma_Polyhedra_Library::CO_Tree::unused_index.

548  : current_index(&(tree1.indexes[i])), current_data(&(tree1.data[i])) {
549 #if PPL_CO_TREE_EXTRA_DEBUG
550  tree = &tree1;
551 #endif
552  PPL_ASSERT(i != 0);
553  PPL_ASSERT(i <= tree1.reserved_size + 1);
554  PPL_ASSERT(tree1.empty() || tree1.indexes[i] != unused_index);
555  PPL_ASSERT(OK());
556 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
static const dimension_type unused_index
An index used as a marker for unused nodes in the tree.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
Parma_Polyhedra_Library::CO_Tree::iterator::iterator ( const tree_iterator itr)
inlineexplicit

The constructor from a tree_iterator.

Parameters
itrThe tree_iterator that will be converted into an iterator.

This is meant for use by CO_Tree only. This is not private to avoid the friend declaration.

This constructor takes $O(1)$ time.

Definition at line 559 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::OK().

559  {
560  *this = itr;
561  PPL_ASSERT(OK());
562 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
Parma_Polyhedra_Library::CO_Tree::iterator::iterator ( const iterator itr)
inline

The copy constructor.

Parameters
itrThe iterator that will be copied.

This constructor takes $O(1)$ time.

Definition at line 565 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::OK().

565  {
566  (*this) = itr2;
567  PPL_ASSERT(OK());
568 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359

Member Function Documentation

dimension_type Parma_Polyhedra_Library::CO_Tree::iterator::index ( ) const
inline

Returns the index of the element pointed to by *this.

Returns
the index of the element pointed to by *this.

Definition at line 674 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::OK().

Referenced by Parma_Polyhedra_Library::Sparse_Row::combine(), Parma_Polyhedra_Library::Sparse_Row::combine_needs_first(), Parma_Polyhedra_Library::Sparse_Row::combine_needs_second(), Parma_Polyhedra_Library::CO_Tree::erase(), Parma_Polyhedra_Library::CO_Tree::fast_shift(), Parma_Polyhedra_Library::Sparse_Row::find(), Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut(), Parma_Polyhedra_Library::CO_Tree::insert(), Parma_Polyhedra_Library::Sparse_Row::linear_combine(), Parma_Polyhedra_Library::Sparse_Row::lower_bound(), Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::remove_space_dimensions(), Parma_Polyhedra_Library::Sparse_Row::reset(), Parma_Polyhedra_Library::MIP_Problem::second_phase(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), Parma_Polyhedra_Library::MIP_Problem::steepest_edge_float_entering_index(), and Parma_Polyhedra_Library::Sparse_Row::swap_coefficients().

674  {
675  PPL_ASSERT(current_index != 0);
676  PPL_ASSERT(current_data != 0);
677  PPL_ASSERT(OK());
678 #if PPL_CO_TREE_EXTRA_DEBUG
679  PPL_ASSERT(current_index != &(tree->indexes[tree->reserved_size + 1]));
680 #endif
681  return *current_index;
682 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
void Parma_Polyhedra_Library::CO_Tree::iterator::m_swap ( iterator itr)
inline

Swaps itr with *this.

Parameters
itrThe iterator that will be swapped with *this.

This method takes $O(1)$ time.

Definition at line 571 of file CO_Tree_inlines.hh.

References current_data, current_index, OK(), Parma_Polyhedra_Library::CO_Tree::OK(), Parma_Polyhedra_Library::swap(), and Parma_Polyhedra_Library::CO_Tree::swap().

Referenced by Parma_Polyhedra_Library::swap().

571  {
572  using std::swap;
573  swap(current_data, itr.current_data);
574  swap(current_index, itr.current_index);
575 #if PPL_CO_TREE_EXTRA_DEBUG
576  swap(tree, itr.tree);
577 #endif
578  PPL_ASSERT(OK());
579  PPL_ASSERT(itr.OK());
580 }
void swap(CO_Tree::iterator &x, CO_Tree::iterator &y)
Swaps x with y.
void swap(CO_Tree::iterator &x, CO_Tree::iterator &y)
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
bool Parma_Polyhedra_Library::CO_Tree::iterator::OK ( ) const
private

Checks the internal invariants, in debug mode only.

Definition at line 1359 of file CO_Tree.cc.

Referenced by iterator(), and m_swap().

1359  {
1360 #if PPL_CO_TREE_EXTRA_DEBUG
1361  if (tree == 0) {
1362  if (current_index != 0) {
1363  return false;
1364  }
1365  if (current_data != 0) {
1366  return false;
1367  }
1368  }
1369  else
1370  if (tree->reserved_size == 0) {
1371  if (current_index != 1 + static_cast<dimension_type*>(0)
1372  || current_data != 1 + static_cast<data_type*>(0)) {
1373  return false;
1374  }
1375  }
1376  else {
1377  if (current_index <= &(tree->indexes[0])) {
1378  return false;
1379  }
1380  if (current_index > &(tree->indexes[tree->reserved_size + 1])) {
1381  return false;
1382  }
1383  if (current_data <= &(tree->data[0])) {
1384  return false;
1385  }
1386  if (current_data > &(tree->data[tree->reserved_size + 1])) {
1387  return false;
1388  }
1389  if (*current_index == unused_index) {
1390  return false;
1391  }
1392  if (current_index - tree->indexes != current_data - tree->data) {
1393  return false;
1394  }
1395  }
1396 #endif
1397  return true;
1398 }
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
static const dimension_type unused_index
An index used as a marker for unused nodes in the tree.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
bool Parma_Polyhedra_Library::CO_Tree::iterator::operator!= ( const iterator x) const
inline

Compares *this with x .

Parameters
xThe iterator that will be compared with *this.

Definition at line 693 of file CO_Tree_inlines.hh.

693  {
694  return !(*this == x);
695 }
CO_Tree::data_type & Parma_Polyhedra_Library::CO_Tree::iterator::operator* ( )
inline

Returns the current element.

Definition at line 652 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::OK().

652  {
653  PPL_ASSERT(current_index != 0);
654  PPL_ASSERT(current_data != 0);
655  PPL_ASSERT(OK());
656 #if PPL_CO_TREE_EXTRA_DEBUG
657  PPL_ASSERT(current_index != &(tree->indexes[tree->reserved_size + 1]));
658 #endif
659  return *current_data;
660 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
Coefficient_traits::const_reference Parma_Polyhedra_Library::CO_Tree::iterator::operator* ( ) const
inline

Returns the current element.

Definition at line 663 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::OK().

663  {
664  PPL_ASSERT(current_index != 0);
665  PPL_ASSERT(current_data != 0);
666  PPL_ASSERT(OK());
667 #if PPL_CO_TREE_EXTRA_DEBUG
668  PPL_ASSERT(current_index != &(tree->indexes[tree->reserved_size + 1]));
669 #endif
670  return *current_data;
671 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
CO_Tree::iterator & Parma_Polyhedra_Library::CO_Tree::iterator::operator++ ( )
inline

Navigates to the next element in the tree.

This method takes $O(1)$ time.

Definition at line 605 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::OK(), and Parma_Polyhedra_Library::CO_Tree::unused_index.

605  {
606  PPL_ASSERT(current_index != 0);
607  PPL_ASSERT(current_data != 0);
608 #if PPL_CO_TREE_EXTRA_DEBUG
609  PPL_ASSERT(current_index != &(tree->indexes[tree->reserved_size + 1]));
610 #endif
611  ++current_index;
612  ++current_data;
613  while (*current_index == unused_index) {
614  ++current_index;
615  ++current_data;
616  }
617 
618  PPL_ASSERT(OK());
619  return *this;
620 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
static const dimension_type unused_index
An index used as a marker for unused nodes in the tree.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
CO_Tree::iterator Parma_Polyhedra_Library::CO_Tree::iterator::operator++ ( int  )
inline

Navigates to the next element in the tree.

This method takes $O(1)$ time.

Definition at line 638 of file CO_Tree_inlines.hh.

638  {
639  iterator itr(*this);
640  ++(*this);
641  return itr;
642 }
iterator()
Constructs an invalid iterator.
CO_Tree::iterator & Parma_Polyhedra_Library::CO_Tree::iterator::operator-- ( )
inline

Navigates to the previous element in the tree.

This method takes $O(1)$ time.

Definition at line 623 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::OK(), and Parma_Polyhedra_Library::CO_Tree::unused_index.

623  {
624  PPL_ASSERT(current_index != 0);
625  PPL_ASSERT(current_data != 0);
626  --current_index;
627  --current_data;
628  while (*current_index == unused_index) {
629  --current_index;
630  --current_data;
631  }
632 
633  PPL_ASSERT(OK());
634  return *this;
635 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
static const dimension_type unused_index
An index used as a marker for unused nodes in the tree.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
CO_Tree::iterator Parma_Polyhedra_Library::CO_Tree::iterator::operator-- ( int  )
inline

Navigates to the previous element in the tree.

This method takes $O(1)$ time.

Definition at line 645 of file CO_Tree_inlines.hh.

645  {
646  iterator itr(*this);
647  --(*this);
648  return itr;
649 }
iterator()
Constructs an invalid iterator.
CO_Tree::iterator & Parma_Polyhedra_Library::CO_Tree::iterator::operator= ( const iterator itr)
inline

Assigns itr to *this .

Parameters
itrThe iterator that will be assigned into *this.

This method takes $O(1)$ time.

Definition at line 594 of file CO_Tree_inlines.hh.

References current_data, current_index, and Parma_Polyhedra_Library::CO_Tree::OK().

594  {
595  current_index = itr2.current_index;
596  current_data = itr2.current_data;
597 #if PPL_CO_TREE_EXTRA_DEBUG
598  tree = itr2.tree;
599 #endif
600  PPL_ASSERT(OK());
601  return *this;
602 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
CO_Tree::iterator & Parma_Polyhedra_Library::CO_Tree::iterator::operator= ( const tree_iterator itr)
inline

Assigns itr to *this .

Parameters
itrThe iterator that will be assigned into *this.

This method takes $O(1)$ time.

Definition at line 583 of file CO_Tree_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::data, Parma_Polyhedra_Library::CO_Tree::tree_iterator::dfs_index(), Parma_Polyhedra_Library::CO_Tree::indexes, Parma_Polyhedra_Library::CO_Tree::OK(), and Parma_Polyhedra_Library::CO_Tree::tree_iterator::tree.

583  {
584  current_index = &(itr.tree.indexes[itr.dfs_index()]);
585  current_data = &(itr.tree.data[itr.dfs_index()]);
586 #if PPL_CO_TREE_EXTRA_DEBUG
587  tree = &(itr.tree);
588 #endif
589  PPL_ASSERT(OK());
590  return *this;
591 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
bool Parma_Polyhedra_Library::CO_Tree::iterator::operator== ( const iterator x) const
inline

Compares *this with x .

Parameters
xThe iterator that will be compared with *this.

Definition at line 685 of file CO_Tree_inlines.hh.

References current_data, current_index, and Parma_Polyhedra_Library::CO_Tree::OK().

685  {
686  PPL_ASSERT((current_index == x.current_index)
687  == (current_data == x.current_data));
688  PPL_ASSERT(OK());
689  return (current_index == x.current_index);
690 }
bool OK() const
Checks the internal invariants, in debug mode only.
Definition: CO_Tree.cc:1359
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.

Friends And Related Function Documentation

const_iterator& const_iterator::operator= ( const iterator )
friend
void swap ( CO_Tree::iterator x,
CO_Tree::iterator y 
)
related

Swaps x with y.

Definition at line 883 of file CO_Tree_inlines.hh.

883  {
884  x.m_swap(y);
885 }

Member Data Documentation

data_type* Parma_Polyhedra_Library::CO_Tree::iterator::current_data
private

A pointer to the corresponding element of the tree's data[] array.

Definition at line 458 of file CO_Tree_defs.hh.

Referenced by iterator(), m_swap(), Parma_Polyhedra_Library::CO_Tree::const_iterator::operator=(), operator=(), and operator==().

const dimension_type* Parma_Polyhedra_Library::CO_Tree::iterator::current_index
private

A pointer to the corresponding element of the tree's indexes[] array.

Definition at line 455 of file CO_Tree_defs.hh.

Referenced by Parma_Polyhedra_Library::CO_Tree::dfs_index(), iterator(), m_swap(), Parma_Polyhedra_Library::CO_Tree::const_iterator::operator=(), operator=(), and operator==().


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