Set.st
author Claus Gittinger <cg@exept.de>
Mon, 19 May 2003 20:40:02 +0200
changeset 7311 6878116b0a27
parent 7268 4a2b7acd6913
child 7598 27f37bd56675
permissions -rw-r--r--
+copyWithout/copyWithoutAll:
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
159
514c749165c3 *** empty log message ***
claus
parents: 119
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
5471
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
    13
"{ Package: 'stx:libbasic' }"
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Collection subclass:#Set
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
    16
	instanceVariableNames:'tally keyArray'
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
    17
	classVariableNames:'DeletedEntry'
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
    18
	poolDictionaries:''
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
    19
	category:'Collections-Unordered'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
2272
9942d9c853c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    22
Object subclass:#EmptySlot
2259
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
    23
	instanceVariableNames:''
4017
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
    24
	classVariableNames:'TheOneAndOnlyInstance'
2259
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
    25
	poolDictionaries:''
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
    26
	privateIn:Set
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
    27
!
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
    28
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
    29
!Set class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 COPYRIGHT (c) 1991 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
    34
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    35
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    44
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
    a Set is a collection where each element occurs at most once.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    48
    The inclusion test is done using = for comparison; 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    49
    see IdentitySet for sets using identity compare.
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
    50
    Keep in mind, that a regular Set therefore treats 3.0 and 3 as equal
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
    51
    and therefore:
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    52
	(Set with:3.0) includes:3
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
    53
    will return true (since 3.0 and 3 are equal).
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
    54
    In contrast, an IdentitySet will return false, because 3.0 and 3 are not
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
    55
    identical.
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
    56
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    57
    Sets use hashing for fast access, this access is considerably faster,
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    58
    if a good hash-number is returned by the elements.
362
claus
parents: 359
diff changeset
    59
claus
parents: 359
diff changeset
    60
    Notice that the default hash (Object>>hash) is not perfect; due to
claus
parents: 359
diff changeset
    61
    the implementation of hash-keys in ST/X, increased hash collisions
claus
parents: 359
diff changeset
    62
    are to be expected for large sets (say: > 20000 element). 
claus
parents: 359
diff changeset
    63
    If your objects are heavyly used in sets or dictionaries, and you need
claus
parents: 359
diff changeset
    64
    big collections, your instances may provide a better hash values.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    65
345
claus
parents: 324
diff changeset
    66
    Performance hints: 
657
449935f15b9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    67
      If only symbols or smallIntegers are used as keys, 
362
claus
parents: 359
diff changeset
    68
      use an instance of IdentitySet for slightly better performance, 
claus
parents: 359
diff changeset
    69
      since both hashing and comparison is faster.
345
claus
parents: 324
diff changeset
    70
claus
parents: 324
diff changeset
    71
      If you have a rough idea how big the set is going to grow,
claus
parents: 324
diff changeset
    72
      create it using #new: instead of #new. Even if the size given is a
claus
parents: 324
diff changeset
    73
      poor guess (say half of the real size), there is some 20-30% performance
claus
parents: 324
diff changeset
    74
      win to expect, since many resizing operations of the set are avoided.
