[15065] | 1 | #include "./bamgobjects.h"
|
---|
[3913] | 2 |
|
---|
| 3 | using namespace std;
|
---|
| 4 | namespace bamg {
|
---|
| 5 |
|
---|
| 6 | /*Constructor*/
|
---|
[18301] | 7 | SetOfEdges4::SetOfEdges4(long mmx,long nnx){/*{{{*/
|
---|
[3913] | 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 | }
|
---|
[12365] | 24 | /*}}}*/
|
---|
[3913] | 25 |
|
---|
| 26 | /*Methods*/
|
---|
[18301] | 27 | long SetOfEdges4::add(long ii,long jj) {/*{{{*/
|
---|
[3913] | 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)
|
---|
[6412] | 34 | _assert_(head);
|
---|
[3913] | 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 ) {
|
---|
[13036] | 50 | _error_("SetOfEdges4::add overflow: NbOfEdges=" << NbOfEdges << " > nbax=" << nbax);
|
---|
[3913] | 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 | }
|
---|
[12365] | 60 | /*}}}*/
|
---|
[18301] | 61 | long SetOfEdges4::find(long ii,long jj) { /*{{{*/
|
---|
[5150] | 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
|
---|
[6412] | 68 | _assert_(head);
|
---|
[5150] | 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 | }
|
---|
[12365] | 86 | /*}}}*/
|
---|
[18301] | 87 | long SetOfEdges4::i(long k){/*{{{*/
|
---|
[5150] | 88 | return Edges[k].i;
|
---|
| 89 | }
|
---|
[12365] | 90 | /*}}}*/
|
---|
[18301] | 91 | long SetOfEdges4::j(long k){/*{{{*/
|
---|
[5150] | 92 | return Edges[k].j;
|
---|
| 93 | }
|
---|
[12365] | 94 | /*}}}*/
|
---|
[18301] | 95 | long SetOfEdges4::nb(){/*{{{*/
|
---|
[5150] | 96 | return NbOfEdges;
|
---|
| 97 | }
|
---|
[12365] | 98 | /*}}}*/
|
---|
[18301] | 99 | long SetOfEdges4::SortAndAdd (long ii,long jj) {/*{{{*/
|
---|
[5150] | 100 | return ii <=jj ? add (ii,jj) : add (jj,ii) ;
|
---|
| 101 | }
|
---|
[12365] | 102 | /*}}}*/
|
---|
[18301] | 103 | long SetOfEdges4::SortAndFind (long ii,long jj) {/*{{{*/
|
---|
[5150] | 104 | return ii <=jj ? find (ii,jj) : find (jj,ii) ;
|
---|
| 105 | }
|
---|
[12365] | 106 | /*}}}*/
|
---|
[3913] | 107 | }
|
---|