Queue.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5431 bf9f5c42a067
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
0f047710f65c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
     1
"{ Encoding: utf8 }"
0f047710f65c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
     2
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
     3
"
78a5b7c73feb Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1993 by Claus Gittinger
47
2fc2796fbec8 *** empty log message ***
claus
parents: 39
diff changeset
     5
	      All Rights Reserved
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
     6
78a5b7c73feb Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
78a5b7c73feb Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
78a5b7c73feb Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
78a5b7c73feb Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
78a5b7c73feb Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
78a5b7c73feb Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
78a5b7c73feb Initial revision
claus
parents:
diff changeset
    13
"
903
2e0a56e8892b category changes
Claus Gittinger <cg@exept.de>
parents: 786
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
2e0a56e8892b category changes
Claus Gittinger <cg@exept.de>
parents: 786
diff changeset
    15
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
    16
"{ NameSpace: Smalltalk }"
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
    17
30
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    18
Collection subclass:#Queue
254
cccfa2590e6e documentation
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    19
	instanceVariableNames:'contentsArray readPosition writePosition tally'
cccfa2590e6e documentation
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    20
	classVariableNames:''
cccfa2590e6e documentation
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    21
	poolDictionaries:''
cccfa2590e6e documentation
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    22
	category:'Collections-Ordered'
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
    23
!
78a5b7c73feb Initial revision
claus
parents:
diff changeset
    24
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
    25
!Queue class methodsFor:'documentation'!
30
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    26
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    27
copyright
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    28
"
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    29
 COPYRIGHT (c) 1993 by Claus Gittinger
47
2fc2796fbec8 *** empty log message ***
claus
parents: 39
diff changeset
    30
	      All Rights Reserved
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
    31
30
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    32
 This software is furnished under a license and may be used
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    33
 only in accordance with the terms of that license and with the
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    35
 be provided or otherwise made available to, or used by, any
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    36
 other person.  No title to or ownership of the software is
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    37
 hereby transferred.
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    38
"
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    39
!
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    40
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    41
documentation
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    42
"
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    43
    Queues provide a simple implementation of a collection,
1245
99e070f7c351 comments
Claus Gittinger <cg@exept.de>
parents: 1121
diff changeset
    44
    where elements are added at one end and removed at the other.
3448
d51b708eb5d7 class: Queue
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
    45
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    46
    Access protocol is somewhat like a stream's protocol, 
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    47
    i.e. access is by #nextPut: and #next.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    48
74
claus
parents: 50
diff changeset
    49
    The queue is created with a size argument, defining how many elements
claus
parents: 50
diff changeset
    50
    are to be stored. It will report an error if the queue ever becomes full
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    51
    and another element is to be added. 
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    52
    Likewise, it will report an error if it is empty and an element is to be removed.
74
claus
parents: 50
diff changeset
    53
4151
32fdabb21a15 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4067
diff changeset
    54
    It is NOT safe when two processes access the same queue-instance simultaneously,
74
claus
parents: 50
diff changeset
    55
    since accesses to the internals are not protected against process-switches.
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    56
    See SharedQueue for a class which IS safe w.r.t. processes and which blocks
74
claus
parents: 50
diff changeset
    57
    on write when full or on read when empty.
254
cccfa2590e6e documentation
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    58
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    59
    [Implementation note:]