claus
parents: 324
diff changeset
    75
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    76
    Examples:
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    77
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    78
	|s|
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    79
	s := Set new.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    80
	s add:'hello'.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    81
	s add:'world'.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    82
	s add:#foo.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    83
	s add:1.2345678.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    84
	s add:'hello'.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    85
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    86
	s printCR.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    87
	's size -> ' print. s size printCR.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    88
	'(s includes:''hello'') -> ' print. (s includes:'hello') printCR.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    89
	'(s includes:#foo)    -> ' print. (s includes:#foo) printCR.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    90
	'(s includes:''foo'')   -> ' print. (s includes:'foo') printCR.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    91
	'(s includes:#bar)    -> ' print. (s includes:#bar) printCR.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
    92
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
    93
    [author:]
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
    94
	Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    95
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    96
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
2259
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
    98
!Set class methodsFor:'initialization'!
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
    99
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   100
initialize
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   101
    "initialize the Set class"
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   102
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   103
    DeletedEntry isNil ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   104
	DeletedEntry := EmptySlot new
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   105
    ].
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   106
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   107
    "Set initialize"
2259
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   108
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   109
    "Modified: 24.1.1997 / 21:09:00 / cg"
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   110
! !
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   111
2259
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   112
!Set class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
6083
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   114
decodeFromLiteralArray:anArray
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   115
    "create & return a new instance from information encoded in anArray."
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   116
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   117
    |col|
6083
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   118
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   119
    col := self new:anArray size - 1.
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   120
    anArray from:2 do:[:el | col add:el decodeAsLiteralArray].
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   121
    ^ col
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   122
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   123
    "
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   124
     (Set with:1234
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   125
	  with:(1 @ 2)
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   126
	  with:'hello'
6083
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   127
     ) literalArrayEncoding decodeAsLiteralArray    
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   128
    "
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   129
!
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   130
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
new
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
    "return a new empty Set"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
    ^ self new:7
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
a27a279701f8 Initial revision
claus
parents:
diff changeset
   137
new:anInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
    "return a new empty Set with space for anInteger elements"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
159
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   140
    "
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   141
     make it somewhat bigger; hashing works better if fill grade is
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   142
     below 10% (make it 75% here ..)
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   143
    "
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   144
    ^ self basicNew setTally:(anInteger * 4 // 3)
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   145
! !
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   146
2259
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   147
!Set class methodsFor:'queries'!
252
   148
   149
goodSizeFrom:arg 
   150
    "return a good array size for the given argument.
   151
     Returns the next prime after arg, since prime sizes are good for hashing."
   152
302
1f76060d58a4 *** empty log message ***
claus
parents: 252
diff changeset
   153
    |n|
1f76060d58a4 *** empty log message ***
claus
parents: 252
diff changeset
   154
2461
2d65e1845502 minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   155
    "/ arg <= 11 ifTrue:[^ 11].
2d65e1845502 minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   156
    "/ n := arg * 3 // 2.
252
   157
2461
2d65e1845502 minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   158
    arg <= 7 ifTrue:[^ 7].
2d65e1845502 minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   159
    n := arg.
302
1f76060d58a4 *** empty log message ***
claus
parents: 252
diff changeset
   160
252
   161
    "
   162
     mhmh - this returns good numbers for collections with up-to about
   163
     500k elements; if you have bigger ones, add some more primes here ...
   164
    "
302
1f76060d58a4 *** empty log message ***
claus
parents: 252
diff changeset
   165
    n <= 524288 ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   166
	   "2  4  8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288"
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   167
	^ #(7  7 11 17 37 67 131 257 521 1031 2053 4099 8209 16411 32771 65537 131101 262147 524309) at:(n highBit)
252
   168
    ].
   169
    "
   170
     make it odd - at least
   171
    "
302
1f76060d58a4 *** empty log message ***
claus
parents: 252
diff changeset
   172
    ^ n bitOr:1
2461
2d65e1845502 minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   173
2d65e1845502 minimum goodSize reduced to 7.
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   174
    "Modified: 19.3.1997 / 16:07:59 / cg"
252
   175
! !
   176
3048
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   177
!Set class methodsFor:'utilities'!
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   178
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   179
rehashAllSubInstances
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   180
    "rehash all sets & dictionaries.
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   181
     Useful utility if hash/identityHash method was changed
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   182
     of some object which is known to be kept in a set"
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   183
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   184
     self allSubInstances do:[:s | s rehash]
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   185
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   186
    "
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   187
     Set rehashAllSubInstances
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   188
    "
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   189
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   190
    "Created: / 24.10.1997 / 23:13:44 / cg"
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   191
! !
88c3a9c669e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2475
diff changeset
   192
7311
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   193
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   194
7268
4a2b7acd6913 method category rename
Claus Gittinger <cg@exept.de>
parents: 7260
diff changeset
   195
!Set methodsFor:'Compatibility-ST80'!
6991
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   196
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   197
initialIndexFor:hashKey boundedBy:length
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   198
    "for ST-80 compatibility only; it is (currently) not used in this
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   199
     implementation of sets. Therefore, in ST/X it does not make sense
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   200
     to redefine it. (which may be a bad design decision, but slightly
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   201
     improves performance, by avoiding an extra message send ...)"
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   202
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   203
    |index "{ Class:SmallInteger }"|
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   204
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   205
    index := hashKey bitAnd:16r3FFFFFFF.
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   206
    index < 16r1FFFFFFF ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   207
	index := index * 2
6991
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   208
    ].
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   209
    index := index \\ length + 1.
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   210
    ^ index.
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   211
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   212
    "Modified: 1.3.1997 / 01:01:13 / cg"
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   213
! !
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   214
7311
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   215
!Set methodsFor:'Compatibility-Squeak'!
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   216
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   217
copyWithout:anElement
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   218
    ^ self select:[:each | each ~= anElement]
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   219
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   220
    "
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   221
     #(1 2 3 4 5 6 7) asSet copyWithout:5
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   222
    "
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   223
!
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   224
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   225
copyWithoutAll:aCollection
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   226
    ^ self select:[:each | (aCollection includes:each)]
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   227
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   228
    "
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   229
     #(1 2 3 4 5 6 7) asSet copyWithoutAll:#(3 5 7 9)
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   230
    "
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   231
! !
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
   232
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   233
!Set methodsFor:'accessing'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
at:index
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
    "report an error: at: is not allowed for Sets"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   237
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   238
    ^ self errorNotKeyed
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   240
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   241
at:index put:anObject
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   242
    "report an error: at:put: is not allowed for Sets"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   243
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   244
    ^ self errorNotKeyed
2469
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   245
!
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   246
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   247
elementAt:anObject
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   248
    "return the element, if contained in the set.
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   249
     If there is none, report an error.
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   250
     This may seem confusing at first - however, it is useful with
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   251
     non-identitysets, to find an existing element, for a 
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   252
     given equal (but not identical) object.
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   253
     This is the same functionality as provided by the goodies/KeyedSet
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   254
     goody."
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   255
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   256
    ^ self elementAt:anObject ifAbsent:[^ self errorNotFound].
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   257
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   258
    "Modified: 20.3.1997 / 20:35:24 / cg"
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   259
!
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   260
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   261
elementAt:anObject ifAbsent:exceptionBlock
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   262
    "return the element, if contained in the set.
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   263
     If there is none, return the result from evaluating exceptionBlock.
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   264
     This may seem confusing at first - however, it is useful with
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   265
     non-identitysets, to find an existing element, for a 
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   266
     given equal (but not identical) object.
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   267
     This is the same functionality as provided by the goodies/KeyedSet
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   268
     goody."
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   269
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   270
    |index "{ Class: SmallInteger }" |
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   271
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   272
    index := self find:anObject ifAbsent:0.
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   273
    index == 0 ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   274
	^ exceptionBlock value
2469
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   275
    ].
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   276
    ^ keyArray basicAt:index
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   277
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   278
    "Created: 20.3.1997 / 20:34:07 / cg"
ecca86d50852 added #elementAt: / #elementAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents: 2461
diff changeset
   279
    "Modified: 20.3.1997 / 20:35:49 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
!Set methodsFor:'adding & removing'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   283
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   284
add:anObject
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   285
    "add the argument, anObject to the receiver.
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   286
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   287
     WARNING: do not add elements while iterating over the receiver.
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   288
	      Iterate over a copy to do this."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
2328
0fd1d715e5a9 oops - the last one was not good
Claus Gittinger <cg@exept.de>
parents: 2323
diff changeset
   290
    |index "{ Class: SmallInteger }"|
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
5335
fae7e0698241 added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents: 5298
diff changeset
   292
    anObject isNil ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   293
	^ self invalidElementError.
5335
fae7e0698241 added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents: 5298
diff changeset
   294
    ].
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
5335
fae7e0698241 added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents: 5298
diff changeset
   296
    index := self findKeyOrNil:anObject.
