compsci 0.1.0.1 → 0.1.1.1

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: 3df760b020e177135c9d73e20f455635ca82250c
4
- data.tar.gz: '0850e990c79b14fa39533e0990d707cb3f1fe7cc'
3
+ metadata.gz: e4f7afa18fdbd091cf4fed0668fe59204f8f05fa
4
+ data.tar.gz: c123e0795298ac870f4b769f97818144e50a6f74
5
5
  SHA512:
6
- metadata.gz: 8997da4e5f98d35b1250d8feab97d9e46d7a193aec42a89b74e720bfff50608624b054e7e3bb85709230d2a038557919c3a2ce0d6f9f4dc22ddf88e8357d6c8c
7
- data.tar.gz: 90069e7be2f383c80e0edd09c41ca566ba8481b3659c4aca90c7b23000027c3eaa1139cf980ba74737ca9ba4d20e99bd0591623be7b5872d9d7cb06ac99ce2ad
6
+ metadata.gz: 9072889f4e3404d945686c1dccf2818d3fd359354f7b78fa42562ecb380918abc9899cacf14ce7e1e4c29b31542b1ba0c57b8f1f15b058b12132302fc77f8f99
7
+ data.tar.gz: adb4c6ec9b7b23ebc5781204db5fb1062826ee19426f8c7e3ad1098c362c535cdc0e5b71c60abe9b009ed66f4ef317b3bffa36c4f8fdbda84d37fac3555f6788
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ metrics_tasks = []
31
31
  begin
32
32
  require 'flog_task'
33
33
  FlogTask.new do |t|
34
- t.threshold = 600
34
+ t.threshold = 800
35
35
  t.dirs = ['lib']
36
36
  t.verbose = true
37
37
  end
@@ -79,7 +79,12 @@ def rprof_sh(script, args = '', rprof_args = '')
79
79
  lib_sh ['ruby-prof', rprof_args, script, '--', args].join(' ')
80
80
  end
81
81
 
82
- scripts = ["examples/binary_tree.rb", "examples/heap.rb"]
82
+ scripts = [
83
+ "examples/binary_tree.rb",
84
+ "examples/complete_tree.rb",
85
+ "examples/heap.rb",
86
+ "examples/tree.rb",
87
+ ]
83
88
 
84
89
  desc "Run ruby-prof on examples/"
85
90
  task "ruby-prof" => "loadavg" do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0.1
1
+ 0.1.1.1
data/compsci.gemspec CHANGED
@@ -15,6 +15,11 @@ Gem::Specification.new do |s|
15
15
  s.files += Dir['test/**/*.rb']
16
16
  s.files += Dir['examples/**/*.rb']
17
17
 
18
+ s.add_development_dependency "buildar" "~> 3.0"
18
19
  s.add_development_dependency "minitest", "~> 5.0"
19
20
  s.add_development_dependency "rake", "~> 0"
21
+ s.add_development_dependency "flog", "~> 0"
22
+ s.add_development_dependency "flay", "~> 0"
23
+ s.add_development_dependency "roodi", "~> 0"
24
+ s.add_development_dependency "ruby-prof", "~> 0"
20
25
  end
@@ -13,7 +13,7 @@ EOF
13
13
  count = 0
14
14
  start = Timer.now
15
15
  start_1k = Timer.now
16
- tree = NaryTree.new(ChildNode, rand(99), child_slots: 2)
16
+ tree = BinaryTree.new ChildNode, rand(99)
17
17
 
