The Trunk: Collections-eem.808.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-eem.808.mcz

commits-2
Eliot Miranda uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-eem.808.mcz

==================== Summary ====================

Name: Collections-eem.808
Author: eem
Time: 22 October 2018, 4:54:43.989805 pm
UUID: c6b15e95-b365-4ea0-8211-71ec7f55084b
Ancestors: Collections-ul.807

Faster ByteString/ByteArray hashing.  The VM will accept either 1 or 2 args for the primitiveStringHash primitive so it can be used on the instance size, avoiding a little overhead.

=============== Diff against Collections-ul.807 ===============

Item was added:
+ ----- Method: ByteArray>>bytesHashWithInitialHash: (in category 'private') -----
+ bytesHashWithInitialHash: speciesHash
+ "Answer the hash of a byte-indexed array, using speciesHash as the initial value.
+ See SmallInteger>>hashMultiply."
+ <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
+
+ ^String stringHash: self initialHash: speciesHash!

Item was changed:
  ----- Method: ByteArray>>hash (in category 'comparing') -----
  hash
  "#hash is implemented, because #= is implemented"
 
+ ^self bytesHashWithInitialHash: self species hash!
- ^self class
- hashBytes: self
- startingWith: self species hash!

Item was added:
+ ----- Method: ByteString>>stringHashWithInitialHash: (in category 'private') -----
+ stringHashWithInitialHash: speciesHash
+ "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
+ See SmallInteger>>hashMultiply."
+ <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
+
+ ^super stringHashWithInitialHash: speciesHash!

Item was added:
+ ----- Method: ByteSymbol>>stringHashWithInitialHash: (in category 'private') -----
+ stringHashWithInitialHash: speciesHash
+ "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
+ See SmallInteger>>hashMultiply."
+ <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
+
+ ^super stringHashWithInitialHash: speciesHash!

Item was changed:
  ----- Method: String>>hash (in category 'comparing') -----
  hash
  "#hash is implemented, because #= is implemented"
  "ar 4/10/2005: I had to change this to use ByteString hash as initial
  hash in order to avoid having to rehash everything and yet compute
  the same hash for ByteString and WideString.
  md 16/10/2006: use identityHash as initialHash, as behavior hash will
  use String hash (name) to have a better hash soon.
  eem 4/17/2017 it's not possible to use String hash (name) for the
  initial hash because that would be recursive."
+ ^self stringHashWithInitialHash: ByteString identityHash!
- ^self class stringHash: self initialHash: ByteString identityHash!

Item was added:
+ ----- Method: String>>stringHashWithInitialHash: (in category 'private') -----
+ stringHashWithInitialHash: speciesHash
+ "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
+ See SmallInteger>>hashMultiply."
+ | hash |
+ hash := speciesHash bitAnd: 16r0FFFFFFF.
+ 1 to: self size do:
+ [:pos |
+ hash := (hash + (self basicAt: pos)) hashMultiply].
+ ^hash!


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-eem.808.mcz

Levente Uzonyi
String already has a method for this use case with a similar name:
#hashWithInitialHash:.
Should we keep the old name and use it for ByteArrays too or are the more
specific names #bytesHashWithInitialHash: and
#stringHashWithInitialHash better?

Levente

On Mon, 22 Oct 2018, [hidden email] wrote:

> Eliot Miranda uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-eem.808.mcz
>
> ==================== Summary ====================
>
> Name: Collections-eem.808
> Author: eem
> Time: 22 October 2018, 4:54:43.989805 pm
> UUID: c6b15e95-b365-4ea0-8211-71ec7f55084b
> Ancestors: Collections-ul.807
>
> Faster ByteString/ByteArray hashing.  The VM will accept either 1 or 2 args for the primitiveStringHash primitive so it can be used on the instance size, avoiding a little overhead.
>
> =============== Diff against Collections-ul.807 ===============
>
> Item was added:
> + ----- Method: ByteArray>>bytesHashWithInitialHash: (in category 'private') -----
> + bytesHashWithInitialHash: speciesHash
> + "Answer the hash of a byte-indexed array, using speciesHash as the initial value.
> + See SmallInteger>>hashMultiply."
> + <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
> +
> + ^String stringHash: self initialHash: speciesHash!
>
> Item was changed:
>  ----- Method: ByteArray>>hash (in category 'comparing') -----
>  hash
>   "#hash is implemented, because #= is implemented"
>
> + ^self bytesHashWithInitialHash: self species hash!
> - ^self class
> - hashBytes: self
> - startingWith: self species hash!
>
> Item was added:
> + ----- Method: ByteString>>stringHashWithInitialHash: (in category 'private') -----
> + stringHashWithInitialHash: speciesHash
> + "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
> + See SmallInteger>>hashMultiply."
> + <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
> +
> + ^super stringHashWithInitialHash: speciesHash!
>
> Item was added:
> + ----- Method: ByteSymbol>>stringHashWithInitialHash: (in category 'private') -----
> + stringHashWithInitialHash: speciesHash
> + "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
> + See SmallInteger>>hashMultiply."
> + <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
> +
> + ^super stringHashWithInitialHash: speciesHash!
>
> Item was changed:
>  ----- Method: String>>hash (in category 'comparing') -----
>  hash
>   "#hash is implemented, because #= is implemented"
>   "ar 4/10/2005: I had to change this to use ByteString hash as initial
>   hash in order to avoid having to rehash everything and yet compute
>   the same hash for ByteString and WideString.
>   md 16/10/2006: use identityHash as initialHash, as behavior hash will
>   use String hash (name) to have a better hash soon.
>   eem 4/17/2017 it's not possible to use String hash (name) for the
>   initial hash because that would be recursive."
> + ^self stringHashWithInitialHash: ByteString identityHash!
> - ^self class stringHash: self initialHash: ByteString identityHash!
>
> Item was added:
> + ----- Method: String>>stringHashWithInitialHash: (in category 'private') -----
> + stringHashWithInitialHash: speciesHash
> + "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
> + See SmallInteger>>hashMultiply."
> + | hash |
> + hash := speciesHash bitAnd: 16r0FFFFFFF.
> + 1 to: self size do:
> + [:pos |
> + hash := (hash + (self basicAt: pos)) hashMultiply].
> + ^hash!

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-eem.808.mcz

