victory 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/USAGE.md +21 -0
- data/lib/containers/list.rb +64 -62
- data/lib/containers/prefix_tree.rb +45 -45
- data/lib/containers/tuple.rb +21 -15
- data/lib/include_rgl.rb +29 -0
- data/lib/victory/version.rb +1 -1
- data/victory.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b16cdc713345fce798e6fc148c348cac1b0f0d0e0e108c9fa5d57f6ea1c287af
|
|
4
|
+
data.tar.gz: 8ea12344ad30454d80bf0117ed4473fe760f7cbd30aac7731e0d6fc9d5f81696
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 674bec3c86ced7d31427151b8988970c0f7cf79d061f0c1a3c28f7ee5474ffd8db4694b2125ed4d26131ce869e16f1db0e897526a5db62f3b597bb9dda9ca9b5
|
|
7
|
+
data.tar.gz: e4b93c1c9809b4c094f847392d9b4caf08277afb9dcacfe1c166c513bbd5991a025800f54d0d48fe10a7f1d63878cbf827636c47189433882802dd7f399dbaeb
|
data/USAGE.md
CHANGED
|
@@ -10,6 +10,7 @@ In this markdown you will see the usage of all the datastructures and algorithms
|
|
|
10
10
|
* [Struct](#struct)
|
|
11
11
|
* [OpenStruct](#openstruct)
|
|
12
12
|
* [Tuple](#tuple)
|
|
13
|
+
* [Graph](#graph)
|
|
13
14
|
|
|
14
15
|
<a name="array" />
|
|
15
16
|
|
|
@@ -137,6 +138,8 @@ x
|
|
|
137
138
|
# => #<OpenStruct a=0, b=123>
|
|
138
139
|
```
|
|
139
140
|
|
|
141
|
+
For the following datastructures you will need to include `Containers` or prefix every container with it.
|
|
142
|
+
|
|
140
143
|
<a name="tuple" />
|
|
141
144
|
|
|
142
145
|
## Tuple
|
|
@@ -153,6 +156,24 @@ t[2]
|
|
|
153
156
|
# => 2
|
|
154
157
|
```
|
|
155
158
|
|
|
159
|
+
<a name="graph" />
|
|
160
|
+
|
|
161
|
+
## Graph
|
|
162
|
+
|
|
163
|
+
### Graph (undirected)
|
|
164
|
+
```ruby
|
|
165
|
+
g = Graph[1,2, 2,3, 2,4]
|
|
166
|
+
g.to_s
|
|
167
|
+
# => "(1=2)(2=3)(2=4)"
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Directed Graph
|
|
171
|
+
```ruby
|
|
172
|
+
dg = DirectedGraph[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6]
|
|
173
|
+
dg.to_s
|
|
174
|
+
# => "(1-2)(1-6)(2-3)(2-4)(4-5)(6-4)"
|
|
175
|
+
```
|
|
176
|
+
|
|
156
177
|
# Other useful links
|
|
157
178
|
|
|
158
179
|
* https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/
|
data/lib/containers/list.rb
CHANGED
|
@@ -1,81 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def self.[](*arr)
|
|
9
|
-
from_a(arr)
|
|
10
|
-
end
|
|
1
|
+
module Containers
|
|
2
|
+
class List
|
|
3
|
+
Node = Struct.new(:data, :prev, :next)
|
|
4
|
+
def initialize
|
|
5
|
+
@first = nil
|
|
6
|
+
@last = nil
|
|
7
|
+
end
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
l
|
|
16
|
-
end
|
|
9
|
+
def self.[](*arr)
|
|
10
|
+
from_a(arr)
|
|
11
|
+
end
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
def self.from_a(arr)
|
|
14
|
+
l = new
|
|
15
|
+
arr.each(&l.method(:push_front))
|
|
16
|
+
l
|
|
17
|
+
end
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if @first.nil?
|
|
25
|
-
@last = node
|
|
26
|
-
else
|
|
27
|
-
@first.prev = node
|
|
19
|
+
def empty?
|
|
20
|
+
@first == @last && @first.nil?
|
|
28
21
|
end
|
|
29
|
-
@first = node
|
|
30
|
-
end
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
unless @first.nil?
|
|
35
|
-
@first = @first.next
|
|
23
|
+
def push_front(element)
|
|
24
|
+
node = Node.new(element, nil, @first)
|
|
36
25
|
if @first.nil?
|
|
37
|
-
@last =
|
|
26
|
+
@last = node
|
|
38
27
|
else
|
|
39
|
-
@first.prev =
|
|
28
|
+
@first.prev = node
|
|
40
29
|
end
|
|
30
|
+
@first = node
|
|
41
31
|
end
|
|
42
|
-
to_return
|
|
43
|
-
end
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
def pop_front
|
|
34
|
+
to_return = @first&.data
|
|
35
|
+
unless @first.nil?
|
|
36
|
+
@first = @first.next
|
|
37
|
+
if @first.nil?
|
|
38
|
+
@last = nil
|
|
39
|
+
else
|
|
40
|
+
@first.prev = nil unless @first.nil?
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
to_return
|
|
51
44
|
end
|
|
52
|
-
@last = node
|
|
53
|
-
end
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
unless @last.nil?
|
|
58
|
-
@last = @last.prev
|
|
46
|
+
def push_back(element)
|
|
47
|
+
node = Node.new(element, @last, nil)
|
|
59
48
|
if @last.nil?
|
|
60
|
-
@first =
|
|
49
|
+
@first = node
|
|
61
50
|
else
|
|
62
|
-
@last.next =
|
|
51
|
+
@last.next = node
|
|
63
52
|
end
|
|
53
|
+
@last = node
|
|
64
54
|
end
|
|
65
|
-
to_return
|
|
66
|
-
end
|
|
67
55
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
def pop_back
|
|
57
|
+
to_return = @last&.data
|
|
58
|
+
unless @last.nil?
|
|
59
|
+
@last = @last.prev
|
|
60
|
+
if @last.nil?
|
|
61
|
+
@first = nil
|
|
62
|
+
else
|
|
63
|
+
@last.next = nil unless @last.nil?
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
to_return
|
|
67
|
+
end
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
def peek_front
|
|
70
|
+
@first&.data
|
|
71
|
+
end
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
def peek_back
|
|
74
|
+
@last&.data
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
alias push push_back
|
|
78
|
+
alias pop pop_back
|
|
79
|
+
alias unshift push_front
|
|
80
|
+
alias shift pop_front
|
|
81
|
+
end
|
|
82
|
+
L = List
|
|
83
|
+
end
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Containers
|
|
2
|
+
class PrefixTree
|
|
3
|
+
class Node
|
|
4
|
+
attr_accessor :data, :children
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@data = nil
|
|
8
|
+
@children = {}
|
|
9
|
+
end
|
|
10
|
+
end
|
|
6
11
|
|
|
7
12
|
def initialize
|
|
8
|
-
@
|
|
9
|
-
@children = {}
|
|
13
|
+
@root = Node.new
|
|
10
14
|
end
|
|
11
|
-
end
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def <<(str, value = true)
|
|
18
|
-
insert(str, value)
|
|
19
|
-
end
|
|
16
|
+
def <<(str, value = true)
|
|
17
|
+
insert(str, value)
|
|
18
|
+
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
def insert(str, value = true)
|
|
21
|
+
current = @root
|
|
22
|
+
str.each_char do |c|
|
|
23
|
+
current.children[c] = Node.new if current.children[c].nil?
|
|
24
|
+
current = current.children[c]
|
|
25
|
+
end
|
|
26
|
+
current.data = value
|
|
26
27
|
end
|
|
27
|
-
current.data = value
|
|
28
|
-
end
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
def [](str)
|
|
30
|
+
find(str)
|
|
31
|
+
end
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
def find(str)
|
|
34
|
+
current = @root
|
|
35
|
+
str.each_char do |c|
|
|
36
|
+
return nil if current.children[c].nil?
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
current = current.children[c]
|
|
39
|
+
end
|
|
40
|
+
current.data
|
|
40
41
|
end
|
|
41
|
-
current.data
|
|
42
|
-
end
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
def count_partial(str)
|
|
44
|
+
current = @root
|
|
45
|
+
str.each_char do |c|
|
|
46
|
+
return 0 if current.children[c].nil?
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
current.children.each_value(&stack.method(:push))
|
|
54
|
-
until stack.empty?
|
|
55
|
-
current = stack.pop
|
|
56
|
-
count += 1 unless current.data.nil?
|
|
48
|
+
current = current.children[c]
|
|
49
|
+
end
|
|
50
|
+
stack = List.new
|
|
51
|
+
count = 0
|
|
57
52
|
current.children.each_value(&stack.method(:push))
|
|
53
|
+
until stack.empty?
|
|
54
|
+
current = stack.pop
|
|
55
|
+
count += 1 unless current.data.nil?
|
|
56
|
+
current.children.each_value(&stack.method(:push))
|
|
57
|
+
end
|
|
58
|
+
count
|
|
58
59
|
end
|
|
59
|
-
count
|
|
60
60
|
end
|
|
61
61
|
end
|
data/lib/containers/tuple.rb
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Containers
|
|
2
|
+
class Tuple
|
|
3
|
+
@elements = []
|
|
4
|
+
def self.[](*elements)
|
|
5
|
+
new(elements)
|
|
6
|
+
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
def initialize(elements)
|
|
9
|
+
@elements = elements
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
def [](idx)
|
|
13
|
+
@elements[idx]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_a
|
|
17
|
+
@elements.to_a
|
|
18
|
+
end
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
def to_s
|
|
21
|
+
"(#{@elements.join(',')})"
|
|
22
|
+
end
|
|
17
23
|
end
|
|
18
|
-
end
|
|
19
24
|
|
|
20
|
-
T = Tuple
|
|
25
|
+
T = Tuple
|
|
26
|
+
end
|
data/lib/include_rgl.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'rgl/adjacency'
|
|
2
|
+
require 'rgl/base'
|
|
3
|
+
require 'rgl/bellman_ford'
|
|
4
|
+
require 'rgl/bidirectional'
|
|
5
|
+
require 'rgl/bipartite'
|
|
6
|
+
require 'rgl/condensation'
|
|
7
|
+
require 'rgl/connected_components'
|
|
8
|
+
require 'rgl/dijkstra'
|
|
9
|
+
require 'rgl/dijkstra_visitor'
|
|
10
|
+
require 'rgl/dot'
|
|
11
|
+
require 'rgl/edge_properties_map'
|
|
12
|
+
require 'rgl/edmonds_karp'
|
|
13
|
+
require 'rgl/graph_iterator'
|
|
14
|
+
require 'rgl/graph_visitor'
|
|
15
|
+
require 'rgl/graph_wrapper'
|
|
16
|
+
require 'rgl/graphxml'
|
|
17
|
+
require 'rgl/implicit'
|
|
18
|
+
require 'rgl/mutable'
|
|
19
|
+
require 'rgl/path_builder'
|
|
20
|
+
require 'rgl/prim'
|
|
21
|
+
require 'rgl/rdot'
|
|
22
|
+
require 'rgl/topsort'
|
|
23
|
+
require 'rgl/transitiv_closure'
|
|
24
|
+
require 'rgl/transitivity'
|
|
25
|
+
require 'rgl/traversal'
|
|
26
|
+
|
|
27
|
+
Containers::Graph = RGL::AdjacencyGraph
|
|
28
|
+
Containers::DirectedGraph = RGL::DirectedAdjacencyGraph
|
|
29
|
+
Containers::ImplicitGraph = RGL::ImplicitGraph
|
data/lib/victory/version.rb
CHANGED
data/victory.gemspec
CHANGED
|
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
|
|
|
39
39
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
40
40
|
spec.add_development_dependency 'rake-compiler'
|
|
41
41
|
spec.add_development_dependency 'require_all'
|
|
42
|
+
spec.add_development_dependency 'rgl', '~> 0.5.4'
|
|
42
43
|
spec.add_development_dependency 'rspec'
|
|
43
44
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: victory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Arnold Szederjesi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-03-
|
|
11
|
+
date: 2019-03-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -80,6 +80,20 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rgl
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 0.5.4
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 0.5.4
|
|
83
97
|
- !ruby/object:Gem::Dependency
|
|
84
98
|
name: rspec
|
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -151,6 +165,7 @@ files:
|
|
|
151
165
|
- lib/containers/suffix_array.rb
|
|
152
166
|
- lib/containers/trie.rb
|
|
153
167
|
- lib/containers/tuple.rb
|
|
168
|
+
- lib/include_rgl.rb
|
|
154
169
|
- lib/victory.rb
|
|
155
170
|
- lib/victory/version.rb
|
|
156
171
|
- victory.gemspec
|