Bag.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 18:29:43 +0100
changeset 633 46e996b3c18f
parent 609 12be97f6d5a7
child 1057 75be0a10cc29
permissions -rw-r--r--
version at the end
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1991 by Claus Gittinger
345
claus
parents: 154
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Collection subclass:#Bag
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    14
	 instanceVariableNames:'contents'
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    15
	 classVariableNames:''
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    16
	 poolDictionaries:''
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    17
	 category:'Collections-Unordered'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
    20
!Bag class methodsFor:'documentation'!
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    24
 COPYRIGHT (c) 1991 by Claus Gittinger
345
claus
parents: 154
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    35
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
    36
documentation
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
    37
"
88
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    38
    Bag implements collections whose elements are unordered and have no
154
d4236ec280a6 *** empty log message ***
claus
parents: 92
diff changeset
    39
    external key. Elements may occur more than once in a bag. There is no defined
d4236ec280a6 *** empty log message ***
claus
parents: 92
diff changeset
    40
    order within a bag. 
345
claus
parents: 154
diff changeset
    41
    The default implementation uses a dictionary to store each objects occurence 
claus
parents: 154
diff changeset
    42
    count, using the object itself as key (i.e. using = and hash for inclusion 
claus
parents: 154
diff changeset
    43
    tests).
399
claus
parents: 384
diff changeset
    44
