--Apple-Mail-2-400134927
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset -ASCII;
delsp¥µ
ðï
¥Þ ¥Ë ¥¢¥¤¥ã ¥¤¡¼¡¼¥«¥ã ¥¢¥¢¥³¥¢¡¼ ¥Á¥Ø¥ã ¥Ï ¥Ë ¥³
¥» ¥Þ¥ã ¥Î¥¡
¥» ¥ã ¥Í¥ç ¥ë¥¡ ¥Õ ¥Ä¥¡ ¥ç
¥Ø ¥ã ¥ã
¥ç ¥Á
¥Î ¥ç
¥Ï ¥Ê ¥Ì ¥Î¥Î
¥å¥å¥Á¥å¥Ø¥å¥¤¥å¥¨¡¼¡¼¥¢¥¦¥¨¥±¥¤¥
¥Æ¥å¥ä¥å¥Ê¥³ ¥
¥Æ¥å¥ä¥³ ¥Ã¥å¥å¥µ
¥å¥å¥¨¥¨¥µ
¡¬¥ç¡Ö
¥Æ¥å¥È¥³ ¥µ
³Í¡¬¥ç
¡×¡£¥Ã¥Ã¥Ã
¡×¥å¥å
¡× ¡¢¥Î¥³ ¥Ã¥Ã¥Ã¥Ã¥ç¥ã ¥¢¥ç¥¯ ¥¤¡¼¡¼¥¢¥Ã¥¢¡¼¥Ã¡¼¥¦ ¡¼¥¯¥³¥ª¥¨¥³¥¦¥¤ ¥Ê ¡¢
¡× ¡¢¥á¥Î¥³ ¥ç¥ã ¥¢¥ç¥¢¡¼ ¥¤¡¼¡¼¥¦¥Ã¥¢¡¼¥Ã¥¢¥¨ ¥¢¥±¥³¥¦¥«¥³¥ª¥¯ ¥Ê ¡¢
¡× ¡¢¥Î¥³ ¥ç¥ã ¥¢¥ç¥¤¥ç¥¤¥ç¥¤ ¥¤¡¼¡¼¥¨¥Ã¡¼¥ª¥Ã¡¼¥ ¡¼¥¯¥³¥¨¥¯¥³¥¤¥¦ ¥Ê ¡¢
¡×¥©¥©
¡×
¡× ¥ç¥³
¡×
¡× ¥Æ ¥£¥¥ ¥¤¡¼¡¼¥¢¥ã¥¤¡¼¡¼¥¦ ¥Á ¥Ø¥æ¥â¥Í¥Á ¥·¥¿¥È¥ç¥»
¡×
¡× ¥Á ¥ç ¥ë ¥Ã
¡× ¥á¥ç
¡×
¡× ¥Þ
¡×
¡× ¥ä ¥Ì ¥ã
¡× ¥£¥ç¥ç ¥Ê ¥¥
¡× ¥ç ¥Î ¥ã ¥ç
¡×
¡× ¥ä ¥â¥Ê ¥ã ¥Ì¥ã
¡× ¥Ê ¥ç
¡×
¡× ¥â ¥ç
¡×
¡× ¥Ì ¥£¥ç¥ç ¥Ê ¥¥
¡× ¥ç
¡×
¡× ¥Û
¡× ¥ã ¥ç
¡×
¡× ¥Ê
¡×
¡× ¥¡¥¡
¡×
¡× ¡× ¥Ì ¥Ê
¡× ¥ç¥£¥í¥¡¥Á¥¡¥ã ¥¡¥Ä¥¡¥ã ¥¡¥Æ¥¡¥ã ¥¡¥ì¥¡¥ó¥¥
¡×
¡× ¥ç¥½
¡× ¥ç
¡×
¡×
¡× ¡× ¥Ì
¡× ¥ç
¡× ¥¡¥Á¥¡¥ç¥ç¥¡¥Æ¥¡
¡× ¥ç
¡×
¡×
¡× ¥ç ¥¡¥ì¥¡
¡×
¡×
¡× ¡× ¥ä
¡× ¥ç¥½
¡× ¥ç
¡×
¡×
¥Æ¥Æ¥Æ¥Ì
¥Ê
¡× ¥Æ ¥Ê
¡× ¥ç
¡×
¡× ¥Î ¥ã ¥ç
¡×
¡× ¥Î ¥ã
¡× ¥ã ¥©¥© ¥ç
¥£ ¥ã ¥ò¥¥
¥¿
¥ç ¥ç
¥¿
¥¿
¥¿ ¥ó
¥¿¡¬ ¡¬ ¡¬
¥¿¡¬
¥¿¥ç¥£¥¥
¥¿¡¬¥ç¥£¥¥ ¥¿¡¬
¡× ¥ë ¥ç
¥£¥¥
¥¿¡¬
¥¿ ¥·¥·
¥¿¡¬¥ç¥£¥¥
¡× ¥á ¥ç
¥½¥£¥¥
¥¿¡¬
¥¿¡¬¥ç¥½ ¥ò¥ò ¥¿¥ç¥½
¥¿¥ç¥½
¡× ¥á ¥ç
¥½¥£¥¥
¡£¥½
¡× ¥á ¥£¥¥ ¥ç
¥£¥¥
¥¿
¡× ¥á ¥£¥¥ ¥ç
¥£¥¥
¥¿
¡× ¥á ¥ç
¥£¥¥
¥½
¥Ê¥Þ¥Ë¥Ê¥ã ¡Ö ¡Ö
¥¿¡¬
¥¿¡¬¥ç¥£¥¥ ¥¿¡¬
¥¿ ¥©
¥¿¥ç
¡× ¥á ¥ç
¥£¥¥
¥¿¥ç¥½
¥Ê¥Þ¥Ë¥Ê¥ã ¡Ö ¡Ö
¥¿¥ç
¡× ¥á ¥ç
¥£¥¥
¥£¥ã ¥ò¥¿¥¥ ¥¿¥ç¥½
¡× ¥á ¥ç
¥½
¥ç
¡×
¡× ¥â¥Ê ¥Ê ¥Ê
¡× ¥ç
¡×
¡× ¥Ê
¡×
¡× ¥¡¥¡
¡×
¡× ¥Ê¥ç¥£¥í¥¢¥ã¥¤¥ã¥¦¥ó¥ã ¥í¥¡¥¡¥ã ¥¡¥¡¥ã ¥¡¥¡¥ó¥¥
¡×
¡× ¡× ¥ë ¥í¥¢¥ã ¥¡¥¡¥ó¥ã ¥í¥¤¥ã ¥¡¥¡¥ó¥ã ¥í¥¦¥ã¥¡¥¡¥ó
¡× ¥ç ¥ç¥£¥¡¥ã ¥¡¥¥
¡×
¡× ¥â¥Ê
¡× ¥Ê
¡×
¡× ¡× ¥Æ ¥â¥Ê
¡× ¡× ¥Ê ¥ç
¡× ¥£¥§¥¥
¡× ¥¿ ¥ç ¥Ì¥ç¥£¥¥
¡×
¡×
¡× ¡× ¥á ¥Ê ¥ã ¥ç¥ç
¡× ¡× ¥ç
¡×
¡× ¥¿¥ç
¡×
¡×
¡× ¡× ¥á ¥Ê ¥ã ¥ç¥ç
¡× ¡× ¥ç
¡×
¡× ¥¿¥ç
¡×
¡×
¡× ¡× ¥á ¥Ê
¡× ¡× ¥ç ¥Î ¥ã
¡× ¡× ¥Ê ¥ç
¡× ¥½¥£ ¥¥
¡× ¥ç¥½
¡× ¥¿¥ç ¥ç¥½ ¥½ ¥³
¡×
¡× ¥¿¥í¥ó¥ç¥½
¡×
¡×
¡×
¡× ¡× ¥Ê ¥Ê ¥ç
¡×
¡× ¥¿¥ç ¥ç
¡×
¡×
¡×
¡×
¡× ¥ç
¡× ¥ç¥½
¡× ¥©
¡×
¡×
¡× ¥ç
¡×
¡×
¡×
¡× ¥¿¥ç
¡×
¡×
¡×
¡×
¡×
¡×
¡×
¡×
¡×
¡¢¡¼ ¡¬¡¬¥Ë¥Î¥Õ¥Ê¡¬¡¬
¥È¥Á¥ä¥Á¥ç¥ã ¥ã ¡¢¡¼¥ã ¡¬¡¬¥Õ¥Î¥Û¥Ê¡¬¡¬¥©¥¨
¡¬¡¬¥Ê¥Û¥È¡¬¡¬
¥¡¥Ã¥¡
¥ä¥Æ¡¬¥Ì ¥· ¥ä¥³¥³¥æ¥³¥³¥ä¥Æ
¡¬¥¢
¥ç
¡× ¥¡
¡¬¥£¡¼¥ã ¥ç¥¥
¡¬¥£¥Ê¥Þ¥Ë¥Ê¥¥ ¥ç
¡¬¥¤
¥ç
¥¡¥Á¥¡¥ç¥ç¥¡¥Æ¥¡
¥ç
¥ç ¥¡¥ì¥¡
¡¬¥£¡¼¥ã ¥ç¥¥
¡¬¥£¥¡¥Á¥¡¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥½¥¥
¡¬¥£¡¼¥ã ¥ç¥¥
¡¬¥£¥¡¥Á¥¡¥ã ¥ç¥¥
¡¬¥£¡¼¥ã ¥ç¥¥
¡¬¥£¥¡¥Á¥¡¥ã ¥ç¥¥
¡¬¥£¥¢¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥½¥¥
¡¬¥£¥¢¥ã ¥ç¥¥
¡¬¥£¥¡¥Ä¥¡¥ã ¥ç¥¥
¡¬¥£¥¢¥ã ¥ç¥¥
¡¬¥£¥¡¥Ä¥¡¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥¥
¡¬¥£¡¼¥ã ¥ç¥¥
¡¬¥£¥¡¥Á¥¡¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥½¥¥
¡¬¥£¡¼¥ã ¥ç¥¥
¡¬¥£¥¡¥Á¥¡¥ã ¥ç¥¥
¡¬¥£¡¼¥ã ¥ç¥¥
¡¬¥£¥¡¥Á¥¡¥ã ¥ç¥¥
¡¬¥£¥¢¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥½¥¥
¡¬¥£¥¢¥ã ¥ç¥¥
¡¬¥£¥¡¥Ä¥¡¥ã ¥ç¥¥
¡¬¥£¥¢¥ã ¥ç¥¥
¡¬¥£¥¡¥Ä¥¡¥ã ¥ç¥¥
¡¬¥£¥¤¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥½¥¥
¡¬¥£¥¤¥ã ¥ç¥¥
¡¬¥£¥¡¥Æ¥¡¥ã ¥ç¥¥
¡¬¥£¥¤¥ã ¥ç¥¥
¡¬¥£¥¡¥Æ¥¡¥ã ¥ç¥¥
¡¬¥£¥¦¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥½¥¥
¡¬¥£¥¦¥ã ¥ç¥¥
¡¬¥£¥¡¥ì¥¡¥ã ¥ç¥¥
¡¬¥£¥¦¥ã ¥ç¥¥
¡¬¥£¥¡¥ì¥¡¥ã ¥ç¥¥
¡¬¥£¥¨¥ã ¥ç¥¥
¡¬¥£¥ã ¥ç¥½¥¥
¡¬¥£¥Ê¥Þ¥Ë¥Ê¥¥ ¥ç
¡¬
¥ª¥ã ¥«¥ã ¥¥ã ¥¯¥ã ¥±¥ó
¥ç¥£¥¥
¥ç
¡¬¥£¥í¥ó¥ã ¥¥
¥©
¥¦
¡¬¥£¥¦¥ã ¥¥
¥ç
¡¬¥£¥í¥ó¥ã ¥¥
¥©
¡¬¥£¥ª¥ã ¥¥
¥ä¥Æ¡¬¥â¥Ê ¥· ¥ä¥³¥³¥æ¥³¥³¥ä¥Æ
¡¬
¥¡¥¡¥ç¥ç¥¡¥¡¥ã ¥¢¥ç¥ç¥¢¡¼¥ã ¥¢¡¼¥ç¥ç¥¤¡¼¥ó
¥ç ¥ç¡¬
¡¼¥ç¥ç¥ç¥£¥ç ¥ç¥ç¥¥¥¥¥ç ¥ç ¥í¥ó
¥Ê¥ç¥£¥§¥¥
¥ç
¡¬¥£¥í¥ó¥ã ¥¥
¥©
¥¦
¡¬¥£¥¦¥ã ¥¥
¥ç
¡¬¥£¥í¥ó¥ã ¥¥
¥©
¡¬¥£¥ç¥ã ¥¥
¥å¥å¥Á¥å¥Ø¥å¥¤¥å¥¨¡¼¡¼¥¢¥¦¥¨¥±¥¤¥
¥Æ¥å¥ä¥å¥Ê¥³ ¥
¥Æ¥å¥ä¥³ ¥Ã¥å¥å¥µ
¥å¥å¥¨¥¨¥µ
aster_generator.rb"
Content-Disposition: attachment;
filenameù¸ter_generator.rb
#!/usr/local/bin/ruby -w
class FasterGenerator
def initialize( enum il )
@index
if enum.nil?
@queue rray.new
yield self
else
@queue num.to_a
end
end
attr_reader :index
alias_method :pos, :index
def current
raise EOFError, "No more elements available." if end?
@queue[@index]
end
def next
raise EOFError, "No more elements available." if end?
@queue[(@index + ) - 1]
end
def next?
not end?
end
def end?
@index > queue.size
end
def rewind
@index
self
end
def yield( object )
@queue << object
end
include Enumerable
def each( &block )
@queue.each(&block)
self
end
end
#class SyncEnumerator
# include Enumerable
#
# def initialize( *enums )
# @gens nums.map { |e| FasterGenerator.new(e) }
# end
#
# def size
# @gens.size
# end
#
# def length
# @gens.length
# end
#
# def end?(i il)
# if i.nil?
# @gens.detect { |g| g.end? } ? true : false
# else
# @gens[i].end?
# end
# end
#
# def each
# @gens.each { |g| g.rewind }
#
# loop do
# count
#
# ret gens.map { |g|
# if g.end?
# count +
# nil
# else
# g.next
# end
# }
#
# if count @gens.size
# break
# end
#
# yield ret
# end
#
# self
# end
#end
if $0 __FILE__
eval DATA.read, nil, $0, __LINE__+4
end
__END__
require 'test/unit'
class TC_Generator < Test::Unit::TestCase
def test_block1
g asterGenerator.new { |g|
# no yield's
}
assert_equal(0, g.pos)
assert_raises(EOFError) { g.current }
end
def test_block2
g asterGenerator.new { |g|
for i in 'A'..'C'
g.yield i
end
g.yield 'Z'
}
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(true, g.next?)
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(0, g.pos)
assert_equal('A', g.next)
assert_equal(1, g.pos)
assert_equal(true, g.next?)
assert_equal(1, g.pos)
assert_equal('B', g.current)
assert_equal(1, g.pos)
assert_equal('B', g.next)
assert_equal(g, g.rewind)
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(true, g.next?)
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(0, g.pos)
assert_equal('A', g.next)
assert_equal(1, g.pos)
assert_equal(true, g.next?)
assert_equal(1, g.pos)
assert_equal('B', g.current)
assert_equal(1, g.pos)
assert_equal('B', g.next)
assert_equal(2, g.pos)
assert_equal(true, g.next?)
assert_equal(2, g.pos)
assert_equal('C', g.current)
assert_equal(2, g.pos)
assert_equal('C', g.next)
assert_equal(3, g.pos)
assert_equal(true, g.next?)
assert_equal(3, g.pos)
assert_equal('Z', g.current)
assert_equal(3, g.pos)
assert_equal('Z', g.next)
assert_equal(4, g.pos)
assert_equal(false, g.next?)
assert_raises(EOFError) { g.next }
end
def test_each
a 5, 6, 7, 8, 9]
g asterGenerator.new(a)
i
g.each { |x|
assert_equal(a[i], x)
i +
break if i 3
}
assert_equal(3, i)
i
g.each { |x|
assert_equal(a[i], x)
i +
}
assert_equal(5, i)
end
end
class TC_SyncEnumerator < Test::Unit::TestCase
def test_each
r 'a'..'f', 1..10, 10..20]
ra .map { |x| x.to_a }
a 0...(ra.map {|x| x.size}.max)).map { |i| ra.map { |x| x[i] } }
s yncEnumerator.new(*r)
i
s.each { |x|
assert_equal(a[i], x)
i +
break if i 3
}
assert_equal(3, i)
i
s.each { |x|
assert_equal(a[i], x)
i +
}
assert_equal(a.size, i)
end
end
--Apple-Mail-2-400134927
Content-Transfer-Encoding: 7bit
Content-Type: text/x-ruby-script;
x-unix-mode44;
name hread_generator.rb"
Content-Disposition: attachment;
filename read_generator.rb
#!/usr/bin/env ruby
#--
# $Idaemons: /home/cvs/rb/generator.rb,v 1.8 2001/10/03 08:54:32 knu Exp $
# $RoughId: generator.rb,v 1.10 2003/10/14 19:36:58 knu Exp $
# $Id: generator.rb,v 1.12 2005/12/31 02:56:46 ocean Exp $
#++
#
# enerator.rb: convert an internal iterator to an external one
#
# Copyright (c) 2001,2003 Akinori MUSHA <knu / iDaemons.org>
#
# All rights reserved. You can redistribute and/or modify it under
# the same terms as Ruby.
#
# Overview
#
# This library provides the Generator class, which converts an
# internal iterator (i.e. an Enumerable object) to an external
# iterator. In that form, you can roll many iterators independently.
#
# The SyncEnumerator class, which is implemented using Generator,
# makes it easy to roll many Enumerable objects synchronously.
#
# See the respective classes for examples of usage.
#
# Generator converts an internal iterator (i.e. an Enumerable object)
# to an external iterator.
#
# Example
#
# require 'generator'
#
# # Generator from an Enumerable object
# g enerator.new(['A', 'B', 'C', 'Z'])
#
# while g.next?
# puts g.next
# end
#
# # Generator from a block
# g enerator.new { |g|
# for i in 'A'..'C'
# g.yield i
# end
#
# g.yield 'Z'
# }
#
# # The same result as above
# while g.next?
# puts g.next
# end
#
class ThreadGenerator
include Enumerable
# Creates a new generator either from an Enumerable object or from a
# block.
#
# In the former, block is ignored even if given.
#
# In the latter, the given block is called with the generator
# itself, and expected to call the +yield+ method for each element.
def initialize(enum il, &block)
if enum
@block roc{|g| enum.each{|value| g.yield value}}
else
@block lock
end
@index
@queue ]
@main_thread il
@loop_thread.kill if defined?(@loop_thread)
@loop_thread hread.new do
Thread.stop
begin
@block.call(self)
rescue
@main_thread.raise $!
ensure
@main_thread.wakeup
end
end
Thread.pass until @loop_thread.stop?
self
end
# Yields an element to the generator.
def yield(value)
if Thread.current ! loop_thread
raise "should be called in Generator.new{|g| ... }"
end
Thread.critical rue
begin
@queue << value
@main_thread.wakeup
Thread.stop
ensure
Thread.critical alse
end
self
end
# Returns true if the generator has reached the end.
def end?
if @queue.empty?
if @main_thread
raise "should not be called in Generator.new{|g| ... }"
end
Thread.critical rue
begin
@main_thread hread.current
@loop_thread.wakeup
Thread.stop
rescue ThreadError
# ignore
ensure
@main_thread il
Thread.critical alse
end
end
@queue.empty?
end
# Returns true if the generator has not reached the end yet.
def next?
!end?
end
# Returns the current index (position) counting from zero.
def index
@index
end
# Returns the current index (position) counting from zero.
def pos
@index
end
# Returns the element at the current position and moves forward.
def next
raise EOFError.new("no more elements available") if end?
@index +
@queue.shift
end
# Returns the element at the current position.
def current
raise EOFError.new("no more elements available") if end?
@queue.first
end
# Rewinds the generator.
def rewind
initialize(nil, &@block) if @index.nonzero?
self
end
# Rewinds the generator and enumerates the elements.
def each
rewind
until end?
yield self.next
end
self
end
end
#
# SyncEnumerator creates an Enumerable object from multiple Enumerable
# objects and enumerates them synchronously.
#
# Example
#
# require 'generator'
#
# s yncEnumerator.new([1,2,3], ['a', 'b', 'c'])
#
# # Yields [1, 'a'], [2, 'b'], and [3,'c']
# s.each { |row| puts row.join(', ') }
#
#class SyncEnumerator
# include Enumerable
#
# # Creates a new SyncEnumerator which enumerates rows of given
# # Enumerable objects.
# def initialize(*enums)
# @gens nums.map { |e| Generator.new(e) }
# end
#
# # Returns the number of enumerated Enumerable objects, i.e. the size
# # of each row.
# def size
# @gens.size
# end
#
# # Returns the number of enumerated Enumerable objects, i.e. the size
# # of each row.
# def length
# @gens.length
# end
#
# # Returns true if the given nth Enumerable object has reached the
# # end. If no argument is given, returns true if any of the
# # Enumerable objects has reached the end.
# def end?(i il)
# if i.nil?
# @gens.detect { |g| g.end? } ? true : false
# else
# @gens[i].end?
# end
# end
#
# # Enumerates rows of the Enumerable objects.
# def each
# @gens.each { |g| g.rewind }
#
# loop do
# count
#
# ret gens.map { |g|
# if g.end?
# count +
# nil
# else
# g.next
# end
# }
#
# if count @gens.size
# break
# end
#
# yield ret
# end
#
# self
# end
#end
if $0 __FILE__
eval DATA.read, nil, $0, __LINE__+4
end
__END__
require 'test/unit'
class TC_Generator < Test::Unit::TestCase
def test_block1
g enerator.new { |g|
# no yield's
}
assert_equal(0, g.pos)
assert_raises(EOFError) { g.current }
end
def test_block2
g enerator.new { |g|
for i in 'A'..'C'
g.yield i
end
g.yield 'Z'
}
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(true, g.next?)
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(0, g.pos)
assert_equal('A', g.next)
assert_equal(1, g.pos)
assert_equal(true, g.next?)
assert_equal(1, g.pos)
assert_equal('B', g.current)
assert_equal(1, g.pos)
assert_equal('B', g.next)
assert_equal(g, g.rewind)
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(true, g.next?)
assert_equal(0, g.pos)
assert_equal('A', g.current)
assert_equal(0, g.pos)
assert_equal('A', g.next)
assert_equal(1, g.pos)
assert_equal(true, g.next?)
assert_equal(1, g.pos)
assert_equal('B', g.current)
assert_equal(1, g.pos)
assert_equal('B', g.next)
assert_equal(2, g.pos)
assert_equal(true, g.next?)
assert_equal(2, g.pos)
assert_equal('C', g.current)
assert_equal(2, g.pos)
assert_equal('C', g.next)
assert_equal(3, g.pos)
assert_equal(true, g.next?)
assert_equal(3, g.pos)
assert_equal('Z', g.current)
assert_equal(3, g.pos)
assert_equal('Z', g.next)
assert_equal(4, g.pos)
assert_equal(false, g.next?)
assert_raises(EOFError) { g.next }
end
def test_each
a 5, 6, 7, 8, 9]
g enerator.new(a)
i
g.each { |x|
assert_equal(a[i], x)
i +
break if i 3
}
assert_equal(3, i)
i
g.each { |x|
assert_equal(a[i], x)
i +
}
assert_equal(5, i)
end
end
class TC_SyncEnumerator < Test::Unit::TestCase
def test_each
r 'a'..'f', 1..10, 10..20]
ra .map { |x| x.to_a }
a 0...(ra.map {|x| x.size}.max)).map { |i| ra.map { |x| x[i] } }
s yncEnumerator.new(*r)
i
s.each { |x|
assert_equal(a[i], x)
i +
break if i 3
}
assert_equal(3, i)
i
s.each { |x|
assert_equal(a[i], x)
i +
}
assert_equal(a.size, i)
end
end
--Apple-Mail-2-400134927
Content-Transfer-Encoding: 7bit
Content-Type: text/x-ruby-script;
x-unix-mode44;
name ime_generators.rb"
Content-Disposition: attachment;
filename me_generators.rb
#!/usr/local/bin/ruby -w
require "benchmark"
require "thread_generator"
require "callcc_generator"
require "faster_generator"
tests 0
enum 1..1000).to_a
puts
puts "### Construction ###"
puts
Benchmark.bmbm do |x|
x.report("New Thread Generator") do
(tests * 100).times { ThreadGenerator.new(enum) }
end
x.report("Old callcc Generator") do
(tests * 100).times { CallCCGenerator.new(enum) }
end
x.report("Array-based FasterGenerator") do
(tests * 100).times { FasterGenerator.new(enum) }
end
end
puts
puts "### next() ###"
puts
Benchmark.bmbm do |x|
x.report("New Thread Generator") do
generator hreadGenerator.new(enum)
tests.times do
generator.rewind
generator.next until generator.end?
end
end
x.report("Old callcc Generator") do
generator allCCGenerator.new(enum)
tests.times do
generator.rewind
generator.next until generator.end?
end
end
x.report("Array-based FasterGenerator") do
generator asterGenerator.new(enum)
tests.times do
generator.rewind
generator.next until generator.end?
end
end
end
--Apple-Mail-2-400134927--