* lib/set.rb (Set#==): [ruby-dev:25206] (ported from ruby_1_8 branch)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
52a590f0cc
commit
66e5af96b2
@ -1,3 +1,7 @@
|
|||||||
|
Sat Jun 25 15:13:54 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
|
* lib/set.rb (Set#==): [ruby-dev:25206] (ported from ruby_1_8 branch)
|
||||||
|
|
||||||
Sat Jun 25 11:37:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
|
Sat Jun 25 11:37:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* ext/nkf/lib/kconv.rb: remove constants
|
* ext/nkf/lib/kconv.rb: remove constants
|
||||||
@ -114,7 +118,8 @@ Thu Jun 16 15:41:32 2005 NAKAMURA Usaku <usa@ruby-lang.org>
|
|||||||
|
|
||||||
Thu Jun 16 15:09:38 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
Thu Jun 16 15:09:38 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
* ext/tk/tcltklib.c (ip_rb_threadVwaitCommand): Tcl_Release was missing.
|
* ext/tk/tcltklib.c (ip_rb_threadVwaitCommand): Tcl_Release
|
||||||
|
was missing.
|
||||||
|
|
||||||
Thu Jun 16 13:34:48 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Thu Jun 16 13:34:48 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
@ -745,7 +750,7 @@ Mon May 16 22:42:52 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
|||||||
|
|
||||||
Mon May 16 03:29:01 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
Mon May 16 03:29:01 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
* win32/win32.{h,c}: define rb_{p,g,u}id_t.
|
* win32/win32.{h,c}: define rb_[pgu]id_t.
|
||||||
|
|
||||||
Mon May 16 00:21:02 2005 Tanaka Akira <akr@m17n.org>
|
Mon May 16 00:21:02 2005 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
24
lib/set.rb
24
lib/set.rb
@ -193,7 +193,7 @@ class Set
|
|||||||
# Adds the given object to the set and returns self. Use +merge+ to
|
# Adds the given object to the set and returns self. Use +merge+ to
|
||||||
# add several elements at once.
|
# add several elements at once.
|
||||||
def add(o)
|
def add(o)
|
||||||
@hash[o] = o
|
@hash[o] = true
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
alias << add
|
alias << add
|
||||||
@ -251,7 +251,7 @@ class Set
|
|||||||
# Merges the elements of the given enumerable object to the set and
|
# Merges the elements of the given enumerable object to the set and
|
||||||
# returns self.
|
# returns self.
|
||||||
def merge(enum)
|
def merge(enum)
|
||||||
if enum.class == self.class
|
if enum.is_a?(Set)
|
||||||
@hash.update(enum.instance_eval { @hash })
|
@hash.update(enum.instance_eval { @hash })
|
||||||
else
|
else
|
||||||
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
|
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
|
||||||
@ -291,7 +291,7 @@ class Set
|
|||||||
def &(enum)
|
def &(enum)
|
||||||
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
|
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
|
||||||
n = self.class.new
|
n = self.class.new
|
||||||
enum.each { |o| include?(o) and n.add(o) }
|
enum.each { |o| n.add(o) if include?(o) }
|
||||||
n
|
n
|
||||||
end
|
end
|
||||||
alias intersection & ##
|
alias intersection & ##
|
||||||
@ -313,7 +313,8 @@ class Set
|
|||||||
|
|
||||||
set.is_a?(Set) && size == set.size or return false
|
set.is_a?(Set) && size == set.size or return false
|
||||||
|
|
||||||
set.all? { |o| @hash.value?(o) }
|
hash = @hash.dup
|
||||||
|
set.all? { |o| hash.include?(o) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def hash # :nodoc:
|
def hash # :nodoc:
|
||||||
@ -321,7 +322,8 @@ class Set
|
|||||||
end
|
end
|
||||||
|
|
||||||
def eql?(o) # :nodoc:
|
def eql?(o) # :nodoc:
|
||||||
@hash.hash == o.hash
|
return false unless o.is_a?(Set)
|
||||||
|
@hash.eql?(o.instance_eval{@hash})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Classifies the set by the return value of the given block and
|
# Classifies the set by the return value of the given block and
|
||||||
@ -471,7 +473,7 @@ class SortedSet < Set
|
|||||||
|
|
||||||
def add(o)
|
def add(o)
|
||||||
@keys = nil
|
@keys = nil
|
||||||
@hash[o] = o
|
@hash[o] = true
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
alias << add
|
alias << add
|
||||||
@ -556,7 +558,7 @@ end
|
|||||||
# if @proc.arity == 2
|
# if @proc.arity == 2
|
||||||
# instance_eval %{
|
# instance_eval %{
|
||||||
# def add(o)
|
# def add(o)
|
||||||
# @hash[o] = o if @proc.call(self, o)
|
# @hash[o] = true if @proc.call(self, o)
|
||||||
# self
|
# self
|
||||||
# end
|
# end
|
||||||
# alias << add
|
# alias << add
|
||||||
@ -565,7 +567,7 @@ end
|
|||||||
# if include?(o) || !@proc.call(self, o)
|
# if include?(o) || !@proc.call(self, o)
|
||||||
# nil
|
# nil
|
||||||
# else
|
# else
|
||||||
# @hash[o] = o
|
# @hash[o] = true
|
||||||
# self
|
# self
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
@ -588,7 +590,9 @@ end
|
|||||||
# else
|
# else
|
||||||
# instance_eval %{
|
# instance_eval %{
|
||||||
# def add(o)
|
# def add(o)
|
||||||
# @hash[o] = o if @proc.call(o)
|
# if @proc.call(o)
|
||||||
|
# @hash[o] = true
|
||||||
|
# end
|
||||||
# self
|
# self
|
||||||
# end
|
# end
|
||||||
# alias << add
|
# alias << add
|
||||||
@ -597,7 +601,7 @@ end
|
|||||||
# if include?(o) || !@proc.call(o)
|
# if include?(o) || !@proc.call(o)
|
||||||
# nil
|
# nil
|
||||||
# else
|
# else
|
||||||
# @hash[o] = o
|
# @hash[o] = true
|
||||||
# self
|
# self
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user