[squeak-dev] The Inbox: Collections-ct.955.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Aug 30 18:13:51 UTC 2021
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.955.mcz
==================== Summary ====================
Name: Collections-ct.955
Author: ct
Time: 30 August 2021, 8:13:48.573551 pm
UUID: f9e64da5-32bd-6a47-9155-f1a5bef9cbe1
Ancestors: Collections-dtl.954
Adds sort function that uses a boolean compare block such as [:a :b | a <= b].
Usage examples:
squotVersions sorted: [:a :b | historyWalker shouldVisit: a before: b] asCompareSortFunction.
#(true nil 42) sorted: #compareSafely: asCompareSortFunction.
Reuploaded, supersedes Collections-ct.947. Now also indicates equality correctly. The compareBlock is now also allowed to be a strict unequality. Thanks to Levente (ul) for the feedback!
=============== Diff against Collections-dtl.954 ===============
Item was added:
+ ----- Method: BlockClosure>>asCompareSortFunction (in category '*Collections-SortFunctions-converting') -----
+ asCompareSortFunction
+
+ ^ CompareBlockFunction usingBlock: self!
Item was changed:
SortFunction subclass: #CollatorBlockFunction
instanceVariableNames: 'collatorBlock'
classVariableNames: ''
poolDictionaries: ''
category: 'Collections-SortFunctions'!
+ !CollatorBlockFunction commentStamp: 'ct 6/10/2021 20:38' prior: 0!
- !CollatorBlockFunction commentStamp: 'nice 11/5/2017 22:57' prior: 0!
A CollatorBlockFunction is a special SortFunction using a dyadic block to collate objects.
Instance Variables
+ collatorBlock <Block> a dyadic block that must return a -1, 0, or 1.!
- collator <Block> a dyadic block that must return a -1, 0, or 1.!
Item was added:
+ SortFunction subclass: #CompareBlockFunction
+ instanceVariableNames: 'compareBlock'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Collections-SortFunctions'!
+
+ !CompareBlockFunction commentStamp: 'ct 6/10/2021 20:38' prior: 0!
+ A CompareBlockFunction is a special SortFunction using a dyadic block to compare objects. The default compare logic is the lower-equals function (#<=).
+
+ Instance Variables
+
+ compareBlock <Block> a dyadic block that must return true iff the first argument should not appear after the second , otherwise false.!
Item was added:
+ ----- Method: CompareBlockFunction class>>usingBlock: (in category 'instance creation') -----
+ usingBlock: twoArgsBlock
+
+ ^ self new compareBlock: twoArgsBlock!
Item was added:
+ ----- Method: CompareBlockFunction>>collate:with: (in category 'evaluating') -----
+ collate: anObject with: anotherObject
+
+ | greaterOrMaybeEquals lowerOrMaybeEquals |
+ lowerOrMaybeEquals := compareBlock value: anObject value: anotherObject.
+ greaterOrMaybeEquals := compareBlock value: anotherObject value: anObject.
+ ^ lowerOrMaybeEquals = greaterOrMaybeEquals
+ ifTrue: [0]
+ ifFalse: [lowerOrMaybeEquals
+ ifTrue: [-1]
+ ifFalse: [1]]!
Item was added:
+ ----- Method: CompareBlockFunction>>compareBlock (in category 'accessing') -----
+ compareBlock
+
+ ^ compareBlock!
Item was added:
+ ----- Method: CompareBlockFunction>>compareBlock: (in category 'accessing') -----
+ compareBlock: aBlock
+
+ compareBlock := aBlock.!
Item was added:
+ ----- Method: Symbol>>asCompareSortFunction (in category '*Collections-SortFunctions-converting') -----
+ asCompareSortFunction
+
+ ^ CompareBlockFunction usingBlock: self!
More information about the Squeak-dev
mailing list
|