Sha256: 41f9aa8bde7d6a3e3c408486f561167c1d73ca535eed033995a58d310b6ffa95

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'compsci/tree'
require 'compsci/timer'

include CompSci

puts <<EOF
#
# 3 seconds worth of pushes
#

EOF

count = 0
start = Timer.now
start_1k = Timer.now
tree = BinaryTree.new(ChildNode, rand(99))

loop {
  count += 1

  if count % 100 == 0
    _ans, push_elapsed = Timer.elapsed { tree.push rand 99 }
    puts "%ith push: %0.8f s" % [count, push_elapsed]

    if count % 1000 == 0
      push_1k_elapsed = Timer.since start_1k
      puts "-----------"
      puts "    1k push: %0.4f s (%i push / s)" %
           [push_1k_elapsed, 1000.to_f / push_1k_elapsed]
      puts
      start_1k = Timer.now
    end
  else
    tree.push rand 99
  end

  break if Timer.since(start) > 3
}

puts "pushed %i items in %0.1f s" % [count, Timer.since(start)]
puts

puts <<EOF
#
# 30 inserts, puts, df_search
#

EOF

vals = []
30.times { vals << rand(99) }
p vals

tree = BinaryTree.new(ChildNode, vals.shift)
tree.push vals.shift until vals.empty?

puts tree

tree.df_search { |n|
  puts "visited #{n}"
  false # or n.value > 90
}
puts

p tree
puts

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
compsci-0.0.3.1 examples/binary_tree.rb
compsci-0.0.2.1 examples/binary_tree.rb