mementus 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/lib/mementus/breadth_first_search.rb +1 -1
- data/lib/mementus/depth_first_search.rb +7 -7
- data/lib/mementus/graph.rb +7 -1
- data/lib/mementus/version.rb +1 -1
- data/spec/mutable_graph_spec.rb +14 -14
- data/spec/traversal_spec.rb +2 -2
- 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: 8406a5839e15190df819f220a4c566c36a9e721c
|
4
|
+
data.tar.gz: 2fc2e1681f4595f12dee0553c74fc7f88fb9ba8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f546423c0cb1b6909b70961311dc99133792df82f787cf385af94be5405a03e5bdd7b2d04ae491ec86fefbdf8f8f49677cc7ae753c194ce9f5c007cd179616f7
|
7
|
+
data.tar.gz: b8e268030552f7b44f61cf786946e019c7fd58bc5681b80c783cc68cc5f7f54affbec1b5901ad1120b74d82e102cc64730fa47aa4fcd22b5c4f1360118687a62
|
data/.travis.yml
CHANGED
@@ -7,18 +7,18 @@ module Mementus
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def each(&block)
|
10
|
-
visit(@start_id, &block)
|
10
|
+
visit(@graph.node(@start_id), &block)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def visit(
|
16
|
-
|
17
|
-
|
15
|
+
def visit(node, &block)
|
16
|
+
block.call(node)
|
17
|
+
@visited[node.id] = true
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
visit(adj_node
|
19
|
+
@graph.outgoing(node.id).each do |adj_node|
|
20
|
+
next if @visited[adj_node.id]
|
21
|
+
visit(adj_node, &block)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/mementus/graph.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module Mementus
|
2
2
|
class Graph
|
3
|
-
def initialize(is_directed
|
3
|
+
def initialize(is_mutable: false, is_directed: true, &block)
|
4
4
|
builder = GraphBuilder.new(is_directed)
|
5
5
|
|
6
6
|
BindingDelegator.new(builder, block.binding).instance_eval(&block) if block_given?
|
7
7
|
|
8
8
|
@structure = builder.graph
|
9
|
+
|
10
|
+
if is_mutable
|
11
|
+
self.class.include Mutators
|
12
|
+
@node_ids = IntegerId.new
|
13
|
+
@edge_ids = IntegerId.new
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
def nodes_count
|
data/lib/mementus/version.rb
CHANGED
data/spec/mutable_graph_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mementus::
|
3
|
+
describe Mementus::Graph do
|
4
4
|
specify '#new' do
|
5
|
-
graph = Mementus::
|
5
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
6
6
|
|
7
7
|
expect(graph.nodes_count).to eq(0)
|
8
8
|
expect(graph.edges_count).to eq(0)
|
9
9
|
end
|
10
10
|
|
11
11
|
specify '#set_node' do
|
12
|
-
graph = Mementus::
|
12
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
13
13
|
graph.set_node(node_1)
|
14
14
|
|
15
15
|
expect(graph.nodes_count).to eq(1)
|
@@ -17,7 +17,7 @@ describe Mementus::MutableGraph do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
specify '#add_node' do
|
20
|
-
graph = Mementus::
|
20
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
21
21
|
graph.add_node(id: 1)
|
22
22
|
|
23
23
|
expect(graph.nodes_count).to eq(1)
|
@@ -26,21 +26,21 @@ describe Mementus::MutableGraph do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
specify '#add_node -> with auto id' do
|
29
|
-
graph = Mementus::
|
29
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
30
30
|
graph.add_node
|
31
31
|
|
32
32
|
expect(graph.node(1).id).to eq(1)
|
33
33
|
end
|
34
34
|
|
35
35
|
specify '#add_node -> with props' do
|
36
|
-
graph = Mementus::
|
36
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
37
37
|
graph.add_node(props: { title: 'Vertex' })
|
38
38
|
|
39
39
|
expect(graph.node(1)[:title]).to eq('Vertex')
|
40
40
|
end
|
41
41
|
|
42
42
|
specify '#create_node' do
|
43
|
-
graph = Mementus::
|
43
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
44
44
|
graph.create_node do |node|
|
45
45
|
node.id = 20
|
46
46
|
node.label = :vertex
|
@@ -58,7 +58,7 @@ describe Mementus::MutableGraph do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
specify '#set_edge' do
|
61
|
-
graph = Mementus::
|
61
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
62
62
|
graph.set_edge(edge_1_2)
|
63
63
|
|
64
64
|
expect(graph.nodes_count).to eq(2)
|
@@ -68,7 +68,7 @@ describe Mementus::MutableGraph do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
specify '#add_edge' do
|
71
|
-
graph = Mementus::
|
71
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
72
72
|
graph.add_edge(id: 3, from: 1, to: 2)
|
73
73
|
|
74
74
|
expect(graph.nodes_count).to eq(2)
|
@@ -79,21 +79,21 @@ describe Mementus::MutableGraph do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
specify '#add_edge -> with auto id' do
|
82
|
-
graph = Mementus::
|
82
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
83
83
|
graph.add_edge(from: 1, to: 2)
|
84
84
|
|
85
85
|
expect(graph.edge(1).id).to eq(1)
|
86
86
|
end
|
87
87
|
|
88
88
|
specify '#add_edge -> with props' do
|
89
|
-
graph = Mementus::
|
89
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
90
90
|
graph.add_edge(from: 1, to: 2, props: { title: 'Relationship' })
|
91
91
|
|
92
92
|
expect(graph.edge(1)[:title]).to eq('Relationship')
|
93
93
|
end
|
94
94
|
|
95
95
|
specify '#create_edge' do
|
96
|
-
graph = Mementus::
|
96
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
97
97
|
graph.create_edge do |edge|
|
98
98
|
edge.id = 123
|
99
99
|
edge.label = :relationship
|
@@ -115,7 +115,7 @@ describe Mementus::MutableGraph do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
specify '#remove_node' do
|
118
|
-
graph = Mementus::
|
118
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
119
119
|
graph.add_edge(from: 1, to: 2)
|
120
120
|
|
121
121
|
graph.remove_node(2)
|
@@ -124,7 +124,7 @@ describe Mementus::MutableGraph do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
specify '#remove_edge' do
|
127
|
-
graph = Mementus::
|
127
|
+
graph = Mementus::Graph.new(is_mutable: true)
|
128
128
|
graph.add_edge(from: 1, to: 2)
|
129
129
|
|
130
130
|
graph.remove_edge(1)
|
data/spec/traversal_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe 'Basic graph traversals' do
|
|
16
16
|
specify 'DepthFirstSearch#each' do
|
17
17
|
traversal = Mementus::DepthFirstSearch.new(graph, 1)
|
18
18
|
|
19
|
-
expected = [2,3,5,9,7,8,6]
|
19
|
+
expected = [1,2,3,5,9,7,8,6]
|
20
20
|
actual = []
|
21
21
|
traversal.each { |n| actual << n.id }
|
22
22
|
|
@@ -26,7 +26,7 @@ describe 'Basic graph traversals' do
|
|
26
26
|
specify 'BreadthFirstSearch#each' do
|
27
27
|
traversal = Mementus::BreadthFirstSearch.new(graph, 1)
|
28
28
|
|
29
|
-
expected = [2,6,3,5,7,9,8]
|
29
|
+
expected = [1,2,6,3,5,7,9,8]
|
30
30
|
|
31
31
|
actual = []
|
32
32
|
traversal.each { |n| actual << n.id }
|
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
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maetl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|