クラス
- Array (21)
- OptionParser (24)
- Pathname (12)
- Set (9)
- String (12)
-
Thread
:: Queue (36) -
Thread
:: SizedQueue (36) - ThreadsWait (18)
-
Zlib
:: Deflate (12) -
Zlib
:: Inflate (12)
モジュール
- TSort (23)
キーワード
- deq (24)
- disjoint? (9)
-
each
_ strongly _ connected _ component _ from (23) -
join
_ nowait (6) - load (12)
-
next
_ wait (6) -
on
_ tail (12) - pack (21)
- pop (24)
-
set
_ dictionary (24) - shift (24)
- unpack (12)
検索結果
先頭5件
-
Pathname
# join(*args) -> Pathname (21220.0) -
与えられたパス名を連結します。
...ます。
@param args 連結したいディレクトリ名やファイル名を文字列で与えます。
//emlist[例][ruby]{
require "pathname"
path0 = Pathname("/usr") # Pathname:/usr
path0 = path0.join("bin/ruby") # Pathname:/usr/bin/ruby
# 上記の path0 の処......理は下記の path1 と同様のパスになります
path1 = Pathname("/usr") + "bin/ruby" # Pathname:/usr/bin/ruby
path0 == path1 #=> true
//}... -
ThreadsWait
# join(*threads) -> () (21220.0) -
終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。
...、threads で指定されたスレッドを指定します。
@param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = Threads......Wait.new
p thall.threads #=> []
thall.join(*threads)
p thall.threads
#=> [#<Thread:0x216ec dead>, #<Thread:0x21660 dead>, #<Thread:0x215d4 dead>, #<Thread:0x214bc dead>]... -
Set
# disjoint?(set) -> bool (12225.0) -
self と set が互いに素な集合である場合に true を返します。
...self と set が互いに素な集合である場合に true を返します。
逆に self と set の共通集合かを確認する場合には Set#intersect? を
使用します。
@param self Set オブジェクトを指定します。
@raise ArgumentError 引数が Set オブジェクトで......ない場合に発生します。
//emlist[][ruby]{
require 'set'
p Set[1, 2, 3].disjoint? Set[3, 4] # => false
p Set[1, 2, 3].disjoint? Set[4, 5] # => true
//}
@see Set#intersect?... -
ThreadsWait
# join _ nowait(*threads) -> () (12220.0) -
終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。 しかし、実際には終了をまちません。
...て、threads で指定されたスレッドを指定します。
しかし、実際には終了をまちません。
@param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.n......ew { sleep 1; p Thread.current }
}
thall = ThreadsWait.new
p thall.threads #=> []
thall.join_nowait(*threads)
p thall.threads #=> [#<Thread:0x21638 sleep>, #<Thread:0x215ac sleep>, #<Thread:0x21520 sleep>, #<Thread:0x21494 sleep>, #<Thread:0x21408 sleep>]
# 実際には終了を待っ... -
OptionParser
# on _ tail(*arg , &block) -> self (6137.0) -
オプションを取り扱うためのブロックを自身の持つリストの最後に登録します。
...
@param arg OptionParser#on と同様です。
@param block OptionParser#on と同様です。
//emlist[例][ruby]{
require "optparse"
opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end
puts opts.help
# => Usage: test......[options]
# -i, --init
# -u, --update
# -h, --help
//}
//emlist[例][ruby]{
require "optparse"
opts = OptionParser.new
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("--version", "Show version") do
puts OptionParser::Version.join('.')
exit
en......d
//}
@see OptionParser#on, OptionParser#on_head... -
Thread
:: SizedQueue # shift(non _ block = false) -> object (6137.0) -
キューからひとつ値を取り出します。 キューに push しようと待っているスレッドがあれば、実行を再開させます。
...ば、実行を再開させます。
@param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。
//emlist[例][ruby]{
require 'thread'
q = SizedQueue.new(4)
th1 = Thread.start do
while resource = q.pop
puts resource
end
end
[:resource1, :reso......r)
}
th1.join
# => resource1
# resource2
# resource3
//}
//emlist[例: nonblock = true][ruby]{
require 'thread'
q = SizedQueue.new(4)
th1 = Thread.start do
while resource = q.pop
puts resource
end
end
[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}
begin
th1.join
q.......pop(true)
rescue => e
p e
p e.message
end
# => resource1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
//}
@see Thread::Queue#pop... -
ThreadsWait
# next _ wait(nonblock = nil) -> Thread (6137.0) -
指定したスレッドのどれかが終了するまで待ちます。
...で待ちます。
@param nonblock true を与えると、キューが空の時、例外 ThreadsWait::ErrNoFinishedThread が発生します。
@raise ErrNoWaitingThread 終了をまつスレッドが存在しない時、発生します。
@raise ErrNoFinishedThread nonblock がtrue でかつ、......キューが空の時、発生します。
#使用例
require 'thwait'
threads = []
2.times {|i|
threads << Thread.new { sleep i }
}
thall = ThreadsWait.new
thall.join_nowait(*threads)
until thall.empty?
th = thall.next_wait
p th
end
@see Queue#pop... -
Zlib
:: Deflate # set _ dictionary(string) -> String (6137.0) -
圧縮に用いる辞書を指定します。string を返します。 このメソッドは Zlib::Deflate.new, Zlib::ZStream#reset を呼び出した直後にのみ有効です。詳細は zlib.h を参照して下さい。
...string を返します。
このメソッドは Zlib::Deflate.new, Zlib::ZStream#reset
を呼び出した直後にのみ有効です。詳細は zlib.h を参照して下さい。
@param string 辞書に用いる文字列を指定します。詳しくは zlib.h を参照してください。
@retur......します。
require 'zlib'
def case1(str)
dez = Zlib::Deflate.new
comp_str = dez.deflate(str)
comp_str << dez.finish
comp_str.size
end
def case2(str, dict)
dez = Zlib::Deflate.new
p dez.set_dictionary(dict)
comp_str = dez.deflate(str)
comp_str << dez.fin......omp_str.size
end
i = 10
dict = 'hoge_fuga_ugougo'
sset = [ dict, 'taeagbamike', 'ugotagma', 'fugebogya' ]
g = [ 0, 1, 1, 1, 0, 0, 0, 3, 3, 3, 0, 0, 1, 1, 0, 0, 0, 1, 2, 2, 0, 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0]
str = (1..i).collect{|m| t = rand(g.size); sset.at(g[t])}.join("")
printf "%... -
Thread
:: Queue # shift(non _ block = false) -> object (6131.0) -
キューからひとつ値を取り出します。キューが空の時、呼出元のスレッドは停止します。
...出元のスレッドは停止します。
@param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。
//emlist[例][ruby]{
require 'thread'
q = Queue.new
th1 = Thread.start do
while resource = q.pop
puts resource
end
end
[:resource1, :resour......ch { |r|
q.push(r)
}
th1.join
//}
//emlist[例: nonblock = true][ruby]{
require 'thread'
q = Queue.new
th1 = Thread.start do
while resource = q.pop
puts resource
end
end
[:resource1, :resource2, :resource3, nil].each { |r|
q.push(r)
}
begin
th1.join
q.pop(true)
rescue => e
p......e
end
# => resource1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
//}... -
TSort
# each _ strongly _ connected _ component _ from(node , id _ map={} , stack=[]) -> Enumerator (6125.0) -
node から到達可能な強連結成分についてのイテレータです。
...ん。
each_strongly_connected_component_from は
tsort_each_node を呼びません。
@param node ノードを指定します。
//emlist[例 到達可能なノードを表示する][ruby]{
require 'tsort'
class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node,......&block)
fetch(node).each(&block)
end
end
non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
non_sort.each_strongly_connected_component{|nodes|
p nodes
nodes.each {|node|
non_sort.each_strongly_connected_component_from(node){|ns|
printf("%s -> %s\n", node, ns.join(","))
}
}
}......#出力
#=> [4]
#=> 4 -> 4
#=> [2, 3]
#=> 2 -> 4
#=> 2 -> 2,3
#=> 3 -> 4
#=> 3 -> 3,2
#=> [1]
#=> 1 -> 4
#=> 1 -> 2,3
#=> 1 -> 1
//}
@see TSort.each_strongly_connected_component_from... -
TSort
# each _ strongly _ connected _ component _ from(node , id _ map={} , stack=[]) {|nodes| . . . } -> () (6125.0) -
node から到達可能な強連結成分についてのイテレータです。
...ん。
each_strongly_connected_component_from は
tsort_each_node を呼びません。
@param node ノードを指定します。
//emlist[例 到達可能なノードを表示する][ruby]{
require 'tsort'
class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node,......&block)
fetch(node).each(&block)
end
end
non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
non_sort.each_strongly_connected_component{|nodes|
p nodes
nodes.each {|node|
non_sort.each_strongly_connected_component_from(node){|ns|
printf("%s -> %s\n", node, ns.join(","))
}
}
}......#出力
#=> [4]
#=> 4 -> 4
#=> [2, 3]
#=> 2 -> 4
#=> 2 -> 2,3
#=> 3 -> 4
#=> 3 -> 3,2
#=> [1]
#=> 1 -> 4
#=> 1 -> 2,3
#=> 1 -> 1
//}
@see TSort.each_strongly_connected_component_from...