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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99a080a6068d0c13965015dcde1887d613174099
4
- data.tar.gz: f6a21b820aa6c97607acafb8114db903b69b5f52
3
+ metadata.gz: 6a0068abd37947c716b1f8d20e9ee3af4e9630c1
4
+ data.tar.gz: 4c9ff1dde33f5e1c53cc2f950a5b73f017305562
5
5
  SHA512:
6
- metadata.gz: 812f6244be3f811151091efbabf3f6667384c6736e60a50071611bccd201c0d600d6da2f3ceff4ac4f92b423a41e185a4c230e7827187fc924da88711494cde4
7
- data.tar.gz: 115cb7f3452413619ec661f312af03426eddfe7c4900d2e1208809666ef30eb0f500cb46acdb27ec618e1575585480feb8f73ab3ae930fa07906342eaedafd51
6
+ metadata.gz: c2c94a944a3edd401d73940b7564d6cbeeec4b6b0b6cdf8d8f6eaefbf924d8a8a0533030a44141da31a1c87c16abe7abb50d786fd93453e4a54647d8e70c08fd
7
+ data.tar.gz: fda7e80839f0d1e021a09f9a5f4c303325178f3ef3f50faa8e42b1c3fea9babfd2d02437aac07f5370db8a52e1edee81fcf817d5c6c15922acfca31c331f3c6a
@@ -1,8 +1,9 @@
1
1
  module Mementus
2
2
  class BreadthFirstSearch
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
  @queue = []
8
9
  end
@@ -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
- @graph.outgoing(node.id).each do |adj_node|
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
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.7.4'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
@@ -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.7.4
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-26 00:00:00.000000000 Z
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler