Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Semantics of 1.9.2 Set

Reply
Thread Tools

Semantics of 1.9.2 Set

 
 
John
Guest
Posts: n/a
 
      03-01-2011
I'm looking at the doc for the 1.9.2 Set class, which says (http://
http://www.ruby-doc.org/stdlib/libdo...ses/Set.html):

Set implements a collection of unordered values with no duplicates.
This is a
hybrid of Array‘s intuitive inter-operation facilities and Hash‘s
fast lookup.

The equality of each couple of elements is determined according to
Object#eql?
and Object#hash, since Set uses Hash as storage.

Since the doc explicitly defines Hash as the underlying store, and
since Hash in 1.9.2 observes insertion order (http://ruby-doc.org/core/
classes/Hash.html) during enumeration, I wonder if the doc for Set
should be changed?
 
Reply With Quote
 
 
 
 
Colin Bartlett
Guest
Posts: n/a
 
      03-04-2011
On Tue, Mar 1, 2011 at 4:45 PM, John <(E-Mail Removed)> wrote:
> I'm looking at the doc for the 1.9.2 Set class, which says
> (http://www.ruby-doc.org/stdlib/libdo...ses/Set.html):
>
> =A0Set implements a collection of unordered values with no duplicates.
> This is a hybrid of Array=91s intuitive inter-operation facilities
> and Hash=91s fast lookup.
>
> The equality of each couple of elements is determined according to
> Object#eql?=A0and Object#hash, since Set uses Hash as storage.
>
> Since the doc explicitly defines Hash as the underlying store, and
> since Hash in 1.9.2 observes insertion order (http://ruby-doc.org/core/
> classes/Hash.html) during enumeration, I wonder if the doc for Set
> should be changed?


I was hoping someone who had a detailed knowledge of Set and Hash
would give you an answer. Since I don't qualify on the detailed
knowledge grounds, I'll try my knowledge of logic, and hope that fits.

Set implements a collection of unordered values with no duplicates,
which means that you shouldn't assume the elements will be in a
particular order (alphabetical, time of insertion into the set,etc) if
you iterate over the set using each: that's important.

But if the current implementation happens to use another class (Hash)
which does have an order (time of insertion), then that's not
important. Code *might* use the fact that using Set with its current
use of Hash means that the iteration order is time of first insertion
into the set (ignoring complications of inserting, then deleting, then
reinserting an element).

But given the actual documentation of Set, it would be unwise to do
this: a later implementation of Set might use something other than an
insertion order preserving Hash.

In short, I think the documentation for Set should remain as it is. Or
possibly say explicitly that whilst the current implementation of Set
uses Hash for storage, it should not be assumed that this will always
be the case.

 
Reply With Quote
 
 
 
 
Adam Prescott
Guest
Posts: n/a
 
      03-04-2011
[Note: parts of this message were removed to make it a legal post.]

On Fri, Mar 4, 2011 at 6:22 PM, Colin Bartlett <(E-Mail Removed)>wrote:

> On Tue, Mar 1, 2011 at 4:45 PM, John <(E-Mail Removed)> wrote:
> > I'm looking at the doc for the 1.9.2 Set class, which says
> > (http://www.ruby-doc.org/stdlib/libdo...ses/Set.html):
> >
> > Since the doc explicitly defines Hash as the underlying store, and
> > since Hash in 1.9.2 observes insertion order (http://ruby-doc.org/core/
> > classes/Hash.html) during enumeration, I wonder if the doc for Set
> > should be changed?

>
> But given the actual documentation of Set, it would be unwise to do
> this: a later implementation of Set might use something other than an
> insertion order preserving Hash.
>
> In short, I think the documentation for Set should remain as it is. Or
> possibly say explicitly that whilst the current implementation of Set
> uses Hash for storage, it should not be assumed that this will always
> be the case.
>
>

I would agree that the documentation should not mention any order, as that's
not what defines a Set, it's just a leftover from an implementation with
Hashes. I don't think it should be stressed that its current implementation
is a Hash, in the documentation, though. If it's included, it definitely
should be pointed out that the implementation with a Hash is not a normative
restriction.

I was hoping someone who had a detailed knowledge of Set and Hash
> would give you an answer. Since I don't qualify on the detailed
> knowledge grounds, I'll try my knowledge of logic, and hope that fits.



I think you responded quite well, for what it's worth.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Set and .equals() semantics Mark Space Java 17 05-09-2008 11:53 PM
it's all about semantics =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?= ASP .Net 2 07-14-2004 08:19 AM
Semantics extractor Luigi Donatello Asero HTML 5 02-14-2004 07:10 PM
std::vector<>::clear semantics Stefan Höhne C++ 10 10-17-2003 09:50 AM
destructor / semantics of delete this Alexander Stippler C++ 6 08-20-2003 03:27 PM



Advertisments