lemon/bits/erasable_graph_extender.h
author alpar
Tue, 21 Feb 2006 12:37:00 +0000
changeset 1977 8ef02f0c4245
parent 1909 2d806130e700
permissions -rw-r--r--
RefPtr: a reference counted pointer class
alpar@1956
     1
/* -*- C++ -*-
alpar@1956
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1956
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1956
     8
 *
alpar@1956
     9
 * Permission to use, modify and distribute this software is granted
alpar@1956
    10
 * provided that this copyright notice appears in all copies. For
alpar@1956
    11
 * precise terms see the accompanying LICENSE file.
alpar@1956
    12
 *
alpar@1956
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1956
    14
 * express or implied, and with no claim as to its suitability for any
alpar@1956
    15
 * purpose.
alpar@1956
    16
 *
alpar@1956
    17
 */
klao@946
    18
klao@946
    19
#ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
klao@946
    20
#define LEMON_ERASABLE_GRAPH_EXTENDER_H
klao@946
    21
deba@1414
    22
#include <vector>
deba@1414
    23
klao@946
    24
#include <lemon/invalid.h>
klao@946
    25
klao@946
    26
klao@946
    27
namespace lemon {
klao@946
    28
klao@946
    29
  template <typename _Base> 
klao@946
    30
  class ErasableGraphExtender : public _Base {
klao@946
    31
  public:
klao@946
    32
klao@946
    33
    typedef ErasableGraphExtender Graph;
klao@946
    34
    typedef _Base Parent;
klao@946
    35
klao@946
    36
    typedef typename Parent::Node Node;
klao@946
    37
    typedef typename Parent::Edge Edge;
klao@946
    38
klao@946
    39
    void erase(const Node& node) {
klao@946
    40
      Edge edge;
klao@946
    41
      Parent::firstOut(edge, node);
klao@946
    42
      while (edge != INVALID ) {
klao@946
    43
	erase(edge);
klao@946
    44
	Parent::firstOut(edge, node);
klao@946
    45
      } 
klao@946
    46
klao@946
    47
      Parent::firstIn(edge, node);
klao@946
    48
      while (edge != INVALID ) {
klao@946
    49
	erase(edge);
klao@946
    50
	Parent::firstIn(edge, node);
klao@946
    51
      }
klao@946
    52
deba@1039
    53
      Parent::getNotifier(Node()).erase(node);
klao@946
    54
      Parent::erase(node);
klao@946
    55
    }
klao@946
    56
    
klao@946
    57
    void erase(const Edge& edge) {
deba@1039
    58
      Parent::getNotifier(Edge()).erase(edge);
klao@946
    59
      Parent::erase(edge);
klao@946
    60
    }
klao@946
    61
klao@946
    62
  };
klao@946
    63
klao@1022
    64
  template <typename _Base> 
deba@1842
    65
  class ErasableEdgeSetExtender : public _Base {
deba@1842
    66
  public:
deba@1842
    67
deba@1842
    68
    typedef ErasableEdgeSetExtender Graph;
deba@1842
    69
    typedef _Base Parent;
deba@1842
    70
deba@1842
    71
    typedef typename Parent::Edge Edge;
deba@1842
    72
deba@1842
    73
    void erase(const Edge& edge) {
deba@1842
    74
      Parent::getNotifier(Edge()).erase(edge);
deba@1842
    75
      Parent::erase(edge);
deba@1842
    76
    }
deba@1842
    77
deba@1842
    78
  };
deba@1842
    79
deba@1842
    80
  template <typename _Base> 
klao@1909
    81
  class ErasableUGraphExtender : public _Base {
klao@1022
    82
  public:
klao@1022
    83
klao@1909
    84
    typedef ErasableUGraphExtender Graph;
klao@1022
    85
    typedef _Base Parent;
klao@1022
    86
klao@1022
    87
    typedef typename Parent::Node Node;
klao@1909
    88
    typedef typename Parent::UEdge UEdge;
klao@1022
    89
    typedef typename Parent::Edge Edge;
klao@1022
    90
klao@1022
    91
    void erase(const Node& node) {
klao@1022
    92
      Edge edge;
klao@1022
    93
      Parent::firstOut(edge, node);
klao@1022
    94
      while (edge != INVALID ) {
klao@1022
    95
	erase(edge);
klao@1022
    96
	Parent::firstOut(edge, node);
klao@1022
    97
      } 
klao@1022
    98
deba@1039
    99
      Parent::getNotifier(Node()).erase(node);
klao@1022
   100
      Parent::erase(node);
klao@1022
   101
    }
klao@1022
   102
    
klao@1909
   103
    void erase(const UEdge& uedge) {
deba@1414
   104
      std::vector<Edge> edges;
deba@1627
   105
      edges.push_back(Parent::direct(uedge,true));
deba@1627
   106
      edges.push_back(Parent::direct(uedge,false));
deba@1414
   107
      Parent::getNotifier(Edge()).erase(edges);
klao@1909
   108
      Parent::getNotifier(UEdge()).erase(uedge);
klao@1022
   109
      Parent::erase(uedge);
klao@1022
   110
    }
klao@1022
   111
klao@1022
   112
  };
klao@1022
   113
deba@1842
   114
  template <typename _Base> 
klao@1909
   115
  class ErasableUEdgeSetExtender : public _Base {
deba@1842
   116
  public:
deba@1842
   117
klao@1909
   118
    typedef ErasableUEdgeSetExtender Graph;
deba@1842
   119
    typedef _Base Parent;
deba@1842
   120
deba@1842
   121
    typedef typename Parent::Node Node;
klao@1909
   122
    typedef typename Parent::UEdge UEdge;
deba@1842
   123
    typedef typename Parent::Edge Edge;
deba@1842
   124
klao@1909
   125
    void erase(const UEdge& uedge) {
deba@1842
   126
      std::vector<Edge> edges;
deba@1842
   127
      edges.push_back(Parent::direct(uedge,true));
deba@1842
   128
      edges.push_back(Parent::direct(uedge,false));
deba@1842
   129
      Parent::getNotifier(Edge()).erase(edges);
klao@1909
   130
      Parent::getNotifier(UEdge()).erase(uedge);
deba@1842
   131
      Parent::erase(uedge);
deba@1842
   132
    }
deba@1842
   133
deba@1842
   134
  };
deba@1842
   135
klao@946
   136
}
klao@946
   137
klao@946
   138
#endif