mementus 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mementus/breadth_first_search.rb +2 -1
- data/lib/mementus/depth_first_search.rb +8 -2
- data/lib/mementus/pipeline/step.rb +8 -0
- data/lib/mementus/version.rb +1 -1
- data/spec/pipeline_spec.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a0068abd37947c716b1f8d20e9ee3af4e9630c1
|
4
|
+
data.tar.gz: 4c9ff1dde33f5e1c53cc2f950a5b73f017305562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c94a944a3edd401d73940b7564d6cbeeec4b6b0b6cdf8d8f6eaefbf924d8a8a0533030a44141da31a1c87c16abe7abb50d786fd93453e4a54647d8e70c08fd
|
7
|
+
data.tar.gz: fda7e80839f0d1e021a09f9a5f4c303325178f3ef3f50faa8e42b1c3fea9babfd2d02437aac07f5370db8a52e1edee81fcf817d5c6c15922acfca31c331f3c6a
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Mementus
|
2
2
|
class DepthFirstSearch
|
3
|
-
def initialize(graph, start_id)
|
3
|
+
def initialize(graph, start_id, method=:out)
|
4
4
|
@graph = graph
|
5
5
|
@start_id = start_id
|
6
|
+
@method = method
|
6
7
|
@visited = { @start_id => true }
|
7
8
|
end
|
8
9
|
|
@@ -16,7 +17,12 @@ module Mementus
|
|
16
17
|
block.call(node)
|
17
18
|
@visited[node.id] = true
|
18
19
|
|
19
|
-
|
20
|
+
method = case @method
|
21
|
+
when :out then :outgoing
|
22
|
+
when :in then :incoming
|
23
|
+
end
|
24
|
+
|
25
|
+
@graph.send(method, node.id).each do |adj_node|
|
20
26
|
next if @visited[adj_node.id]
|
21
27
|
visit(adj_node, &block)
|
22
28
|
end
|
@@ -107,6 +107,14 @@ module Mementus
|
|
107
107
|
def take(num)
|
108
108
|
to_enum.take(num)
|
109
109
|
end
|
110
|
+
|
111
|
+
def depth_first(method=:out)
|
112
|
+
Step.new(DepthFirstSearch.new(graph, source.first.id, method))
|
113
|
+
end
|
114
|
+
|
115
|
+
def breadth_first(method=:out)
|
116
|
+
Step.new(BreadthFirstSearch.new(graph, source.first.id, method))
|
117
|
+
end
|
110
118
|
end
|
111
119
|
end
|
112
120
|
end
|
data/lib/mementus/version.rb
CHANGED
data/spec/pipeline_spec.rb
CHANGED
@@ -144,4 +144,36 @@ describe 'pipeline api' do
|
|
144
144
|
expect(pipeline.all.first.from.id).to eq(1)
|
145
145
|
end
|
146
146
|
end
|
147
|
+
|
148
|
+
describe 'pipeline steps pull values lazily' do
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#traversal API pending' do
|
153
|
+
let(:traversal_graph) do
|
154
|
+
Mementus::Graph.new do
|
155
|
+
set_edge(Mementus::Edge.new(from: Mementus::Node.new(id: 1), to: Mementus::Node.new(id: 2)))
|
156
|
+
set_edge(Mementus::Edge.new(from: Mementus::Node.new(id: 2), to: Mementus::Node.new(id: 3)))
|
157
|
+
set_edge(Mementus::Edge.new(from: Mementus::Node.new(id: 2), to: Mementus::Node.new(id: 5)))
|
158
|
+
set_edge(Mementus::Edge.new(from: Mementus::Node.new(id: 1), to: Mementus::Node.new(id: 6)))
|
159
|
+
set_edge(Mementus::Edge.new(from: Mementus::Node.new(id: 2), to: Mementus::Node.new(id: 7)))
|
160
|
+
set_edge(Mementus::Edge.new(from: Mementus::Node.new(id: 7), to: Mementus::Node.new(id: 8)))
|
161
|
+
set_edge(Mementus::Edge.new(from: Mementus::Node.new(id: 5), to: Mementus::Node.new(id: 9)))
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'traverses through outgoing nodes breadth first' do
|
166
|
+
pipeline = traversal_graph.n(1)
|
167
|
+
|
168
|
+
expected = [1,2,6,3,5,7,9,8]
|
169
|
+
expect(pipeline.breadth_first.all.map(&:id)).to eq(expected)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'traverses through incoming nodes depth first' do
|
173
|
+
pipeline = traversal_graph.n(1)
|
174
|
+
|
175
|
+
expected = [1,2,3,5,9,7,8,6]
|
176
|
+
expect(pipeline.depth_first.all.map(&:id)).to eq(expected)
|
177
|
+
end
|
178
|
+
end
|
147
179
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mementus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maetl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|