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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e42c083e1ae9ae809d54f14f7b591e2bc284f3d
4
- data.tar.gz: fae1ead8b3ad28db5f8577dede5f050009cc0006
3
+ metadata.gz: 8406a5839e15190df819f220a4c566c36a9e721c
4
+ data.tar.gz: 2fc2e1681f4595f12dee0553c74fc7f88fb9ba8b
5
5
  SHA512:
6
- metadata.gz: bbb064bc33f02815ecbb090150fa9a312ab96e4f4b42fea44f5fecd1c58cdfa7ee7d103f90e0b9bae6b93dac09d7aef46e68bf0c83a90535401fba7e5f3dd4b3
7
- data.tar.gz: 27bbf6b5a7962eef54d519207d710123cafc7a4b247cafec5beefeba23c0c3669cd01823662464c8aef497141bfadf1dd7e153ab72fc46dc99cf4c478309c1be
6
+ metadata.gz: f546423c0cb1b6909b70961311dc99133792df82f787cf385af94be5405a03e5bdd7b2d04ae491ec86fefbdf8f8f49677cc7ae753c194ce9f5c007cd179616f7
7
+ data.tar.gz: b8e268030552f7b44f61cf786946e019c7fd58bc5681b80c783cc68cc5f7f54affbec1b5901ad1120b74d82e102cc64730fa47aa4fcd22b5c4f1360118687a62
data/.travis.yml CHANGED
@@ -5,6 +5,5 @@ rvm:
5
5
  - ruby-head
6
6
  - jruby-9.1.13.0
7
7
  - jruby-head
8
- - rbx-3
9
8
  before_install: gem install bundler
10
9
  script: bundle exec rspec
@@ -14,7 +14,7 @@ module Mementus
14
14
  private
15
15
 
16
16
  def visit(id, &block)
17
- @queue.concat(@graph.outgoing(id))
17
+ @queue << @graph.node(id)
18
18
 
19
19
  while next_node = @queue.shift
20
20
  next if @visited[next_node]
@@ -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(id, &block)
16
- @graph.outgoing(id).each do |adj_node|
17
- next if @visited[adj_node.id]
15
+ def visit(node, &block)
16
+ block.call(node)
17
+ @visited[node.id] = true
18
18
 
19
- @visited[adj_node.id] = true
20
- block.call(adj_node)
21
- visit(adj_node.id, &block)
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
@@ -1,11 +1,17 @@
1
1
  module Mementus
2
2
  class Graph
3
- def initialize(is_directed=true, &block)
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
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.7.2'.freeze
3
3
  end
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mementus::MutableGraph do
3
+ describe Mementus::Graph do
4
4
  specify '#new' do
5
- graph = Mementus::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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::MutableGraph.new
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)
@@ -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.1
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: 2017-12-14 00:00:00.000000000 Z
11
+ date: 2018-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler