The Trunk: Collections-jar.924.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-jar.924.mcz

commits-2
David T. Lewis uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-jar.924.mcz

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

Name: Collections-jar.924
Author: jar
Time: 7 February 2021, 9:42:07.649004 am
UUID: 073b26bc-8e5e-ba41-9aac-9d424bbe6848
Ancestors: Collections-dtl.923

Fixes SharedQueue >> nextOrNilSuchThat bug to pass the existing test

=============== Diff against Collections-dtl.923 ===============

Item was changed:
  ----- Method: SharedQueue>>nextOrNilSuchThat: (in category 'accessing') -----
  nextOrNilSuchThat: aBlock
  "Answer the next object that satisfies aBlock, skipping any intermediate objects.
  If no object has been sent, answer <nil> and leave me intact.
  NOTA BENE:  aBlock MUST NOT contain a non-local return (^)."
 
  ^accessProtect critical: [
  | value readPos |
  value := nil.
  readPos := readPosition.
  [ readPos < writePosition and: [ value isNil ] ] whileTrue: [
  value := contentsArray at: readPos.
  readPos := readPos + 1.
  (aBlock value: value)
  ifFalse: [ value := nil ]
  ifTrue: [
  readSynch waitIfLocked: [ ^nil ]. "We found the value, but someone else booked it."
+ readPos-1 to: readPosition+1 by: -1 do: [ :j | contentsArray at: j put: (contentsArray at: j-1) ].
+ contentsArray at: readPosition put: nil.
+ readPosition := readPosition+1 ] ].
- readPosition to: readPos - 1 do: [ :j | contentsArray at: j put: nil ].
- readPosition := readPos ] ].
  value ].
  "===
  q := SharedQueue new.
  1 to: 10 do: [ :i | q nextPut: i].
  c := OrderedCollection new.
  [
  v := q nextOrNilSuchThat: [ :e | e odd].
  v notNil
  ] whileTrue: [
  c add: {v. q size}
  ].
  {c. q} explore
  ==="!