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.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +674 -0
- data/README.md +6 -0
- data/ext/lemon-1.3.1/AUTHORS +26 -0
- data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
- data/ext/lemon-1.3.1/INSTALL +167 -0
- data/ext/lemon-1.3.1/LICENSE +32 -0
- data/ext/lemon-1.3.1/NEWS +337 -0
- data/ext/lemon-1.3.1/README +50 -0
- data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
- data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
- data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
- data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
- data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
- data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
- data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
- data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
- data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
- data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
- data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
- data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
- data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
- data/ext/lemon-1.3.1/lemon/assert.h +214 -0
- data/ext/lemon-1.3.1/lemon/base.cc +37 -0
- data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
- data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
- data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
- data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
- data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
- data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
- data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
- data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
- data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
- data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
- data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
- data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
- data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
- data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
- data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
- data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
- data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
- data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
- data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
- data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
- data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
- data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
- data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
- data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
- data/ext/lemon-1.3.1/lemon/clp.h +164 -0
- data/ext/lemon-1.3.1/lemon/color.cc +44 -0
- data/ext/lemon-1.3.1/lemon/color.h +204 -0
- data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
- data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
- data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
- data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
- data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
- data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
- data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
- data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
- data/ext/lemon-1.3.1/lemon/core.h +2506 -0
- data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
- data/ext/lemon-1.3.1/lemon/counter.h +249 -0
- data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
- data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
- data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
- data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
- data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
- data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
- data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
- data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
- data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
- data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
- data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
- data/ext/lemon-1.3.1/lemon/error.h +276 -0
- data/ext/lemon-1.3.1/lemon/euler.h +287 -0
- data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
- data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
- data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
- data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
- data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
- data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
- data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
- data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
- data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
- data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
- data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
- data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
- data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
- data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
- data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
- data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
- data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
- data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
- data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
- data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
- data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
- data/ext/lemon-1.3.1/lemon/lp.h +95 -0
- data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
- data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
- data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
- data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
- data/ext/lemon-1.3.1/lemon/math.h +77 -0
- data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
- data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
- data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
- data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
- data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
- data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
- data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
- data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
- data/ext/lemon-1.3.1/lemon/path.h +1164 -0
- data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
- data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
- data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
- data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
- data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
- data/ext/lemon-1.3.1/lemon/random.cc +29 -0
- data/ext/lemon-1.3.1/lemon/random.h +1005 -0
- data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
- data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
- data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
- data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
- data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
- data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
- data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
- data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
- data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
- data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
- data/ext/lemongraph/arc_map.cc +1007 -0
- data/ext/lemongraph/digraph.cc +282 -0
- data/ext/lemongraph/digraph_arc.cc +153 -0
- data/ext/lemongraph/digraph_node.cc +277 -0
- data/ext/lemongraph/edge_map.cc +770 -0
- data/ext/lemongraph/extconf.rb +53 -0
- data/ext/lemongraph/graph.cc +351 -0
- data/ext/lemongraph/graph_arc.cc +95 -0
- data/ext/lemongraph/graph_edge.cc +153 -0
- data/ext/lemongraph/graph_item.cc +76 -0
- data/ext/lemongraph/graph_node.cc +321 -0
- data/ext/lemongraph/lemongraph.cc +260 -0
- data/ext/lemongraph/lemongraph.hh +295 -0
- data/ext/lemongraph/lemongraph.map +6 -0
- data/ext/lemongraph/lemongraph_export.hh +31 -0
- data/ext/lemongraph/node_map.cc +1011 -0
- data/lemongraph.gemspec +176 -0
- data/lib/lemongraph/graphviz.rb +240 -0
- data/lib/lemongraph/version.rb +4 -0
- data/lib/lemongraph.rb +21 -0
- data/samples/lemondeps.rb +38 -0
- metadata +202 -0
|
@@ -0,0 +1,770 @@
|
|
|
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_EdgeMap;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
namespace LemonGraph {
|
|
28
|
+
|
|
29
|
+
class EdgeMap {
|
|
30
|
+
private:
|
|
31
|
+
VALUE m_self;
|
|
32
|
+
VALUE m_graph;
|
|
33
|
+
VALUE m_default_value;
|
|
34
|
+
VALUE m_default_proc;
|
|
35
|
+
lemon::ListGraph::EdgeMap<RBValue> *m_unedgemap;
|
|
36
|
+
public:
|
|
37
|
+
EdgeMap();
|
|
38
|
+
~EdgeMap();
|
|
39
|
+
void initialize(VALUE self, VALUE graph, VALUE default_value, VALUE default_proc);
|
|
40
|
+
void mark();
|
|
41
|
+
VALUE graph() const { return m_graph; }
|
|
42
|
+
VALUE default_value() const { return m_default_value; }
|
|
43
|
+
void set_default_value(VALUE dflt) { m_default_value = dflt; }
|
|
44
|
+
VALUE default_proc() const { return m_default_proc; }
|
|
45
|
+
void set_default_proc(VALUE prc);
|
|
46
|
+
RBValue& operator[](lemon::ListGraph::Edge& e);
|
|
47
|
+
VALUE get(VALUE edge);
|
|
48
|
+
void set(VALUE edge, VALUE value);
|
|
49
|
+
VALUE keys();
|
|
50
|
+
VALUE values();
|
|
51
|
+
VALUE length();
|
|
52
|
+
VALUE is_empty();
|
|
53
|
+
VALUE each_edge();
|
|
54
|
+
VALUE each_value();
|
|
55
|
+
VALUE each_pair();
|
|
56
|
+
void clear();
|
|
57
|
+
VALUE del(VALUE edge);
|
|
58
|
+
VALUE del_if();
|
|
59
|
+
VALUE has_edge(VALUE edge);
|
|
60
|
+
VALUE has_value(VALUE val);
|
|
61
|
+
bool is_equal(const EdgeMap& other);
|
|
62
|
+
VALUE hash();
|
|
63
|
+
|
|
64
|
+
private:
|
|
65
|
+
void check_key_un(VALUE edge);
|
|
66
|
+
VALUE value_or_default(VALUE val, VALUE edgekey);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
EdgeMap::EdgeMap() :
|
|
71
|
+
m_self(Qnil),
|
|
72
|
+
m_graph(Qnil),
|
|
73
|
+
m_default_value(Qnil),
|
|
74
|
+
m_default_proc(Qnil),
|
|
75
|
+
m_unedgemap(NULL)
|
|
76
|
+
{
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
EdgeMap::~EdgeMap()
|
|
81
|
+
{
|
|
82
|
+
if (m_unedgemap)
|
|
83
|
+
delete m_unedgemap;
|
|
84
|
+
m_unedgemap = NULL;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
void EdgeMap::mark()
|
|
89
|
+
{
|
|
90
|
+
rb_gc_mark(m_graph);
|
|
91
|
+
rb_gc_mark(m_default_value);
|
|
92
|
+
rb_gc_mark(m_default_proc);
|
|
93
|
+
if (!m_unedgemap)
|
|
94
|
+
return;
|
|
95
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
96
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e)
|
|
97
|
+
rb_gc_mark((*m_unedgemap)[e].value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
void EdgeMap::initialize(VALUE self, VALUE graph, VALUE default_value, VALUE default_proc)
|
|
102
|
+
{
|
|
103
|
+
if (m_self != Qnil)
|
|
104
|
+
rb_raise(rb_eRuntimeError, "EdgeMap already initialized");
|
|
105
|
+
m_self = self;
|
|
106
|
+
m_graph = graph;
|
|
107
|
+
m_default_value = default_value;
|
|
108
|
+
m_default_proc = default_proc;
|
|
109
|
+
if (rb_obj_is_kind_of(m_graph, c_Graph) != Qtrue) {
|
|
110
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE " or a %" PRIsVALUE ", not a %s",
|
|
111
|
+
rb_class_name(c_Digraph), rb_class_name(c_Graph), rb_obj_classname(m_graph));
|
|
112
|
+
}
|
|
113
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
114
|
+
m_unedgemap = new lemon::ListGraph::EdgeMap<RBValue>(g);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
void EdgeMap::set_default_proc(VALUE prc)
|
|
119
|
+
{
|
|
120
|
+
if (!rb_obj_is_kind_of(prc, rb_cProc) && prc != Qnil) {
|
|
121
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
|
|
122
|
+
rb_class_name(rb_cProc), rb_obj_classname(prc));
|
|
123
|
+
}
|
|
124
|
+
m_default_proc = prc;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
VALUE EdgeMap::value_or_default(VALUE val, VALUE edgekey)
|
|
129
|
+
{
|
|
130
|
+
if (val == Qundef) {
|
|
131
|
+
if (m_default_proc != Qnil) {
|
|
132
|
+
VALUE args = rb_ary_new_from_args(2, edgekey, m_self);
|
|
133
|
+
val = rb_proc_call(m_default_proc, args);
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
val = m_default_value;
|
|
137
|
+
}
|
|
138
|
+
return val;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
void EdgeMap::check_key_un(VALUE edge)
|
|
143
|
+
{
|
|
144
|
+
if (rb_class_of(edge) != c_UnEdge) {
|
|
145
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE " as key, not a %s",
|
|
146
|
+
rb_class_name(c_UnEdge), rb_obj_classname(edge));
|
|
147
|
+
}
|
|
148
|
+
VALUE rbg = rb_iv_get(edge, "@graph");
|
|
149
|
+
if (rbg != m_graph)
|
|
150
|
+
rb_raise(rb_eRuntimeError, "key edge and edge map do not belong to the same graph");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
RBValue& EdgeMap::operator[](lemon::ListGraph::Edge& e)
|
|
155
|
+
{
|
|
156
|
+
if (!m_unedgemap)
|
|
157
|
+
rb_raise(rb_eRuntimeError, "accessing empty EdgeMap");
|
|
158
|
+
return (*m_unedgemap)[e];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
VALUE EdgeMap::get(VALUE edge)
|
|
163
|
+
{
|
|
164
|
+
VALUE v = Qundef;
|
|
165
|
+
check_key_un(edge);
|
|
166
|
+
lemon::ListGraph::Edge e = lemongraph_rbunedge2unedge(edge);
|
|
167
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
168
|
+
if (!g.valid(e))
|
|
169
|
+
rb_raise(rb_eRuntimeError, "key edge is not a valid edge for its graph");
|
|
170
|
+
v = (*m_unedgemap)[e].value;
|
|
171
|
+
return value_or_default(v, edge);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
void EdgeMap::set(VALUE edge, VALUE value)
|
|
176
|
+
{
|
|
177
|
+
check_key_un(edge);
|
|
178
|
+
lemon::ListGraph::Edge e = lemongraph_rbunedge2unedge(edge);
|
|
179
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
180
|
+
if (!g.valid(e))
|
|
181
|
+
rb_raise(rb_eRuntimeError, "key edge is not a valid edge for its graph");
|
|
182
|
+
m_unedgemap->set(e, RBValue(value));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
VALUE EdgeMap::del(VALUE edge)
|
|
187
|
+
{
|
|
188
|
+
VALUE v = Qundef;
|
|
189
|
+
check_key_un(edge);
|
|
190
|
+
lemon::ListGraph::Edge e = lemongraph_rbunedge2unedge(edge);
|
|
191
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
192
|
+
if (!g.valid(e))
|
|
193
|
+
rb_raise(rb_eRuntimeError, "key edge is not a valid edge for its graph");
|
|
194
|
+
v = (*m_unedgemap)[e].value;
|
|
195
|
+
m_unedgemap->set(e, Qundef);
|
|
196
|
+
return value_or_default(v, edge);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
VALUE EdgeMap::has_edge(VALUE edge)
|
|
201
|
+
{
|
|
202
|
+
VALUE klass = rb_class_of(edge);
|
|
203
|
+
if (klass != c_UnEdge)
|
|
204
|
+
return Qfalse;
|
|
205
|
+
if (rb_iv_get(edge, "@graph") != m_graph)
|
|
206
|
+
return Qfalse;
|
|
207
|
+
lemon::ListGraph::Edge e = lemongraph_rbunedge2unedge(edge);
|
|
208
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
209
|
+
if (!g.valid(e))
|
|
210
|
+
return Qfalse;
|
|
211
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
212
|
+
return Qtrue;
|
|
213
|
+
return Qfalse;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
VALUE EdgeMap::has_value(VALUE value)
|
|
218
|
+
{
|
|
219
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
220
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
221
|
+
VALUE v = (*m_unedgemap)[e].value;
|
|
222
|
+
if (v != Qundef) {
|
|
223
|
+
if (rb_funcallv(v, id_eqeq, 1, &value) == Qtrue)
|
|
224
|
+
return Qtrue;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return Qfalse;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
VALUE EdgeMap::keys()
|
|
232
|
+
{
|
|
233
|
+
int cnt = 0;
|
|
234
|
+
VALUE ar;
|
|
235
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
236
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
237
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
238
|
+
cnt++;
|
|
239
|
+
}
|
|
240
|
+
ar = rb_ary_new_capa(cnt);
|
|
241
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
242
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
243
|
+
rb_ary_push(ar, lemongraph_make_unedge(e, m_graph));
|
|
244
|
+
}
|
|
245
|
+
return ar;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
VALUE EdgeMap::values()
|
|
250
|
+
{
|
|
251
|
+
int cnt = 0;
|
|
252
|
+
VALUE ar;
|
|
253
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
254
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
255
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
256
|
+
cnt++;
|
|
257
|
+
}
|
|
258
|
+
ar = rb_ary_new_capa(cnt);
|
|
259
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
260
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
261
|
+
rb_ary_push(ar, (*m_unedgemap)[e].value);
|
|
262
|
+
}
|
|
263
|
+
return ar;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
VALUE EdgeMap::length()
|
|
268
|
+
{
|
|
269
|
+
int cnt = 0;
|
|
270
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
271
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
272
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
273
|
+
cnt++;
|
|
274
|
+
}
|
|
275
|
+
return INT2NUM(cnt);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
VALUE EdgeMap::is_empty()
|
|
280
|
+
{
|
|
281
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
282
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
283
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
284
|
+
return Qfalse;
|
|
285
|
+
}
|
|
286
|
+
return Qtrue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
static VALUE lemongraph_edgemap_enum_length(VALUE obj, VALUE args, VALUE eobj)
|
|
291
|
+
{
|
|
292
|
+
(void)args;
|
|
293
|
+
(void)eobj;
|
|
294
|
+
return lemongraph_edgemap_length(obj);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
VALUE EdgeMap::each_edge()
|
|
299
|
+
{
|
|
300
|
+
RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_edgemap_enum_length);
|
|
301
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
302
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
303
|
+
if ((*m_unedgemap)[e].is_valid())
|
|
304
|
+
rb_yield(lemongraph_make_unedge(e, m_graph));
|
|
305
|
+
}
|
|
306
|
+
return m_self;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
VALUE EdgeMap::each_value()
|
|
311
|
+
{
|
|
312
|
+
RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_edgemap_enum_length);
|
|
313
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
314
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
315
|
+
VALUE v = (*m_unedgemap)[e].value;
|
|
316
|
+
if (v != Qundef)
|
|
317
|
+
rb_yield(v);
|
|
318
|
+
}
|
|
319
|
+
return m_self;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
VALUE EdgeMap::each_pair()
|
|
324
|
+
{
|
|
325
|
+
RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_edgemap_enum_length);
|
|
326
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
327
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
328
|
+
VALUE v = (*m_unedgemap)[e].value;
|
|
329
|
+
if (v != Qundef)
|
|
330
|
+
rb_yield_values(2, lemongraph_make_unedge(e, m_graph), v);
|
|
331
|
+
}
|
|
332
|
+
return m_self;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
VALUE EdgeMap::del_if()
|
|
337
|
+
{
|
|
338
|
+
RETURN_SIZED_ENUMERATOR(m_self, 0, 0, lemongraph_edgemap_enum_length);
|
|
339
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
340
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
341
|
+
VALUE v = (*m_unedgemap)[e].value;
|
|
342
|
+
if (v != Qundef) {
|
|
343
|
+
VALUE b = rb_yield_values(2, lemongraph_make_unedge(e, m_graph), v);
|
|
344
|
+
if (b != Qnil && b != Qfalse)
|
|
345
|
+
m_unedgemap->set(e, Qundef);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return m_self;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
void EdgeMap::clear()
|
|
353
|
+
{
|
|
354
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
355
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e)
|
|
356
|
+
m_unedgemap->set(e, Qundef);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
bool EdgeMap::is_equal(const EdgeMap& other)
|
|
361
|
+
{
|
|
362
|
+
if (other.m_graph != m_graph)
|
|
363
|
+
return false;
|
|
364
|
+
if (rb_funcallv(other.m_default_value, id_eqeq, 1, &m_default_value) != Qtrue)
|
|
365
|
+
return false;
|
|
366
|
+
if (rb_funcallv(other.m_default_proc, id_eqeq, 1, &m_default_proc) != Qtrue)
|
|
367
|
+
return false;
|
|
368
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
369
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
370
|
+
if ((*m_unedgemap)[e].value == Qundef) {
|
|
371
|
+
if ((*other.m_unedgemap)[e].value != Qundef)
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
else if (rb_funcall((*m_unedgemap)[e].value, id_eqeq, 1, (*other.m_unedgemap)[e].value) != Qtrue)
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
VALUE EdgeMap::hash()
|
|
382
|
+
{
|
|
383
|
+
st_index_t size = NUM2INT(length());
|
|
384
|
+
st_index_t hval = rb_hash_start(size);
|
|
385
|
+
hval = rb_hash_uint(hval, (st_index_t)lemongraph_edgemap_hash);
|
|
386
|
+
hval = rb_hash_uint(hval, NUM2LONG(rb_hash(m_graph)));
|
|
387
|
+
hval = rb_hash_uint(hval, NUM2LONG(rb_hash(m_default_value)));
|
|
388
|
+
hval = rb_hash_uint(hval, NUM2LONG(rb_hash(m_default_proc)));
|
|
389
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(m_graph);
|
|
390
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e) {
|
|
391
|
+
VALUE v = (*m_unedgemap)[e].value;
|
|
392
|
+
if (v != Qundef) {
|
|
393
|
+
hval = rb_hash_uint(hval, lemon::ListGraph::id(e));
|
|
394
|
+
hval = rb_hash_uint(hval, NUM2LONG(rb_hash(v)));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
hval = rb_hash_end(hval);
|
|
398
|
+
return ST2FIX(hval);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
} // namespace LemonGraph
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
static void lemongraph_edgemap_mark(void *p)
|
|
406
|
+
{
|
|
407
|
+
LemonGraph::EdgeMap *nm = (LemonGraph::EdgeMap*)p;
|
|
408
|
+
nm->mark();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
static void lemongraph_edgemap_free(void *p)
|
|
413
|
+
{
|
|
414
|
+
LemonGraph::EdgeMap *nm = (LemonGraph::EdgeMap*)p;
|
|
415
|
+
delete nm;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
static size_t lemongraph_edgemap_size(const void* p)
|
|
420
|
+
{
|
|
421
|
+
return 0;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
static const rb_data_type_t lemongraph_edgemap_type = {
|
|
426
|
+
.wrap_struct_name = "LemonGraph::EdgeMap",
|
|
427
|
+
.function = {
|
|
428
|
+
.dmark = lemongraph_edgemap_mark,
|
|
429
|
+
.dfree = lemongraph_edgemap_free,
|
|
430
|
+
.dsize = lemongraph_edgemap_size,
|
|
431
|
+
},
|
|
432
|
+
.parent = NULL,
|
|
433
|
+
.data = NULL,
|
|
434
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
VALUE lemongraph_edgemap_alloc(VALUE klass)
|
|
439
|
+
{
|
|
440
|
+
LemonGraph::EdgeMap *nm = new LemonGraph::EdgeMap();
|
|
441
|
+
return TypedData_Wrap_Struct(klass, &lemongraph_edgemap_type, nm);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
static inline LemonGraph::EdgeMap& lemongraph_edgemap_rb2ref(VALUE obj) {
|
|
446
|
+
LemonGraph::EdgeMap *nm;
|
|
447
|
+
TypedData_Get_Struct(obj, LemonGraph::EdgeMap, &lemongraph_edgemap_type, nm);
|
|
448
|
+
return *nm;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
/* Returns a new edge map related to _graph_.
|
|
453
|
+
*
|
|
454
|
+
* If no block is given, _default_value_ will be returned when
|
|
455
|
+
* a value is fetched for a edge for which no value was set.
|
|
456
|
+
*
|
|
457
|
+
* If a block is given, it will be called if needed
|
|
458
|
+
* to provide values for edges for which no value was set, instead of returning _default_value_.
|
|
459
|
+
*
|
|
460
|
+
* @return [EdgeMap]
|
|
461
|
+
* @overload initialize(graph, default_value = nil)
|
|
462
|
+
* @param graph [Graph, Digraph] the graph this edge map is to be bound to
|
|
463
|
+
* @param default_value [Object] the default value returned for edges with no value.
|
|
464
|
+
* @overload initialize(graph)
|
|
465
|
+
* @param graph [Graph, Digraph] the graph this edge map is to be bound to
|
|
466
|
+
* @yieldparam edge [Graph::Edge,Digraph::Edge] the edge for which to provide a value
|
|
467
|
+
* @yieldparam edgemap [EdgeMap] _self_
|
|
468
|
+
* @yieldreturn [Object] the default value returned for this _edge_
|
|
469
|
+
*/
|
|
470
|
+
VALUE lemongraph_edgemap_initialize(int argc, VALUE *argv, VALUE self)
|
|
471
|
+
{
|
|
472
|
+
VALUE rbg;
|
|
473
|
+
VALUE dflt = Qnil;
|
|
474
|
+
VALUE proc = Qnil;
|
|
475
|
+
rb_scan_args(argc, argv, "11&", &rbg, &dflt, &proc);
|
|
476
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
477
|
+
nm.initialize(self, rbg, dflt, proc);
|
|
478
|
+
return self;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
/* Method called by _dup_ and _clone_ methods.
|
|
484
|
+
* @return [self]
|
|
485
|
+
*/
|
|
486
|
+
VALUE lemongraph_edgemap_initialize_copy(VALUE self, VALUE orig)
|
|
487
|
+
{
|
|
488
|
+
rb_call_super(1, &orig);
|
|
489
|
+
LemonGraph::EdgeMap& from = lemongraph_edgemap_rb2ref(orig);
|
|
490
|
+
LemonGraph::EdgeMap& to = lemongraph_edgemap_rb2ref(self);
|
|
491
|
+
to.initialize(self, from.graph(), from.default_value(), from.default_proc());
|
|
492
|
+
for (lemon::ListGraph::EdgeIt e(lemongraph_graph_rb2ref(from.graph())); e != lemon::INVALID; ++e) {
|
|
493
|
+
const LemonGraph::RBValue& v = from[e];
|
|
494
|
+
if (v.is_valid())
|
|
495
|
+
to[e] = v;
|
|
496
|
+
}
|
|
497
|
+
return self;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
/* Returns the graph this edge map is related to.
|
|
502
|
+
* @return [Graph,Digraph]
|
|
503
|
+
*/
|
|
504
|
+
VALUE lemongraph_edgemap_graph(VALUE self)
|
|
505
|
+
{
|
|
506
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
507
|
+
return nm.graph();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
/* Returns the default value set for this edge map.
|
|
512
|
+
* @return [Object]
|
|
513
|
+
*/
|
|
514
|
+
VALUE lemongraph_edgemap_get_dflt_val(VALUE self)
|
|
515
|
+
{
|
|
516
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
517
|
+
return nm.default_value();
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
/* Sets the default value for this edge map.
|
|
522
|
+
*/
|
|
523
|
+
VALUE lemongraph_edgemap_set_dflt_val(VALUE self, VALUE dflt)
|
|
524
|
+
{
|
|
525
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
526
|
+
nm.set_default_value(dflt);
|
|
527
|
+
return self;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
/* Returns the default proc set for this edge map.
|
|
532
|
+
* @return [Proc, nil]
|
|
533
|
+
*/
|
|
534
|
+
VALUE lemongraph_edgemap_get_dflt_proc(VALUE self)
|
|
535
|
+
{
|
|
536
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
537
|
+
return nm.default_proc();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
/* Sets the default proc for this edge map.
|
|
542
|
+
*
|
|
543
|
+
* If set, the default proc is called when a value is fetched for a edge
|
|
544
|
+
* which was not assigned a value.
|
|
545
|
+
* The proc parameters must be the edge key and the edge map.
|
|
546
|
+
*
|
|
547
|
+
* Set to _nil_ to reset it so that the default value is returned
|
|
548
|
+
* when needed instead of calling the default proc.
|
|
549
|
+
* @param proc [Proc, nil]
|
|
550
|
+
*/
|
|
551
|
+
VALUE lemongraph_edgemap_set_dflt_proc(VALUE self, VALUE proc)
|
|
552
|
+
{
|
|
553
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
554
|
+
nm.set_default_proc(proc);
|
|
555
|
+
return self;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
/* Returns the value associated with the given edge key.
|
|
560
|
+
* @param key [Graph::Edge,Digraph::Edge]
|
|
561
|
+
* @return [Object]
|
|
562
|
+
*/
|
|
563
|
+
VALUE lemongraph_edgemap_get(VALUE self, VALUE key)
|
|
564
|
+
{
|
|
565
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
566
|
+
return nm.get(key);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
/* Associates the given value with the given edge key; returns value.
|
|
571
|
+
* @param key [Graph::Edge, Digraph::Edge]
|
|
572
|
+
* @param value [Object]
|
|
573
|
+
*/
|
|
574
|
+
VALUE lemongraph_edgemap_set(VALUE self, VALUE key, VALUE value)
|
|
575
|
+
{
|
|
576
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
577
|
+
nm.set(key, value);
|
|
578
|
+
return value;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
/* Returns an array containing all edge keys for which a value has been set.
|
|
583
|
+
* @return [Array<Graph::Edge,Digraph::Edge>]
|
|
584
|
+
*/
|
|
585
|
+
VALUE lemongraph_edgemap_edges(VALUE self)
|
|
586
|
+
{
|
|
587
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
588
|
+
return nm.keys();
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
/* Returns an array containing all values set for edges.
|
|
593
|
+
* @return [Array<Object>]
|
|
594
|
+
*/
|
|
595
|
+
VALUE lemongraph_edgemap_values(VALUE self)
|
|
596
|
+
{
|
|
597
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
598
|
+
return nm.values();
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
/* Return the count of entries in _slef_ for which a value has been set
|
|
603
|
+
* @return [Integer]
|
|
604
|
+
*/
|
|
605
|
+
VALUE lemongraph_edgemap_length(VALUE self)
|
|
606
|
+
{
|
|
607
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
608
|
+
return nm.length();
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
/* Returns _true_ if there are no entries, _false_ otherwise
|
|
613
|
+
* @return [Boolean]
|
|
614
|
+
*/
|
|
615
|
+
VALUE lemongraph_edgemap_is_empty(VALUE self)
|
|
616
|
+
{
|
|
617
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
618
|
+
return nm.is_empty();
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
/* Calls the block, if given, once for each edge key for which a value has been set.
|
|
623
|
+
* The edges are passed as parameters to the block.
|
|
624
|
+
*
|
|
625
|
+
* Returns _self_, or, if no block is given, an Enumerator is returned.
|
|
626
|
+
* @return [self, Enumerator]
|
|
627
|
+
* @overload each_edge
|
|
628
|
+
* @yieldparam edge [Graph::Edge,Digraph::Edge]
|
|
629
|
+
* @return [self]
|
|
630
|
+
* @overload each_edge
|
|
631
|
+
* @return [Enumerator]
|
|
632
|
+
*/
|
|
633
|
+
VALUE lemongraph_edgemap_each_edge(VALUE self)
|
|
634
|
+
{
|
|
635
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
636
|
+
return nm.each_edge();
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
/* Calls the block, if given, once for each value that has been set.
|
|
641
|
+
* The values are passed as parameters to the block.
|
|
642
|
+
*
|
|
643
|
+
* Returns _self_, or, if no block is given, an Enumerator is returned.
|
|
644
|
+
* @return [self, Enumerator]
|
|
645
|
+
* @overload each_value
|
|
646
|
+
* @yieldparam value [Object]
|
|
647
|
+
* @return [self]
|
|
648
|
+
* @overload each_value
|
|
649
|
+
* @return [Enumerator]
|
|
650
|
+
*/
|
|
651
|
+
VALUE lemongraph_edgemap_each_value(VALUE self)
|
|
652
|
+
{
|
|
653
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
654
|
+
return nm.each_value();
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
/* Calls the block, if given, once for each edge key and value pair.
|
|
659
|
+
* The edges and values are passed as parameters to the block.
|
|
660
|
+
*
|
|
661
|
+
* Returns _self_, or, if no block is given, an Enumerator is returned.
|
|
662
|
+
* @return [self, Enumerator]
|
|
663
|
+
* @overload each_pair
|
|
664
|
+
* @yieldparam edge [Graph::Edge,Digraph::Edge]
|
|
665
|
+
* @yieldparam value [Object]
|
|
666
|
+
* @return [self]
|
|
667
|
+
* @overload each_pair
|
|
668
|
+
* @return [Enumerator]
|
|
669
|
+
* @overload each
|
|
670
|
+
* @yieldparam edge [Graph::Edge,Digraph::Edge]
|
|
671
|
+
* @yieldparam value [Object]
|
|
672
|
+
* @return [self]
|
|
673
|
+
* @overload each
|
|
674
|
+
* @return [Enumerator]
|
|
675
|
+
*/
|
|
676
|
+
VALUE lemongraph_edgemap_each_pair(VALUE self)
|
|
677
|
+
{
|
|
678
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
679
|
+
return nm.each_pair();
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
/* Removes all values.
|
|
684
|
+
* @return [self]
|
|
685
|
+
*/
|
|
686
|
+
VALUE lemongraph_edgemap_clear(VALUE self)
|
|
687
|
+
{
|
|
688
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
689
|
+
nm.clear();
|
|
690
|
+
return self;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
/* Deletes the entry for the given edge and returns its associated value, or the default one.
|
|
695
|
+
* @param key [Graph::Edge,Digraph::Edge]
|
|
696
|
+
*/
|
|
697
|
+
VALUE lemongraph_edgemap_delete(VALUE self, VALUE key)
|
|
698
|
+
{
|
|
699
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
700
|
+
return nm.del(key);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
/* Delete entries for which the block returns a truthy value.
|
|
705
|
+
* Returns _self_, or, if no block is given, an Enumerator is returned.
|
|
706
|
+
*
|
|
707
|
+
* @return [self, Enumerator]
|
|
708
|
+
* @overload delete_if
|
|
709
|
+
* Calls the block with each edge-value pair;
|
|
710
|
+
* deletes each entry for which the block returns a truthy value;
|
|
711
|
+
* returns self
|
|
712
|
+
* @yieldparam edge [Graph::Edge,Digraph::Edge]
|
|
713
|
+
* @yieldparam value [Object]
|
|
714
|
+
* @yieldreturn [Boolean] whether to delete or not the entry
|
|
715
|
+
* @return [self]
|
|
716
|
+
* @overload delete_if
|
|
717
|
+
* @return [Enumerator]
|
|
718
|
+
*/
|
|
719
|
+
VALUE lemongraph_edgemap_delete_if(VALUE self)
|
|
720
|
+
{
|
|
721
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
722
|
+
return nm.del_if();
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
/* Returns _true_ if a value was set for _edge_, otherwise _false_.
|
|
727
|
+
* @param edge [Graph::Edge,Digraph::Edge]
|
|
728
|
+
* @return [Boolean]
|
|
729
|
+
*/
|
|
730
|
+
VALUE lemongraph_edgemap_has_edge(VALUE self, VALUE edge)
|
|
731
|
+
{
|
|
732
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
733
|
+
return nm.has_edge(edge);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
/* Returns _true_ if _value_ is a value in _self_, otherwise _false_.
|
|
738
|
+
* @return [Boolean]
|
|
739
|
+
*/
|
|
740
|
+
VALUE lemongraph_edgemap_has_value(VALUE self, VALUE value)
|
|
741
|
+
{
|
|
742
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
743
|
+
return nm.has_value(value);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
/* Returns _true_ if _other_ is a EdgeMap and share the same graph, default value and proc as _self_
|
|
748
|
+
* and and all entries from _other_ and _self_ are equal (==).
|
|
749
|
+
* @return [Boolean]
|
|
750
|
+
*/
|
|
751
|
+
VALUE lemongraph_edgemap_is_equal(VALUE self, VALUE other)
|
|
752
|
+
{
|
|
753
|
+
if (rb_obj_is_kind_of(other, c_EdgeMap) != Qtrue)
|
|
754
|
+
return Qfalse;
|
|
755
|
+
LemonGraph::EdgeMap& m = lemongraph_edgemap_rb2ref(self);
|
|
756
|
+
LemonGraph::EdgeMap& o = lemongraph_edgemap_rb2ref(other);
|
|
757
|
+
return o.is_equal(m) ? Qtrue : Qfalse;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
/* Returns the integer hash value for _self_.
|
|
762
|
+
* @return [Integer]
|
|
763
|
+
*/
|
|
764
|
+
VALUE lemongraph_edgemap_hash(VALUE self)
|
|
765
|
+
{
|
|
766
|
+
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
|
|
767
|
+
return nm.hash();
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
|