The Trunk: Collections-ul.807.mcz

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

The Trunk: Collections-ul.807.mcz

commits-2
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.807.mcz

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

Name: Collections-ul.807
Author: ul
Time: 22 October 2018, 9:27:33.883624 pm
UUID: c2efe147-56f8-43ff-a08b-f42390390418
Ancestors: Collections-eem.806

- introduced KeyedSet >> #put: which works like #add:, but replaces existing objects with the argument as Dictionary's #at:put: does
- unified the usage of primitiveStringHash by adding it to ByteSymbol and by using String's implementation as fallback, which works for ByteArrays too

=============== Diff against Collections-eem.806 ===============

Item was changed:
  ----- Method: ByteArray class>>hashBytes:startingWith: (in category 'byte based hash') -----
  hashBytes: aByteArray startingWith: speciesHash
  "Answer the hash of a byte-indexed collection, using speciesHash as the initial value.
  See SmallInteger>>hashMultiply.
 
  The primitive should be renamed at a suitable point in the future"
  <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
+
+ ^String stringHash: aByteArray initialHash: speciesHash!
- | byteArraySize hash |
- <var: 'aByteArray' type: #'unsigned char *'>
- <var: 'speciesHash' type: #int>
-
- byteArraySize := aByteArray size.
- hash := speciesHash bitAnd: 16rFFFFFFF.
- 1 to: byteArraySize do:
- [:pos |
- hash := hash + (aByteArray basicAt: pos).
- "Inlined hashMultiply, written this way for translation to C."
- hash := hash * 1664525 bitAnd: 16r0FFFFFFF].
- ^hash!

Item was changed:
  ----- Method: ByteString class>>stringHash:initialHash: (in category 'primitives') -----
  stringHash: aString initialHash: speciesHash
  "Answer the hash of a byte-indexed string, using speciesHash as the initial value.
  See SmallInteger>>hashMultiply."
  <primitive: 'primitiveStringHash' module: 'MiscPrimitivePlugin'>
+
+ ^super stringHash: aString initialHash: speciesHash!
- | hash |
- hash := speciesHash bitAnd: 16rFFFFFFF.
- 1 to: aString size do:
- [:pos |
- hash := (hash + (aString basicAt: pos)) hashMultiply].
- ^hash!

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

Item was added:
+ ----- Method: KeyedSet>>put: (in category 'accessing') -----
+ put: newObject
+ "Include newObject as one of the receiver's elements even if there is already an element with the same key. Answer the replaced SetElement object or nil if no element existed with newObject's key. This method's behavior is similar to Dictionary >> #at:put:'s, hence the name."
+
+ | index |
+ index := self scanFor: (keyBlock value: newObject).
+ (array at: index)
+ ifNil: [
+ self atNewIndex: index put: newObject asSetElement.
+ ^nil ]
+ ifNotNil: [ :oldObject |
+ array at: index put: newObject asSetElement.
+ ^oldObject ]!