Class: LemonGraph::Digraph::Node
- Defined in:
- ext/lemongraph/lemongraph.cc,
ext/lemongraph/lemongraph.cc
Overview
Node of a LemonGraph::Digraph.
Instance Attribute Summary
Attributes inherited from GraphItem
Instance Method Summary collapse
-
#arc_from(source) ⇒ Arc
Creates an Arc from source source to target self.
-
#arc_to(target) ⇒ Arc
Creates an Arc from source self to target target.
-
#contract_in(other, remove_new_loops = true) ⇒ Node
Contracts self into the given node.
-
#each_inarc ⇒ self, Enumerator
Calls the block, if given, once for each incoming Arc to the node.
-
#each_outarc ⇒ self, Enumerator
Calls the block, if given, once for each outgoing Arc from the node.
-
#erase ⇒ self
Erases the node from the graph it belongs to.
-
#inarcs ⇒ Array<Arc>
Returns an array containing all the incoming arcs to the node.
-
#nb_inarcs ⇒ Integer
Number of incoming arcs to the node.
-
#nb_outarcs ⇒ Integer
Number of outgoing arcs from the node.
-
#opposite(arc) ⇒ Node
Returns the node opposite to self on arc.
-
#outarcs ⇒ Array<Arc>
Returns an array containing all the outgoing arcs from the node.
-
#split(connect = true) ⇒ Node
Splits the node.
-
#valid? ⇒ Boolean
Test if the node is valid, i.e.
Methods inherited from GraphItem
Instance Method Details
#arc_from(source) ⇒ Arc
Creates an Arc from source source to target self.
252 253 254 255 256 |
# File 'ext/lemongraph/digraph_node.cc', line 252 VALUE lemongraph_dinode_arc_from(VALUE self, VALUE source) { VALUE rbg = rb_iv_get(self, "@graph"); return lemongraph_digraph_add_arc(rbg, source, self); } |
#arc_to(target) ⇒ Arc
Creates an Arc from source self to target target.
241 242 243 244 245 |
# File 'ext/lemongraph/digraph_node.cc', line 241 VALUE lemongraph_dinode_arc_to(VALUE self, VALUE target) { VALUE rbg = rb_iv_get(self, "@graph"); return lemongraph_digraph_add_arc(rbg, self, target); } |
#contract_in(other, remove_new_loops = true) ⇒ Node
Contracts self into the given node. self is removed, but instead of deleting its incident arcs, they are joined to node other. If remove_new_loops is true (this is the default), then the newly created loops are removed.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'ext/lemongraph/digraph_node.cc', line 103 VALUE lemongraph_dinode_contract(int argc, VALUE *argv, VALUE self) { if (argc < 1 || argc > 2) rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 1..2)", argc); bool remove_new_loops = true; VALUE other = argv[0]; if (argc == 2) remove_new_loops = (argv[1] != Qnil && argv[1] != Qfalse); VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph &g = lemongraph_digraph_rb2ref(rbg); lemongraph_digraph_raise_if_not_valid_node(g, rbg, self); lemongraph_digraph_raise_if_not_valid_node(g, rbg, other); g.contract(lemongraph_rbdinode2dinode(other), lemongraph_rbdinode2dinode(self), remove_new_loops); return other; } |
#each_inarc {|arc| ... } ⇒ self #each_inarc ⇒ Enumerator
Calls the block, if given, once for each incoming Arc to the node. The arcs are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
166 167 168 169 170 171 172 173 174 175 |
# File 'ext/lemongraph/digraph_node.cc', line 166 VALUE lemongraph_dinode_each_inarc(VALUE self) { RETURN_SIZED_ENUMERATOR(self, 0, 0, lemongraph_dinode_inarcenum_nbinarcs); VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbg); lemon::ListDigraph::Node n = lemongraph_rbdinode2dinode(self); for (lemon::ListDigraph::InArcIt a(g, n); a != lemon::INVALID; ++a) rb_yield(lemongraph_make_diarc(a, rbg)); return self; } |
#each_outarc {|arc| ... } ⇒ self #each_outarc ⇒ Enumerator
Calls the block, if given, once for each outgoing Arc from the node. The arcs are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
225 226 227 228 229 230 231 232 233 234 |
# File 'ext/lemongraph/digraph_node.cc', line 225 VALUE lemongraph_dinode_each_outarc(VALUE self) { RETURN_SIZED_ENUMERATOR(self, 0, 0, lemongraph_dinode_outarcenum_nboutarcs); VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbg); lemon::ListDigraph::Node n = lemongraph_rbdinode2dinode(self); for (lemon::ListDigraph::OutArcIt a(g, n); a != lemon::INVALID; ++a) rb_yield(lemongraph_make_diarc(a, rbg)); return self; } |
#erase ⇒ self
Erases the node from the graph it belongs to.
65 66 67 68 69 |
# File 'ext/lemongraph/digraph_node.cc', line 65 VALUE lemongraph_dinode_erase(VALUE self) { lemongraph_digraph_rb2ref(rb_iv_get(self, "@graph")).erase(lemongraph_rbdinode2dinode(self)); return self; } |
#inarcs ⇒ Array<Arc>
Returns an array containing all the incoming arcs to the node.
135 136 137 138 139 140 141 142 143 144 |
# File 'ext/lemongraph/digraph_node.cc', line 135 VALUE lemongraph_dinode_inarcs(VALUE self) { VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbg); lemon::ListDigraph::Node n = lemongraph_rbdinode2dinode(self); VALUE ar = rb_ary_new_capa(lemon::countInArcs(g, n)); for (lemon::ListDigraph::InArcIt a(g, n); a != lemon::INVALID; ++a) rb_ary_push(ar, lemongraph_make_diarc(a, rbg)); return ar; } |
#nb_inarcs ⇒ Integer
Number of incoming arcs to the node.
123 124 125 126 127 128 129 |
# File 'ext/lemongraph/digraph_node.cc', line 123 VALUE lemongraph_dinode_nb_inarcs(VALUE self) { VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbg); lemon::ListDigraph::Node n = lemongraph_rbdinode2dinode(self); return INT2NUM(lemon::countInArcs(g, n)); } |
#nb_outarcs ⇒ Integer
Number of outgoing arcs from the node.
182 183 184 185 186 187 188 |
# File 'ext/lemongraph/digraph_node.cc', line 182 VALUE lemongraph_dinode_nb_outarcs(VALUE self) { VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbg); lemon::ListDigraph::Node n = lemongraph_rbdinode2dinode(self); return INT2NUM(lemon::countOutArcs(g, n)); } |
#opposite(arc) ⇒ Node
Returns the node opposite to self on arc. Returns nil if arc is not incident to self.
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'ext/lemongraph/digraph_node.cc', line 264 VALUE lemongraph_dinode_opposite(VALUE self, VALUE arc) { VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbg); if (rb_class_of(arc) != c_DiArc) { rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s", rb_class_name(c_DiArc), rb_obj_classname(arc)); } if (rb_iv_get(arc, "@graph") != rbg) rb_raise(rb_eRuntimeError, "node and arc are not from the same graph"); return lemongraph_make_dinode(g.oppositeNode(lemongraph_rbdinode2dinode(self), lemongraph_rbdiarc2diarc(arc)), rbg); } |
#outarcs ⇒ Array<Arc>
Returns an array containing all the outgoing arcs from the node.
194 195 196 197 198 199 200 201 202 203 |
# File 'ext/lemongraph/digraph_node.cc', line 194 VALUE lemongraph_dinode_outarcs(VALUE self) { VALUE rbg = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbg); lemon::ListDigraph::Node n = lemongraph_rbdinode2dinode(self); VALUE ar = rb_ary_new_capa(lemon::countOutArcs(g, n)); for (lemon::ListDigraph::OutArcIt a(g, n); a != lemon::INVALID; ++a) rb_ary_push(ar, lemongraph_make_diarc(a, rbg)); return ar; } |
#split(connect = true) ⇒ Node
Splits the node. First, a new node is added to the digraph, then the source of each outgoing arc of self is moved to this new node. If the parameter connect is true (this is the default), then a new arc from self to the newly created node is also added.
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'ext/lemongraph/digraph_node.cc', line 81 VALUE lemongraph_dinode_split(int argc, VALUE *argv, VALUE self) { bool connect = true; if (argc == 1) connect = (argv[0] != Qnil && argv[0] != Qfalse); else if (argc > 1) rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0..1)", argc); VALUE rbgraph = rb_iv_get(self, "@graph"); lemon::ListDigraph& g = lemongraph_digraph_rb2ref(rbgraph); lemon::ListDigraph::Node n = g.split(lemongraph_rbdinode2dinode(self), connect); return lemongraph_make_dinode(n, rbgraph); } |
#valid? ⇒ Boolean
Test if the node is valid, i.e. it is a real node of the graph it belongs to.
56 57 58 59 |
# File 'ext/lemongraph/digraph_node.cc', line 56 VALUE lemongraph_dinode_is_valid(VALUE self) { return lemongraph_digraph_rb2ref(rb_iv_get(self, "@graph")).valid(lemongraph_rbdinode2dinode(self)) ? Qtrue : Qfalse; } |