|
|
Class: Collection
Object
|
+--Collection
|
+--BTree
|
+--Bag
|
+--BinaryTree
|
+--Iterator
|
+--KeyedCollection
|
+--MappedCollection
|
+--Queue
|
+--SequenceableCollection
|
+--Set
|
+--SharedCollection
|
+--TSTree
|
+--TreeSet
- Package:
- stx:libbasic
- Category:
- Collections-Abstract
- Version:
- rev:
1.241
date: 2010/01/29 16:41:43
- user: cg
- file: Collection.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
Abstract superclass for all collections.
This abstract class provides functionality common to all collections,
without knowing how the concrete class implements things. Thus, all
methods found here depend on some basic mechanisms to be defined in the
concrete class.
These basic methods are usually defined as #subclassResponsibility here.
Some methods are also redefined for better performance.
Subclasses should at least implement:
do: - enumerate elements
they should implement one of the following set of access messages:
keyed collections:
at:ifAbsent: - fetching an element
at: - fetching an element
at:put: - storing an element
unkeyed collections:
add: - add an element
remove:ifAbsent: - remove an element
Compatibility-Squeak
-
ofSize: n
-
return a new collection which really provides space for n elements.
Kludges around the stupid definition of OrderedCollection>>new:
JS syntactic sugar
-
with: el1 _: el2
-
for JS easy syntax - allows: Array.with(el1, el2,...)
-
with: el1 _: el2 _: el3
-
for JS easy syntax - allows: Array.with(el1, el2,...)
-
with: el1 _: el2 _: el3 _: el4
-
for JS easy syntax - allows: Array.with(el1, el2,...)
-
with: el1 _: el2 _: el3 _: el4 _: el5
-
for JS easy syntax - allows: Array.with(el1, el2,...)
-
with: el1 _: el2 _: el3 _: el4 _: el5 _: el6
-
for JS easy syntax - allows: Array.with(el1, el2,...)
-
with: el1 _: el2 _: el3 _: el4 _: el5 _: el6 _: el7
-
for JS easy syntax - allows: Array.with(el1, el2,...)
-
with: el1 _: el2 _: el3 _: el4 _: el5 _: el6 _: el7 _: el8
-
for JS easy syntax - allows: Array.with(el1, el2,...)
Signal constants
-
emptyCollectionSignal
-
return the signal used to report non-allowed operation on empty collections
-
invalidKeySignal
-
return the signal used to report bad key usage
-
notEnoughElementsSignal
-
return the signal used to report attempts for an operation, for which
there are not enough elements in the collection
-
valueNotFoundSignal
-
return the signal used to report a nonexisting element.
initialization
-
initialize
-
setup the signal
instance creation
-
new: size withAll: element
-
return a new Collection of size, where all elements are
initialized to element
-
newFrom: aCollection
-
Return an instance of me containing the same elements as aCollection.
-
with: anObject
-
return a new Collection with one element:anObject
-
with: firstObject with: secondObject
-
return a new Collection with two elements:firstObject and secondObject
-
with: firstObject with: secondObject with: thirdObject
-
return a new Collection with three elements
-
with: firstObject with: secondObject with: thirdObject with: fourthObject
-
return a new Collection with four elements
-
with: a1 with: a2 with: a3 with: a4 with: a5
-
return a new Collection with five elements
-
with: a1 with: a2 with: a3 with: a4 with: a5 with: a6
-
return a new Collection with size elements
-
with: a1 with: a2 with: a3 with: a4 with: a5 with: a6 with: a7
-
return a new Collection with seven elements
-
with: a1 with: a2 with: a3 with: a4 with: a5 with: a6 with: a7 with: a8
-
return a new Collection with eight elements
-
withAll: aCollection
-
return a new Collection with all elements taken from the argument,
aCollection
-
withSize: n
-
return a new collection which really provides space for n elements.
Kludges around the stupid definition of OrderedCollection>>new:
misc ui support
-
iconInBrowserSymbol
-
queries
-
growIsCheap
-
return true, if this collection can easily grow
(i.e. without a need for become:).
Returns true here; this method is redefined in fix-size
collections
-
isAbstract
-
Return if this class is an abstract class.
True is returned for Collection here; false for subclasses.
Abstract subclasses must redefine again.
Compatibility-Dolphin
-
identityIncludes: anObject
-
return true, if the argument, anObject is in the collection.
Same as #includesIdentical for Dolphin compatibility.
-
includesAnyOf: aCollection
-
same as #includesAny for Dolphin compatibility.
-
symmetricDifference: aCollection
-
return a new set containing all elements,
which are contained in either the receiver or aCollection, but not in both.
Same as xor: - for compatibility
Compatibility-Squeak
-
addIfNotPresent: anObject
-
Include anObject as one of the receiver's elements, but only if there
is no such element already. Anwser anObject.
-
anyOne
-
return any element from the collection.
Report an error if there is none.
Same as #anElement - for Squeak compatibility
-
difference: aCollection
-
Answer the set-theoretic difference of two collections.
-
gather: aBlock
-
return an Array,
containing all elements as returned from applying aBlock to each element if the receiver,
where the block returns a collection of to-be-added elements.
This could also be called: collectAllAsArray:
-
gather: aBlock as: aClass
-
return an instance of the collection-class aClass,
containing all elements as returned from applying aBlock to each element if the receiver.
where the block returns a collection of to-be-added elements.
This could also be called: collectAll:as:
-
groupBy: keyBlock having: selectBlock
-
Like in SQL operation - Split the receiver's contents into collections of
elements for which keyBlock returns the same results, and return those
collections allowed by selectBlock.
-
ifEmpty: ifEmptyValue ifNotEmpty: ifNotEmptyValue
-
-
ifEmpty: ifEmptyValue ifNotEmptyDo: ifNotEmptyValue
-
-
ifEmptyDo: ifEmptyValue ifNotEmpty: ifNotEmptyValue
-
-
ifNotEmpty: ifNotEmptyValue
-
-
ifNotEmptyDo: ifNotEmptyValue
-
-
ifNotEmptyDo: ifNotEmptyValue ifEmpty: ifEmptyValue
-
-
intersection: aCollection
-
-
withIndexDo: aTwoArgBlock
-
evaluate the argument, aBlock for every element in the collection,
passing both element and index as arguments.
JavaScript support
-
length
-
returns the length of the string
accessing
-
anElement
-
return any element from the collection,
report an error if there is none
-
atAll: indexCollection put: anObject
-
put anObject into all indexes from indexCollection in the receiver.
This abstract implementation requires that the receiver supports
access via a key (and indexCollection contains valid keys).
Notice: This operation modifies the receiver, NOT a copy;
therefore the change may affect all others referencing the receiver.
-
fifth
-
return the fifth element of the collection.
For unordered collections, this simply returns the fifth
element when enumerating them.
This should be redefined in subclasses.
-
first
-
return the first element of the collection.
For unordered collections, this simply returns the first
element when enumerating them.
This should be redefined in subclasses.
-
first: n
-
return the n first elements of the collection.
Raises an error if there are not enough elements in the receiver.
For unordered collections, this simply returns the first
n elements when enumerating them
(Warning: the contents of the returned collection is not deterministic in this case).
This should be redefined in subclasses.
-
firstIfEmpty: exceptionValue
-
return the first element of the collection.
If its empty, return the exceptionValue.
(i.e. dont trigger an error as done in #first)
-
firstOrNil
-
return the first element of the collection.
If its empty, return nil.
(i.e. dont trigger an error as done in #first)
-
fourth
-
return the fourth element of the collection.
For unordered collections, this simply returns the fourth
element when enumerating them.
This should be redefined in subclasses.
-
last
-
return the last element of the collection.
This should be redefined in subclasses.
-
last: n
-
return the n last elements of the collection.
Raises an error if there are not enough elements in the receiver.
For unordered collections, this simply returns the last
n elements when enumerating them
(Warning: the contents of the returned collection is not deterministic in this case).
This should be redefined in subclasses since the implementation here is VERY inefficient.
-
lastIfEmpty: exceptionValue
-
return the last element of the collection.
If its empty, return the exceptionValue.
(i.e. dont trigger an error as done in #last)
-
median
-
Return the middle element, or as close as we can get.
-
nth: n
-
return the nth element of the collection.
For unordered collections, this simply returns the nth
element when enumerating them.
This should be redefined in subclasses.
-
order
-
report an error that only OrderedXXX's have an order
-
second
-
return the second element of the collection.
For unordered collections, this simply returns the second
element when enumerating them.
This should be redefined in subclasses.
-
seventh
-
return the seventh element of the collection.
For unordered collections, this simply returns the sixth
element when enumerating them.
This should be redefined in subclasses.
-
sixth
-
return the sixth element of the collection.
For unordered collections, this simply returns the sixth
element when enumerating them.
This should be redefined in subclasses.
-
third
-
return the third element of the collection.
For unordered collections, this simply returns the third
element when enumerating them.
This should be redefined in subclasses.
-
values
-
return a collection containing all values of the receiver.
This is to make value access to an OrderedDictionary compatible with any-Collection
adding & removing
-
add: anObject
-
add the argument, anObject to the receiver.
If the receiver is ordered, the position of the new element is undefined
(i.e. don't depend on where it will be put).
An error is raised here - it is to be implemented by a concrete subclass.
** This method raises an error - it must be redefined in concrete classes **
-
add: newObject withOccurrences: anInteger
-
add the argument, anObject anInteger times to the receiver.
Returns the object.
-
addAll: aCollection
-
add all elements of the argument, aCollection to the receiver.
Returns the argument, aCollection (sigh).
-
addAllFirst: aCollection
-
insert all elements of the argument, aCollection at the beginning
of the receiver. Returns the argument, aCollection.
-
addAllLast: aCollection
-
add all elements of the argument, aCollection to the receiver.
Returns the argument, aCollection.
-
addFirst: anObject
-
add the argument, anObject to the receiver.
If the receiver is ordered, the new element will be added at the beginning.
An error is raised here - it is to be implemented by a concrete subclass.
** This method raises an error - it must be redefined in concrete classes **
-
addLast: anObject
-
add the argument, anObject to the receiver.
If the receiver is ordered, the new element will be added at the end.
Return the argument, anObject.
This usually has the same semantics as #add:.
OrderedSet and OrderedDictionary redefine this, to move anObject to
the end, even if it is already present in the collection.
-
contents: aCollection
-
set my contents from aCollection
- this may be redefined in a concrete subclass for more performance
-
remove: anObject
-
search for the first element, which is equal to anObject;
if found, remove and return it.
If not found, report a 'value not found'-error.
Uses equality compare (=) to search for the occurrence.
-
remove: anObject ifAbsent: exceptionBlock
-
search for the first element, which is equal to anObject;
if found, remove and return it.
If not found, return the the value of the exceptionBlock.
Uses equality compare (=) to search for the occurrence.
An error is raised here - it is to be implemented by a concrete subclass.
** This method raises an error - it must be redefined in concrete classes **
-
removeAll
-
remove all elements from the receiver. Returns the receiver.
This should be reimplemented in subclasses for better
performance.
-
removeAll: aCollection
-
remove all elements of the argument, aCollection from the receiver.
Return the argument, aCollection.
Raises an error, if some element-to-remove is not in the receiver.
(see also: #removeAllFoundIn:, which does not raise an error).
Notice: for some collections (those not tuned for
resizing themself) this may be very slow.
If the number of removed elements is big compared to to
the receivers size, it may be better to copy the
ones which are not to be removed into a new collection.
-
removeAllFoundIn: aCollection
-
Remove each element of aCollection, which is present in the receiver
from the receiver.
No error is raised, if some element-to-remove is not in the receiver.
(see also: #removeAll:, which does raise an error).
-
removeAllKeys: aCollection
-
remove all keys of the argument, aCollection from the receiver.
Raises an error, if some element-to-remove is not in the receiver.
Notice: only works for keyed collections, such as dictionaries.
-
removeAllSuchThat: aBlock
-
Apply the condition to each element and remove it if the condition is true.
Return a collection of removed elements.
First elements-to-remove are collected, then removed in one operation.
-
removeFirst
-
remove the first element from the receiver.
Return the removed element.
-
removeFirst: n
-
remove the first n elements from the receiver.
Return a collection of removed elements.
Notice: for some collections (those not tuned for
resizing themself) this may be very slow.
-
removeIdentical: anObject
-
search for the first element, which is identical to anObject;
if found, remove and return it.
If not found, report a 'value not found'-error.
Uses identity compare (==) to search for the occurrence.
-
removeIdentical: anObject ifAbsent: exceptionBlock
-
search for the first element, which is identical to anObject;
if found, remove and return it.
If not found, return the the value of the exceptionBlock.
Uses identity compare (==) to search for the occurrence.
An error is raised here - it is to be implemented by a concrete subclass.
** This method raises an error - it must be redefined in concrete classes **
-
removeLast
-
remove the last element from the receiver.
Return the removed element.
An error is raised here - it is to be implemented by a concrete subclass.
** This method raises an error - it must be redefined in concrete classes **
-
removeLast: n
-
remove the last n elements from the receiver collection.
Return a collection of removed elements.
Notice: for some collections this may be very slow
(those not tuned for resizing themself).
bulk operations
-
abs
-
Absolute value of all elements in the collection
-
negated
-
Negated value of all elements in the collection
-
product
-
multiply up all elements.
-
sum
-
sum up all elements; return 0 for an empty collection.
-
sum: aBlock
-
for each element in the receiver, evaluate the argument, aBlock
and sum up the results. Return the total sum or 0 for an empty collection.
Similar to (self collect...) sum, but avoids creation of an intermediate collection.
converting
-
asArray
-
return a new Array with the collections elements
-
asBag
-
return a new Bag with the receiver collections elements
-
asByteArray
-
return a new ByteArray with the collections elements
(which must convert to 8bit integers in the range 0..255).
-
asCollection
-
return myself as a Collection.
I am already a Collection.
-
asDictionary
-
return a new Dictionary with the receiver collections elements
-
asDoubleArray
-
return a new DoubleArray with the collections elements
(which must convert to 64bit floats).
-
asFlatOrderedCollection
-
-
asFloatArray
-
return a new FloatArray with the collections elements
(which must convert to 32bit floats).
-
asIdentitySet
-
return a new IdentitySet with the receiver collections elements
-
asIntegerArray
-
return a new IntegerArray with the collection's elements
(which must convert to 32bit integers in the range 0..16rFFFFFFFF).
-
asIntegerArray: arrayClass
-
return a new Array with the collection's elements
-
asList
-
return a new List with the receiver collections elements
-
asLongIntegerArray
-
return a new LongIntegerArray with the collections elements
(which must convert to 64bit integers in the range 0..16rFFFFFFFFFFFFFFFF).
-
asOrderedCollection
-
return a new OrderedCollection with the receiver collections elements
-
asRunArray
-
return a new RunArray with the collections elements
-
asSequenceableCollection
-
return myself as a SequenceableCollection.
I am already a Collection, but not sequenceable.
-
asSet
-
return a new Set with the receiver collections elements
-
asSharedCollection
-
return a shared collection on the receiver.
This implements synchronized access to me.
-
asSortedCollection
-
return a new SortedCollection with the receiver collections elements
-
asSortedCollection: sortBlock
-
return a new SortedCollection with the receiver collections elements,
using sortBlock for comparing
-
asSortedStrings
-
Create & return a SortedCollection that sorts the receivers
elements according to the locales collating policy.
This is currently not really support - strings are sorted
without caring for the locale.
-
asSortedStrings: sortBlock
-
Create & return a SortedCollection that sorts the receivers
elements using sortBlock and according to the locales collating policy,
which is passed as first arg to sortBlock.
This is currently not really support - strings are sorted
without caring for the locale.
-
asSortedStrings: sortBlock with: aCollationPolicy
-
Create & return a SortedCollection that sorts the receivers
elements using sortBlock and according to the specified locales collating policy.
This is currently not really support - strings are sorted
without caring for the locale.
-
asSortedStringsWith: aCollationPolicy
-
Create & return a SortedCollection that sorts the receivers
elements according to the specified locales collating policy.
This is currently not really support - strings are sorted
without caring for the locale.
-
asString
-
return a String with the collection's elements
(which must convert to characters)
-
asStringCollection
-
return a new string collection containing the elements;
these ought to be strings. (i.e. String or Text instances)
-
asUnicodeString
-
return a String with the collections elements
(which must convert to characters)
-
asWordArray
-
return a new WordArray with the collections elements
(which must convert to integers in the range 0..16rFFFF).
-
copyAs: collectionClass
-
return a new instance of collectionClass with the receiver collection's elements.
This is similar to copy as:collectionClass, to ensure that we get a new
(unshared) collection, but avoids the copy if the receiver is not already an
instance of collectionClass.
-
copyAsOrderedCollection
-
return a new OrderedCollection with the receiver collection's elements.
This is similar to copy asOrderedCollection, to ensure that we get a new
(unshared) collection, but avoids the copy if the receiver is not already an
OrderedCollection.
-
keysAndValues
-
-
literalArrayEncoding
-
encode myself as an array literal, from which a copy of the receiver
can be reconstructed with #decodeAsLiteralArray.
-
readStream
-
return a stream for reading from the receiver
-
readStreamOrNil
-
return a stream for reading from the receiver.
This has been defined for protocol compatibility with FileName,
but nil is never returned here
-
readWriteStream
-
return a stream for reading and writing from/to the receiver
-
writeStream
-
return a stream for writing onto the receiver
-
writeStreamOrNil
-
return a stream for writing onto the receiver.
This has been defined for protocol compatibility with FileName,
but nil is never returned here
copying
-
copy
-
return a copy of the receiver.
Redefined to pass the original as argument to the postCopyFrom method.
-
copyEmpty
-
return a copy of the receiver with no elements.
This is used by copying and enumeration methods
to get a new instance which is similar to the receiver.
-
copyEmpty: size
-
return a copy of the receiver with no elements, but space for
size elements. This is used by copying and enumeration methods
to get a new instance which is similar to the receiver.
This method should be redefined in subclasses with instance
variables, which should be put into the copy too.
For example, SortedCollection has to copy its sortBlock into the
new collection.
-
copyEmptyAndGrow: size
-
return a copy of the receiver with size nil elements.
This is used by copying and enumeration methods
to get a new instance which is similar to the receiver.
-
postCopyFrom: original
-
sent to a freshly copied object to give it a chance to adjust things.
Notice, that for Sets/Dicts etc. a rehash is not needed, since the copy
will have the same hash key as the receiver (as long as ST/X provides the
setHash: functionality).
enumerating
-
addAllNonNilElementsTo: aCollection
-
add all nonNil elements of the receiver to aCollection.
Return aCollection.
-
addAllTo: aCollection
-
add all elements of the receiver, to aCollection.
Return aCollection.
-
collect: aBlock
-
for each element in the receiver, evaluate the argument, aBlock
and return a new collection with the results
-
collect: aBlock as: aClass
-
like collect, but use an instance of aClass to collect the results.
Also avoids the need for an extra intermediate collection which is created with
the standard coding: 'self asXXXX collect:[...]
-
collect: collectBlock thenReject: rejectBlock
-
combination of collect followed by reject.
May be redefined by some subclasses for optimal performance
(avoiding the creation of intermediate garbage)
-
collect: collectBlock thenSelect: selectBlock
-
combination of collect followed by select.
May be redefined by some subclasses for optimal performance
(avoiding the creation of intermediate garbage)
-
collectAll: aBlock
-
for each element in the receiver, evaluate the argument, aBlock.
The block is supposed to return a collection, whose elements are collected.
The species of the returned collection is that of the first returned
partial result.
-
count: aBlock
-
count elements, for which aBlock returns true.
Return the sum.
-
detect: aBlock
-
evaluate the argument, aBlock for each element in the receiver until
the block returns true; in this case return the element which caused
the true evaluation.
If none of the evaluations returns true, report an error
-
detect: generatorBlock forWhich: testBlock ifNone: exceptionBlock
-
evaluate generatorBlock for each element in the receiver until
testBlock returns true for it;
in this case return the value from generatorBlock, which caused the true evaluation.
If none of the test evaluations returns true, return the result of the
evaluation of the exceptionBlock
-
detect: aOneArgBlock ifNone: exceptionBlock
-
evaluate the argument, aBlock for each element in the receiver until
the block returns true; in this case return the element which caused
the true evaluation.
If none of the evaluations returns true, return the result of the
evaluation of the exceptionBlock
-
detectLast: aBlock
-
evaluate the argument, aBlock for each element in the receiver until
the block returns true; in this case return the element which caused
the true evaluation. The elements are processed in reverse order.
If none of the evaluations returns true, report an error
-
detectLast: aBlock ifNone: exceptionBlock
-
evaluate the argument, aBlock for each element in the receiver until
the block returns true; in this case return the element which caused
the true evaluation. The elements are processed in reverse order.
If none of the evaluations returns true, return the result of the
evaluation of the exceptionBlock
-
do: aBlock
-
evaluate the argument, aBlock for each element
** This method raises an error - it must be redefined in concrete classes **
-
do: aBlock inBetweenDo: betweenBlock
-
evaluate the argument, aBlock for each element.
Between elements (i.e. after each except for the last),
evaluate betweenBlock.
This is a utility helper for collection printers
(for example, to print a space between elements).
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
do: aBlock separatedBy: betweenBlock
-
evaluate the argument, aBlock for each element.
Between elements (i.e. after each except for the last),
evaluate betweenBlock.
This is a utility helper for collection printers
(for example, to print a space between elements).
-
doWithExit: aBlock
-
evaluate the argument, aBlock for each element.
Passes an additional exit object, which can be used to leave
the loop early, by sending it a #value: message.
Returns nil or the value passed to the exit>>value: message.
Notice, that this is different to a return statement in the block,
which returns from the enclosed method, NOT only from the block.
-
flatDo: aBlock
-
for each element of the collection, if its a scalar, evaluate aBlock for it;
otherwise, recursively invoke flatDo on the collection.
-
inject: thisValue into: binaryBlock
-
starting with thisValue for value, pass this value and each element
to binaryBlock, replacing value with the result returned from the block
in the next iteration.
-
keysAndValuesDo: aTwoArgBlock
-
evaluate the argument, aBlock for every element in the collection,
passing both index and element as arguments.
-
keysAndValuesReverseDo: aTwoArgBlock
-
evaluate the argument, aBlock in reverse order for every element in the collection,
passing both index and element as arguments.
-
keysAndValuesSelect: selectBlockWith2Args thenCollect: collectBlockWith2Args
-
-
map: selector
-
for lisp fans - similar to collect
-
map: selector with: arg
-
for lisp fans - similar to collect
-
nonNilElementsDo: aBlock
-
evaluate the argument, aBlock for every non-nil element in the collection.
-
pairsDo: aTwoArgBlock
-
evaluate the argument, aTwoArgBlock for every element in the collection,
which is supposed to consist of 2-element collections.
The block is called with 2 arguments for each collection in the receiver.
CONFUSION ATTACK:
this is different from pairWiseDo:.
but the Squeak-pairsDo: does the same as our pairWiseDo:
(sigh: but we were first, so they should have adapted...)
-
reject: aBlock
-
return a new collection with all elements from the receiver, for which
the argument aBlock evaluates to false
-
reject: rejectBlock thenCollect: collectBlock
-
combination of reject followed by collect.
May be redefined by some subclasses for optimal performance
(avoiding the creation of intermediate garbage)
-
reverseDo: aBlock
-
evaluate the argument, aBlock for each element in reverse order.
** This method raises an error - it must be redefined in concrete classes **
-
select: aBlock
-
return a new collection with all elements from the receiver, for which
the argument aBlock evaluates to true.
See also: #removeAllFoundIn: and #removeAllSuchThat:
-
select: aBlock ifNone: exceptionBlock
-
try a new collection with all elements from the receiver, for which
the argument aBlock evaluates to true. If none of the elements passes
the check of aBlock, return the result of evaluating exceptionBlock.
See also: #removeAllFoundIn: and #removeAllSuchThat:
-
select: selectBlock thenCollect: collectBlock
-
combination of select followed by collect.
May be redefined by some subclasses for optimal performance
(avoiding the creation of intermediate garbage)
-
select: selectBlock thenDo: doBlock
-
combination of select followed by do
Avoids the creation of intermediate garbage
-
triplesDo: aBlock
-
evaluate the argument, aBlock for every element in the collection,
which is supposed to consist of 3-element collections.
The block is called with 3 arguments for each collection in the receiver.
-
with: aCollection collect: aTwoArgBlock
-
evaluate the argument, aBlock for successive elements from
each the receiver and the argument, aSequenceableCollection;
The second argument, aBlock must be a two-argument block, which is
evaluated for each element-pair.
Collect the results and return a collection containing them.
This method fails if neither the receiver nor aCollection is
a sequenceable collection (i.e. implements numeric key access).
-
with: aCollection count: aTwoArgBlock
-
evaluate the argument, aBlock for successive elements from
each the receiver and the argument, aSequenceableCollection.
Count, how often the second argument, aTwoArgBlock returns true.
This method fails if neither the receiver nor aCollection is
a sequenceable collection (i.e. implements numeric key access).
-
with: aCollection do: aTwoArgBlock
-
evaluate the argument, aBlock for successive elements from
each the receiver and the argument, aSequenceableCollection.
The second argument, aBlock must be a two-argument block.
This method fails if neither the receiver nor aCollection is
a sequenceable collection (i.e. implements numeric key access).
enumerating-tests
-
allSatisfy: aBlock
-
evaluate aBlock for each of the receiver's elements.
Return true, if aBlock returns true for all elements, false otherwise
(i.e. false if any element fails to satisfy the block-condition).
This is an ANSI renomer of #conform:
-
anySatisfy: aBlock
-
evaluate aBlock for each of the receiver's elements.
Return true, if aBlock ever returns true, false otherwise
(i.e. if any element satisfies the block-condition).
This is an ANSI renomer of #contains:
-
conform: aOneArgBlock
-
return true, if every element conforms to some condition.
I.e. return false, if aBlock returns false for any element;
true otherwise.
-
contains: aOneArgBlock
-
evaluate aOneArgBlock for each of the receiver's elements.
Return true, if aBlock ever returns true, false otherwise.
-
noneSatisfy: aBlock
-
evaluate aBlock for each of the receiver's elements.
Return true, if aBlock returns false for all elements, false otherwise
(i.e. false if any element satisfies the block-condition).
error handling
-
emptyCheck
-
check if the receiver is empty; report an error if so
-
emptyCollectionError
-
report an error that the operation is not allowed for
empty collections
-
errorInvalidKey: aKey
-
report an error that the given key was invalid
-
errorNotKeyed
-
report an error that keyed access methods are not allowed
-
errorValueNotFound: anObject
-
report an error that an object was not found in the collection
-
notEnoughElementsError
-
report an error that the operation is not allowed,
since not enough elements are in the collection
growing
-
changeCapacityTo: newSize
-
-
grow
-
make the receiver larger
-
grow: howBig
-
change the receivers size
** This method raises an error - it must be redefined in concrete classes **
-
growSize
-
return a suitable size increment for growing.
The default returned here may be (and is) redefined in subclasses.
inspecting
-
inspectorExtraAttributes
-
extra (pseudo instvar) entries to be shown in an inspector.
operations
-
decrementAt: aKey
-
-
incrementAt: aKey
-
printing & storing
-
displayString
-
return a printed representation of the receiver for display in inspectors etc.
-
displayStringName
-
redefinable helper for displayString
-
maxPrint
-
the print-limit; printOn: will try to not produce more output
than the limit defined here.
-
printElementsDo: aBlock
-
perform aBlock (1 arg) for all elements.
Used in #printOn:.
Subclasses (e.g. Dictionary) may redefine this.
-
printElementsOn: aStream
-
append a user readable representation of the receiver to aStream.
The text appended is not meant to be read back for reconstruction of
the receiver. Also, this method limits the size of generated string.
-
printOn: aStream
-
append a user readable representation of the receiver to aStream.
The text appended is not meant to be read back for reconstruction of
the receiver. Also, this method limits the size of generated string.
-
storeOn: aStream
-
output a printed representation onto the argument, aStream.
The text can be re-read to reconstruct (a copy of) the receiver.
Recursive (i.e. cyclic) collections cannot be stored correctly
(use storeBinaryOn: to handle those).
queries
-
defaultElement
-
-
largest: n
-
return the n largest elements
-
longestCommonPrefix
-
return the longest common prefix of my elements.
Typically used with string collections.
-
longestCommonPrefixIgnoreCase: ignoreCase
-
return the longest common prefix of my elements (which must be sequenceableCollections).
Typically used with string collections,
especially with completion of selectors or filenames.
-
longestCommonSuffix
-
return the longest common suffix (tail) of my elements.
Typically used with string collections.
-
longestCommonSuffixIgnoreCase: ignoreCase
-
return the longest common suffix (tail) of my elements
(which must be sequenceableCollections).
-
max
-
return the maximum value in the receiver collection,
using #< to compare elements.
Raises an error, if the receiver is empty.
-
min
-
return the minimum value in the receiver collection,
using < to compare elements.
Raises an error, if the receiver is empty.
-
minMax
-
return the minimum and maximum values in the receiver collection
as a two element array, using #< to compare elements.
Raises an error, if the receiver is empty.
-
nthLargest: n
-
return the n-largest element
-
size
-
return the number of elements in the receiver.
This is usually redefined in subclasses for more performance.
-
speciesForAdding
-
like species, but redefined for collections which cannot grow easily.
Used by functions which create a growing collection (see collect:with:, for example)
searching
-
findFirst: aBlock
-
find the index of the first element, for which evaluation of the argument, aBlock
returns true; return its index or 0 if none detected.
This is much like #detect, however, here an INDEX is returned,
while #detect returns the element.
set operations
-
\ aCollection
-
return a new set containing all elements of the receiver,
which are NOT also contained in the aCollection
For large collections you better use a Set for aCollection
-
intersect: aCollection
-
return a new set containing all elements of the receiver,
which are also contained in the argument collection.
For large collections you better use a Set for self
-
union: aCollection
-
return a new set containing all elements of the receiver
plus those of the aCollection
-
xor: aCollection
-
return a new set containing all elements,
which are contained in either the receiver or aCollection, but not in both.
For large collections you better use Sets for both self and aCollection
sorting & reordering
-
topologicalSort
-
Sort a partial ordered collection.
The receiver consists of tupels defining a partial order.
Use the algorithm by R. E. Tarjan from 1972.
Answer an OrderedCollection containing the sorted items
testing
-
capacity
-
return the number of elements, that the receiver is
prepared to take. For most collections, this is the actual
size. However, some have more space preallocated to allow
for faster adding of elements.
Not used by the system; added for ST-80 compatibility.
-
includes: anElement
-
return true, if an object equal to the argument, anObject is in the list.
This compares using #= (i.e. it does not look for the object itself,
instead, one that compares equal).
See #includesIdentical: when identity is asked for.
This is a *very* slow fallback - many subclasses redefine this for performance.
-
includesAll: aCollection
-
return true, if the the receiver includes all elements of
the argument, aCollection; false if any is missing.
Notice: this method has O-square runtime behavior and may be
slow for big receivers/args.
Think about using a Set, or Dictionary.
-
includesAny: aCollection
-
return true, if the the receiver includes any elements of
the argument, aCollection; false if it includes none.
Notice: this method has O^2(N) runtime behavior and may be
slow for big receivers/args.
Think about using a Set or Dictionary.
Some speedup is also possible, by arranging highly
probable elements towards the beginning of aCollection,
to avoid useless searches.
-
includesAnyIdentical: aCollection
-
return true, if the the receiver includes any elements of
the argument, aCollection; false if it includes none.
Use identity compare for comparing.
Notice: this method has O^2(N) runtime behavior and may be
slow for big receivers/args.
Think about using a Set or Dictionary.
Some speedup is also possible, by arranging highly
probable elements towards the beginning of aCollection,
to avoid useless searches.
-
includesIdentical: anElement
-
return true, if the argument, anObject is in the collection.
This compares using #== (i.e. object identity).
See #includes: when equality is asked for.
This is a *very* slow fallback - many subclasses redefine this for performance.
-
isCollection
-
return true, if the receiver is some kind of collection;
true is returned here - the method is redefined from Object.
-
isEmpty
-
return true, if the receiver is empty
-
isEmptyOrNil
-
return true if I am nil or an empty collection - true here, if the receivers size is 0,
(from Sqeak)
-
isNilOrEmptyCollection
-
return true if I am nil or an empty collection - false here.
Obsolete, use isEmptyOrNil.
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
isNonByteCollection
-
return true, if the receiver is some kind of collection, but not a String, ByteArray etc.;
true is returned here - the method is redefined from Object.
-
isSorted
-
return true, if the receiver is sorted.
Collections which hold their elements in sorted order
should return true. Some algorithms (quicksort) degenerate when
operating on sorted collections and can be avoided if this information
is given. The default returned here (false) should not hurt.
I.e. you should NEVER depend on that in your application.
-
isSortedBy: aBlock
-
return true, if my elements are sorted (already) by the given criterion (sortBlock).
Collections which hold their elements in sorted order
should return true. Some algorithms (quicksort) degenerate when
operating on sorted collections and can be avoided if this information
is given. The default returned here (false) should not hurt.
I.e. you should NEVER depend on that in your application.
-
isSortedCollection
-
return true, if the receiver is a sortedCollection.
-
isWeakCollection
-
return true, if the receiver has weak references to its elements.
-
notEmpty
-
return true, if the receiver is not empty
-
notEmptyOrNil
-
Squeak compatibility:
return true if I am neither nil nor an empty collection.
-
occurrencesOf: anElement
-
return the number of occurrences of the argument, anElement in
the receiver. Uses #= (i.e. equality) compare.
-
occurrencesOfAny: aCollectionOfElements
-
return the number of occurrences of any in aCollectionOfElements in the receiver.
Uses #= (i.e. equality) compare.
Should be redefined in subclass(es) if ever used heavily.
tracing
-
traceInto: aRequestor level: level from: referrer
-
double dispatch into tracer, passing my type implicitely in the selector
visiting
-
acceptVisitor: aVisitor with: aParameter
-
|