Queue.st
changeset 4035 c6509f2ef728
parent 3448 d51b708eb5d7
child 4036 677462d5333b
--- a/Queue.st	Mon Aug 15 12:52:27 2016 +0200
+++ b/Queue.st	Mon Aug 15 15:05:02 2016 +0200
@@ -11,6 +11,8 @@
 "
 "{ Package: 'stx:libbasic2' }"
 
+"{ NameSpace: Smalltalk }"
+
 Collection subclass:#Queue
 	instanceVariableNames:'contentsArray readPosition writePosition tally'
 	classVariableNames:''
@@ -36,7 +38,7 @@
 
 documentation
 "
-    Queues provide a simple implementation of a queue, 
+    Queues provide a simple implementation of a queue,
     where elements are added at one end and removed at the other.
 
     Access protocol is somewhat like a streams protocol, i.e. access
@@ -44,7 +46,7 @@
     The queue is created with a size argument, defining how many elements
     are to be stored. It will report an error if the queue ever becomes full
     and another element is to be added. Likewise, it will report an error
-    if its empty and an element is to be removed.
+    if it is empty and an element is to be removed.
 
     It is NOT safe when two processes access Queues simultanously,
     since accesses to the internals are not protected against process-switches.
@@ -54,15 +56,15 @@
     [Implementation note:]
         All of queue's functionality is also provided by the OrderedCollection (OC)
         class; OC could easily simulate a queue (using #addLast: / #removeFirst).
-        The reason for providing Queue is not any speed advantage 
-        (actually, OC seems to be even a tiny bit faster). 
+        The reason for providing Queue is not any speed advantage
+        (actually, OC seems to be even a tiny bit faster).
         The point is that an implementation of SharedQueue as a subclass of OC
         would require that many OC methods had to be blocked and/or redefined in
         such a subclass, to care for simultaneous access.
-        Since queue implements a much more lightweight protocol, 
+        Since queue implements a much more lightweight protocol,
         the sharedQueue implementation is much cleaner when based on a more
         lightweight Queue class.
-        
+
     [author:]
         Claus Gittinger
 "
@@ -75,7 +77,7 @@
     |q element  |
 
     q := Queue new:10.
-    1 to:5 do:[:i | 
+    1 to:5 do:[:i |
         Transcript showCR:('adding ' , i printString).
         q nextPut:i
     ].
@@ -95,7 +97,7 @@
     q := Queue new:100.
     tQueue := Time millisecondsToRun:[
         1000 timesRepeat:[
-            1 to:100 do:[:i | 
+            1 to:100 do:[:i |
                 q nextPut:i
             ].
             [q isEmpty] whileFalse:[
@@ -107,7 +109,7 @@
     oc := OrderedCollection new:100.
     tOC := Time millisecondsToRun:[
         1000 timesRepeat:[
-            1 to:100 do:[:i | 
+            1 to:100 do:[:i |
                 oc addLast:i
             ].
             [oc isEmpty] whileFalse:[
@@ -190,14 +192,14 @@
 !
 
 next
-    "return the next value in the queue; 
+    "return the next value in the queue;
      Return nil, if the queue is empty"
 
     ^ self nextOrNil
 !
 
 nextOrNil
-    "return the next value in the queue; 
+    "return the next value in the queue;
      Return nil, if the queue is empty"
 
     |value pos "{ Class: SmallInteger }"|
@@ -292,7 +294,7 @@
      countRemoved
      el sz|
 
-    
+
     (tally == 0) ifTrue:[
         ^ exceptionalValue value
     ].
@@ -316,7 +318,7 @@
             ] ifFalse:[
                 wPos := wPos + 1.
             ].
-        ].    
+        ].
         rPos == sz ifTrue:[
             rPos := 1.
         ] ifFalse:[
@@ -344,7 +346,7 @@
      q next.
      q nextPut:12.
      q next.
-     q removeIdentical:5.     
+     q removeIdentical:5.
      q
 
      |q|
@@ -360,7 +362,7 @@
      self assert:(q next == 7).
      self assert:(q next == 8).
      self assert:(q isEmpty).
-     q       
+     q
 
      |q|
 
@@ -393,7 +395,7 @@
 !
 
 removeLast
-    "return the last value in the queue; 
+    "return the last value in the queue;
      Return nil, if the queue is empty"
 
     |value pos "{ Class: SmallInteger }"|
@@ -466,7 +468,7 @@
 
 !Queue methodsFor:'queries'!
 
-capacity 
+capacity
     "return the number of elements the queue can hold"
 
     ^ contentsArray size
@@ -508,10 +510,10 @@
 !Queue class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.38 2014-11-26 08:50:35 cg Exp $'
+    ^ '$Header$'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.38 2014-11-26 08:50:35 cg Exp $'
+    ^ '$Header$'
 ! !