* lib/resolv.rb (Resolv::DNS::Resource#hash): use XOR to accumulate
hash value. * lib/tsort.rb (TSort#each_strongly_connected_component): don't use block argument. (each_strongly_connected_component_from): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3939629ddf
commit
808e9289e6
|
@ -1,3 +1,12 @@
|
||||||
|
Tue Apr 22 06:06:22 2003 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* lib/resolv.rb (Resolv::DNS::Resource#hash): use XOR to accumulate
|
||||||
|
hash value.
|
||||||
|
|
||||||
|
* lib/tsort.rb (TSort#each_strongly_connected_component): don't use
|
||||||
|
block argument.
|
||||||
|
(each_strongly_connected_component_from): ditto.
|
||||||
|
|
||||||
Mon Apr 21 21:59:48 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Mon Apr 21 21:59:48 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* marshal.c: one more digit for decimal point. [ruby-talk:69808]
|
* marshal.c: one more digit for decimal point. [ruby-talk:69808]
|
||||||
|
|
|
@ -1272,7 +1272,7 @@ class Resolv
|
||||||
def hash
|
def hash
|
||||||
h = 0
|
h = 0
|
||||||
self.instance_variables.each {|name|
|
self.instance_variables.each {|name|
|
||||||
h += self.instance_eval("#{name}.hash")
|
h ^= self.instance_eval("#{name}.hash")
|
||||||
}
|
}
|
||||||
return h
|
return h
|
||||||
end
|
end
|
||||||
|
@ -1550,7 +1550,7 @@ class Resolv
|
||||||
|
|
||||||
def initialize(address)
|
def initialize(address)
|
||||||
unless address.kind_of?(String) && address.length == 4
|
unless address.kind_of?(String) && address.length == 4
|
||||||
raise ArgumentError.new('IPv4 address muse be 4 bytes')
|
raise ArgumentError.new('IPv4 address must be 4 bytes')
|
||||||
end
|
end
|
||||||
@address = address
|
@address = address
|
||||||
end
|
end
|
||||||
|
@ -1658,7 +1658,7 @@ class Resolv
|
||||||
|
|
||||||
def initialize(address)
|
def initialize(address)
|
||||||
unless address.kind_of?(String) && address.length == 16
|
unless address.kind_of?(String) && address.length == 16
|
||||||
raise ArgumentError.new('IPv6 address muse be 16 bytes')
|
raise ArgumentError.new('IPv6 address must be 16 bytes')
|
||||||
end
|
end
|
||||||
@address = address
|
@address = address
|
||||||
end
|
end
|
||||||
|
|
26
lib/tsort.rb
26
lib/tsort.rb
|
@ -199,18 +199,20 @@ module TSort
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_strongly_connected_component(&block)
|
def each_strongly_connected_component
|
||||||
id_map = {}
|
id_map = {}
|
||||||
stack = []
|
stack = []
|
||||||
tsort_each_node {|node|
|
tsort_each_node {|node|
|
||||||
unless id_map.include? node
|
unless id_map.include? node
|
||||||
each_strongly_connected_component_from(node, id_map, stack, &block)
|
each_strongly_connected_component_from(node, id_map, stack) {|c|
|
||||||
|
yield c
|
||||||
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_strongly_connected_component_from(node, id_map={}, stack=[], &block)
|
def each_strongly_connected_component_from(node, id_map={}, stack=[])
|
||||||
minimum_id = node_id = id_map[node] = id_map.size
|
minimum_id = node_id = id_map[node] = id_map.size
|
||||||
stack_length = stack.length
|
stack_length = stack.length
|
||||||
stack << node
|
stack << node
|
||||||
|
@ -221,7 +223,9 @@ module TSort
|
||||||
minimum_id = child_id if child_id && child_id < minimum_id
|
minimum_id = child_id if child_id && child_id < minimum_id
|
||||||
else
|
else
|
||||||
sub_minimum_id =
|
sub_minimum_id =
|
||||||
each_strongly_connected_component_from(child, id_map, stack, &block)
|
each_strongly_connected_component_from(child, id_map, stack) {|c|
|
||||||
|
yield c
|
||||||
|
}
|
||||||
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
|
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
@ -286,6 +290,20 @@ if __FILE__ == $0
|
||||||
assert_equal([[0], [1]],
|
assert_equal([[0], [1]],
|
||||||
a.strongly_connected_components.map {|nodes| nodes.sort})
|
a.strongly_connected_components.map {|nodes| nodes.sort})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def orphaned_proc(block_str)
|
||||||
|
eval "lambda {#{block_str}}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_orphaned_break
|
||||||
|
a = [[1], [2], []]
|
||||||
|
@n = 0
|
||||||
|
x = orphaned_proc %{|c| @n += 1; break :break_value}
|
||||||
|
assert_nothing_raised {
|
||||||
|
assert_equal(:break_value, a.each_strongly_connected_component(&x))
|
||||||
|
}
|
||||||
|
assert_equal(1, @n)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue