The Trunk: Collections-eem.743.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-eem.743.mcz

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

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

Name: Collections-eem.743
Author: eem
Time: 30 March 2017, 6:02:18.123591 pm
UUID: c8c62336-051e-4025-82d1-7dc2bebe4b6e
Ancestors: Collections-ul.742

Replace mention of MethodContext with Context in class comments as appropriate.

=============== Diff against Collections-ul.742 ===============

Item was changed:
  Stream subclass: #Generator
  instanceVariableNames: 'block next continue home'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Collections-Streams'!
 
+ !Generator commentStamp: 'eem 3/30/2017 17:31' prior: 0!
- !Generator commentStamp: 'ar 2/10/2010 20:51' prior: 0!
  A Generator transforms callback interfaces into stream interfaces.
 
  When a producer algorithm provide results as callbacks (blocks) and a consumer algorithm expects streamable input, a Generator transforms one into the other, for example:
 
  | generator |
  generator := Generator on: [:g| Integer primesUpTo: 100 do:[:prime| g yield: prime]].
  [generator atEnd] whileFalse:[Transcript show: generator next].
 
  Instance Variables
+ block: <BlockClosure> The block associated with the generator.
+ continue: <Context> The continuation to return to.
+ home: <Context> The home (root) context of the activated block
+ next: <Object> The next object to return from the Generator.!
- block: <BlockClosure> The block associated with the generator.
- continue: <MethodContext> The continuation to return to.
- home: <MethodContext> The home (root) context of the activated block
- next: <Object> The next object to return from the Generator.
- !

Item was changed:
  Dictionary subclass: #PluggableDictionary
  instanceVariableNames: 'hashBlock equalBlock'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Collections-Unordered'!
 
+ !PluggableDictionary commentStamp: 'eem 3/30/2017 17:44' prior: 0!
- !PluggableDictionary commentStamp: '<historical>' prior: 0!
  Class PluggableDictionary allows the redefinition of hashing and equality by clients. This is in particular useful if the clients know about specific properties of the objects stored in the dictionary. See the class comment of PluggableSet for an example.
 
  Instance variables:
+ hashBlock <BlockClosure> A one argument block used for hashing the elements.
+ equalBlock <BlockClosure> A two argument block used for comparing the elements.
- hashBlock <BlockContext> A one argument block used for hashing the elements.
- equalBlock <BlockContext> A two argument block used for comparing the elements.
  !

Item was changed:
  Set subclass: #PluggableSet
  instanceVariableNames: 'hashBlock equalBlock'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Collections-Unordered'!
 
+ !PluggableSet commentStamp: 'eem 3/30/2017 17:59' prior: 0!
- !PluggableSet commentStamp: 'nice 3/25/2010 23:02' prior: 0!
  PluggableSets allow the redefinition of hashing and equality by clients. This is in particular useful if the clients know about specific properties of the objects stored in the set which in turn can heavily improve the performance of sets and dictionaries.
 
  Instance variables:
+ hashBlock <BlockClosure> A one argument block used for hashing the elements.
+ equalBlock <BlockClosure> A two argument block used for comparing the elements.
- hashBlock <BlockContext> A one argument block used for hashing the elements.
- equalBlock <BlockContext> A two argument block used for comparing the elements.
 
+ Example: Adding 1000000 integer points in the range (0@0) to: (100@100) to a set.
- Example: Adding 1000 integer points in the range (0@0) to: (100@100) to a set.
 
+ ( | n rnd set max points |
+ set := Set new: (n := 1000000).
- | rnd set max pt |
- set := Set new: 1000.
  rnd := Random new.
  max := 100.
+ points := (1 to: n) collect: [:ign| (rnd next @ rnd next * max) truncated].
+ Smalltalk garbageCollectMost. "to reduce variability in the run-to-run times"
+ [1 to: 1000000 do: [:i| set add: (points at: i)]]
+ timeToRun
+ )
- Time millisecondsToRun:[
- 1 to: 1000 do:[:i|
- pt := (rnd next * max) truncated @ (rnd next * max) truncated.
- set add: pt.
- ].
- ].
 
  The above is way slow since the default hashing function of points leads to an awful lot of collisions in the set. And now the same, with a somewhat different hash function:
 
+ ( | n rnd set max points |
+ set := PluggableSet new: (n := 1000000).
+ set hashBlock: [:item| (item x bitShift: 10) + item y].
- | rnd set max pt |
- set := PluggableSet new: 1000.
- set hashBlock:[:item| (item x bitShift: 16) + item y].
  rnd := Random new.
  max := 100.
+ points := (1 to: n) collect: [:ign| (rnd next @ rnd next * max) truncated].
+ Smalltalk garbageCollectMost. "to reduce variability in the run-to-run times"
+ [1 to: 1000000 do: [:i| set add: (points at: i)]]
+ timeToRun
+ )!
- Time millisecondsToRun:[
- 1 to: 1000 do:[:i|
- pt := (rnd next * max) truncated @ (rnd next * max) truncated.
- set add: pt.
- ].
- ].
- !

Item was changed:
  OrderedCollection subclass: #SortedCollection
  instanceVariableNames: 'sortBlock'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Collections-Sequenceable'!
 
+ !SortedCollection commentStamp: 'eem 3/30/2017 17:33' prior: 0!
+ I represent a collection of objects ordered by some property of the objects themselves. The ordering is specified in a two argument BlockClosure. The default sorting function is a <= comparison on elements.!
- !SortedCollection commentStamp: 'dtl 9/6/2009 16:02' prior: 0!
- I represent a collection of objects ordered by some property of the objects themselves. The ordering is specified in a BlockContext. The default sorting function is a <= comparison on elements.!