fae7e0698241 added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents: 5298
diff changeset
   297
    (keyArray basicAt:index) isNil ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   298
	"/ not already there
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   299
	keyArray basicAt:index put:anObject.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   300
	tally := tally + 1.
5335
fae7e0698241 added a warning: adding nil will soon be an error.
Claus Gittinger <cg@exept.de>
parents: 5298
diff changeset
   301
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   302
	self fullCheck.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    ].
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
    ^ anObject
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   305
2328
0fd1d715e5a9 oops - the last one was not good
Claus Gittinger <cg@exept.de>
parents: 2323
diff changeset
   306
    "Modified: 30.1.1997 / 14:58:08 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
remove:oldObject ifAbsent:exceptionBlock
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
    "remove oldObject from the collection and return it.
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   311
     If it was not in the collection return the value of exceptionBlock.
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   312
     Notice, that the returned object could be non-identical to the argument
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   313
     (although it will always be equal).
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   314
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   315
     WARNING: do not remove elements while iterating over the receiver.
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   316
	      See #saveRemove: to do this."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   318
    |index next objectRemoved|
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   319
3265
18d96c910653 handle attempt to remove nil.
Claus Gittinger <cg@exept.de>
parents: 3261
diff changeset
   320
    oldObject isNil ifTrue:[^ exceptionBlock value].
18d96c910653 handle attempt to remove nil.
Claus Gittinger <cg@exept.de>
parents: 3261
diff changeset
   321
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
    index := self find:oldObject ifAbsent:0.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    index == 0 ifTrue:[^ exceptionBlock value].
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   325
    objectRemoved := keyArray basicAt:index.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
    keyArray basicAt:index put:nil.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   327
    tally := tally - 1.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
    tally == 0 ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   329
	keyArray := self keyContainerOfSize:(self class goodSizeFrom:0). 
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
    ] ifFalse:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   331
	index == keyArray basicSize ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   332
	    next := 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   333
	] ifFalse:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   334
	    next := index + 1.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   335
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   336
	(keyArray basicAt:next) notNil ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   337
	    keyArray basicAt:index put:DeletedEntry.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   338
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   339
	self emptyCheck
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
    ].
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   341
    ^ objectRemoved
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   342
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   343
    "Modified: / 16.11.2001 / 10:14:24 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   344
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   345
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   346
removeAll
1164
38c54a4f1273 commentary
Claus Gittinger <cg@exept.de>
parents: 1144
diff changeset
   347
    "remove all elements from the receiver. Returns the receiver."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   348
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   349
    self setTally:7.
1164
38c54a4f1273 commentary
Claus Gittinger <cg@exept.de>
parents: 1144
diff changeset
   350
38c54a4f1273 commentary
Claus Gittinger <cg@exept.de>
parents: 1144
diff changeset
   351
    "Modified: 12.4.1996 / 13:35:06 / cg"
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   352
!
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   353
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   354
saveRemove:oldObject 
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   355
    "remove the element, oldObject from the collection.
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   356
     Return the element 
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   357
     (could be non-identical to oldObject, since I hash on equality, not on identity).
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   358
     If it was not in the collection return nil.
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   359
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   360
     In contrast to #remove:, this does not resize the underlying collection
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   361
     and therefore does NOT rehash & change the elements order.
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   362
     Therefor this can be used while enumerating the receiver,
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   363
     which is not possible if #remove: is used.
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   364
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   365
     WARNING: since no resizing is done, the physical amount of memory used
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   366
	      by the container remains the same, although the logical size shrinks.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   367
	      You may want to manually resize the receiver using #emptyCheck.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   368
	      (after the loop)"
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   369
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   370
    |index "{ Class:SmallInteger }"
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   371
     next  "{ Class:SmallInteger }"
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   372
     removedObject|
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   373
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   374
    oldObject isNil ifTrue:[^ nil].
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   375
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   376
    index := self find:oldObject ifAbsent:0.
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   377
    index == 0 ifTrue:[^ nil].
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   378
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   379
    removedObject := keyArray basicAt:index.
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   380
    keyArray basicAt:index put:nil.
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   381
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   382
    tally := tally - 1.
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   383
    tally ~~ 0 ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   384
	index == keyArray basicSize ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   385
	    next := 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   386
	] ifFalse:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   387
	    next := index + 1.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   388
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   389
	(keyArray basicAt:next) notNil ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   390
	    keyArray basicAt:index put:DeletedEntry
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   391
	].
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   392
    ].
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   393
    ^ removedObject
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   394
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   395
    "does NOT work:
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   396
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   397
	|s|
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   398
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   399
	s := Set new.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   400
	s add:1.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   401
	s add:2.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   402
	s add:3.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   403
	s add:4.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   404
	s add:5.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   405
	s add:6.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   406
	s add:7.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   407
	s add:8.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   408
	s add:9.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   409
	s do:[:v |
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   410
	    v odd ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   411
		s remove:v 
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   412
	    ]
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   413
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   414
	s inspect
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   415
    "
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   416
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   417
    "DOES work:
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   418
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   419
	|s|
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   420
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   421
	s := Set new.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   422
	s add:1.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   423
	s add:2.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   424
	s add:3.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   425
	s add:4.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   426
	s add:5.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   427
	s add:6.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   428
	s add:7.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   429
	s add:8.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   430
	s add:9.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   431
	s do:[:v |
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   432
	    v odd ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   433
		s saveRemove:v 
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   434
	    ]
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   435
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   436
	s inspect
1052
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   437
    "
7d43187f7e11 added saveRemove: & commentaries
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
   438
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   439
    "Created: / 1.3.1996 / 21:14:26 / cg"
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
   440
    "Modified: / 16.11.2001 / 10:22:59 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   443