3448
d51b708eb5d7 class: Queue
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
    60
        All of queue's functionality is also provided by the OrderedCollection (OC)
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    61
        class; OC could easily simulate a queue (using #addLast: / #removeFirst).
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
    62
        The reason for providing Queue is not any speed advantage
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
    63
        (actually, OC seems to be even a tiny bit faster).
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    64
        The point is that an implementation of SharedQueue as a subclass of OC
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    65
        would require that many OC methods had to be blocked and/or redefined in
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    66
        such a subclass, to care for simultaneous access.
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
    67
        Since queue implements a much more lightweight protocol,
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
    68
        the sharedQueue implementation is much cleaner when based on this more
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    69
        lightweight Queue class.
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
    70
254
cccfa2590e6e documentation
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    71
    [author:]
cccfa2590e6e documentation
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    72
        Claus Gittinger
30
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
    73
"
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    74
!
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    75
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    76
examples
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    77
"
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    78
  adding at one end, removing at the other ...
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    79
                                                        [exBegin]
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    80
    |q element  |
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    81
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    82
    q := Queue new:10.
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
    83
    1 to:5 do:[:i |
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    84
        Transcript showCR:('adding ' , i printString).
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    85
        q nextPut:i
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    86
    ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    87
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    88
    [q notEmpty] whileTrue:[
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    89
        element := q next.
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    90
        Transcript showCR:('removed ' , element printString).
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    91
    ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    92
                                                        [exEnd]
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    93
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    94
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    95
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    96
  timing; Queue vs. OrderedCollection
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    97
                                                        [exBegin]
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    98
    |q oc tQueue tOC  |
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    99
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   100
    q := Queue new:100.
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   101
    tQueue := Time millisecondsToRun:[
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   102
        1000 timesRepeat:[
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   103
            1 to:100 do:[:i |
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   104
                q nextPut:i
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   105
            ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   106
            [q isEmpty] whileFalse:[
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   107
                q next
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   108
            ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   109
        ]
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   110
    ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   111
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   112
    oc := OrderedCollection new:100.
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   113
    tOC := Time millisecondsToRun:[
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   114
        1000 timesRepeat:[
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   115
            1 to:100 do:[:i |
587
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   116
                oc addLast:i
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   117
            ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   118
            [oc isEmpty] whileFalse:[
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   119
                oc removeFirst
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   120
            ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   121
        ]
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   122
    ].
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   123
    Transcript showCR:('queue time: ' , tQueue printString , ' ms').
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   124
    Transcript showCR:('oc time   : ' , tOC printString , ' ms').
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   125
                                                        [exEnd]
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   126
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   127
3edcd7c02966 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   128
"
30
f34b335ac2d7 *** empty log message ***
claus
parents: 14
diff changeset
   129
! !
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   130
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   131
!Queue class methodsFor:'instance creation'!
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   132
122
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   133
new
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   134
    "return a new queue with space for some elements"
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   135
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   136
    ^ self new:50
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   137
!
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   138
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   139
new:size
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   140
    "return a new queue with space for size elements"
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   141
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   142
    ^ super new init:size
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   143
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   144
    "
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   145
     |q|
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   146
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   147
     q := Queue new.
39
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   148
     (1 to:5) do:[:i | q nextPut:i].
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   149
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   150
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   151
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   152
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   153
     q nextPutAll:(6 to:10).
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   154
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   155
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   156
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   157
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   158
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   159
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   160
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   161
     Transcript show:(q next); space.
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   162
     Transcript show:(q next); space.
350
93d5932c76e6 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
   163
     Transcript showCR:(q next).
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   164
    "
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   165
! !
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   166
2361
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   167
!Queue class methodsFor:'defaults'!
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   168
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   169
defaultSize
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   170
    ^ 50
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   171
! !
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   172
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   173
!Queue methodsFor:'accessing'!
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   174
2163
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   175
at:index
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   176
    "return an element from the queue - indexing starts at 1 with the element
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   177
     which would next be fetched"
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   178
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   179
    (index between:1 and:tally) ifFalse:[ self subscriptBoundsError:index ].
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   180
    ^ contentsArray at:((readPosition+index-1-1) \\ contentsArray size)+1.
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   181
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   182
    "
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   183
     |q|
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   184
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   185
     q := Queue new:10.
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   186
     (1 to:5) do:[:i | q add:i].
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   187
     (6 to:100) do:[:i | q removeFirst. q add:i ].
2164
18a6388957f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2163
diff changeset
   188
     self assert:(q at:1) = 96.
18a6388957f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2163
diff changeset
   189
     self assert:(q at:2) = 97.
18a6388957f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2163
diff changeset
   190
     self assert:(q at:3) = 98.
18a6388957f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2163
diff changeset
   191
     self assert:(q at:4) = 99.
18a6388957f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2163
diff changeset
   192
     self assert:(q at:5) = 100.
18a6388957f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2163
diff changeset
   193
     self should:[ q at:6 ] raise:Error.
2163
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   194
    "
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   195
!
Claus Gittinger <cg@exept.de>
parents: 2148
diff changeset
   196
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   197
remove:anElement ifAbsent:exceptionalValue
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   198
    "remove and return a particular element from the queue;
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   199
     Return the value from exceptionalValue if the element is not in the queue"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   200
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   201
    |rPos "{ Class: SmallInteger }"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   202
     wPos "{ Class: SmallInteger }"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   203
     countRemoved
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   204
     el sz|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   205
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   206
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   207
    (tally == 0) ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   208
        ^ exceptionalValue value
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   209
    ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   210
    sz := contentsArray size.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   211
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   212
    rPos := wPos := readPosition.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   213
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   214
    countRemoved := 0.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   215
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   216
    1 to:tally do:[:index|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   217
        el := contentsArray at:rPos.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   218
        el = anElement ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   219
            countRemoved := countRemoved + 1.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   220
            contentsArray at:wPos put:nil.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   221
        ] ifFalse:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   222
            rPos ~~ wPos ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   223
                contentsArray at:wPos put:el.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   224
            ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   225
            wPos == sz ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   226
                wPos := 1.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   227
            ] ifFalse:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   228
                wPos := wPos + 1.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   229
            ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   230
        ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   231
        rPos == sz ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   232
            rPos := 1.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   233
        ] ifFalse:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   234
            rPos := rPos + 1.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   235
        ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   236
    ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   237
    countRemoved == 0 ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   238
        ^ exceptionalValue value
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   239
    ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   240
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   241
    tally = countRemoved ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   242
        wPos := readPosition.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   243
    ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   244
    writePosition := wPos.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   245
    tally := tally - countRemoved.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   246
    ^ el
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   247
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   248
    "
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   249
     |q|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   250
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   251
     q := Queue new:10.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   252
     q nextPut:1; nextPut:2; nextPutAll:(3 to:10).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   253
     q next.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   254
     q nextPut:11.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   255
     q next.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   256
     q nextPut:12.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   257
     q next.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   258
     q remove:5.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   259
     q
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   260
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   261
     |q|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   262
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   263
     q := Queue new:10.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   264
     q nextPut:1; nextPut:2; nextPutAll:(3 to:8).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   265
     self assert:(q next == 1).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   266
     self assert:(q next == 2).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   267
     q removeIdentical:5.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   268
     self assert:(q next == 3).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   269
     self assert:(q next == 4).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   270
     self assert:(q next == 6).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   271
     self assert:(q next == 7).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   272
     self assert:(q next == 8).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   273
     self assert:(q isEmpty).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   274
     q
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   275
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   276
     |q|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   277
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   278
     q := Queue new:10.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   279
     q nextPut:1; nextPut:2.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   280
     self assert:(q next == 1).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   281
     q remove:2.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   282
     self assert:(q isEmpty).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   283
     q nextPut:3.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   284
     self assert:(q isEmpty not).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   285
     self assert:(q next == 3).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   286
     self assert:(q isEmpty).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   287
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   288
     |q|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   289
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   290
     q := Queue new:10.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   291
     q nextPut:1; nextPut:2; nextPut:3.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   292
     self assert:(q next == 1).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   293
     q remove:3.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   294
     self assert:(q isEmpty not).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   295
     q nextPut:4.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   296
     q removeI:4.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   297
     q nextPut:5.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   298
     self assert:(q isEmpty not).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   299
     self assert:(q next == 2).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   300
     self assert:(q next == 5).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   301
     self assert:(q isEmpty).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   302
    "
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   303
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   304
    "Created: / 22-02-2017 / 14:49:26 / stefan"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   305
!
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   306
647
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   307
removeAll
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 686
diff changeset
   308
    "remove all elements in the queue; return the receiver"
647
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   309
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   310
    tally := 0.
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   311
    readPosition := writePosition := 1.
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   312
    contentsArray atAllPut:nil          "/ to help the garbage collector
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   313
!
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   314
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   315
removeIdentical:anElement ifAbsent:exceptionalValue
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   316
    "remove and return a particular element from the queue;
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   317
     Return the value from exceptionalValue if the element is not in the queue"
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   318
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   319
    |rPos "{ Class: SmallInteger }"
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   320
     wPos "{ Class: SmallInteger }"
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   321
     countRemoved
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   322
     el sz|
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   323
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   324
1497
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   325
    (tally == 0) ifTrue:[
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   326
        ^ exceptionalValue value
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   327
    ].
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   328
    sz := contentsArray size.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   329
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   330
    rPos := wPos := readPosition.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   331
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   332
    countRemoved := 0.
1497
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   333
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   334
    1 to:tally do:[:index|
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   335
        el := contentsArray at:rPos.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   336
        el == anElement ifTrue:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   337
            countRemoved := countRemoved + 1.
1497
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   338
            contentsArray at:wPos put:nil.
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   339
        ] ifFalse:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   340
            rPos ~~ wPos ifTrue:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   341
                contentsArray at:wPos put:el.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   342
            ].
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   343
            wPos == sz ifTrue:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   344
                wPos := 1.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   345
            ] ifFalse:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   346
                wPos := wPos + 1.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   347
            ].
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   348
        ].
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   349
        rPos == sz ifTrue:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   350
            rPos := 1.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   351
        ] ifFalse:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   352
            rPos := rPos + 1.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   353
        ].
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   354
    ].
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   355
    countRemoved == 0 ifTrue:[
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   356
        ^ exceptionalValue value
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   357
    ].
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   358
1497
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   359
    tally = countRemoved ifTrue:[
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   360
        wPos := readPosition.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   361
    ].
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   362
    writePosition := wPos.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   363
    tally := tally - countRemoved.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   364
    ^ anElement
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   365
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   366
    "
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   367
     |q|
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   368
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   369
     q := Queue new:10.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   370
     q nextPut:1; nextPut:2; nextPutAll:(3 to:10).
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   371
     q next.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   372
     q nextPut:11.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   373
     q next.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   374
     q nextPut:12.
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   375
     q next.
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   376
     q removeIdentical:5.
1497
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   377
     q
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   378
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   379
     |q|
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   380
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   381
     q := Queue new:10.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   382
     q nextPut:1; nextPut:2; nextPutAll:(3 to:8).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   383
     self assert:(q next == 1).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   384
     self assert:(q next == 2).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   385
     q removeIdentical:5.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   386
     self assert:(q next == 3).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   387
     self assert:(q next == 4).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   388
     self assert:(q next == 6).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   389
     self assert:(q next == 7).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   390
     self assert:(q next == 8).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   391
     self assert:(q isEmpty).
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   392
     q
1497
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   393
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   394
     |q|
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   395
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   396
     q := Queue new:10.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   397
     q nextPut:1; nextPut:2.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   398
     self assert:(q next == 1).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   399
     q removeIdentical:2.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   400
     self assert:(q isEmpty).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   401
     q nextPut:3.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   402
     self assert:(q isEmpty not).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   403
     self assert:(q next == 3).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   404
     self assert:(q isEmpty).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   405
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   406
     |q|
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   407
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   408
     q := Queue new:10.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   409
     q nextPut:1; nextPut:2; nextPut:3.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   410
     self assert:(q next == 1).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   411
     q removeIdentical:3.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   412
     self assert:(q isEmpty not).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   413
     q nextPut:4.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   414
     q removeIdentical:4.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   415
     q nextPut:5.
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   416
     self assert:(q isEmpty not).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   417
     self assert:(q next == 2).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   418
     self assert:(q next == 5).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   419
     self assert:(q isEmpty).
5db4d4288c2c fix removeIdentical: ifAbsent:
penk
parents: 1494
diff changeset
   420
1494
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   421
    "
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   422
!
8f617564556b +removeIdentical
penk
parents: 1245
diff changeset
   423
396
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   424
removeLast
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   425
    "remove and return the last value in the queue;
396
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   426
     Return nil, if the queue is empty"
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   427
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   428
    |value pos "{ Class: SmallInteger }"|
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   429
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   430
    (tally == 0) ifTrue:[^ nil].
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   431
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   432
    pos := writePosition.
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   433
    pos == 1 ifTrue:[
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   434
        pos := contentsArray size
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   435
    ] ifFalse:[
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   436
        pos := pos - 1.
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   437
    ].
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   438
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   439
    value := contentsArray at:pos.
647
f937d30a8afc remove all elements in the queue:
ca
parents: 587
diff changeset
   440
    contentsArray at:pos put:nil.       "/ to help the garbage collector
396
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   441
    writePosition := pos.
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   442
    tally := tally - 1.
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   443
    ^ value
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   444
88bd6136ee67 added #removeLast
Claus Gittinger <cg@exept.de>
parents: 350
diff changeset
   445
    "Created: 22.6.1996 / 18:49:41 / cg"
39
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   446
! !
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   447
903
2e0a56e8892b category changes
Claus Gittinger <cg@exept.de>
parents: 786
diff changeset
   448
