Semantics of 1.9.2 Set

Discussion in 'Ruby' started by John, Mar 1, 2011.

  1. John

    John Guest

    I'm looking at the doc for the 1.9.2 Set class, which says (http://
    www.ruby-doc.org/stdlib/libdoc/set/rdoc/classes/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?
     
    John, Mar 1, 2011
    #1
    1. Advertising

  2. On Tue, Mar 1, 2011 at 4:45 PM, John <> wrote:
    > I'm looking at the doc for the 1.9.2 Set class, which says
    > (http://www.ruby-doc.org/stdlib/libdoc/set/rdoc/classes/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.
     
    Colin Bartlett, Mar 4, 2011
    #2
    1. Advertising

  3. [Note: parts of this message were removed to make it a legal post.]

    On Fri, Mar 4, 2011 at 6:22 PM, Colin Bartlett <>wrote:

    > On Tue, Mar 1, 2011 at 4:45 PM, John <> wrote:
    > > I'm looking at the doc for the 1.9.2 Set class, which says
    > > (http://www.ruby-doc.org/stdlib/libdoc/set/rdoc/classes/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. :)
     
    Adam Prescott, Mar 4, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=

    it's all about semantics

    =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=, Jul 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    334
    =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=
    Jul 14, 2004
  2. Luigi Donatello Asero

    Semantics extractor

    Luigi Donatello Asero, Feb 14, 2004, in forum: HTML
    Replies:
    5
    Views:
    548
    Eric Bohlman
    Feb 14, 2004
  3. Alexander Stippler

    destructor / semantics of delete this

    Alexander Stippler, Aug 20, 2003, in forum: C++
    Replies:
    6
    Views:
    2,181
    Chris Theis
    Aug 20, 2003
  4. Stefan Höhne

    std::vector<>::clear semantics

    Stefan Höhne, Oct 16, 2003, in forum: C++
    Replies:
    10
    Views:
    2,937
    tom_usenet
    Oct 17, 2003
  5. Mark Space

    Re: Set and .equals() semantics

    Mark Space, May 8, 2008, in forum: Java
    Replies:
    17
    Views:
    611
    Mark Space
    May 10, 2008
Loading...

Share This Page