!Set methodsFor:'binary storage'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   444
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   445
readBinaryContentsFrom: stream manager: manager
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   446
    "must rehash after reload"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
    super readBinaryContentsFrom: stream manager: manager.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   449
    self rehash
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   450
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   451
5280
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   452
!Set methodsFor:'comparing'!
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   453
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   454
= aCollection
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   455
    "return true, if the argument is a Set containing the same elements
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   456
     as I do"
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   457
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   458
    aCollection species == self species ifFalse:[^ false].
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   459
    aCollection size == self size ifFalse:[^ false].
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   460
    "/ same number of elements; since I am a Set, all of
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   461
    "/ of my elements must be in the other collection ...
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   462
    self do:[:element |
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   463
	(aCollection includes:element) ifFalse:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   464
	    ^ false
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   465
	]
5280
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   466
    ].
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   467
    ^ true
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   468
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   469
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   470
     #(1 2 3 4 5) asSet = #(2 3 4 5 1) asSet
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   471
     #(1 2 3 4 5) asSet = #(2 3 4 5 1.0) asSet 
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   472
     #(1 2 3 4 5) asSet = #(2 3 4 5 'one') asSet 
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   473
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   474
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   475
     |d1 d2|
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   476
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   477
     d1 := Dictionary new.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   478
     d2 := Dictionary new.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   479
     d1 at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   480
     d1 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   481
     d1 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   482
     d1 at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   483
     d1 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   484
     d1 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   485
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   486
     d2 at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   487
     d2 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   488
     d2 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   489
     d2 at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   490
     d2 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   491
     d2 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   492
     d1 = d2     
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   493
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   494
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   495
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   496
     |d1 d2|
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   497
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   498
     d1 := Dictionary new.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   499
     d2 := Dictionary new.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   500
     d1 at:1 put:'uno'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   501
     d1 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   502
     d1 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   503
     d1 at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   504
     d1 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   505
     d1 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   506
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   507
     d2 at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   508
     d2 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   509
     d2 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   510
     d2 at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   511
     d2 at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   512
     d2 at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   513
     d1 = d2     
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   514
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   515
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   516
!
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   517
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   518
hash
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   519
    "return a hash key for the receiver"
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   520
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   521
    "this hash is stupid - but for larger collections, the hashing
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   522
     time can become much bigger than the time lost in added probing.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   523
     Time will show ...
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   524
     Notice & warning:
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   525
	if the #= method is ever changed to compare non-dictionaries equal,
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   526
	the code below must be changed to assert that the same hash-value is 
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   527
	still returned.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   528
	(which may be hard to acomplish)
5280
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   529
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   530
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   531
    |mySize|
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   532
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   533
    mySize := self size.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   534
    mySize == 0 ifTrue:[^ 0].
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   535
    ^ ((self first) hash times:mySize) bitAnd:16r3FFFFFFF
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   536
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   537
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   538
     |d|
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   539
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   540
     d := Dictionary new.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   541
     d at:1 put:'one'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   542
     d at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   543
     d at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   544
     d at:'two' put:2.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   545
     d hash     
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   546
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   547
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   548
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   549
     |d|
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   550
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   551
     d := Dictionary new.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   552
     d at:1 put:'uno'.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   553
     d at:'one' put:1.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   554
     d at:2 put:#two.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   555
     d at:'two' put:2.
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   556
     d hash     
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   557
    "
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   558
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   559
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   560
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   561
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   562
! !
ad806c9b992e added #= & #hash; EXPERIMENTAL
Claus Gittinger <cg@exept.de>
parents: 5048
diff changeset
   563
6083
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   564
!Set methodsFor:'converting'!
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   565
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   566
literalArrayEncoding
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   567
    "encode myself as an array literal, from which a copy of the receiver
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   568
     can be reconstructed with #decodeAsLiteralArray."
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   569
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   570
    |encoding|
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   571
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   572
    encoding := OrderedCollection with:(self class name).
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   573
    self do:[:el| encoding add:(el literalArrayEncoding) ].
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   574
  ^ encoding asArray
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   575
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   576
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   577
    "
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   578
     (Set with:1234
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   579
	  with:(1 @ 2)
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   580
	  with:'hello'
6083
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   581
     ) literalArrayEncoding decodeAsLiteralArray  
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   582
    "
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   583
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   584
    "Modified: 22.4.1996 / 13:00:56 / cg"
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   585
! !
98a14d57e673 added: literalArrayEncoding
tm
parents: 5845
diff changeset
   586
159
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   587
!Set methodsFor:'copying'!
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   588
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   589
postCopy
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   590
    "have to copy the keyArray too"
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   591
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   592
    keyArray := keyArray shallowCopy
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   593
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   594
5471
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   595
!Set methodsFor:'encoding'!
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   596
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   597
encodeOn:anEncoder with:aParameter
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   598
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   599
    anEncoder encodeSet:self with:aParameter
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   600
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   601
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   602
! !
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   603
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   604
!Set methodsFor:'enumerating'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   605
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   606
do:aBlock
1056
991ed2a9318b commentary
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   607
    "perform the block for all members in the collection.
991ed2a9318b commentary
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   608
991ed2a9318b commentary
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   609
     WARNING: do not add/remove elements while iterating over the receiver.
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   610
	      Iterate over a copy to do this."
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   611
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   612
    |sz "{ Class: SmallInteger }"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   613
     element|
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   614
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   615
    sz := keyArray size.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   616
    1 to:sz do:[:index |
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   617
	element := keyArray at:index.
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   618
	(element notNil and:[element ~~ DeletedEntry]) ifTrue:[
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   619
	    aBlock value:element
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   620
	]
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   621
    ]
1056
991ed2a9318b commentary
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   622
991ed2a9318b commentary
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
   623
    "Modified: 1.3.1996 / 21:41:13 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
! !
61
claus
parents: 50
diff changeset
   625
969
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   626
!Set methodsFor:'inspecting'!
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   627
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   628
inspectorClass
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   629
    "redefined to use SetInspector
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   630
     (instead of the default Inspector)."
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   631
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   632
    ^ SetInspectorView
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   633
! !
6c285e945e8f Use SetInspectorView.
Stefan Vogel <sv@exept.de>
parents: 657
diff changeset
   634
7169
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   635
!Set methodsFor:'obsolete set operations'!
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   636
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   637
+ aCollection
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   638
    "Kept for backward compatibility. Use #union: instead, to isolate
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   639
     arithmethic and set operations"
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   640
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   641
    <resource: #obsolete>
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   642
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   643
    ^ self union:aCollection.
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   644
!
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   645
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   646
- aCollection
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   647
    "Kept for backward compatibility. Use #union: instead, to isolate
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   648
     arithmethic and set operations"
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   649
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   650
    <resource: #obsolete>
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   651
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   652
    ^ self \ aCollection
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   653
! !
74576ccad3c0 Clean up set operations
Stefan Vogel <sv@exept.de>
parents: 7167
diff changeset
   654
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   655
!Set methodsFor:'private'!
2
claus
parents: 1
diff changeset
   656
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   657
find:key ifAbsent:aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
   658
    "Look for the key in the receiver.  If it is found, return
a27a279701f8 Initial revision
claus
parents:
diff changeset
   659
     the index of the slot containing the key, otherwise
a27a279701f8 Initial revision
claus
parents:
diff changeset
   660
     return the value of evaluating aBlock."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   661
61
claus
parents: 50
diff changeset
   662
    |index  "{ Class:SmallInteger }"
claus
parents: 50
diff changeset
   663
     length "{ Class:SmallInteger }"
claus
parents: 50
diff changeset
   664
     startIndex probe|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   665
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   666
    length := keyArray basicSize.
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   667
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   668
"/
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   669
"/  length < 10 ifTrue:[
362
claus
parents: 359
diff changeset
   670
"/      "assuming, that for small collections the overhead of hashing
claus
parents: 359
diff changeset
   671
"/       is larger ... maybe that proves wrong 
claus
parents: 359
diff changeset
   672
"/       (if overhead of comparing is higher)"
claus
parents: 359
diff changeset
   673
"/      ^ keyArray indexOf:key ifAbsent:aBlock
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   674
"/  ].
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   675
6917
979bfb9267e3 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6577
diff changeset
   676
    startIndex := index := self initialIndexForKey:key.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   677
a27a279701f8 Initial revision
claus
parents:
diff changeset
   678
    [true] whileTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   679
	probe := (keyArray basicAt:index).
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   680
	key = probe ifTrue:[^ index].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   681
	(self slotIsEmpty:probe) ifTrue:[^ aBlock value].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   682
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   683
	index == length ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   684
	    index := 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   685
	] ifFalse:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   686
	    index := index + 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   687
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   688
	index == startIndex ifTrue:[^ aBlock value].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   689
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   690
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   691
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   692
findKeyOrNil:key
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   693
    "Look for the key in the receiver.  
3082
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   694
     If it is found, return the index of the first unused slot. 
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   695
     Grow the receiver, if key was not found, and no unused slots were present"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   696
61
claus
parents: 50
diff changeset
   697
    |index  "{ Class:SmallInteger }"
claus
parents: 50
diff changeset
   698
     length "{ Class:SmallInteger }"
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   699
     startIndex probe 
6917
979bfb9267e3 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6577
diff changeset
   700
     delIndex|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   701
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   702
    length := keyArray basicSize.
6917
979bfb9267e3 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6577
diff changeset
   703
    startIndex := index := self initialIndexForKey:key.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   704
a27a279701f8 Initial revision
claus
parents:
diff changeset
   705
    [true] whileTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   706
	probe := keyArray basicAt:index.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   707
	key = probe ifTrue:[^ index].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   708
	(self slotIsEmpty:probe) ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   709
	    delIndex isNil ifTrue:[^ index].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   710
	    keyArray basicAt:delIndex put:nil.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   711
	    ^ delIndex
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   712
	].
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 1056
diff changeset
   713
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   714
	probe == DeletedEntry ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   715
	    delIndex isNil ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   716
		delIndex := index
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   717
	    ]
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   718
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   719
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   720
	index == length ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   721
	    index := 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   722
	] ifFalse:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   723
	    index := index + 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   724
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   725
	index == startIndex ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   726
	    delIndex notNil ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   727
		keyArray basicAt:delIndex put:nil.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   728
		^ delIndex
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   729
	    ].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   730
	    ^ self grow findKeyOrNil:key
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   731
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   732
    ]
1450
18c2a1da8be2 first look for nil-entry in findKeyOrNil: - saves a compare in the good case, when adding new elements
Claus Gittinger <cg@exept.de>
parents: 1319
diff changeset
   733
3082
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   734
    "Modified: / 30.10.1997 / 16:01:57 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   735
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   736
a27a279701f8 Initial revision
claus
parents:
diff changeset
   737
findNil:key
2475
dffcb8b97178 use #hashFor: in #findNil:
Claus Gittinger <cg@exept.de>
parents: 2469
diff changeset
   738
    "Look for the next slot usable for key.  
dffcb8b97178 use #hashFor: in #findNil:
Claus Gittinger <cg@exept.de>
parents: 2469
diff changeset
   739
     WARNING:
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   740
	This method assumes that key is not already in the receiver 
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   741
	AND that keyArray does not have previously removed entries 
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   742
	AND that there is an empty slot.
2475
dffcb8b97178 use #hashFor: in #findNil:
Claus Gittinger <cg@exept.de>
parents: 2469
diff changeset
   743
     To be used ONLY while growing/rehashing to enter elements into a fresh
dffcb8b97178 use #hashFor: in #findNil:
Claus Gittinger <cg@exept.de>
parents: 2469
diff changeset
   744
     collection - if any of the above conditions is not met, the method
dffcb8b97178 use #hashFor: in #findNil:
Claus Gittinger <cg@exept.de>
parents: 2469
diff changeset
   745
     loops forever."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   746
2475
dffcb8b97178 use #hashFor: in #findNil:
Claus Gittinger <cg@exept.de>
parents: 2469
diff changeset
   747
    |index  "{ Class:SmallInteger }"
61
claus
parents: 50
diff changeset
   748
     length "{ Class:SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   749
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   750
    length := keyArray basicSize.
6917
979bfb9267e3 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6577
diff changeset
   751
    index := self initialIndexForKey:key.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   752
5772
e45edba144f1 nope - not better.
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
   753
"/    index := keyArray identityIndexOf:nil startingAt:index.
e45edba144f1 nope - not better.
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
   754
"/    index == 0 ifTrue:[
e45edba144f1 nope - not better.
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
   755
"/        index := keyArray identityIndexOf:nil startingAt:1 endingAt:index.
e45edba144f1 nope - not better.
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
   756
"/    ].
e45edba144f1 nope - not better.
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
   757
    "/ that code is completely inlined by stc ...
e45edba144f1 nope - not better.
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
   758
    [(keyArray basicAt:index) notNil] whileTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   759
	index == length ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   760
	    index := 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   761
	] ifFalse:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   762
	    index := index + 1
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   763
	].
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   764
	"notice: no check for no nil found - we must find one since
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   765
	 this is only called after growing"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   766
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   767
    ^ index
1055
d3784a235a2e commentary
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   768
2475
dffcb8b97178 use #hashFor: in #findNil:
Claus Gittinger <cg@exept.de>
parents: 2469
diff changeset
   769
    "Modified: 21.3.1997 / 10:32:58 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   770
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   771
2459
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   772
hashFor:aKey
6991
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   773
    "return the arguments hash value.
e95313d7c780 comment and category change only
Claus Gittinger <cg@exept.de>
parents: 6917
diff changeset
   774
     Redefined in subclasses, which use a different comparison (i.e. identity compare)"
2459
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   775
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   776
    ^ aKey hash
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   777
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   778
    "Created: 19.3.1997 / 15:03:03 / cg"
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   779
!
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   780
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   781
initialIndexForKey:aKey
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   782
    "return an initial index given a key."
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   783
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   784
    |index  "{ Class:SmallInteger }"
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   785
     length "{ Class:SmallInteger }"|
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   786
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   787
    length := keyArray basicSize.
6917
979bfb9267e3 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6577
diff changeset
   788
    index := (self hashFor:aKey) bitAnd:16r3FFFFFFF.
2459
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   789
    index < 16r1FFFFFFF ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   790
	index := index * 2
2459
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   791
    ].
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   792
    index := index \\ length + 1.
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   793
    ^ index.
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   794
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   795
    "Modified: 1.3.1997 / 01:01:13 / cg"
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   796
    "Created: 19.3.1997 / 15:02:41 / cg"
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   797
!
0a38e8602aac findNil: no need to check for wraparound;
Claus Gittinger <cg@exept.de>
parents: 2427
diff changeset
   798
5845
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   799
invalidElementError
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   800
    "this is send when a nil is used with a Set.
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   801
     For now this is just an info-Message. Will become an error sometimes."
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   802
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   803
    "/ self elementBoundError.
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   804
6540
cf1a6a1a8645 better invalidElementError message
Claus Gittinger <cg@exept.de>
parents: 6519
diff changeset
   805
    |con|
cf1a6a1a8645 better invalidElementError message
Claus Gittinger <cg@exept.de>
parents: 6519
diff changeset
   806
5845
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   807
    'Set [warning]: nil is not a valid element - will be an error in later versions' errorPrintCR.
6540
cf1a6a1a8645 better invalidElementError message
Claus Gittinger <cg@exept.de>
parents: 6519
diff changeset
   808
    con := thisContext sender.
cf1a6a1a8645 better invalidElementError message
Claus Gittinger <cg@exept.de>
parents: 6519
diff changeset
   809
    ('         from ' , con printString) errorPrintCR.
cf1a6a1a8645 better invalidElementError message
Claus Gittinger <cg@exept.de>
parents: 6519
diff changeset
   810
    con := con sender.
cf1a6a1a8645 better invalidElementError message
Claus Gittinger <cg@exept.de>
parents: 6519
diff changeset
   811
    con notNil ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   812
	('         from ' , con printString) errorPrintCR.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   813
	con := con sender.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   814
	con notNil ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   815
	    ('         from ' , con printString) errorPrintCR.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   816
	]
6540
cf1a6a1a8645 better invalidElementError message
Claus Gittinger <cg@exept.de>
parents: 6519
diff changeset
   817
    ].
5845
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   818
!
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
   819
3261
7e4e57c041df added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents: 3082
diff changeset
   820
keyArray
7e4e57c041df added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents: 3082
diff changeset
   821
    ^ keyArray
7e4e57c041df added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents: 3082
diff changeset
   822
7e4e57c041df added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents: 3082
diff changeset
   823
    "Created: / 2.2.1998 / 14:50:55 / cg"
7e4e57c041df added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents: 3082
diff changeset
   824
!
7e4e57c041df added access to my (private) keyArray instVar (sorry)
Claus Gittinger <cg@exept.de>
parents: 3082
diff changeset
   825
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   826
keyContainerOfSize:n
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   827
    "return a container for keys of size n.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   828
     Extracted to make life of weak subclasses easier ..."
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   829
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   830
    ^ Array basicNew:n
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   831
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   832
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   833
rehash
61
claus
parents: 50
diff changeset
   834
    "rehash is done by re-adding all elements to a new empty set.
claus
parents: 50
diff changeset
   835
     Rehash is needed after a binaryRead, for example."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   836
3082
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   837
    |element oldKeyArray newKeyArray newIdx
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   838
     n "{ Class:SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   839
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   840
    oldKeyArray := keyArray.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   841
    n := oldKeyArray size.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   842
    keyArray := newKeyArray := self keyContainerOfSize:n.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   843
2
claus
parents: 1
diff changeset
   844
    1 to:n do:[:index |
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   845
	element := oldKeyArray at:index.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   846
	(element notNil and:[element ~~ DeletedEntry]) ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   847
	    "cannot be already there"
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   848
	    newIdx := self findNil:element.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   849
	    newKeyArray basicAt:newIdx put:element
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   850
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   851
    ]
3082
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   852
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   853
    "Modified: / 30.10.1997 / 16:04:46 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   854
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   855
a27a279701f8 Initial revision
claus
parents:
diff changeset
   856
rehashFrom:startIndex
61
claus
parents: 50
diff changeset
   857
    "rehash elements starting at index - after a remove.
claus
parents: 50
diff changeset
   858
     Notice: due to the new implementation of remove, 
159
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   859
	     this is no longer needed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   860
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   861
    |element i "{ Class:SmallInteger }"
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   862
     length
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
     index "{ Class:SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   864
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   865
    length := keyArray basicSize.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   866
    index := startIndex.
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   867
    element := keyArray basicAt:index.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   868
    [element notNil] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   869
	i := self findNil:element.
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   870
	i == index ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   871
	    ^ self
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   872
	].
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   873
	keyArray basicAt:i put:element.
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   874
	keyArray basicAt:index put:nil.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   875
159
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   876
	index == length ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   877
	    index := 1
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   878
	] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   879
	    index := index + 1.
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   880
	].
514c749165c3 *** empty log message ***
claus
parents: 119
diff changeset
   881
	element := keyArray basicAt:index.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   882
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   883
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   884
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   885
setTally:count
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   886
    "initialize the contents array (for at least count slots) 
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   887
     and set tally to zero.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   888
     The size is increased to the next prime for better hashing behavior."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   889
3726
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   890
    |n|
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   891
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   892
    n := self class goodSizeFrom:count.
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   893
    n == keyArray size ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   894
	keyArray atAllPut:nil.
3726
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   895
    ] ifFalse:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   896
	keyArray := self keyContainerOfSize:n. 
3726
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   897
    ].
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   898
    tally := 0
3726
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   899
cf3eafa152a4 try to avoid allocation of a new keyArray in #setTally:
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   900
    "Modified: / 4.8.1998 / 22:07:25 / cg"
6233
0a79cbd07543 *** empty log message ***
martin
parents: 6191
diff changeset
   901
!
0a79cbd07543 *** empty log message ***
martin
parents: 6191
diff changeset
   902
0a79cbd07543 *** empty log message ***
martin
parents: 6191
diff changeset
   903
slotIsEmpty:aSlotValue
0a79cbd07543 *** empty log message ***
martin
parents: 6191
diff changeset
   904
    "only redefined in weak subclasses, since they treat a 0-value
0a79cbd07543 *** empty log message ***
martin
parents: 6191
diff changeset
   905
     as being empty"
0a79cbd07543 *** empty log message ***
martin
parents: 6191
diff changeset
   906
0a79cbd07543 *** empty log message ***
martin
parents: 6191
diff changeset
   907
    ^ aSlotValue isNil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   908
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   909
7260
edfa8d6a6046 method category rename
Claus Gittinger <cg@exept.de>
parents: 7169
diff changeset
   910
!Set methodsFor:'private-grow & shrink'!
3082
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   911
6127
0c4d7890cf6c + changeCapacityTo: (VW compatibility)
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
   912
changeCapacityTo:newSize
0c4d7890cf6c + changeCapacityTo: (VW compatibility)
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
   913
    newSize > self capacity ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   914
	self grow:newSize
6127
0c4d7890cf6c + changeCapacityTo: (VW compatibility)
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
   915
    ].
0c4d7890cf6c + changeCapacityTo: (VW compatibility)
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
   916
0c4d7890cf6c + changeCapacityTo: (VW compatibility)
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
   917
    "Created: / 30.10.2001 / 17:56:50 / cg"
0c4d7890cf6c + changeCapacityTo: (VW compatibility)
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
   918
!
0c4d7890cf6c + changeCapacityTo: (VW compatibility)
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
   919
3082
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   920
emptyCheck
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   921
    "check if the receiver has become too empty (after a remove)
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   922
     and shrink if it makes sense.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   923
     Definition of 'too empty' is 'filled less than 12.5% (i.e. 1/8th)'"
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   924
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   925
    |sz      "{Class: SmallInteger}"
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   926
     newSize "{Class: SmallInteger}" |
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   927
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   928
    sz := keyArray basicSize.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   929
    sz > 56 ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   930
	"
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   931
	 shrink if too empty
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   932
	"
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   933
	tally < (sz // 8) ifTrue:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   934
	    newSize := sz // 4.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   935
	    self grow:newSize
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
   936
	]
3082
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   937
    ]
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   938
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   939
    "Modified: 19.3.1997 / 16:02:55 / cg"
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   940
!
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   941
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   942
fullCheck
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   943
    "check if collection is full (after an add); grow if so.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   944
     Definition of 'full' is currently: 'filled more than 75% (i.e. 3/4th)'"
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   945
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   946
    |sz "{Class: SmallInteger}" |
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   947
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   948
    "
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   949
     grow if filled more than 75% 
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   950
    "
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   951
    sz := keyArray basicSize.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   952
    tally > (sz * 3 // 4) ifTrue:[
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   953
       self grow
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   954
    ]
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   955
!
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   956
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   957
grow
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   958
    "change the number of element slots of the collection to a useful
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   959
     new size"
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   960
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   961
    self grow:(keyArray basicSize * 2)
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   962
!
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   963
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   964
grow:newSize
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   965
    "change the number of element slots of the collection - to do this,
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   966
     we have to rehash (which is done by re-adding all elements to a new
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   967
     empty set)."
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   968
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   969
    |elem oldKeyArray newKeyArray deletedEntry
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   970
     containerSize oldSize "{ Class:SmallInteger }"|
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   971
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   972
    oldKeyArray := keyArray.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   973
    oldSize := oldKeyArray size.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   974
    containerSize := (self class goodSizeFrom:newSize).
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   975
    containerSize == oldSize ifTrue:[^ self].
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   976
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   977
    keyArray := newKeyArray := self keyContainerOfSize:containerSize. 
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   978
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   979
    deletedEntry := DeletedEntry.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   980
    1 to:oldSize do:[:srcIndex |
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   981
	elem := oldKeyArray basicAt:srcIndex.
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   982
	(elem notNil and:[elem ~~ deletedEntry]) ifTrue:[
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   983
	    "cannot be already there"
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   984
	    newKeyArray basicAt:(self findNil:elem) put:elem
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   985
	].
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   986
    ].
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   987
! !
d09ee5fdcc7b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3048
diff changeset
   988
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
   989