345
claus
parents: 154
diff changeset
    45
    There is also an instance creation variant (#identityNew:) creating a
claus
parents: 154
diff changeset
    46
    bag which compares using #== and hashes using #identityHash.
399
claus
parents: 384
diff changeset
    47
    (I'd say that an IdentityBag was a better thing to implement ... 
claus
parents: 384
diff changeset
    48
     ... but for compatibility ... we do it here as well)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    49
88
81dacba7a63a *** empty log message ***
claus
parents: 54
diff changeset
    50
    Instance variables:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    51
345
claus
parents: 154
diff changeset
    52
	contents        <Dictionary>    for each element, the number of occurrences
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
    53
"
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
    54
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    55
a27a279701f8 Initial revision
claus
parents:
diff changeset
    56
!Bag class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    57
345
claus
parents: 154
diff changeset
    58
equalityNew:size
claus
parents: 154
diff changeset
    59
    "return a new empty Bag with initial space for size elements.
claus
parents: 154
diff changeset
    60
     Elements will be compared using equality compare (i.e. #= not #== identity)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    61
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
    ^ super new initContents:size
345
claus
parents: 154
diff changeset
    63
!
claus
parents: 154
diff changeset
    64
claus
parents: 154
diff changeset
    65
identityNew:size
claus
parents: 154
diff changeset
    66
    "return a new empty Bag with initial space for size elements.
claus
parents: 154
diff changeset
    67
     Elements will be compared using identity compare (i.e. #== not #= equality)."
claus
parents: 154
diff changeset
    68
claus
parents: 154
diff changeset
    69
    ^ super new initContentsForIdentity:size
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    72
new
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    73
    "return a new empty Bag which compares for equality (i.e. not identity)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    75
    ^ super new initContents
345
claus
parents: 154
diff changeset
    76
!
claus
parents: 154
diff changeset
    77
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    78
new:size
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    79
    "return a new empty Bag with initial space for size elements.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    80
     Elements will be compared using equality compare (i.e. #= not #== identity)."
345
claus
parents: 154
diff changeset
    81
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    82
    ^ self equalityNew:size
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
!Bag methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
at:index
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
    "report an error: at: is not allowed for Bags"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
    ^ self errorNotKeyed
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
at:index put:anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
    "report an error: at:put: is not allowed for Bags"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
    ^ self errorNotKeyed
345
claus
parents: 154
diff changeset
    97
!
claus
parents: 154
diff changeset
    98
claus
parents: 154
diff changeset
    99
contents
claus
parents: 154
diff changeset
   100
    "return the dictionary which associates occurrence-counts
claus
parents: 154
diff changeset
   101
     to the bags elements."
claus
parents: 154
diff changeset
   102
claus
parents: 154
diff changeset
   103
    ^ contents
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
!Bag methodsFor:'adding & removing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   107
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   108
add:newObject
345
claus
parents: 154
diff changeset
   109
    "add the argument, anObject to the receiver.
claus
parents: 154
diff changeset
   110
     Returns the object."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   112
    |n|
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   113
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   114
    n := contents at:newObject ifAbsent:[0].
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   115
    contents at:newObject put:(n + 1).
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   116
    ^ newObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
a27a279701f8 Initial revision
claus
parents:
diff changeset
   119
add:newObject withOccurences:anInteger
345
claus
parents: 154
diff changeset
   120
    "add the argument, anObject anInteger times to the receiver.
claus
parents: 154
diff changeset
   121
     Returns the object."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   123
    |n|
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   124
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   125
    n := contents at:newObject ifAbsent:[0].
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   126
    contents at:newObject put:(n + anInteger).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
    ^ newObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
a27a279701f8 Initial revision
claus
parents:
diff changeset
   130
remove:oldObject ifAbsent:anExceptionBlock
345
claus
parents: 154
diff changeset
   131
    "Remove oldObject from the collection.
claus
parents: 154
diff changeset
   132
     If it was not present, return the value of the exceptionBlock;
claus
parents: 154
diff changeset
   133
     otherwise return the removed object."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
    |count|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   137
    count := contents at:oldObject ifAbsent:[0].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
    (count == 0) ifTrue:[^ anExceptionBlock value].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
    (count == 1) ifTrue:[
345
claus
parents: 154
diff changeset
   140
	contents removeKey:oldObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
    ] ifFalse:[ 
345
claus
parents: 154
diff changeset
   142
	contents at:oldObject put:(count - 1)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
    ^ oldObject
345
claus
parents: 154
diff changeset
   145
!
claus
parents: 154
diff changeset
   146
claus
parents: 154
diff changeset
   147
removeAllOccurrencesOf:oldObject ifAbsent:anExceptionBlock
claus
parents: 154
diff changeset
   148
    "Remove all occurrences of oldObject from the collection.
claus
parents: 154
diff changeset
   149
     If it was not present, return the value of the exceptionBlock;
claus
parents: 154
diff changeset
   150
     otherwise return the number of removes."
claus
parents: 154
diff changeset
   151
claus
parents: 154
diff changeset
   152
    |count|
claus
parents: 154
diff changeset
   153
claus
parents: 154
diff changeset
   154
    count := contents at:oldObject ifAbsent:[0].
claus
parents: 154
diff changeset
   155
    (count == 0) ifTrue:[^ anExceptionBlock value].
claus
parents: 154
diff changeset
   156
    contents removeKey:oldObject.
claus
parents: 154
diff changeset
   157
    ^ oldObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   160
!Bag methodsFor:'converting'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   161
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   162
asBag
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   163
    "return the receiver as a bag"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   164
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   165
    "could be an instance of a subclass..."
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   166
    self class == Bag ifTrue:[
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   167
	^ self
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   168
    ].
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   169
    ^ super asBag
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   170
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   171
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   172
!Bag methodsFor:'copying'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   173
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   174
postCopy
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   175
    "must copy the contents as well"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   176
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   177
    contents := contents copy
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   178
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   179
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
!Bag methodsFor:'enumerating'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
do:aBlock
345
claus
parents: 154
diff changeset
   183
    "evaluate the block for all elements in the collection."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 11
diff changeset
   185
    contents keysAndValuesDo:[:key :value|
345
claus
parents: 154
diff changeset
   186
	value timesRepeat:[
claus
parents: 154
diff changeset
   187
	    aBlock value:key
claus
parents: 154
diff changeset
   188
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
    ]
345
claus
parents: 154
diff changeset
   190
!
claus
parents: 154
diff changeset
   191
claus
parents: 154
diff changeset
   192
valuesAndCountsDo:aTwoArgBlock
claus
parents: 154
diff changeset
   193
    "evaluate the block for all distinct elements in the collection,
claus
parents: 154
diff changeset
   194
     passing both the element and the occurence count as arguments."
claus
parents: 154
diff changeset
   195
claus
parents: 154
diff changeset
   196
    ^ contents keysAndValuesDo:aTwoArgBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   197
! !
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   198
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   199
!Bag methodsFor:'private'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   200
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   201
initContents
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   202
    "set the contents to be an empty Dictionary"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   203
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   204
    contents := Dictionary new
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   205
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   206
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   207
initContents:size
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   208
    "set the contents to be an empty Dictionary with initial size"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   209
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   210
    contents := Dictionary new:size
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   211
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   212
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   213
initContentsForIdentity:size
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   214
    "set the contents to be an empty IdentityDictionary with initial size"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   215
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   216
    contents := IdentityDictionary new:size
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   217
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   218
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   219
!Bag methodsFor:'testing'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   220
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   221
includes:anObject
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   222
    "return true, if anObject is in the receiver"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   223
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   224
    ^ contents includesKey:anObject
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   225
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   226
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   227
occurrencesOf:anObject
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   228
    "return how many times anObject is in the receiver"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   229
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   230
    ^ contents at:anObject ifAbsent:[0]
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   231
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   232
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   233
size
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   234
    "return the number of bag elements"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   235
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   236
    |count|
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   237
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   238
    count := 0.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   239
    contents do:[:element | count := count + element].
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   240
    ^ count
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   241
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   242
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   243
!Bag class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   244
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   245
version
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   246
    ^ '$Header: /cvs/stx/stx/libbasic/Bag.st,v 1.16 1995-11-23 17:29:24 cg Exp $'
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   247
! !