From: Joshua Ballanco Date: 2011-12-05T07:34:03+09:00 Subject: [ruby-core:41483] Re: [ruby-trunk - Feature #5478] import Set into core, add syntax --20cf303f69ae799dfd04b34bcc5e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, Dec 4, 2011 at 1:05 PM, Eero Saynatkari wro= te: > On 2011-12-04, at 16:15:00, Alexey Muranov wrote: > > > > But what is wrong with having one class instead of two, if internally > they behave mostly the same, and one literal notation instead of two? > Anyway, this was just an idea. > > Hash tables aren't Sets, nor the other way around. I'd like to avoid > messing up data structure definitions any more than they already are. > > The only compelling reason for bringing Set into core would be a literal > syntax =E2=80=93 and I agree, as a data structure it would be a useful ad= dition and > encourage its usage =E2=80=93 but I don't really have anything to contrib= ute to the > particular bikeshed of syntax thereof. > Actually, the bulk of Set's functionality is already built on top of Hash. Personally, since the ability to create Hashes from comma-delimited key,value lists has been removed in 1.9, I think reintroducing it to create Set literals is not the worst idea in the world. Additionally, implementing Set functionality directly on top of Hash would remove the unfortunate method call overhead that currently exists in the Set library (note that the implementation of Set#include? is just a call through to Hash#include?): >> Benchmark.bmbm do |x| ?> h =3D {} >> s =3D Set.new >> 10000.times { |i| h[i] =3D nil; s << i } >> x.report("Hash#include?") { 1000000.times { h.include? rand(20000) } } >> x.report("Set#include?") { 1000000.times { s.include? rand(20000) } } >> end Rehearsal ------------------------------------------------- Hash#include? 0.370000 0.000000 0.370000 ( 0.370516) Set#include? 0.440000 0.000000 0.440000 ( 0.436806) ---------------------------------------- total: 0.810000sec user system total real Hash#include? 0.370000 0.000000 0.370000 ( 0.361795) Set#include? 0.430000 0.000000 0.430000 ( 0.426560) --20cf303f69ae799dfd04b34bcc5e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Sun, Dec 4, 2011 at 1:05 PM, Eero Saynatkari = <ruby-ml@kit= tensoft.org> wrote:
On 2011-12-04, at 16:15:00, Alexey Muranov wrote:
>
> But what is wrong with having one class instead of two, if internally = they behave mostly the same, and one literal notation instead of two? Anywa= y, this was just an idea.

Hash tables aren't Sets, nor the other way around. I'd like t= o avoid messing up data structure definitions any more than they already ar= e.

The only compelling reason for bringing Set into core would be a literal sy= ntax =E2=80=93 and I agree, as a data structure it would be a useful additi= on and encourage its usage =E2=80=93 but I don't really have anything t= o contribute to the particular bikeshed of syntax thereof.

Actually, the bulk of Set's functional= ity is already built on top of Hash. Personally, since the ability to creat= e Hashes from comma-delimited key,value lists has been removed in 1.9, I th= ink reintroducing it to create Set literals is not the worst idea in the wo= rld.

Additionally, implementing Set functionality directly o= n top of Hash would remove the unfortunate method call overhead that curren= tly exists in the Set library (note that the implementation of Set#include?= is just a call through to Hash#include?):

>> Benchmark.bmbm do |x|
?> =C2= =A0 h =3D {}
>> =C2=A0 s =3D Set.new
>> =C2= =A0 10000.times { |i| h[i] =3D nil; s << i }
>> =C2= =A0 x.report("Hash#include?") { 1000000.times { h.include? rand(2= 0000) } }
>> =C2=A0 x.report("Set#include?") { 1000000.times { s= .include? rand(20000) } }
>> end
Rehearsal ------= -------------------------------------------
Hash#include? =C2=A0 = 0.370000 =C2=A0 0.000000 =C2=A0 0.370000 ( =C2=A00.370516)
Set#include? =C2=A0 =C2=A00.440000 =C2=A0 0.000000 =C2=A0 0.440000 ( = =C2=A00.436806)
---------------------------------------- total: 0= .810000sec

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 user =C2=A0 =C2=A0 system =C2=A0 =C2=A0 =C2= =A0total =C2=A0 =C2=A0 =C2=A0 =C2=A0real
Hash#include? =C2=A0 0.370000 =C2=A0 0.000000 =C2=A0 0.370000 ( =C2=A0= 0.361795)
Set#include? =C2=A0 =C2=A00.430000 =C2=A0 0.000000 =C2= =A0 0.430000 ( =C2=A00.426560)

--20cf303f69ae799dfd04b34bcc5e--