lemongraph 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +8 -0
  3. data/LICENSE +674 -0
  4. data/README.md +6 -0
  5. data/ext/lemon-1.3.1/AUTHORS +26 -0
  6. data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
  7. data/ext/lemon-1.3.1/INSTALL +167 -0
  8. data/ext/lemon-1.3.1/LICENSE +32 -0
  9. data/ext/lemon-1.3.1/NEWS +337 -0
  10. data/ext/lemon-1.3.1/README +50 -0
  11. data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
  12. data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
  13. data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
  14. data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
  15. data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
  16. data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
  17. data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
  18. data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
  19. data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
  20. data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
  21. data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
  22. data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
  23. data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
  24. data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
  25. data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
  26. data/ext/lemon-1.3.1/lemon/assert.h +214 -0
  27. data/ext/lemon-1.3.1/lemon/base.cc +37 -0
  28. data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
  29. data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
  30. data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
  31. data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
  32. data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
  33. data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
  34. data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
  35. data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
  36. data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
  37. data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
  38. data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
  39. data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
  40. data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
  41. data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
  42. data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
  43. data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
  44. data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
  45. data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
  46. data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
  47. data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
  48. data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
  49. data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
  50. data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
  51. data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
  52. data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
  53. data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
  54. data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
  55. data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
  56. data/ext/lemon-1.3.1/lemon/clp.h +164 -0
  57. data/ext/lemon-1.3.1/lemon/color.cc +44 -0
  58. data/ext/lemon-1.3.1/lemon/color.h +204 -0
  59. data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
  60. data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
  61. data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
  62. data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
  63. data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
  64. data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
  65. data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
  66. data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
  67. data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
  68. data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
  69. data/ext/lemon-1.3.1/lemon/core.h +2506 -0
  70. data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
  71. data/ext/lemon-1.3.1/lemon/counter.h +249 -0
  72. data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
  73. data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
  74. data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
  75. data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
  76. data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
  77. data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
  78. data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
  79. data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
  80. data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
  81. data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
  82. data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
  83. data/ext/lemon-1.3.1/lemon/error.h +276 -0
  84. data/ext/lemon-1.3.1/lemon/euler.h +287 -0
  85. data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
  86. data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
  87. data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
  88. data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
  89. data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
  90. data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
  91. data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
  92. data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
  93. data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
  94. data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
  95. data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
  96. data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
  97. data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
  98. data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
  99. data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
  100. data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
  101. data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
  102. data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
  103. data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
  104. data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
  105. data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
  106. data/ext/lemon-1.3.1/lemon/lp.h +95 -0
  107. data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
  108. data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
  109. data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
  110. data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
  111. data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
  112. data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
  113. data/ext/lemon-1.3.1/lemon/math.h +77 -0
  114. data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
  115. data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
  116. data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
  117. data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
  118. data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
  119. data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
  120. data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
  121. data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
  122. data/ext/lemon-1.3.1/lemon/path.h +1164 -0
  123. data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
  124. data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
  125. data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
  126. data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
  127. data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
  128. data/ext/lemon-1.3.1/lemon/random.cc +29 -0
  129. data/ext/lemon-1.3.1/lemon/random.h +1005 -0
  130. data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
  131. data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
  132. data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
  133. data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
  134. data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
  135. data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
  136. data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
  137. data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
  138. data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
  139. data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
  140. data/ext/lemongraph/arc_map.cc +1007 -0
  141. data/ext/lemongraph/digraph.cc +282 -0
  142. data/ext/lemongraph/digraph_arc.cc +153 -0
  143. data/ext/lemongraph/digraph_node.cc +277 -0
  144. data/ext/lemongraph/edge_map.cc +770 -0
  145. data/ext/lemongraph/extconf.rb +53 -0
  146. data/ext/lemongraph/graph.cc +351 -0
  147. data/ext/lemongraph/graph_arc.cc +95 -0
  148. data/ext/lemongraph/graph_edge.cc +153 -0
  149. data/ext/lemongraph/graph_item.cc +76 -0
  150. data/ext/lemongraph/graph_node.cc +321 -0
  151. data/ext/lemongraph/lemongraph.cc +260 -0
  152. data/ext/lemongraph/lemongraph.hh +295 -0
  153. data/ext/lemongraph/lemongraph.map +6 -0
  154. data/ext/lemongraph/lemongraph_export.hh +31 -0
  155. data/ext/lemongraph/node_map.cc +1011 -0
  156. data/lemongraph.gemspec +176 -0
  157. data/lib/lemongraph/graphviz.rb +240 -0
  158. data/lib/lemongraph/version.rb +4 -0
  159. data/lib/lemongraph.rb +21 -0
  160. data/samples/lemondeps.rb +38 -0
  161. metadata +202 -0