!Queue methodsFor:'accessing-protocol compatibility'!
686
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   449
1918
38fa135c92ef Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1497
diff changeset
   450
add:someObject
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   451
    "same as #nextPut: - for protocol compatibility with other collections"
686
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   452
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   453
    self nextPut:someObject.
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   454
    ^ someObject
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   455
!
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   456
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   457
addFirst:someObject
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   458
    "same as #nextPutFirst: - for protocol compatibility with other collections"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   459
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   460
    self nextPutFirst:someObject.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   461
    ^ someObject
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   462
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   463
    "Created: / 22-02-2017 / 15:12:58 / stefan"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   464
!
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   465
686
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   466
removeFirst
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   467
    "same as #next - for protocol compatibility with other collections"
686
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   468
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   469
    ^ self next
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   470
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   471
    "Created: / 27.8.1998 / 11:15:48 / cg"
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   472
! !
d2daab8e8c8a added #addLast: and #removeFirst for protocoll compatibility
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   473
4067
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   474
!Queue methodsFor:'accessing-reading'!
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   475
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   476
next
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   477
    "return the next value in the queue;
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   478
     Return nil, if the queue is empty.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   479
     WARNING: this is an old behavior, which should be changed
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   480
     to raise an error if empty.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   481
     It is left in here until all queue-users have been changed to
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   482
     call nextOrNil instead, to avoid breaking existing applications."
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   483
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   484
    ^ self nextOrNil
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   485
!
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   486
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   487
nextOrNil
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   488
    "return the next value in the queue;
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   489
     Return nil, if the queue is empty"
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   490
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   491
    |value pos "{ Class: SmallInteger }"|
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   492
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   493
    (tally == 0) ifTrue:[^ nil].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   494
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   495
    pos := readPosition.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   496
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   497
    value := contentsArray at:pos.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   498
    contentsArray at:pos put:nil.       "/ to help the garbage collector
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   499
    pos := pos + 1.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   500
    pos > contentsArray size ifTrue:[pos := 1].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   501
    readPosition := pos.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   502
    tally := tally - 1.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   503
    ^ value
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   504
!
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   505
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   506
peek
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   507
    "return the next value in the queue without removing it.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   508
     If the queue is empty, return nil."
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   509
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   510
    (tally == 0) ifTrue:[^ nil].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   511
    ^ contentsArray at:readPosition.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   512