18
18
  loop {
19
19
  count += 1
@@ -50,7 +50,7 @@ EOF
50
50
  vals = Array.new(30) { rand 99 }
51
51
  p vals
52
52
 
53
- tree = NaryTree.new(ChildNode, vals.shift, child_slots: 2)
53
+ tree = BinaryTree.new ChildNode, vals.shift
54
54
  tree.push vals.shift until vals.empty?
55
55
  puts tree
56
56
 
data/lib/compsci/names.rb CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  module CompSci
3
2
  module Names
4
3
  WW1 = [:apples, :butter, :charlie, :duff, :edward, :freddy, :george,
@@ -53,80 +52,5 @@ module CompSci
53
52
  end
54
53
  names[pos]
55
54
  end
56
-
57
- module Greek
58
- UPPER = [*'Α'..'Ρ', *'Σ'..'Ω']
59
- LOWER = [*('α'..'ρ'), *('σ'..'ω')]
60
- SYMBOLS = [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta, :theta,
61
- :iota, :kappa, :lambda, :mu, :nu, :xi, :omicron, :pi, :rho,
62
- :sigma, :tau, :upsilon, :phi, :chi, :psi, :omega]
63
-
64
- # e.g. { alpha: ['Α', 'α'] ...
65
- CHAR_MAP = {}
66
- SYMBOLS.each_with_index { |sym, i| CHAR_MAP[sym] = [UPPER[i], LOWER[i]] }
67
-
68
- LATIN_SYMBOLS = {
69
- a: :alpha,
70
- b: :beta,
71
- c: :gamma,
72
- d: :delta,
73
- e: :epsilon,
74
- f: :zeta,
75
- g: :eta,
76
- h: :theta,
77
- i: :iota,
78
- j: :xi, # use for j, q and w
79
- k: :kappa,
80
- l: :lambda,
81
- m: :mu,
82
- n: :nu,
83
- # nonesuch: => :xi,
84
- o: :omicron,
85
- p: :pi,
86
- q: :xi, # use for j, q and w
87
- r: :rho,
88
- s: :sigma,
89
- t: :tau,
90
- u: :upsilon,
91
- v: :phi,
92
- w: :xi, # use for j, q and w
93
- x: :chi,
94
- y: :psi,
95
- z: :omega,
96
- }
97
- SYMBOLS26 = LATIN_SYMBOLS.values
98
-
99
- def self.upper(latin_str)
100
- CHAR_MAP.fetch(self.sym(latin_str)).first
101
- end
102
-
103
- def self.lower(latin_str)
104
- CHAR_MAP.fetch(self.sym(latin_str)).last
105
- end
106
-
107
- def self.sym(val)
108
- case val
109
- when String
110
- if val.match %r{\A\d+\z}
111
- val = val.to_i
112
- if val >= 0 and val < SYMBOLS.size
113
- SYMBOLS[val]
114
- else
115
- raise "val #{val} not in range (#{SYMBOLS.size})"
116
- end
117
- else
118
- LATIN_SYMBOLS.fetch val[0].downcase.to_sym
119
- end
120
- when Integer
121
- if val >= 0 and val < SYMBOLS.size
122
- SYMBOLS[val]
123
- else
124
- raise "val #{val} not in range (#{SYMBOLS.size})"
125
- end
126
- else
127
- raise "unexpected val #{val} (#{val.class})"
128
- end
129
- end
130
- end
131
55
  end
132
56
  end
@@ -0,0 +1,83 @@
1
+ # coding: utf-8
2
+
3
+ module CompSci
4
+ module Names
5
+ module Greek
6
+ UPPER = [*'Α'..'Ρ', *'Σ'..'Ω']
7
+ LOWER = [*('α'..'ρ'), *('σ'..'ω')]
8
+ SYMBOLS = [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta, :theta,
9
+ :iota, :kappa, :lambda, :mu, :nu, :xi, :omicron, :pi, :rho,
10
+ :sigma, :tau, :upsilon, :phi, :chi, :psi, :omega]
11
+
12
+ # e.g. { alpha: ['Α', 'α'] ...
13
+ CHAR_MAP = {}
14
+ SYMBOLS.each_with_index { |sym, i| CHAR_MAP[sym] = [UPPER[i], LOWER[i]] }
15
+
16
+ LATIN_SYMBOLS = {
17
+ a: :alpha,
18
+ b: :beta,
19
+ c: :gamma,
20
+ d: :delta,
21
+ e: :epsilon,
22
+ f: :zeta,
23
+ g: :eta,
24
+ h: :theta,
25
+ i: :iota,
26
+ j: :xi, # use for j, q and w
27
+ k: :kappa,
28
+ l: :lambda,
29
+ m: :mu,
30
+ n: :nu,
31
+ # nonesuch: => :xi,
32
+ o: :omicron,
33
+ p: :pi,
34
+ q: :xi, # use for j, q and w
35
+ r: :rho,
36
+ s: :sigma,
37
+ t: :tau,
38
+ u: :upsilon,
39
+ v: :phi,
40
+ w: :xi, # use for j, q and w
41
+ x: :chi,
42
+ y: :psi,
43
+ z: :omega,
44
+ }
45
+ SYMBOLS26 = LATIN_SYMBOLS.values
46
+
47
+ def self.upper(latin_str)
48
+ CHAR_MAP.fetch(self.sym(latin_str)).first
49
+ end
50
+
51
+ def self.lower(latin_str)
52
+ CHAR_MAP.fetch(self.sym(latin_str)).last
53
+ end
54
+
55
+ def self.sym(val)
56
+ case val
57
+ when String
58
+ if val.match %r{\A\d+\z}
59
+ # treat positive integer strings as positive integers
60
+ val = val.to_i
61
+ if val >= 0 and val < SYMBOLS.size
62
+ SYMBOLS[val]
63
+ else
64
+ raise "val #{val} not in range (#{SYMBOLS.size})"
65
+ end
66
+ else
67
+ # map the first character to a greek symbol
68
+ LATIN_SYMBOLS.fetch val[0].downcase.to_sym
69
+ end
70
+ when Integer
71
+ if val >= 0 and val < SYMBOLS.size
72
+ # map the integer to a greek symbol
73
+ SYMBOLS[val]
74
+ else
75
+ raise "val #{val} not in range (#{SYMBOLS.size})"
76
+ end
77
+ else
78
+ raise "unexpected val #{val} (#{val.class})"
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
data/lib/compsci/timer.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module CompSci
2
-
3
2
  module Timer
4
3
  # lifted from seattlerb/minitest
5
4
  if defined? Process::CLOCK_MONOTONIC
data/lib/compsci/tree.rb CHANGED
@@ -100,12 +100,14 @@ module CompSci
100
100
  def display(width: 80)
101
101
  count = 0
102
102
  str = ''
103
- self.bf_search { |n|
103
+ self.bf_search { |node|
104
104
  count += 1
105
105
  level = Math.log(count, 2).floor
106
106
  block_width = width / (2**level)
107
+ val = node.to_s
107
108
  str += "\n" if 2**level == count and count > 1
108
- str += n.to_s.ljust(block_width / 2, ' ').rjust(block_width, ' ')
109
+ space = [(block_width + val.size) / 2, val.size + 1].max
110
+ str += val.ljust(space, ' ').rjust(block_width, ' ')
109
111
  false # keep searching to visit every node
110
112
  }
111
113
  str
data/test/names.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'compsci/names'
2
+ require 'compsci/names/greek'
2
3
  require 'minitest/autorun'
3
4
 
4
5
  include CompSci
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compsci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.1
4
+ version: 0.1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: buildar~> 3.0
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,62 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: flog
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: flay
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: roodi
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby-prof
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
41
111
  description: Trees, Heaps, Timers, Error fitting, etc
42
112
  email:
43
113
  executables: []
@@ -58,6 +128,7 @@ files:
58
128
  - lib/compsci/fit.rb
59
129
  - lib/compsci/heap.rb
60
130
  - lib/compsci/names.rb
131
+ - lib/compsci/names/greek.rb
61
132
  - lib/compsci/node.rb
62
133
  - lib/compsci/timer.rb
63
134
  - lib/compsci/tree.rb