Eliot Miranda-2


> On Oct 26, 2018, at 3:06 PM, Levente Uzonyi <[hidden email]> wrote:
>
> String already has a method for this use case with a similar name: #hashWithInitialHash:.
> Should we keep the old name and use it for ByteArrays too or are the more specific names #bytesHashWithInitialHash: and #stringHashWithInitialHash better?

I would go for hashWithInitialHash:.  Forgive me for missing that.

>
> Levente
>
>> On Mon, 22 Oct 2018, [hidden email] wrote:
>>
>> Eliot Miranda uploaded a new version of Collections to project The Trunk:
>> http://source.squeak.org/trunk/Collections-eem.808.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Collections-eem.808
>> Author: eem
>> Time: 22 October 2018, 4:54:43.989805 pm
>> UUID: c6b15e95-b365-4ea0-8211-71ec7f55084b
>> Ancestors: Collections-ul.807
>>
>> Faster ByteString/ByteArray hashing.  The VM will accept either 1 or 2 args for the primitiveStringHash primitive so it can be used on the instance size, avoiding a little overhead.
>>
>> =============== Diff against Collections-ul.807 ===============
>>
>> Item was added:
>> + ----- Method: ByteArray>>bytesHashWithInitialHash: (in category 'private') -----
>> + bytesHashWithInitialHash: speciesHash
>> +    "Answer the hash of a byte-indexed array, using speciesHash as the initial value.
>> +     See SmallInteger>>hashMultiply."
>> +    <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
>> + +    ^String stringHash: self initialHash: speciesHash!
>>
>> Item was changed:
>> ----- Method: ByteArray>>hash (in category 'comparing') -----
>> hash
>>    "#hash is implemented, because #= is implemented"
>> +    ^self bytesHashWithInitialHash: self species hash!
>> -    ^self class
>> -        hashBytes: self
>> -        startingWith: self species hash!
>>
>> Item was added:
>> + ----- Method: ByteString>>stringHashWithInitialHash: (in category 'private') -----
>> + stringHashWithInitialHash: speciesHash
>> +    "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
>> +     See SmallInteger>>hashMultiply."
>> +    <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
>> + +    ^super stringHashWithInitialHash: speciesHash!
>>
>> Item was added:
>> + ----- Method: ByteSymbol>>stringHashWithInitialHash: (in category 'private') -----
>> + stringHashWithInitialHash: speciesHash
>> +    "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
>> +     See SmallInteger>>hashMultiply."
>> +    <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
>> + +    ^super stringHashWithInitialHash: speciesHash!
>>
>> Item was changed:
>> ----- Method: String>>hash (in category 'comparing') -----
>> hash
>>    "#hash is implemented, because #= is implemented"
>>    "ar 4/10/2005: I had to change this to use ByteString hash as initial
>>    hash in order to avoid having to rehash everything and yet compute
>>    the same hash for ByteString and WideString.
>>    md 16/10/2006: use identityHash as initialHash, as behavior hash will
>>    use String hash (name) to have a better hash soon.
>>    eem 4/17/2017 it's not possible to use String hash (name) for the
>>    initial hash because that would be recursive."
>> +    ^self stringHashWithInitialHash: ByteString identityHash!
>> -    ^self class stringHash: self initialHash: ByteString identityHash!
>>
>> Item was added:
>> + ----- Method: String>>stringHashWithInitialHash: (in category 'private') -----
>> + stringHashWithInitialHash: speciesHash
>> +    "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
>> +     See SmallInteger>>hashMultiply."
>> +    | hash |
>> +    hash := speciesHash bitAnd: 16r0FFFFFFF.
>> +    1 to: self size do:
>> +        [:pos |
>> +        hash := (hash + (self basicAt: pos)) hashMultiply].
>> +    ^hash!
>