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