node_set.h
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:2k
开发平台:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  node_set.h
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #ifndef LEDA_NODE_SET_H
  12. #define LEDA_NODE_SET_H
  13. //------------------------------------------------------------------------------
  14. // node_set  
  15. //------------------------------------------------------------------------------
  16. #include <LEDA/graph.h>
  17. /*{Manpage {node_set} {} {Sets of Nodes} }*/
  18. class node_set 
  19. {
  20. /*{Mdefinition
  21. An instance $S$ of the data type $node_set$ is a subset of
  22. the nodes of a graph $G$. $S$ is said to be valid for the nodes
  23. of $G$.}*/
  24.   graph* g;
  25.   list<node> L;
  26.   node_array<list_item> A;
  27. public:
  28. /*{Mcreation S }*/
  29. node_set(const graph& G) : A(G,nil) { g = (graph*)&G; }
  30. /*{Mcreate creates an instance $S$ of type $node_set$ valid for all 
  31.             nodes currently contained in graph $G$ and initializes it 
  32.             to the empty set.}*/
  33. ~node_set() {}
  34. /*{Moperations 1.3 4 }*/
  35. void insert(node x)  { if (A[x] == nil) A[x] = L.append(x); }
  36. /*{Mop       adds node $x$ to $S$. }*/
  37. void del(node x)     { if (A[x] != nil) { L.del(A[x]); A[x] = nil;} }
  38. /*{Mop       removes node $x$ from $S$. }*/
  39. bool member(node x)  { return (A[x] != nil); }
  40. /*{Mop      returns true if $x$ in $S$, false otherwise. }*/
  41. node choose()  const { return L.head(); }
  42. /*{Mop      returns a node of $S$. }*/
  43. int  size()    const { return L.length(); }
  44. /*{Mop      returns the size of $S$. }*/
  45. bool empty()   const { return L.empty(); }
  46. /*{Mop      returns true iff $S$ is the empty set. }*/
  47. void clear()         { L.clear(); A.init(*g,nil); }
  48. /*{Mop      makes $S$ the empty set. }*/
  49. };
  50. /*{Mimplementation
  51. A node set $S$ for a graph $G$ is implemented by a combination of a 
  52. list  $L$ of nodes and a node array of list_items 
  53. associating with each node its position in $L$. All operations 
  54. take constant time, except for clear which takes time $O(|S|)$. The space 
  55. requirement is $O(n)$, where $n$ is the number of nodes of $G$.}*/
  56. #endif