compsci 0.2.0.1 → 0.3.0.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: 3fa74f40bbc97fa685c811d2b15738da31d69c66
4
- data.tar.gz: '02965023a412fae230e7fe3e42704982c6410bab'
3
+ metadata.gz: 6b9d3fa913e9dc0f7aa9f8711e9aa231c00d1022
4
+ data.tar.gz: 8436157b3364c791cee0471ae74ca3817f0f4dde
5
5
  SHA512:
6
- metadata.gz: b4832093f2d37d27b55f2b32fe20422704100d7cd515d51790d745dbf22d7006866959dc844939d2cff19e60d3ee54b78100a9785511274ed43aa22dd86a7fd8
7
- data.tar.gz: 5b5ad3eeedadddd92abca745bf7822dbd9cff07fa79ccc6d34cae075d6a1c24dbc747aa1939d44806e1ad83b914b9e0b880fc6be26c505c98f869fa3dd1ff9f6
6
+ metadata.gz: 1670fd7283f147996dea2ed2a7a190797a33a5b22b60e8ccfa98a5dc48d61aa6a43302badbc7776b6b7c5a7171a32923ed2dc95f88c23ca998bd1d023d3f4f72
7
+ data.tar.gz: f30dd40fb2e5f9e04db6044d7801f1776fb0e1214fd23c29bfbef028dbcd87cab612e434e4df43da477012975561cb7eeef6dab867a53e479612893c53a9e086
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0.1
1
+ 0.3.0.1
@@ -15,7 +15,7 @@ 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
+ s.add_development_dependency "buildar", "~> 3.0"
19
19
  s.add_development_dependency "minitest", "~> 5.0"
20
20
  s.add_development_dependency "rake", "~> 0"
21
21
  s.add_development_dependency "flog", "~> 0"
@@ -3,6 +3,8 @@ require 'compsci/timer'
3
3
 
4
4
  include CompSci
5
5
 
6
+ runtime = (ARGV.shift || "3").to_i
7
+
6
8
  puts <<EOF
7
9
  #
8
10
  # 3 seconds worth of pushes
@@ -10,6 +12,18 @@ puts <<EOF
10
12
 
11
13
  EOF
12
14
 
15
+ RANDMAX = 1_000
16
+ NUMBERWANG = 1_000
17
+ NUMS = (0..(RANDMAX - 1)).to_a.shuffle
18
+
19
+ def number(num)
20
+ if num % NUMBERWANG == 0
21
+ NUMS.shift
22
+ NUMS.push rand RANDMAX
23
+ end
24
+ NUMS[num % RANDMAX]
25
+ end
26
+
13
27
  count = 0
14
28
  start = Timer.now
15
29
  start_100k = Timer.now
@@ -19,10 +33,10 @@ loop {
19
33
  count += 1
20
34
 
21
35
  if count % 10000 == 0
22
- _answer, push_elapsed = Timer.elapsed { h.push rand 99999 }
36
+ _answer, push_elapsed = Timer.elapsed { h.push number(count) }
23
37
  puts "%ith push: %0.8f s" % [count, push_elapsed]
24
38
  if count % 100000 == 0
25
- h.push rand 99999
39
+ h.push number(count)
26
40
  push_100k_elapsed = Timer.since start_100k
27
41
  puts "-------------"
28
42
  puts " 100k push: %0.8f s (%ik push / s)" %
@@ -31,10 +45,10 @@ loop {
31
45
  start_100k = Timer.now
32
46
  end
33
47
  else
34
- h.push rand 99999
48
+ h.push number(count)
35
49
  end
36
50
 
37
- break if Timer.since(start) > 3
51
+ break if Timer.since(start) > runtime
38
52
  }
39
53
 
40
54
  puts "pushed %i items in %0.1f s" % [count, Timer.since(start)]
@@ -65,6 +65,7 @@ class CompSci::Heap < CompSci::CompleteNaryTree
65
65
  #
66
66
  def sift_up(idx)
67
67
  return self if idx <= 0
68
+ # print '.'
68
69
  pidx = self.class.parent_idx(idx, @child_slots)
69
70
  if !self.heapish?(pidx, idx)
70
71
  @array[idx], @array[pidx] = @array[pidx], @array[idx] # swap
@@ -50,11 +50,12 @@ module CompSci
50
50
 
51
51
  # accumulate children; no child gaps
52
52
  class FlexNode < Node
53
+ # These methods look like convenience methods, but they provide the
54
+ # FlexNode interface also used by ChildFlexNode
53
55
  def add_child(node)
54
56
  @children << node
55
57
  end
56
58
 
57
- # TODO: are we passing everything needed to self.class.new ?
58
59
  def new_child(value)
59
60
  self.add_child self.class.new(value)
60
61
  end
@@ -95,6 +96,8 @@ module CompSci
95
96
  end
96
97
 
97
98
  # ChildNode which accumulates children with no gaps
99
+ # It meets the FlexNode API but does not inherit from FlexNode since it
100
+ # needs to reimplement each method; instead get parent stuff from ChildNode
98
101
  class ChildFlexNode < ChildNode
99
102
  def add_child(node)
100
103
  node.parent ||= self
@@ -6,16 +6,8 @@ require 'minitest/autorun'
6
6
  include CompSci
7
7
 
8
8
  describe BinarySearchTree do
9
- def ww2_names(count)
10
- Array.new(count) { |i| Names::WW2[i].to_s }
11
- end
12
-
13
- def nato_names(count)
14
- Array.new(count) { |i| Names::NATO[i].to_s }
15
- end
16
-
17
9
  before do
18
- @keys = ww2_names(4)
10
+ @keys = Array.new(4) { |i| Names::WW2[i] }
19
11
  @values = Array.new(4) { Names::SOLAR.sample }
20
12
  @nodes = Array.new(4) { |i|
21
13
  KeyNode.new(@values[i], key: @keys[i], children: 2)
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compsci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.1
4
+ version: 0.3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: buildar~> 3.0
14
+ name: buildar
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement