[FIX] SequenceableCollections as hash keys

John Sarkela john_sarkela at 4thEstate.com
Mon Nov 1 14:38:17 UTC 1999


Hello,

Whilst debugging some first and follow set closures it was discovered
that
SequenceableCollections redefine #= and do not redefine #hash.
(For newbies, it should be an invariant that at all times objects that
are
equivalent have identical hash values.) I addressed this problem with
the
following implementation of #hash along with a mildly optimized
implementation of #=.

BTW, a quick port of TGen will be following in the next few days.
Still tracking down some gotcha's, but it is creating LL parsers and
created its first LR parser last night.

Cheers,

John Sarkela
CTO The Fourth Estate, Inc.

-----------------------------------file in the
following-------------------------------------

'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 1 November
1999 at 6:19:23 am'!

!SequenceableCollection methodsFor: 'comparing' stamp: 'tfei 10/31/1999
10:49'!
hash
    "Answer an integer hash value for the receiver such that,
  -- the hash value of an unchanged object is constant over time, and
  -- two equal objects have equal hash values."

    ^self size! !

'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 1 November
1999 at 6:19:21 am'!

!SequenceableCollection methodsFor: 'comparing' stamp: 'tfei 10/31/1999
10:46'!
= otherCollection
 "Answer true if the receiver is equivalent to the <otherCollection>.
First test
for identity, then rule out different species and sizes of collections.
As a last
resort, examine each element of the receiver and the <otherCollection>."

    | index |
    self == otherCollection
        ifTrue: [^true].
    (self species == otherCollection species)
        ifFalse: [^false].
    index := self size.
    index ~= otherCollection size
        ifTrue: [^false].
    [index > 0]
        whileTrue:
            [(self at: index) = (otherCollection at: index)
                ifFalse: [^false].
            index := index - 1].
    ^true! !





More information about the Squeak-dev mailing list