@@ -0,0 +1,1007 @@
1
+ /* Copyright (C) 2022 Théotime Bollengier <theotime.bollengier@ensta-bretagne.fr>
2
+ *
3
+ * This file is part of LemonGraph. <https://gitlab.ensta-bretagne.fr/bollenth/lemongraph>
4
+ *
5
+ * LemonGraph is free software: you can redistribute it and/or modify it
6
+ * under the terms of the GNU General Public License as published
7
+ * by the Free Software Foundation, either version 3 of the License,
8
+ * or (at your option) any later version.
9
+ *
10
+ * LemonGraph is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ * See the GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with LemonGraph. If not, see <https://www.gnu.org/licenses/>. 
17
+ */
18
+
19
+
20
+ #include <ruby.h>
21
+ #include "lemongraph.hh"
22
+
23
+
24
+ VALUE c_ArcMap;
25
+
26
+
27
+ namespace LemonGraph {
28
+
29
+ class ArcMap {
30
+ private:
31
+ VALUE m_self;
32
+ VALUE m_graph;
33
+ VALUE m_default_value;
34
+ VALUE m_default_proc;
35
+ union {
36
+ lemon::ListDigraph::ArcMap<RBValue> *m_diarcmap;
37
+ lemon::ListGraph::ArcMap<RBValue> *m_unarcmap;
38
+ void *m_ptr;
39
+ };
40
+ bool m_diunbar;
41
+ public:
42
+ ArcMap();
43
+ ~ArcMap();
44
+ void initialize(VALUE self, VALUE graph, VALUE default_value, VALUE default_proc);
45
+ void mark();
46
+ bool is_for_directed_graph() const { return m_diunbar; }
47
+ VALUE graph() const { return m_graph; }
48
+ VALUE default_value() const { return m_default_value; }
49
+ void set_default_value(VALUE dflt) { m_default_value = dflt; }
50
+ VALUE default_proc() const { return m_default_proc; }
51
+ void set_default_proc(VALUE prc);
52
+ RBValue& operator[](lemon::ListDigraph::Arc& a);
53
+ RBValue& operator[](lemon::ListGraph::Arc& a);
54
+ VALUE get(VALUE arc);
55
+ void set(VALUE arc, VALUE value);
56
+ VALUE keys();
57
+ VALUE values();
58
+ VALUE length();
59
+ VALUE is_empty();
60
+ VALUE each_arc();
61
+ VALUE each_value();
62
+ VALUE each_pair();
63
+ void clear();
64
+ VALUE del(VALUE arc);
65
+ VALUE del_if();
66
+ VALUE has_arc(VALUE arc);
67
+ VALUE has_value(VALUE val);
68
+ bool is_equal(const ArcMap& other);
69
+ VALUE hash();
70
+
71
+ private:
72
+ void check_key_di(VALUE arc);
73
+ void check_key_un(VALUE arc);
74
+ VALUE value_or_default(VALUE val, VALUE arckey);
75
+ };
76
+
77
+
78
+ ArcMap::ArcMap() :
79
+ m_self(Qnil),
80
+ m_graph(Qnil),
81
+ m_default_value(Qnil),
82
+ m_default_proc(Qnil),
83
+ m_ptr(NULL),
84
+ m_diunbar(false)
85
+ {
86
+ }
87
+
88
+
89
+ ArcMap::~ArcMap()
90
+ {
91
+ if (m_ptr) {
92
+ if (m_diunbar)
93
+ delete m_diarcmap;
94
+ else if (rb_class_of(m_graph) == c_Graph)
95
+ delete m_unarcmap;
96
+ }
97
+ m_ptr = NULL;
98
+ }
99
+
100
+
101
+ void ArcMap::mark()
102
+ {
103
+ rb_gc_mark(m_graph);
104
+ rb_gc_mark(m_default_value);
105
+ rb_gc_mark(m_default_proc);
106
+ if (!m_ptr)
107
+ return;
108
+ if (m_diunbar) {
109
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
110
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a)
111
+ rb_gc_mark((*m_diarcmap)[a].value);
112
+ }
113
+ else if (rb_class_of(m_graph) == c_Graph) {
114
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
115
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a)
116
+ rb_gc_mark((*m_unarcmap)[a].value);
117
+ }
118
+ }
119
+
120
+
121
+ void ArcMap::initialize(VALUE self, VALUE graph, VALUE default_value, VALUE default_proc)
122
+ {
123
+ if (m_self != Qnil)
124
+ rb_raise(rb_eRuntimeError, "ArcMap already initialized");
125
+ m_self = self;
126
+ m_graph = graph;
127
+ m_default_value = default_value;
128
+ m_default_proc = default_proc;
129
+ if (rb_obj_is_kind_of(m_graph, c_Digraph) == Qtrue) {
130
+ m_diunbar = true;
131
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
132
+ m_diarcmap = new lemon::ListDigraph::ArcMap<RBValue>(g);
133
+ }
134
+ else if (rb_obj_is_kind_of(m_graph, c_Graph) == Qtrue) {
135
+ m_diunbar = false;
136
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
137
+ m_unarcmap = new lemon::ListGraph::ArcMap<RBValue>(g);
138
+ }
139
+ else {
140
+ rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE " or a %" PRIsVALUE ", not a %s",
141
+ rb_class_name(c_Digraph), rb_class_name(c_Graph), rb_obj_classname(m_graph));
142
+ }
143
+ }
144
+
145
+
146
+ void ArcMap::set_default_proc(VALUE prc)
147
+ {
148
+ if (!rb_obj_is_kind_of(prc, rb_cProc) && prc != Qnil) {
149
+ rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
150
+ rb_class_name(rb_cProc), rb_obj_classname(prc));
151
+ }
152
+ m_default_proc = prc;
153
+ }
154
+
155
+
156
+ VALUE ArcMap::value_or_default(VALUE val, VALUE arckey)
157
+ {
158
+ if (val == Qundef) {
159
+ if (m_default_proc != Qnil) {
160
+ VALUE args = rb_ary_new_from_args(2, arckey, m_self);
161
+ val = rb_proc_call(m_default_proc, args);
162
+ }
163
+ else
164
+ val = m_default_value;
165
+ }
166
+ return val;
167
+ }
168
+
169
+
170
+ void ArcMap::check_key_di(VALUE arc)
171
+ {
172
+ if (rb_class_of(arc) != c_DiArc) {
173
+ rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE " as key, not a %s",
174
+ rb_class_name(c_DiArc), rb_obj_classname(arc));
175
+ }
176
+ VALUE rbg = rb_iv_get(arc, "@graph");
177
+ if (rbg != m_graph)
178
+ rb_raise(rb_eRuntimeError, "key arc and arc map do not belong to the same graph");
179
+ }
180
+
181
+
182
+ void ArcMap::check_key_un(VALUE arc)
183
+ {
184
+ if (rb_class_of(arc) != c_UnArc) {
185
+ rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE " as key, not a %s",
186
+ rb_class_name(c_UnArc), rb_obj_classname(arc));
187
+ }
188
+ VALUE rbg = rb_iv_get(arc, "@graph");
189
+ if (rbg != m_graph)
190
+ rb_raise(rb_eRuntimeError, "key arc and arc map do not belong to the same graph");
191
+ }
192
+
193
+
194
+ RBValue& ArcMap::operator[](lemon::ListDigraph::Arc& a)
195
+ {
196
+ if (!m_diarcmap)
197
+ rb_raise(rb_eRuntimeError, "accessing empty ArcMap");
198
+ return (*m_diarcmap)[a];
199
+ }
200
+
201
+
202
+ RBValue& ArcMap::operator[](lemon::ListGraph::Arc& a)
203
+ {
204
+ if (!m_unarcmap)
205
+ rb_raise(rb_eRuntimeError, "accessing empty ArcMap");
206
+ return (*m_unarcmap)[a];
207
+ }
208
+
209
+
210
+ VALUE ArcMap::get(VALUE arc)
211
+ {
212
+ VALUE v = Qundef;
213
+ if (m_diunbar) {
214
+ check_key_di(arc);
215
+ lemon::ListDigraph::Arc a = lemongraph_rbdiarc2diarc(arc);
216
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
217
+ if (!g.valid(a))
218
+ rb_raise(rb_eRuntimeError, "key arc is not a valid arc for its graph");
219
+ v = (*m_diarcmap)[a].value;
220
+ }
221
+ else {
222
+ check_key_un(arc);
223
+ lemon::ListGraph::Arc a = lemongraph_rbunarc2unarc(arc);
224
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
225
+ if (!g.valid(a))
226
+ rb_raise(rb_eRuntimeError, "key arc is not a valid arc for its graph");
227
+ v = (*m_unarcmap)[a].value;
228
+ }
229
+ return value_or_default(v, arc);
230
+ }
231
+
232
+
233
+ void ArcMap::set(VALUE arc, VALUE value)
234
+ {
235
+ if (m_diunbar) {
236
+ check_key_di(arc);
237
+ lemon::ListDigraph::Arc a = lemongraph_rbdiarc2diarc(arc);
238
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
239
+ if (!g.valid(a))
240
+ rb_raise(rb_eRuntimeError, "key arc is not a valid arc for its graph");
241
+ m_diarcmap->set(a, RBValue(value));
242
+ }
243
+ else {
244
+ check_key_un(arc);
245
+ lemon::ListGraph::Arc a = lemongraph_rbunarc2unarc(arc);
246
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
247
+ if (!g.valid(a))
248
+ rb_raise(rb_eRuntimeError, "key arc is not a valid arc for its graph");
249
+ m_unarcmap->set(a, RBValue(value));
250
+ }
251
+ }
252
+
253
+
254
+ VALUE ArcMap::del(VALUE arc)
255
+ {
256
+ VALUE v = Qundef;
257
+ if (m_diunbar) {
258
+ check_key_di(arc);
259
+ lemon::ListDigraph::Arc a = lemongraph_rbdiarc2diarc(arc);
260
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
261
+ if (!g.valid(a))
262
+ rb_raise(rb_eRuntimeError, "key arc is not a valid arc for its graph");
263
+ v = (*m_diarcmap)[a].value;
264
+ m_diarcmap->set(a, Qundef);
265
+ }
266
+ else {
267
+ check_key_un(arc);
268
+ lemon::ListGraph::Arc a = lemongraph_rbunarc2unarc(arc);
269
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
270
+ if (!g.valid(a))
271
+ rb_raise(rb_eRuntimeError, "key arc is not a valid arc for its graph");
272
+ v = (*m_unarcmap)[a].value;
273
+ m_unarcmap->set(a, Qundef);
274
+ }
275
+ return value_or_default(v, arc);
276
+ }
277
+
278
+
279
+ VALUE ArcMap::has_arc(VALUE arc)
280
+ {
281
+ VALUE klass = rb_class_of(arc);
282
+ if (m_diunbar) {
283
+ if (klass != c_DiArc)
284
+ return Qfalse;
285
+ if (rb_iv_get(arc, "@graph") != m_graph)
286
+ return Qfalse;
287
+ lemon::ListDigraph::Arc a = lemongraph_rbdiarc2diarc(arc);
288
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
289
+ if (!g.valid(a))
290
+ return Qfalse;
291
+ if ((*m_diarcmap)[a].is_valid())
292
+ return Qtrue;
293
+ }
294
+ else {
295
+ if (klass != c_UnArc)
296
+ return Qfalse;
297
+ if (rb_iv_get(arc, "@graph") != m_graph)
298
+ return Qfalse;
299
+ lemon::ListGraph::Arc a = lemongraph_rbunarc2unarc(arc);
300
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
301
+ if (!g.valid(a))
302
+ return Qfalse;
303
+ if ((*m_unarcmap)[a].is_valid())
304
+ return Qtrue;
305
+ }
306
+ return Qfalse;
307
+ }
308
+
309
+
310
+ VALUE ArcMap::has_value(VALUE value)
311
+ {
312
+ if (m_diunbar) {
313
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
314
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
315
+ VALUE v = (*m_diarcmap)[a].value;
316
+ if (v != Qundef) {
317
+ if (rb_funcallv(v, id_eqeq, 1, &value) == Qtrue)
318
+ return Qtrue;
319
+ }
320
+ }
321
+ }
322
+ else {
323
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
324
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
325
+ VALUE v = (*m_unarcmap)[a].value;
326
+ if (v != Qundef) {
327
+ if (rb_funcallv(v, id_eqeq, 1, &value) == Qtrue)
328
+ return Qtrue;
329
+ }
330
+ }
331
+ }
332
+ return Qfalse;
333
+ }
334
+
335
+
336
+ VALUE ArcMap::keys()
337
+ {
338
+ int cnt = 0;
339
+ VALUE ar;
340
+ if (m_diunbar) {
341
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
342
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
343
+ if ((*m_diarcmap)[a].is_valid())
344
+ cnt++;
345
+ }
346
+ ar = rb_ary_new_capa(cnt);
347
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
348
+ if ((*m_diarcmap)[a].is_valid())
349
+ rb_ary_push(ar, lemongraph_make_diarc(a, m_graph));
350
+ }
351
+ }
352
+ else {
353
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
354
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
355
+ if ((*m_unarcmap)[a].is_valid())
356
+ cnt++;
357
+ }
358
+ ar = rb_ary_new_capa(cnt);
359
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
360
+ if ((*m_unarcmap)[a].is_valid())
361
+ rb_ary_push(ar, lemongraph_make_unarc(a, m_graph));
362
+ }
363
+ }
364
+ return ar;
365
+ }
366
+
367
+
368
+ VALUE ArcMap::values()
369
+ {
370
+ int cnt = 0;
371
+ VALUE ar;
372
+ if (m_diunbar) {
373
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
374
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
375
+ if ((*m_diarcmap)[a].is_valid())
376
+ cnt++;
377
+ }
378
+ ar = rb_ary_new_capa(cnt);
379
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
380
+ if ((*m_diarcmap)[a].is_valid())
381
+ rb_ary_push(ar, (*m_diarcmap)[a].value);
382
+ }
383
+ }
384
+ else {
385
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
386
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
387
+ if ((*m_unarcmap)[a].is_valid())
388
+ cnt++;
389
+ }
390
+ ar = rb_ary_new_capa(cnt);
391
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
392
+ if ((*m_unarcmap)[a].is_valid())
393
+ rb_ary_push(ar, (*m_unarcmap)[a].value);
394
+ }
395
+ }
396
+ return ar;
397
+ }
398
+
399
+
400
+ VALUE ArcMap::length()
401
+ {
402
+ int cnt = 0;
403
+ if (m_diunbar) {
404
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
405
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
406
+ if ((*m_diarcmap)[a].is_valid())
407
+ cnt++;
408
+ }
409
+ }
410
+ else {
411
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
412
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
413
+ if ((*m_unarcmap)[a].is_valid())
414
+ cnt++;
415
+ }
416
+ }
417
+ return INT2NUM(cnt);
418
+ }
419
+
420
+
421
+ VALUE ArcMap::is_empty()
422
+ {
423
+ if (m_diunbar) {
424
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
425
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
426
+ if ((*m_diarcmap)[a].is_valid())
427
+ return Qfalse;
428
+ }
429
+ }
430
+ else {
431
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
432
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
433
+ if ((*m_unarcmap)[a].is_valid())
434
+ return Qfalse;
435
+ }
436
+ }
437
+ return Qtrue;
438
+ }
439
+
440
+
441
+ static VALUE lemongraph_arcmap_enum_length(VALUE obj, VALUE args, VALUE eobj)
442
+ {
443
+ (void)args;
444
+ (void)eobj;
445
+ return lemongraph_arcmap_length(obj);
446
+ }
447
+
448
+
449
+ VALUE ArcMap::each_arc()
450
+ {
451
+ RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_arcmap_enum_length);
452
+ if (m_diunbar) {
453
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
454
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
455
+ if ((*m_diarcmap)[a].is_valid())
456
+ rb_yield(lemongraph_make_diarc(a, m_graph));
457
+ }
458
+ }
459
+ else {
460
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
461
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
462
+ if ((*m_unarcmap)[a].is_valid())
463
+ rb_yield(lemongraph_make_unarc(a, m_graph));
464
+ }
465
+ }
466
+ return m_self;
467
+ }
468
+
469
+
470
+ VALUE ArcMap::each_value()
471
+ {
472
+ RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_arcmap_enum_length);
473
+ if (m_diunbar) {
474
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
475
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
476
+ VALUE v = (*m_diarcmap)[a].value;
477
+ if (v != Qundef)
478
+ rb_yield(v);
479
+ }
480
+ }
481
+ else {
482
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
483
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
484
+ VALUE v = (*m_unarcmap)[a].value;
485
+ if (v != Qundef)
486
+ rb_yield(v);
487
+ }
488
+ }
489
+ return m_self;
490
+ }
491
+
492
+
493
+ VALUE ArcMap::each_pair()
494
+ {
495
+ RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_arcmap_enum_length);
496
+ if (m_diunbar) {
497
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
498
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
499
+ VALUE v = (*m_diarcmap)[a].value;
500
+ if (v != Qundef)
501
+ rb_yield_values(2, lemongraph_make_diarc(a, m_graph), v);
502
+ }
503
+ }
504
+ else {
505
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
506
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
507
+ VALUE v = (*m_unarcmap)[a].value;
508
+ if (v != Qundef)
509
+ rb_yield_values(2, lemongraph_make_unarc(a, m_graph), v);
510
+ }
511
+ }
512
+ return m_self;
513
+ }
514
+
515
+
516
+ VALUE ArcMap::del_if()
517
+ {
518
+ RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_arcmap_enum_length);
519
+ if (m_diunbar) {
520
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
521
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
522
+ VALUE v = (*m_diarcmap)[a].value;
523
+ if (v != Qundef) {
524
+ VALUE b = rb_yield_values(2, lemongraph_make_diarc(a, m_graph), v);
525
+ if (b != Qnil && b != Qfalse)
526
+ m_diarcmap->set(a, Qundef);
527
+ }
528
+ }
529
+ }
530
+ else {
531
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
532
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
533
+ VALUE v = (*m_unarcmap)[a].value;
534
+ if (v != Qundef) {
535
+ VALUE b = rb_yield_values(2, lemongraph_make_unarc(a, m_graph), v);
536
+ if (b != Qnil && b != Qfalse)
537
+ m_unarcmap->set(a, Qundef);
538
+ }
539
+ }
540
+ }
541
+ return m_self;
542
+ }
543
+
544
+
545
+ void ArcMap::clear()
546
+ {
547
+ if (m_diunbar) {
548
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
549
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a)
550
+ m_diarcmap->set(a, Qundef);
551
+ }
552
+ else {
553
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
554
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a)
555
+ m_unarcmap->set(a, Qundef);
556
+ }
557
+ }
558
+
559
+
560
+ bool ArcMap::is_equal(const ArcMap& other)
561
+ {
562
+ if (other.m_graph != m_graph)
563
+ return false;
564
+ if (other.m_diunbar != m_diunbar)
565
+ return false;
566
+ if (rb_funcallv(other.m_default_value, id_eqeq, 1, &m_default_value) != Qtrue)
567
+ return false;
568
+ if (rb_funcallv(other.m_default_proc, id_eqeq, 1, &m_default_proc) != Qtrue)
569
+ return false;
570
+ if (m_diunbar) {
571
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
572
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
573
+ if ((*m_diarcmap)[a].value == Qundef) {
574
+ if ((*other.m_diarcmap)[a].value != Qundef)
575
+ return false;
576
+ }
577
+ else if (rb_funcall((*m_diarcmap)[a].value, id_eqeq, 1, (*other.m_diarcmap)[a].value) != Qtrue)
578
+ return false;
579
+ }
580
+ }
581
+ else {
582
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
583
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
584
+ if ((*m_unarcmap)[a].value == Qundef) {
585
+ if ((*other.m_unarcmap)[a].value != Qundef)
586
+ return false;
587
+ }
588
+ else if (rb_funcall((*m_unarcmap)[a].value, id_eqeq, 1, (*other.m_unarcmap)[a].value) != Qtrue)
589
+ return false;
590
+ }
591
+ }
592
+ return true;
593
+ }
594
+
595
+
596
+ VALUE ArcMap::hash()
597
+ {
598
+ st_index_t size = NUM2INT(length());
599
+ st_index_t hval = rb_hash_start(size);
600
+ hval = rb_hash_uint(hval, (st_index_t)lemongraph_arcmap_hash);
601
+ hval = rb_hash_uint(hval, NUM2LONG(rb_hash(m_graph)));
602
+ hval = rb_hash_uint(hval, NUM2LONG(rb_hash(m_default_value)));
603
+ hval = rb_hash_uint(hval, NUM2LONG(rb_hash(m_default_proc)));
604
+ if (m_diunbar) {
605
+ lemon::ListDigraph& g = lemongraph_digraph_rb2ref(m_graph);
606
+ for (lemon::ListDigraph::ArcIt a(g); a != lemon::INVALID; ++a) {
607
+ VALUE v = (*m_diarcmap)[a].value;
608
+ if (v != Qundef) {
609
+ hval = rb_hash_uint(hval, lemon::ListDigraph::id(a));
610
+ hval = rb_hash_uint(hval, NUM2LONG(rb_hash(v)));
611
+ }
612
+ }
613
+ }
614
+ else {
615
+ lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
616
+ for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a) {
617
+ VALUE v = (*m_unarcmap)[a].value;
618
+ if (v != Qundef) {
619
+ hval = rb_hash_uint(hval, lemon::ListGraph::id(a));
620
+ hval = rb_hash_uint(hval, NUM2LONG(rb_hash(v)));
621
+ }
622
+ }
623
+ }
624
+ hval = rb_hash_end(hval);
625
+ return ST2FIX(hval);
626
+ }
627
+
628
+
629
+ } // namespace LemonGraph
630
+
631
+
632
+ static void lemongraph_arcmap_mark(void *p)
633
+ {
634
+ LemonGraph::ArcMap *nm = (LemonGraph::ArcMap*)p;
635
+ nm->mark();
636
+ }
637
+
638
+
639
+ static void lemongraph_arcmap_free(void *p)
640
+ {
641
+ LemonGraph::ArcMap *nm = (LemonGraph::ArcMap*)p;
642
+ delete nm;
643
+ }
644
+
645
+
646
+ static size_t lemongraph_arcmap_size(const void* p)
647
+ {
648
+ return 0;
649
+ }
650
+
651
+
652
+ static const rb_data_type_t lemongraph_arcmap_type = {
653
+ .wrap_struct_name = "LemonGraph::ArcMap",
654
+ .function = {
655
+ .dmark = lemongraph_arcmap_mark,
656
+ .dfree = lemongraph_arcmap_free,
657
+ .dsize = lemongraph_arcmap_size,
658
+ },
659
+ .parent = NULL,
660
+ .data = NULL,
661
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
662
+ };
663
+
664
+
665
+ VALUE lemongraph_arcmap_alloc(VALUE klass)
666
+ {
667
+ LemonGraph::ArcMap *nm = new LemonGraph::ArcMap();
668
+ return TypedData_Wrap_Struct(klass, &lemongraph_arcmap_type, nm);
669
+ }
670
+
671
+
672
+ static inline LemonGraph::ArcMap& lemongraph_arcmap_rb2ref(VALUE obj) {
673
+ LemonGraph::ArcMap *nm;
674
+ TypedData_Get_Struct(obj, LemonGraph::ArcMap, &lemongraph_arcmap_type, nm);
675
+ return *nm;
676
+ }
677
+
678
+
679
+ /* Returns a new arc map related to _graph_.
680
+ *
681
+ * If no block is given, _default_value_ will be returned when
682
+ * a value is fetched for a arc for which no value was set.
683
+ *
684
+ * If a block is given, it will be called if needed
685
+ * to provide values for arcs for which no value was set, instead of returning _default_value_.
686
+ *
687
+ * @return [ArcMap]
688
+ * @overload initialize(graph, default_value = nil)
689
+ * @param graph [Graph, Digraph] the graph this arc map is to be bound to
690
+ * @param default_value [Object] the default value returned for arcs with no value.
691
+ * @overload initialize(graph)
692
+ * @param graph [Graph, Digraph] the graph this arc map is to be bound to
693
+ * @yieldparam arc [Graph::Arc,Digraph::Arc] the arc for which to provide a value
694
+ * @yieldparam arcmap [ArcMap] _self_
695
+ * @yieldreturn [Object] the default value returned for this _arc_
696
+ */
697
+ VALUE lemongraph_arcmap_initialize(int argc, VALUE *argv, VALUE self)
698
+ {
699
+ VALUE rbg;
700
+ VALUE dflt = Qnil;
701
+ VALUE proc = Qnil;
702
+ rb_scan_args(argc, argv, "11&", &rbg, &dflt, &proc);
703
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
704
+ nm.initialize(self, rbg, dflt, proc);
705
+ return self;
706
+ }
707
+
708
+
709
+
710
+ /* Method called by _dup_ and _clone_ methods.
711
+ * @return [self]
712
+ */
713
+ VALUE lemongraph_arcmap_initialize_copy(VALUE self, VALUE orig)
714
+ {
715
+ rb_call_super(1, &orig);
716
+ LemonGraph::ArcMap& from = lemongraph_arcmap_rb2ref(orig);
717
+ LemonGraph::ArcMap& to = lemongraph_arcmap_rb2ref(self);
718
+ to.initialize(self, from.graph(), from.default_value(), from.default_proc());
719
+ if (from.is_for_directed_graph()) {
720
+ for (lemon::ListDigraph::ArcIt a(lemongraph_digraph_rb2ref(from.graph())); a != lemon::INVALID; ++a) {
721
+ const LemonGraph::RBValue& v = from[a];
722
+ if (v.is_valid())
723
+ to[a] = v;
724
+ }
725
+ }
726
+ else {
727
+ for (lemon::ListGraph::ArcIt a(lemongraph_graph_rb2ref(from.graph())); a != lemon::INVALID; ++a) {
728
+ const LemonGraph::RBValue& v = from[a];
729
+ if (v.is_valid())
730
+ to[a] = v;
731
+ }
732
+ }
733
+ return self;
734
+ }
735
+
736
+
737
+ /* Returns the graph this arc map is related to.
738
+ * @return [Graph,Digraph]
739
+ */
740
+ VALUE lemongraph_arcmap_graph(VALUE self)
741
+ {
742
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
743
+ return nm.graph();
744
+ }
745
+
746
+
747
+ /* Returns the default value set for this arc map.
748
+ * @return [Object]
749
+ */
750
+ VALUE lemongraph_arcmap_get_dflt_val(VALUE self)
751
+ {
752
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
753
+ return nm.default_value();
754
+ }
755
+
756
+
757
+ /* Sets the default value for this arc map.
758
+ */
759
+ VALUE lemongraph_arcmap_set_dflt_val(VALUE self, VALUE dflt)
760
+ {
761
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
762
+ nm.set_default_value(dflt);
763
+ return self;
764
+ }
765
+
766
+
767
+ /* Returns the default proc set for this arc map.
768
+ * @return [Proc, nil]
769
+ */
770
+ VALUE lemongraph_arcmap_get_dflt_proc(VALUE self)
771
+ {
772
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
773
+ return nm.default_proc();
774
+ }
775
+
776
+
777
+ /* Sets the default proc for this arc map.
778
+ *
779
+ * If set, the default proc is called when a value is fetched for a arc
780
+ * which was not assigned a value.
781
+ * The proc parameters must be the arc key and the arc map.
782
+ *
783
+ * Set to _nil_ to reset it so that the default value is returned
784
+ * when needed instead of calling the default proc.
785
+ * @param proc [Proc, nil]
786
+ */
787
+ VALUE lemongraph_arcmap_set_dflt_proc(VALUE self, VALUE proc)
788
+ {
789
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
790
+ nm.set_default_proc(proc);
791
+ return self;
792
+ }
793
+
794
+
795
+ /* Returns the value associated with the given arc key.
796
+ * @param key [Graph::Arc,Digraph::Arc]
797
+ * @return [Object]
798
+ */
799
+ VALUE lemongraph_arcmap_get(VALUE self, VALUE key)
800
+ {
801
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
802
+ return nm.get(key);
803
+ }
804
+
805
+
806
+ /* Associates the given value with the given arc key; returns value.
807
+ * @param key [Graph::Arc, Digraph::Arc]
808
+ * @param value [Object]
809
+ */
810
+ VALUE lemongraph_arcmap_set(VALUE self, VALUE key, VALUE value)
811
+ {
812
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
813
+ nm.set(key, value);
814
+ return value;
815
+ }
816
+
817
+
818
+ /* Returns an array containing all arc keys for which a value has been set.
819
+ * @return [Array<Graph::Arc,Digraph::Arc>]
820
+ */
821
+ VALUE lemongraph_arcmap_arcs(VALUE self)
822
+ {
823
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
824
+ return nm.keys();
825
+ }
826
+
827
+
828
+ /* Returns an array containing all values set for arcs.
829
+ * @return [Array<Object>]
830
+ */
831
+ VALUE lemongraph_arcmap_values(VALUE self)
832
+ {
833
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
834
+ return nm.values();
835
+ }
836
+
837
+
838
+ /* Return the count of entries in _slef_ for which a value has been set
839
+ * @return [Integer]
840
+ */
841
+ VALUE lemongraph_arcmap_length(VALUE self)
842
+ {
843
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
844
+ return nm.length();
845
+ }
846
+
847
+
848
+ /* Returns _true_ if there are no entries, _false_ otherwise
849
+ * @return [Boolean]
850
+ */
851
+ VALUE lemongraph_arcmap_is_empty(VALUE self)
852
+ {
853
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
854
+ return nm.is_empty();
855
+ }
856
+
857
+
858
+ /* Calls the block, if given, once for each arc key for which a value has been set.
859
+ * The arcs are passed as parameters to the block.
860
+ *
861
+ * Returns _self_, or, if no block is given, an Enumerator is returned.
862
+ * @return [self, Enumerator]
863
+ * @overload each_arc
864
+ * @yieldparam arc [Graph::Arc,Digraph::Arc]
865
+ * @return [self]
866
+ * @overload each_arc
867
+ * @return [Enumerator]
868
+ */
869
+ VALUE lemongraph_arcmap_each_arc(VALUE self)
870
+ {
871
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
872
+ return nm.each_arc();
873
+ }
874
+
875
+
876
+ /* Calls the block, if given, once for each value that has been set.
877
+ * The values are passed as parameters to the block.
878
+ *
879
+ * Returns _self_, or, if no block is given, an Enumerator is returned.
880
+ * @return [self, Enumerator]
881
+ * @overload each_value
882
+ * @yieldparam value [Object]
883
+ * @return [self]
884
+ * @overload each_value
885
+ * @return [Enumerator]
886
+ */
887
+ VALUE lemongraph_arcmap_each_value(VALUE self)
888
+ {
889
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
890
+ return nm.each_value();
891
+ }
892
+
893
+
894
+ /* Calls the block, if given, once for each arc key and value pair.
895
+ * The arcs and values are passed as parameters to the block.
896
+ *
897
+ * Returns _self_, or, if no block is given, an Enumerator is returned.
898
+ * @return [self, Enumerator]
899
+ * @overload each_pair
900
+ * @yieldparam arc [Graph::Arc,Digraph::Arc]
901
+ * @yieldparam value [Object]
902
+ * @return [self]
903
+ * @overload each_pair
904
+ * @return [Enumerator]
905
+ * @overload each
906
+ * @yieldparam arc [Graph::Arc,Digraph::Arc]
907
+ * @yieldparam value [Object]
908
+ * @return [self]
909
+ * @overload each
910
+ * @return [Enumerator]
911
+ */
912
+ VALUE lemongraph_arcmap_each_pair(VALUE self)
913
+ {
914
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
915
+ return nm.each_pair();
916
+ }
917
+
918
+
919
+ /* Removes all values.
920
+ * @return [self]
921
+ */
922
+ VALUE lemongraph_arcmap_clear(VALUE self)
923
+ {
924
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
925
+ nm.clear();
926
+ return self;
927
+ }
928
+
929
+
930
+ /* Deletes the entry for the given arc and returns its associated value, or the default one.
931
+ * @param key [Graph::Arc,Digraph::Arc]
932
+ */
933
+ VALUE lemongraph_arcmap_delete(VALUE self, VALUE key)
934
+ {
935
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
936
+ return nm.del(key);
937
+ }
938
+
939
+
940
+ /* Delete entries for which the block returns a truthy value.
941
+ * Returns _self_, or, if no block is given, an Enumerator is returned.
942
+ *
943
+ * @return [self, Enumerator]
944
+ * @overload delete_if
945
+ * Calls the block with each arc-value pair;
946
+ * deletes each entry for which the block returns a truthy value;
947
+ * returns self
948
+ * @yieldparam arc [Graph::Arc,Digraph::Arc]
949
+ * @yieldparam value [Object]
950
+ * @yieldreturn [Boolean] whether to delete or not the entry
951
+ * @return [self]
952
+ * @overload delete_if
953
+ * @return [Enumerator]
954
+ */
955
+ VALUE lemongraph_arcmap_delete_if(VALUE self)
956
+ {
957
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
958
+ return nm.del_if();
959
+ }
960
+
961
+
962
+ /* Returns _true_ if a value was set for _arc_, otherwise _false_.
963
+ * @param arc [Graph::Arc,Digraph::Arc]
964
+ * @return [Boolean]
965
+ */
966
+ VALUE lemongraph_arcmap_has_arc(VALUE self, VALUE arc)
967
+ {
968
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
969
+ return nm.has_arc(arc);
970
+ }
971
+
972
+
973
+ /* Returns _true_ if _value_ is a value in _self_, otherwise _false_.
974
+ * @return [Boolean]
975
+ */
976
+ VALUE lemongraph_arcmap_has_value(VALUE self, VALUE value)
977
+ {
978
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
979
+ return nm.has_value(value);
980
+ }
981
+
982
+
983
+ /* Returns _true_ if _other_ is a ArcMap and share the same graph, default value and proc as _self_
984
+ * and and all entries from _other_ and _self_ are equal (==).
985
+ * @return [Boolean]
986
+ */
987
+ VALUE lemongraph_arcmap_is_equal(VALUE self, VALUE other)
988
+ {
989
+ if (rb_obj_is_kind_of(other, c_ArcMap) != Qtrue)
990
+ return Qfalse;
991
+ LemonGraph::ArcMap& m = lemongraph_arcmap_rb2ref(self);
992
+ LemonGraph::ArcMap& o = lemongraph_arcmap_rb2ref(other);
993
+ return o.is_equal(m) ? Qtrue : Qfalse;
994
+ }
995
+
996
+
997
+ /* Returns the integer hash value for _self_.
998
+ * @return [Integer]
999
+ */
1000
+ VALUE lemongraph_arcmap_hash(VALUE self)
1001
+ {
1002
+ LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
1003
+ return nm.hash();
1004
+ }
1005
+
1006
+
1007
+