!
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   513
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   514
peekOrNil
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   515
    "return the next value in the queue without removing it.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   516
     If the queue is empty, return nil."
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   517
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   518
    (tally == 0) ifTrue:[^ nil].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   519
    ^ contentsArray at:readPosition.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   520
! !
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   521
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   522
!Queue methodsFor:'accessing-writing'!
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   523
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   524
nextPut:anObject
5187
cba4d5fc4f6d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5170
diff changeset
   525
    "enter anObject into the queue - if the queue is full, report an error.
cba4d5fc4f6d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5170
diff changeset
   526
     Answer anObject"
4067
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   527
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   528
    |sz pos "{ Class: SmallInteger }" |
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   529
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   530
    sz := contentsArray size.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   531
    pos := writePosition.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   532
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   533
    (tally == sz) ifTrue:[
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   534
        self error:'queue is full' mayProceed:true.
5170
125d0cc824ff #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 5155
diff changeset
   535
        ^ anObject
4067
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   536
    ].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   537
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   538
    contentsArray at:pos put:anObject.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   539
    pos := pos + 1.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   540
    pos > sz ifTrue:[pos := 1].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   541
    writePosition := pos.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   542
    tally := tally + 1.
5170
125d0cc824ff #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 5155
diff changeset
   543
    ^ anObject
4347
71185f66cd54 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 4345
diff changeset
   544
71185f66cd54 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 4345
diff changeset
   545
    "Modified: / 22-02-2017 / 16:33:22 / stefan"
4067
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   546
!
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   547
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   548
nextPutAll:aCollection
5155
2f28067db22c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
   549
    "enter all elements from aCollection into the queue.
2f28067db22c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
   550
     Answer the receiver"
4067
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   551
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   552
    aCollection do:[:element | self nextPut:element].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   553
    ^ self
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   554
!
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   555
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   556
nextPutFirst:anObject
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   557
    |sz pos "{ Class: SmallInteger }" |
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   558
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   559
    tally == 0 ifTrue:[
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   560
        self nextPut:anObject.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   561
        ^ self
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   562
    ].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   563
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   564
    sz := contentsArray size.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   565
    (tally == sz) ifTrue:[
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   566
        self error:'queue is full' mayProceed:true.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   567
        ^ self
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   568
    ].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   569
    pos := readPosition - 1.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   570
    pos < 1 ifTrue:[pos := sz].
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   571
    contentsArray at:pos put:anObject.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   572
    readPosition := pos.
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   573
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   574
    tally := tally + 1
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   575
! !
b462a3ff3a61 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4064
diff changeset
   576
50
983d862738c1 *** empty log message ***
claus
parents: 47
diff changeset
   577
!Queue methodsFor:'enumerating'!
39
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   578
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   579
do:aBlock
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   580
    "evaluate the argument, aBlock for each element in the queue"
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   581
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   582
    |n   "{ Class: SmallInteger }"
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   583
     pos "{ Class: SmallInteger }"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   584
     sz|
39
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   585
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   586
    pos := readPosition.
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   587
    sz := contentsArray size.
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   588
    n := tally.
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   589
    n timesRepeat:[
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   590
        aBlock value:(contentsArray at:pos).
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   591
        pos := pos + 1.
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   592
        pos > sz ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   593
            pos := 1.
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   594
        ]
39
47fc4acc24db added do:, nextPutAll:
claus
parents: 33
diff changeset
   595
    ]
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   596
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   597
    "Modified: / 18-10-1997 / 16:24:01 / cg"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   598
    "Modified (format): / 22-02-2017 / 14:59:38 / stefan"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   599
