mementus 0.5.13 → 0.6.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: 370fd832daecae6063fc22be3eb5cab1ca2708cb
4
- data.tar.gz: 783911cfac6d8d59f3393ff9376957b15610b6e7
3
+ metadata.gz: c8d7aae1069c6ccb20e101540608915d4c0b157b
4
+ data.tar.gz: 2b8273eb17e130395902b111c6d2714fd76ee444
5
5
  SHA512:
6
- metadata.gz: 62ea1f77ad1e71f6b441ff86ac928deccf75a46128dc1fe4090db668d51218c759f1c683a796baa4f85d9f50edc723187600e5bf6f1ebeba6f966a423ee5584b
7
- data.tar.gz: be965f81ebe52be72f30a7055518cca83f60d5f51f70ca04f54f966508fcc9f1e18b8e45426164f54ab75d218a18783293aa3c8a96bc93a3833eb4dd059aa37f
6
+ metadata.gz: e3080d4ed7e24a87065cf575e3df8675d30053f2afc5313f9f321a9a8b4677a04563e810d4168b4b461e8057a6a831d26c622c5983f9ca21fc747768abc61249
7
+ data.tar.gz: 39cd8b39a4dac486d3c24d9ccc9e0b53665c5406341d89695e82fc87c364c09b431097b8414e582196026c68222e13e02369a34dbc17a48bcc8f4d136f7181a9
data/README.md CHANGED
@@ -2,19 +2,6 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/maetl/mementus.svg?branch=master)](https://travis-ci.org/maetl/mementus)
4
4
 
5
- ## Roadmap
6
-
7
- | Version | Summary |
8
- |---------|--------------------------------------------------------------|
9
- | `0.5` | ~~Support fiber based lazily evaluated pipeline traversals~~ |
10
- | `0.6` | Modular graph processing API and query style |
11
- | `0.7` | Implement basic filter, side effect and transform pipes |
12
- | `0.8` | API support for Dijkstra/A* traversals using edge props |
13
- | `0.9` | Pluggable graph structure representations |
14
- | `0.10` | API support for tsort and strongly connected components |
15
- | `0.11` | Expand graph library with interesting sample data |
16
- | `0.12` | Import/export via JSON and XML formats |
17
-
18
5
  ## License
19
6
 
20
7
  Provided under the terms of the MIT License. See the `LICENSE` file in the root of this project for more information.
@@ -1,5 +1,3 @@
1
- require 'set'
2
-
3
1
  module Mementus
4
2
  class Graph
5
3
  def initialize(is_directed=true, &block)
@@ -41,9 +41,12 @@ module Mementus
41
41
  @graph.incoming(@node.id, match)
42
42
  end
43
43
 
44
- # TODO: Fix
45
44
  def outgoing_edges(match=nil)
46
45
  @graph.outgoing_edges(@node.id, match)
47
46
  end
47
+
48
+ def incoming_edges(match=nil)
49
+ @graph.incoming_edges(@node.id, match)
50
+ end
48
51
  end
49
52
  end
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module Mementus
2
4
  module Structure
3
5
  class AdjacencyList
@@ -163,6 +163,46 @@ module Mementus
163
163
  def incoming_edges(id, match=nil)
164
164
  incident_edges(id, match, :in)
165
165
  end
166
+
167
+ def remove_node(node)
168
+ if node.is_a?(Mementus::Node) || node.is_a?(Mementus::NodeProxy)
169
+ node_id = node.id
170
+ else
171
+ node_id = node
172
+ end
173
+
174
+ @outgoing_e[node_id].each do |edge_id|
175
+ @incoming[@edges[edge_id].to.id].delete(node_id)
176
+ @incoming_e[@edges[edge_id].to.id].delete(edge_id)
177
+ @edges.delete(edge_id)
178
+ end
179
+
180
+ @incoming_e[node_id].each do |edge_id|
181
+ @outgoing[@edges[edge_id].from.id].delete(node_id)
182
+ @outgoing_e[@edges[edge_id].from.id].delete(edge_id)
183
+ @edges.delete(edge_id)
184
+ end
185
+
186
+ @nodes.delete(node_id)
187
+ end
188
+
189
+ def remove_edge(edge)
190
+ if edge.is_a?(Mementus::Edge) || edge.is_a?(Mementus::EdgeProxy)
191
+ edge_id = edge.id
192
+ else
193
+ edge_id = edge
194
+ end
195
+
196
+ edge = @edges[edge_id]
197
+
198
+ @outgoing[edge.from.id].delete(edge.to.id)
199
+ @incoming[edge.to.id].delete(edge.from.id)
200
+
201
+ @outgoing_e[edge.from.id].delete(edge_id)
202
+ @incoming_e[edge.to.id].delete(edge_id)
203
+
204
+ @edges.delete(edge_id)
205
+ end
166
206
  end
167
207
  end
168
208
  end
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.5.13'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require_relative 'indexed_graph_example'
2
2
  require_relative 'directed_graph_example'
3
3
  require_relative 'property_graph_example'
4
+ require_relative 'mutable_graph_example'
4
5
 
5
6
  describe Mementus::Structure::IncidenceList do
6
7
  let(:structure) do
@@ -10,4 +11,5 @@ describe Mementus::Structure::IncidenceList do
10
11
  it_behaves_like 'an indexed graph data structure'
11
12
  it_behaves_like 'a directed graph data structure'
12
13
  it_behaves_like 'a property graph data structure'
14
+ it_behaves_like 'a mutable graph data structure'
13
15
  end
@@ -0,0 +1,60 @@
1
+ shared_examples_for 'a mutable graph data structure' do
2
+ before do
3
+ structure.set_node(Mementus::Node.new(id: 1))
4
+ structure.set_node(Mementus::Node.new(id: 2))
5
+ structure.set_node(Mementus::Node.new(id: 3))
6
+
7
+ structure.set_edge(Mementus::Edge.new(id: 10, from: 1, to: 2))
8
+ structure.set_edge(Mementus::Edge.new(id: 20, from: 2, to: 3))
9
+ structure.set_edge(Mementus::Edge.new(id: 30, from: 1, to: 3))
10
+ end
11
+
12
+ describe '#remove_node' do
13
+ it 'removes all references to a given node' do
14
+ structure.remove_node(Mementus::Node.new(id: 2))
15
+
16
+ expect(structure.nodes.count).to eq(2)
17
+ expect(structure.edges.count).to eq(1)
18
+ expect(structure.node(1).outgoing.count).to eq(1)
19
+ expect(structure.node(3).incoming.count).to eq(1)
20
+ expect(structure.node(1).outgoing_edges.count).to eq(1)
21
+ expect(structure.node(3).incoming_edges.count).to eq(1)
22
+ end
23
+
24
+ it 'removes all references to a given node id' do
25
+ structure.remove_node(2)
26
+
27
+ expect(structure.nodes.count).to eq(2)
28
+ expect(structure.edges.count).to eq(1)
29
+ expect(structure.node(1).outgoing.count).to eq(1)
30
+ expect(structure.node(3).incoming.count).to eq(1)
31
+ expect(structure.node(1).outgoing_edges.count).to eq(1)
32
+ expect(structure.node(3).incoming_edges.count).to eq(1)
33
+ end
34
+ end
35
+
36
+ describe '#remove_edge' do
37
+ it 'removes all references to a given edge' do
38
+ edge = Mementus::Edge.new(id: 10, from: 1, to: 2)
39
+ structure.remove_edge(edge)
40
+
41
+ expect(structure.nodes.count).to eq(3)
42
+ expect(structure.edges.count).to eq(2)
43
+ expect(structure.node(1).outgoing.count).to eq(1)
44
+ expect(structure.node(2).incoming.count).to eq(0)
45
+ expect(structure.node(1).outgoing_edges.count).to eq(1)
46
+ expect(structure.node(2).incoming_edges.count).to eq(0)
47
+ end
48
+
49
+ it 'removes all references to a given edge id' do
50
+ structure.remove_edge(10)
51
+
52
+ expect(structure.nodes.count).to eq(3)
53
+ expect(structure.edges.count).to eq(2)
54
+ expect(structure.node(1).outgoing.count).to eq(1)
55
+ expect(structure.node(2).incoming.count).to eq(0)
56
+ expect(structure.node(1).outgoing_edges.count).to eq(1)
57
+ expect(structure.node(2).incoming_edges.count).to eq(0)
58
+ end
59
+ end
60
+ 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.5.13
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maetl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -111,6 +111,7 @@ files:
111
111
  - spec/structure/directed_graph_example.rb
112
112
  - spec/structure/incidence_list_spec.rb
113
113
  - spec/structure/indexed_graph_example.rb
114
+ - spec/structure/mutable_graph_example.rb
114
115
  - spec/structure/property_graph_example.rb
115
116
  - spec/traversal_spec.rb
116
117
  homepage: https://github.com/maetl/mementus
@@ -154,6 +155,7 @@ test_files:
154
155
  - spec/structure/directed_graph_example.rb
155
156
  - spec/structure/incidence_list_spec.rb
156
157
  - spec/structure/indexed_graph_example.rb
158
+ - spec/structure/mutable_graph_example.rb
157
159
  - spec/structure/property_graph_example.rb
158
160
  - spec/traversal_spec.rb
159
161
  has_rdoc: