|
|
Class: OrderedSet
Object
|
+--Collection
|
+--Set
|
+--OrderedSet
|
+--AbstractFileBrowser::FilenameHistory
- Package:
- stx:libbasic2
- Category:
- Collections-Sequenceable
- Version:
- rev:
1.16
date: 2009/09/11 15:20:04
- user: cg
- file: OrderedSet.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
I am a subclass of Set whose elements are ordered in a
similar fashion to OrderedCollection.
That is, I have both Set behavior (only keeping a single instance of
an element) but I also remember the original order, in which elements
were added.
I have one additional instance variable:
order <OrderedCollection> Ordered collection of values reflecting the order
in the set.
OrderedCollection
Dictionary
OrderedDictionary
Set
Bag
instance creation
-
new
-
-
new: anInteger
-
accessing
-
at: index
-
return the indexed instance variable with index, anInteger.
Report an error, if the index is wrong.
-
at: index ifAbsent: exceptionalValue
-
return the indexed instance variable with index, anInteger.
If not present, return the value from exceptionalValue.
-
order
-
returns the values in the order of their appearance
adding & removing
-
add: anObject
-
Add anObject to the receiver (if not already included).
Also, remember in the order (i.e. add to the end)
If anAssociation is already present in the dictionary,
the order will not be changed. (See also: #addLast:)
-
addFirst: anObject
-
Add anObject to the receiver (if not already included).
Also, remember in the order (i.e. add to the beginning)
-
addLast: anObject
-
Add anObject to the receiver (if not already included).
Also, remember in the order (i.e. add to the end)
If anAssociation is already present in the receiver,
it will be moved to the end. (See also: #add:)
-
remove: oldObject ifAbsent: exceptionValueProvider
-
remove oldObject from the collection and return it.
If it was not in the collection return the value of exceptionValueProvider.
WARNING: do not remove elements while iterating over the receiver.
-
removeAll
-
remove all elements from the receiver. Returns the receiver.
-
removeFirst
-
remove the first object from the collection and return it.
If it was not in the collection, raise an error.
WARNING: do not remove elements while iterating over the receiver.
-
removeFirstIfAbsent: exceptionalValue
-
remove the first object from the collection and return it.
If it was not in the collection, return the value from exceptionalValue.
WARNING: do not remove elements while iterating over the receiver.
-
removeLast
-
remove the last object from the collection and return it.
If it was not in the collection, raise an error.
WARNING: do not remove elements while iterating over the receiver.
-
removeLastIfAbsent: exceptionalValue
-
remove the last object from the collection and return it.
If it was not in the collection, return the value from exceptionalValue.
WARNING: do not remove elements while iterating over the receiver.
-
saveRemove: oldObject
-
remove the element, oldObject from the collection.
Return the element
(could be non-identical to oldObject, since I hash on equality, not on identity).
If it was not in the collection return nil.
In contrast to #remove:, this does not resize the underlying collection
and therefore does NOT rehash & change the elements order.
Therefor this can be used while enumerating the receiver,
which is not possible if #remove: is used.
WARNING: since no resizing is done, the physical amount of memory used
by the container remains the same, although the logical size shrinks.
You may want to manually resize the receiver using #emptyCheck.
(after the loop)
copying
-
postCopy
-
have to copy the keyArray too
enumerating
-
do: aBlock
-
Evaluate aBlock for each of the sets's values
in the order they have been added.
-
reverseDo: aBlock
-
Evaluate aBlock for each of the sets's values
in the reverse order they have been added.
enumerting & searching
-
indexOf: anObject
-
initialization
-
initializeOrder
-
|s|
s := OrderedSet new.
s add:'one'.
s add:'two'.
s add:'one'.
s add:'two'.
s add:'three'.
s size.
s do:[:each | Transcript showCR:each].
|
|s|
s := OrderedSet new.
s add:'one'.
s add:'two'.
s add:'one'.
s add:'two'.
s add:'three'.
s remove:'one'.
s size.
s do:[:each | Transcript showCR:each].
|
|s|
s := OrderedSet new.
s add:'one'.
s addFirst:'two'.
s addFirst:'three'.
s add:'one'.
s add:'two'.
s add:'three'.
s size.
s do:[:each | Transcript showCR:each].
|
|