!
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   600
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   601
reverseDo:aBlock
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   602
    "evaluate the argument, aBlock for each element in the queue"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   603
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   604
    |n   "{ Class: SmallInteger }"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   605
     pos "{ Class: SmallInteger }"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   606
     sz|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   607
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   608
    pos := writePosition.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   609
    sz := contentsArray size.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   610
    n := tally.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   611
    n timesRepeat:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   612
        pos := pos - 1.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   613
        pos <= 0 ifTrue:[
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   614
            pos := sz.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   615
        ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   616
        aBlock value:(contentsArray at:pos).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   617
    ].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   618
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   619
    "
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   620
     |q coll|
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   621
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   622
     coll := OrderedCollection new.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   623
     q := Queue new:10.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   624
     q nextPut:1; nextPut:2; nextPutAll:(3 to:8).
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   625
     q removeFirst; removeLast.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   626
     q reverseDo:[:el| coll add:el].
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   627
     coll.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   628
    "
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   629
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   630
    "Created: / 22-02-2017 / 15:03:02 / stefan"
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   631
! !
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   632
122
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   633
!Queue methodsFor:'initialization'!
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   634
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   635
capacity:newSize
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   636
    "change the capacity of the queue. 
4976
0f047710f65c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   637
     That is the number of slots it can hold 
0f047710f65c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   638
     before the writer gets an exception (here)
