--- a/Queue.st Fri Oct 28 04:08:21 1994 +0100
+++ b/Queue.st Thu Nov 17 15:17:57 1994 +0100
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 1993 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -11,17 +11,17 @@
"
Collection subclass:#Queue
- instanceVariableNames:'contentsArray readPosition writePosition tally'
- classVariableNames:''
- poolDictionaries:''
- category:'Collections-Ordered'
+ instanceVariableNames:'contentsArray readPosition writePosition tally'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Collections-Ordered'
!
Queue comment:'
COPYRIGHT (c) 1993 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
-$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.5 1994-08-22 12:12:17 claus Exp $
+$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.6 1994-11-17 14:17:57 claus Exp $
'!
!Queue class methodsFor:'documentation'!
@@ -29,7 +29,7 @@
copyright
"
COPYRIGHT (c) 1993 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.5 1994-08-22 12:12:17 claus Exp $
+$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.6 1994-11-17 14:17:57 claus Exp $
"
!
@@ -107,14 +107,16 @@
"return the next value in the queue;
Return nil, if the queue is empty"
- |value|
+ |value pos "{ Class: SmallInteger }"|
(tally == 0) ifTrue:[^ nil].
- value := contentsArray at:readPosition.
- readPosition := readPosition + 1.
- readPosition > contentsArray size ifTrue:[
- readPosition := 1
- ].
+
+ pos := readPosition.
+
+ value := contentsArray at:pos.
+ pos := pos + 1.
+ pos > contentsArray size ifTrue:[pos := 1].
+ readPosition := pos.
tally := tally - 1.
^ value
!
@@ -122,15 +124,20 @@
nextPut:anObject
"enter anObject into the queue - if the queue is full, report an error"
- (tally == contentsArray size) ifTrue:[
- self error:'queue is full'.
- ^ self
+ |sz pos "{ Class: SmallInteger }" |
+
+ sz := contentsArray size.
+ pos := writePosition.
+
+ (tally == sz) ifTrue:[
+ self error:'queue is full'.
+ ^ self
].
- contentsArray at:writePosition put:anObject.
- writePosition := writePosition + 1.
- writePosition > contentsArray size ifTrue:[
- writePosition := 1
- ].
+
+ contentsArray at:pos put:anObject.
+ pos := pos + 1.
+ pos > sz ifTrue:[pos := 1].
+ writePosition := pos.
tally := tally + 1
!
@@ -150,11 +157,11 @@
pos := readPosition.
endPos := writePosition.
1 to:tally do:[:i |
- aBlock value:(contentsArray at:pos).
- pos := pos + 1.
- pos > contentsArray size ifTrue:[
- pos := 1
- ]
+ aBlock value:(contentsArray at:pos).
+ pos := pos + 1.
+ pos > contentsArray size ifTrue:[
+ pos := 1
+ ]
]
! !