ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/outil/src/HypergraphLib_Arc.cpp
Revision: 27
Committed: Thu Jul 5 15:26:40 2007 UTC (17 years, 10 months ago) by foucault
Original Path: magic/lib/outil/outil/src/HypergraphLib_Arc.cpp
File size: 1785 byte(s)
Log Message:

File Contents

# User Rev Content
1 foucault 27
2     #include <iostream>
3    
4     #pragma hdrstop
5     #include "HypergraphLib_platform.h"
6    
7     #include "HypergraphLib_Arc.h"
8     #include "HypergraphLib_Graph.h"
9     #include "HypergraphLib_Node.h"
10    
11    
12     namespace HypergraphLib {
13    
14     Arc::Arc(Graph * __owner, int __id)
15     : GraphObject (__owner, __id)
16     {
17     }
18    
19     Arc::Arc(const Arc &__from, Graph * __owner)
20     : GraphObject(__from, __owner)
21     {
22     for (Arc::MultimapNodesById::const_iterator it = __from._nodes.begin();
23     it != __from._nodes.end();
24     it++)
25     {
26     Node * n = _owner->GetNode(it->first);
27     if (n)
28     {
29     Add (n);
30     }
31     }
32     }
33    
34     Arc::~Arc()
35     {
36    
37     }
38    
39     void Arc::Add (Node * __node)
40     {
41     _nodes.insert ( Int_Node_Pair ( __node->Id(), __node ));
42     }
43    
44     int Arc::Remove (Node * __node)
45     {
46     return Remove (__node->Id());
47     }
48    
49     int Arc::Remove (int __id)
50     {
51     int result=0;
52     MultimapNodesById::iterator it;
53     for (it = _nodes.find ( __id );
54     it != _nodes.end();
55     it = _nodes.find ( __id ), result++)
56     _nodes.erase ( it );
57    
58     /*while(it!=_nodes.end())
59     {
60     _nodes.erase ( it );
61     it = _nodes.find ( __id );
62     }*/
63    
64     return result;
65     }
66    
67     int Arc::Rank () const
68     {
69     return _nodes.size();
70     }
71    
72     int Arc::NodeCount(int __id) const
73     {
74     return _nodes.count(__id);
75     }
76    
77     Arc::MultimapNodesById & Arc::Nodes()
78     {
79     return _nodes;
80     }
81    
82     Node * Arc::First() const
83     {
84     MultimapNodesById::const_iterator it = _nodes.begin();
85     return it->second;
86     }
87    
88     Node * Arc::Last() const
89     {
90     MultimapNodesById::const_iterator it = _nodes.end();
91     it--;
92     return it->second;
93     }
94    
95     bool Arc::IsLoopOfNode(int __NodeId)
96     {
97     return (NodeCount(__NodeId ) == 2);
98     }
99    
100     bool Arc::IsLoop()
101     {
102     return (_nodes.size() == 2 && First() == Last() );
103     }
104    
105     }
106