Ice Sheet System Model  4.18
Code documentation
SetOfE4.cpp
Go to the documentation of this file.
1 #include "./bamgobjects.h"
2 
3 using namespace std;
4 namespace bamg {
5 
6  /*Constructor*/
7  SetOfEdges4::SetOfEdges4(long mmx,long nnx){/*{{{*/
8  /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/SetOfEdges4)*/
9 
10  /*Intermediary*/
11  int i;
12 
13  //initialize fields
14  nx =nnx; //number of vertices
15  nbax =mmx; // 3 * number of triangles
16  NbOfEdges=0;
17  head = new long [nx];
18  Edges= new IntEdge[nbax];
19 
20  //initialize head (-1 everywhere)
21  i=nx;
22  while(i--) head[i]=-1;
23  }
24  /*}}}*/
25 
26  /*Methods*/
27  long SetOfEdges4::add(long ii,long jj) {/*{{{*/
28  /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/add)*/
29 
30  /*Intermediary*/
31  int h,n;
32 
33  //get n from h (usually h=ii)
34  _assert_(head);
35  n=head[h=Abs(ii)%nx];
36 
37  //go through the existing edges that holds h (=ii) and check that
38  //the edge ii jj is not already in Edge
39  while (n >= 0){
40 
41  //if the edge ii jj is already in Edges, return n
42  if (ii == Edges[n].i && jj == Edges[n].j) return n;
43 
44  //else go to next edge that holds ii
45  else n = Edges[n].next;
46  }
47 
48  //check that nbax <=NbOfEdges
49  if (nbax <=NbOfEdges ) {
50  _error_("SetOfEdges4::add overflow: NbOfEdges=" << NbOfEdges << " > nbax=" << nbax);
51  }
52 
53  //update chain
54  Edges[NbOfEdges].i=ii;
55  Edges[NbOfEdges].j=jj;
56  Edges[NbOfEdges].next= head[h];
57  head[h] = NbOfEdges;
58  return NbOfEdges ++;
59  }
60  /*}}}*/
61  long SetOfEdges4::find(long ii,long jj) { /*{{{*/
62  /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/find)*/
63 
64  /*Intermediary*/
65  int n;
66 
67  //check that head is not empty
68  _assert_(head);
69 
70  //get n from h (usually h=ii)
71  n=head[Abs(ii)%nx];
72 
73  //go through the existing edges that holds h (=ii) and return position in Edge
74  while (n >= 0){
75 
76  //if the edge ii jj is already in Edges, return n
77  if (ii == Edges[n].i && jj == Edges[n].j) return n;
78 
79  //else go to next edge that holds ii
80  else n = Edges[n].next;
81  }
82 
83  //if we reach this point, the edge does not exist return -1
84  return -1;
85  }
86  /*}}}*/
87  long SetOfEdges4::i(long k){/*{{{*/
88  return Edges[k].i;
89  }
90  /*}}}*/
91  long SetOfEdges4::j(long k){/*{{{*/
92  return Edges[k].j;
93  }
94  /*}}}*/
95  long SetOfEdges4::nb(){/*{{{*/
96  return NbOfEdges;
97  }
98  /*}}}*/
99  long SetOfEdges4::SortAndAdd (long ii,long jj) {/*{{{*/
100  return ii <=jj ? add (ii,jj) : add (jj,ii) ;
101  }
102  /*}}}*/
103  long SetOfEdges4::SortAndFind (long ii,long jj) {/*{{{*/
104  return ii <=jj ? find (ii,jj) : find (jj,ii) ;
105  }
106  /*}}}*/
107 }
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
bamg
Definition: AdjacentTriangle.cpp:9
bamg::IntEdge
Definition: SetOfE4.h:8
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
bamg::Abs
T Abs(const T &a)
Definition: Abs.h:5
bamgobjects.h