home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + _g_array.c
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
- #include <LEDA/graph.h>
-
-
- //------------------------------------------------------------------------------
- // node and edge arrays
- //------------------------------------------------------------------------------
-
- #define graph_arrayimplement(itype)\
- \
- ent& graph_array(itype)::entry(itype x)\
- { if (g != graph_of(x) || index(x) > max_i)\
- error_handler(102,"(node/edge)_array[x]: not defined for x");\
- return arr[index(x)];\
- }\
- \
- ent graph_array(itype)::inf(itype x) const\
- { if (g != graph_of(x) || index(x) > max_i)\
- error_handler(102,"(node/edge)_array[x]: not defined for x");\
- return arr[index(x)];\
- }\
- \
- void graph_array(itype)::init(const graph& G, int n, ent i)\
- { if (g!=0) clear();\
- g = (graph*)&G;\
- max_i=n-1;\
- arr=new ent[n];\
- if (arr==0) error_handler(104,"(node/edge)_array.init(G): out of memory");\
- if (max_i<0) error_handler(0,"(node/edge)_array.init(G): empty graph");\
- for (int j=0;j<=max_i;j++) { copy_entry(i);\
- arr[j] = i;\
- }\
- }\
- \
- \
- void graph_array(itype)::init(const graph& G, ent i)\
- { init(G,name3(G.max_,itype,_i)()+1,i); }\
- \
- void graph_array(itype)::init(const graph_array(itype)& A)\
- { if (g!=0) clear();\
- g = A.g;\
- max_i=A.max_i;\
- arr=new ent[max_i+1];\
- if (arr==0) error_handler(1,"(node/edge)_array.init: out of memory");\
- for (int j=0;j<=max_i;j++)\
- { ent x = A.arr[j];\
- copy_entry(x);\
- arr[j] = x;\
- }\
- }\
- \
- void graph_array(itype)::clear()\
- { int j;\
- for (j=0;j<=max_i;j++) clear_entry(arr[j]);\
- if (arr) delete arr;\
- arr=0; g=0; max_i = -1;\
- }\
-
-
- implement(graph_array,node)
- implement(graph_array,edge)
-
- //------------------------------------------------------------------------------
- // node matrices
- //------------------------------------------------------------------------------
-
- graph_array(node)& Node_Matrix::operator[](node v)
- { return *(M[v]); }
-
- ent& Node_Matrix::entry(node v, node w) { return M[v]->entry(w); }
- ent Node_Matrix::inf(node v, node w) const { return M[v]->inf(w); }
-
- void Node_Matrix::init(const graph& G, int n, ent x)
- { int i,j;
- g = (graph*)&G;
- M.init(G,n,0);
- for(i=0;i<M.size();i++)
- { M.elem(i) = new graph_array(node);
- M.elem(i) -> init(G,n,0);
- for(j=0;j<M.elem(i)->size();j++)
- { copy_entry(x);
- M.elem(i)->elem(j) = x;
- }
- }
- }
-
- void Node_Matrix::init(const graph& G, ent x)
- { init(G,G.max_node_i()+1,x); }
-
- void Node_Matrix::init(Node_Matrix& A)
- { int i,j;
- g = A.g;
- M.init(*g,0);
- for(i=0;i<M.size();i++)
- { M.elem(i) = new graph_array(node);
- M.elem(i) -> init(*g,0);
- for(j=0;j<M.elem(i)->size();j++)
- { ent x = A.M.elem(i)->elem(j);
- copy_entry(x);
- M.elem(i)->elem(j) = x;
- }
- }
- }
-
- void Node_Matrix::clear()
- { int i,j;
- for(i=0;i<M.size();i++)
- { for(j=0;j<M.elem(i)->size();j++)
- { ent x = M.elem(i)->elem(j);
- clear_entry(x);
- }
- delete M.elem(i);
- }
- M.clear();
- }
-
-