!Set methodsFor:'queries'!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
   990
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
   991
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
   992
    "return the number of set elements"
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
   993
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
   994
    ^ tally
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
   995
! !
5471
a57eeb01c5ab General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5335
diff changeset
   996
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   997
!Set methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   998
362
claus
parents: 359
diff changeset
   999
capacity 
claus
parents: 359
diff changeset
  1000
    "return the number of elements, that the receiver is
claus
parents: 359
diff changeset
  1001
     prepared to take.
claus
parents: 359
diff changeset
  1002
     Not used by the system; added for ST-80 compatibility."
claus
parents: 359
diff changeset
  1003
claus
parents: 359
diff changeset
  1004
    ^ keyArray size
claus
parents: 359
diff changeset
  1005
!
claus
parents: 359
diff changeset
  1006
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1007
includes:anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1008
    "return true if the argument anObject is in the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1009
5568
826390eef742 includes:nil - allowed, but send out a warning
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  1010
    anObject isNil ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1011
	"even if adding nil to a set is forbidden, asking for it should be ok!!"
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1012
	"self invalidElementError."
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1013
	^ false 
5568
826390eef742 includes:nil - allowed, but send out a warning
Claus Gittinger <cg@exept.de>
parents: 5557
diff changeset
  1014
    ].
362
claus
parents: 359
diff changeset
  1015
    ^ (self find:anObject ifAbsent:0) ~~ 0
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1016
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1017
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1018
isEmpty
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1019
    "return true if the receiver is empty"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1020
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1021
    ^ tally == 0
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1022
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1023
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1024
isFixedSize
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1025
    "return true if the receiver cannot grow - this will vanish once
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1026
     Arrays and Strings learn how to grow ..."
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1027
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1028
    ^ false
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1029
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1030
2383
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1031
notEmpty
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1032
    "return true if the receiver is not empty"
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1033
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1034
    ^ tally ~~ 0
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1035
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1036
    "Created: 12.2.1997 / 12:39:02 / cg"
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1037
!
8b2957f5ec90 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2328
diff changeset
  1038
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1039
occurrencesOf:anObject
5048
b1e10ce753fd comment
Claus Gittinger <cg@exept.de>
parents: 4795
diff changeset
  1040
    "return the number of occurrences of anObject in the receiver.
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
  1041
     As I am a Set, this can only return 0 or 1."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1042
5845
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
  1043
    anObject isNil ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1044
	"even if adding nil to a set is forbidden, asking for it should be ok!!"
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1045
	"self invalidElementError."
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1046
	^ 0.
5845
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
  1047
    ].
64a385f14970 Use #invalidElementError to warn about illegal use of nil in Sets
Stefan Vogel <sv@exept.de>
parents: 5834
diff changeset
  1048
362
claus
parents: 359
diff changeset
  1049
    (self find:anObject ifAbsent:0) == 0 ifTrue:[^ 0].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1050
    ^ 1
6191
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
  1051
28ac2bdae9e9 comments;
Claus Gittinger <cg@exept.de>
parents: 6127
diff changeset
  1052
    "Modified: / 16.11.2001 / 10:30:14 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1053
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1054
4795
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1055
sameContentsAs:aCollection
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1056
    "answer true, if all the elements in self and aCollection
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1057
     are common. This is not defined as #=, since we cannot redefine #hash
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1058
     for aCollection."
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1059
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1060
    aCollection size ~~ self size ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1061
	^ false
4795
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1062
    ].
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1063
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1064
    aCollection do:[:e|
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1065
	(self includes:e) ifFalse:[
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1066
	    ^ false.
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1067
	]
4795
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1068
    ].
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1069
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1070
    ^ true.
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1071
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1072
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1073
    "
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1074
      #(1 2 3) asSet sameContentsAs: #(1 2 3)
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1075
      #(1 2 3 4) asSet sameContentsAs: #(1 2 3)
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1076
      #(1 2 3) asSet sameContentsAs: #(1 2 3 3)
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1077
      #(1 2 3 'aa') asSet sameContentsAs: #(1 2 3 'aa')
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1078
      #(1 2 3 'aa') asIdentitySet sameContentsAs: #(1 2 3 'aa')
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1079
      #(1 2 3 #aa) asIdentitySet sameContentsAs: #(1 2 3 #aa)
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1080
    "
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1081
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1082
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1083
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1084
4bdb6488d5b2 New method #sameContentsAs:
Stefan Vogel <sv@exept.de>
parents: 4017
diff changeset
  1085
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1086
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1087
4017
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1088
!Set::EmptySlot class methodsFor:'instance creation'!
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1089
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1090
basicNew
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1091
    TheOneAndOnlyInstance isNil ifTrue:[
6994
0f08c1d8c2ac Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6991
diff changeset
  1092
	TheOneAndOnlyInstance := super basicNew
4017
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1093
    ].
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1094
    ^ TheOneAndOnlyInstance
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1095
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1096
! !
cdf103ce2e30 there can be only one EmptySlot
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
  1097
2259
685b96fb41b6 a better deletedClass
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
  1098
!Set class methodsFor:'documentation'!
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
  1099
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
  1100
version
7311
6878116b0a27 +copyWithout/copyWithoutAll:
Claus Gittinger <cg@exept.de>
parents: 7268
diff changeset
  1101
    ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.86 2003-05-19 18:40:02 cg Exp $'
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
  1102
! !
6917
979bfb9267e3 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6577
diff changeset
  1103
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1104
Set initialize!