0f047710f65c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   639
     or is suspended (in SharedQueue)."
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   640
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   641
    |newContentsArray n1 n2|
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   642
    
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   643
    newSize < tally ifTrue:[
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   644
        "/ cannot make me smaller, if I hold at least this number of elements.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   645
        self error:'queue cannot be resized to this size while holding more elements' mayProceed:true.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   646
        "/ if proceeded
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   647
        ^ self
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   648
    ].
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   649
    newContentsArray := Array new:newSize.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   650
    tally ~~ 0 ifTrue:[
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   651
        n1 := contentsArray size - readPosition + 1.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   652
        n1 > tally ifTrue:[
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   653
            newContentsArray replaceFrom:1 to:tally with:contentsArray startingAt:readPosition.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   654
        ] ifFalse:[
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   655
            newContentsArray replaceFrom:1 to:n1 with:contentsArray startingAt:readPosition.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   656
            n2 := writePosition - 1.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   657
            newContentsArray replaceFrom:n1+1 to:tally with:contentsArray startingAt:1.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   658
        ].    
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   659
    ].    
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   660
    contentsArray := newContentsArray.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   661
    readPosition := 1.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   662
    writePosition := tally+1.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   663
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   664
    "
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   665
     |q|
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   666
     1 to:10 do:[:fill |
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   667
         1 to:10 do:[:read |
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   668
             Transcript show:'fill: '; show:fill; show:' read: '; showCR:read.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   669
             q := Queue new:10.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   670
             fill timesRepeat:[ q nextPut: #foo ].
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   671
             read timesRepeat:[ q next ].
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   672
             q capacity:12.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   673
             self assert:(q size == (fill-read)).
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   674
             self assert:((Array streamContents:[:s | q do:[:e |s nextPut:e]]) = (Array new:(fill-read) withAll:#foo)).
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   675
        ].    
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   676
     ].    
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   677
    "
4976
0f047710f65c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   678
0f047710f65c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   679
    "Modified (comment): / 04-06-2019 / 12:37:16 / Claus Gittinger"
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   680
!
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   681
122
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   682
init:size
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   683
    "initialize the receiver for size entries"
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   684
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   685
    contentsArray := Array new:size.
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   686
    readPosition := writePosition := 1.
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   687
    tally := 0.
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   688
! !
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   689
4345
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   690
!Queue methodsFor:'not implemented'!
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   691
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   692
findFirst:anObject ifNone:aBlock
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   693
    ^ self shouldNotImplement.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   694
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   695
    "Created: / 22-02-2017 / 15:14:04 / stefan"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   696
!
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   697
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   698
findLast:anObject ifNone:aBlock
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   699
    ^ self shouldNotImplement.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   700
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   701
    "Created: / 22-02-2017 / 15:14:11 / stefan"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   702
!
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   703
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   704
grow:newSize
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   705
    ^ self shouldNotImplement.
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   706
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   707
    "Created: / 22-02-2017 / 15:14:58 / stefan"
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   708
! !
0000c66ef9f0 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 4151
diff changeset
   709
5
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   710
!Queue methodsFor:'queries'!
78a5b7c73feb Initial revision
claus
parents:
diff changeset
   711
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   712
capacity
4064
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   713
    "return the number of elements the queue can hold.
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   714
     Trying to add more will:
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   715
        - raise an error in queue
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   716
        - block the writer in sharedQueue
24ce8feaa923 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   717
        - lead to an automatic resize in UnlimitedSharedQueue"
122
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   718
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   719
    ^ contentsArray size
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   720
!
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   721
4806
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   722
isEmpty
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   723
    "return true, if there are no elements in the queue"
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   724
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   725
    ^ tally == 0
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   726
!
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   727
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   728
isFull
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   729
    "return true, if the queue is full i.e. if writing is not
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   730
     possible"
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   731
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   732
    ^ tally == contentsArray size
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   733
!
c4cde561294c #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4347
diff changeset
   734
5431
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   735
notEmpty
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   736
    "return true, if there are elements in the queue"
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   737
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   738
    ^ tally ~~ 0
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   739
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   740
    "Created: / 23-01-2020 / 14:18:33 / stefan"
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   741
!
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   742
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   743
notEmptyOrNil
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   744
    "return true, if there are elements in the queue"
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   745
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   746
    ^ tally ~~ 0
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   747
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   748
    "Created: / 23-01-2020 / 14:18:47 / stefan"
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   749
!
bf9f5c42a067 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5187
diff changeset
   750
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   751
size
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   752
    "return the number of elements in the queue"
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   753
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   754
    ^ tally
2148
5fe0c7beef0c Define #species, so that #collect: and #select return OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 1918
diff changeset
   755
!
5fe0c7beef0c Define #species, so that #collect: and #select return OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 1918
diff changeset
   756
5fe0c7beef0c Define #species, so that #collect: and #select return OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 1918
diff changeset
   757
species
5fe0c7beef0c Define #species, so that #collect: and #select return OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 1918
diff changeset
   758
    "return the type of collection to be returned by collect, select etc."
5fe0c7beef0c Define #species, so that #collect: and #select return OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 1918
diff changeset
   759
5fe0c7beef0c Define #species, so that #collect: and #select return OrderedCollection
Stefan Vogel <sv@exept.de>
parents: 1918
diff changeset
   760
    ^ OrderedCollection
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   761
! !
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   762
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   763
!Queue methodsFor:'testing'!
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 903
diff changeset
   764
3021
1c303429ca85 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   765
isFixedSize
1c303429ca85 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   766
    "return true if the receiver cannot grow"
1c303429ca85 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   767
1c303429ca85 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   768
    ^ false
122
c379960395f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   769
! !
81
claus
parents: 75
diff changeset
   770
582
837907b61b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   771
!Queue class methodsFor:'documentation'!
131
19e548711b65 version at the end
Claus Gittinger <cg@exept.de>
parents: 122
diff changeset
   772
19e548711b65 version at the end
Claus Gittinger <cg@exept.de>
parents: 122
diff changeset
   773
version
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   774
    ^ '$Header$'
2361
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   775
!
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   776
52dcd370623f changed: #defaultSize
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   777
version_CVS
4035
c6509f2ef728 #DOCUMENTATION by mawalch
mawalch
parents: 3448
diff changeset
   778
    ^ '$Header$'
131
19e548711b65 version at the end
Claus Gittinger <cg@exept.de>
parents: 122
diff changeset
   779
! !
3021
1c303429ca85 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2361
diff changeset
   780