turbine-graph 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -0
- data/Guardfile +6 -0
- data/LICENSE +27 -0
- data/README.md +189 -0
- data/Rakefile +126 -0
- data/examples/energy.rb +80 -0
- data/examples/family.rb +125 -0
- data/lib/turbine.rb +29 -0
- data/lib/turbine/algorithms/filtered_tarjan.rb +33 -0
- data/lib/turbine/algorithms/tarjan.rb +50 -0
- data/lib/turbine/edge.rb +94 -0
- data/lib/turbine/errors.rb +74 -0
- data/lib/turbine/graph.rb +113 -0
- data/lib/turbine/node.rb +246 -0
- data/lib/turbine/pipeline/README.mdown +31 -0
- data/lib/turbine/pipeline/dsl.rb +275 -0
- data/lib/turbine/pipeline/expander.rb +67 -0
- data/lib/turbine/pipeline/filter.rb +52 -0
- data/lib/turbine/pipeline/journal.rb +130 -0
- data/lib/turbine/pipeline/journal_filter.rb +71 -0
- data/lib/turbine/pipeline/pump.rb +19 -0
- data/lib/turbine/pipeline/segment.rb +175 -0
- data/lib/turbine/pipeline/sender.rb +51 -0
- data/lib/turbine/pipeline/split.rb +132 -0
- data/lib/turbine/pipeline/trace.rb +55 -0
- data/lib/turbine/pipeline/transform.rb +49 -0
- data/lib/turbine/pipeline/traversal.rb +34 -0
- data/lib/turbine/pipeline/unique.rb +47 -0
- data/lib/turbine/properties.rb +48 -0
- data/lib/turbine/traversal/base.rb +133 -0
- data/lib/turbine/traversal/breadth_first.rb +49 -0
- data/lib/turbine/traversal/depth_first.rb +46 -0
- data/lib/turbine/version.rb +4 -0
- data/turbine.gemspec +84 -0
- metadata +120 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
module Turbine
|
2
|
+
module Traversal
|
3
|
+
# Traverses the graph breadth-first, following each item to its adjacent
|
4
|
+
# items.
|
5
|
+
#
|
6
|
+
# A
|
7
|
+
# / \
|
8
|
+
# B C
|
9
|
+
# / / \
|
10
|
+
# D E F
|
11
|
+
# / /
|
12
|
+
# G H
|
13
|
+
#
|
14
|
+
# In the above graph, using a breadth-first algorithm, starting from A,
|
15
|
+
# the nodes are traversed in the order B -> C -> D -> E -> F -> G -> H.
|
16
|
+
class BreadthFirst < Base
|
17
|
+
|
18
|
+
#######
|
19
|
+
private
|
20
|
+
#######
|
21
|
+
|
22
|
+
# Internal: Given a +node+ iterates through each of it's adjacent nodes
|
23
|
+
# using the +method+ and +args+ supplied when initializing the
|
24
|
+
# BreadthFirst instance.
|
25
|
+
#
|
26
|
+
# When the node itself has matching adjacent nodes, those will also be
|
27
|
+
# visited. If there are loops within the graph, they will not be
|
28
|
+
# followed; each node is visited no more than once.
|
29
|
+
#
|
30
|
+
# node - The node from which to traverse.
|
31
|
+
# block - A block executed for each matching node.
|
32
|
+
#
|
33
|
+
# Returns nothing.
|
34
|
+
def visit(node, &block)
|
35
|
+
queue = node.public_send(@method, *@args).to_a.dup
|
36
|
+
|
37
|
+
while item = queue.shift
|
38
|
+
next if @seen[item]
|
39
|
+
|
40
|
+
@seen[item] = true
|
41
|
+
block.call(item)
|
42
|
+
|
43
|
+
queue.push(*fetch(item).public_send(@method, *@args).to_a)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end # BreadthFirst
|
48
|
+
end # Traversal
|
49
|
+
end # Turbine
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Turbine
|
2
|
+
module Traversal
|
3
|
+
# Traverses the graph depth-first, following each edge from a node to its
|
4
|
+
# adjacent nodes, and to *their* adjacent nodes, etc...
|
5
|
+
#
|
6
|
+
# A
|
7
|
+
# / \
|
8
|
+
# B C
|
9
|
+
# / / \
|
10
|
+
# D E F
|
11
|
+
# / /
|
12
|
+
# G H
|
13
|
+
#
|
14
|
+
# In the above graph, using a depth-first algorithm, starting from A,
|
15
|
+
# the nodes are traversed in the order B -> D -> G -> C -> E -> H -> F.
|
16
|
+
class DepthFirst < Base
|
17
|
+
|
18
|
+
#######
|
19
|
+
private
|
20
|
+
#######
|
21
|
+
|
22
|
+
# Internal: Given a +node+ iterates through each of it's adjacent nodes
|
23
|
+
# using the +method+ and +args+ supplied when initializing the
|
24
|
+
# DepthFirst instance.
|
25
|
+
#
|
26
|
+
# When the node itself has matching adjacent nodes, those will also be
|
27
|
+
# visited. If there are loops within the graph, they will not be
|
28
|
+
# followed; each node is visited no more than once.
|
29
|
+
#
|
30
|
+
# node - The node from which to traverse.
|
31
|
+
# block - A block executed for each matching node.
|
32
|
+
#
|
33
|
+
# Returns nothing.
|
34
|
+
def visit(node, &block)
|
35
|
+
node.public_send(@method, *@args).each do |adjacent|
|
36
|
+
next if @seen[adjacent]
|
37
|
+
|
38
|
+
@seen[adjacent] = true
|
39
|
+
block.call(adjacent)
|
40
|
+
visit(fetch(adjacent), &block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end # DepthFirst
|
45
|
+
end # Traversal
|
46
|
+
end # Turbine
|
data/turbine.gemspec
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.required_rubygems_version = '>= 1.3.6'
|
6
|
+
|
7
|
+
# The following four lines are automatically updates by the "gemspec"
|
8
|
+
# rake task. It it completely safe to edit them, but using the rake task
|
9
|
+
# is easier.
|
10
|
+
s.name = 'turbine-graph'
|
11
|
+
s.version = '0.1.0'
|
12
|
+
s.date = '2013-04-10'
|
13
|
+
s.rubyforge_project = 'turbine-graph'
|
14
|
+
|
15
|
+
# You may safely edit the section below.
|
16
|
+
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
|
19
|
+
s.authors = [ 'Anthony Williams',
|
20
|
+
'Dennis Schoenmakers',
|
21
|
+
'Paolo Zaccagnini',
|
22
|
+
'Sebastian Burkhard' ]
|
23
|
+
|
24
|
+
s.email = [ 'hi@antw.me',
|
25
|
+
'dennis.schoenmakers@quintel.com',
|
26
|
+
'paolo.zaccagnini@quintel.com',
|
27
|
+
'sebastian.burkhard@quintel.com' ]
|
28
|
+
|
29
|
+
s.homepage = 'http://github.com/quintel/turbine'
|
30
|
+
s.summary = 'An in-memory graph database written in Ruby.'
|
31
|
+
s.description = 'An experiment in graph databases, with Ruby...'
|
32
|
+
|
33
|
+
s.require_path = 'lib'
|
34
|
+
|
35
|
+
s.add_development_dependency 'rake', '>= 0.9.0'
|
36
|
+
s.add_development_dependency 'rspec', '>= 2.11.0'
|
37
|
+
|
38
|
+
s.rdoc_options = ['--charset=UTF-8']
|
39
|
+
s.extra_rdoc_files = %w[LICENSE README.md]
|
40
|
+
|
41
|
+
# The manifest is created by the "gemspec" rake task. Do not edit it
|
42
|
+
# directly; your changes will be wiped out when you next run the task.
|
43
|
+
|
44
|
+
# = MANIFEST =
|
45
|
+
s.files = %w[
|
46
|
+
Gemfile
|
47
|
+
Guardfile
|
48
|
+
LICENSE
|
49
|
+
README.md
|
50
|
+
Rakefile
|
51
|
+
examples/energy.rb
|
52
|
+
examples/family.rb
|
53
|
+
lib/turbine.rb
|
54
|
+
lib/turbine/algorithms/filtered_tarjan.rb
|
55
|
+
lib/turbine/algorithms/tarjan.rb
|
56
|
+
lib/turbine/edge.rb
|
57
|
+
lib/turbine/errors.rb
|
58
|
+
lib/turbine/graph.rb
|
59
|
+
lib/turbine/node.rb
|
60
|
+
lib/turbine/pipeline/README.mdown
|
61
|
+
lib/turbine/pipeline/dsl.rb
|
62
|
+
lib/turbine/pipeline/expander.rb
|
63
|
+
lib/turbine/pipeline/filter.rb
|
64
|
+
lib/turbine/pipeline/journal.rb
|
65
|
+
lib/turbine/pipeline/journal_filter.rb
|
66
|
+
lib/turbine/pipeline/pump.rb
|
67
|
+
lib/turbine/pipeline/segment.rb
|
68
|
+
lib/turbine/pipeline/sender.rb
|
69
|
+
lib/turbine/pipeline/split.rb
|
70
|
+
lib/turbine/pipeline/trace.rb
|
71
|
+
lib/turbine/pipeline/transform.rb
|
72
|
+
lib/turbine/pipeline/traversal.rb
|
73
|
+
lib/turbine/pipeline/unique.rb
|
74
|
+
lib/turbine/properties.rb
|
75
|
+
lib/turbine/traversal/base.rb
|
76
|
+
lib/turbine/traversal/breadth_first.rb
|
77
|
+
lib/turbine/traversal/depth_first.rb
|
78
|
+
lib/turbine/version.rb
|
79
|
+
turbine.gemspec
|
80
|
+
]
|
81
|
+
# = MANIFEST =
|
82
|
+
|
83
|
+
s.test_files = s.files.select { |path| path =~ /^spec\/.*\.rb/ }
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turbine-graph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anthony Williams
|
9
|
+
- Dennis Schoenmakers
|
10
|
+
- Paolo Zaccagnini
|
11
|
+
- Sebastian Burkhard
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rake
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.9.0
|
25
|
+
type: :development
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.11.0
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.11.0
|
49
|
+
description: An experiment in graph databases, with Ruby...
|
50
|
+
email:
|
51
|
+
- hi@antw.me
|
52
|
+
- dennis.schoenmakers@quintel.com
|
53
|
+
- paolo.zaccagnini@quintel.com
|
54
|
+
- sebastian.burkhard@quintel.com
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
files:
|
61
|
+
- Gemfile
|
62
|
+
- Guardfile
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- examples/energy.rb
|
67
|
+
- examples/family.rb
|
68
|
+
- lib/turbine.rb
|
69
|
+
- lib/turbine/algorithms/filtered_tarjan.rb
|
70
|
+
- lib/turbine/algorithms/tarjan.rb
|
71
|
+
- lib/turbine/edge.rb
|
72
|
+
- lib/turbine/errors.rb
|
73
|
+
- lib/turbine/graph.rb
|
74
|
+
- lib/turbine/node.rb
|
75
|
+
- lib/turbine/pipeline/README.mdown
|
76
|
+
- lib/turbine/pipeline/dsl.rb
|
77
|
+
- lib/turbine/pipeline/expander.rb
|
78
|
+
- lib/turbine/pipeline/filter.rb
|
79
|
+
- lib/turbine/pipeline/journal.rb
|
80
|
+
- lib/turbine/pipeline/journal_filter.rb
|
81
|
+
- lib/turbine/pipeline/pump.rb
|
82
|
+
- lib/turbine/pipeline/segment.rb
|
83
|
+
- lib/turbine/pipeline/sender.rb
|
84
|
+
- lib/turbine/pipeline/split.rb
|
85
|
+
- lib/turbine/pipeline/trace.rb
|
86
|
+
- lib/turbine/pipeline/transform.rb
|
87
|
+
- lib/turbine/pipeline/traversal.rb
|
88
|
+
- lib/turbine/pipeline/unique.rb
|
89
|
+
- lib/turbine/properties.rb
|
90
|
+
- lib/turbine/traversal/base.rb
|
91
|
+
- lib/turbine/traversal/breadth_first.rb
|
92
|
+
- lib/turbine/traversal/depth_first.rb
|
93
|
+
- lib/turbine/version.rb
|
94
|
+
- turbine.gemspec
|
95
|
+
homepage: http://github.com/quintel/turbine
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options:
|
99
|
+
- --charset=UTF-8
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 1.3.6
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project: turbine-graph
|
116
|
+
rubygems_version: 1.8.23
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: An in-memory graph database written in Ruby.
|
120
|
+
test_files: []
|