eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'OrderedDictionary':

Home

everywhere
www.exept.de
for:
[back]

Class: OrderedDictionary


Inheritance:

   Object
   |
   +--Collection
      |
      +--Set
         |
         +--Dictionary
            |
            +--OrderedDictionary

Package:
stx:libbasic2
Category:
Collections-Sequenceable
Version:
rev: 1.31 date: 2009/11/03 17:55:31
user: sr
file: OrderedDictionary.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Ifor Wyn Williams <ifor@uk.ac.man.cs>

Description:


I am a subclass of Dictionary whose elements (associations) are ordered in a
similar fashion to OrderedCollection.
That is, while being filled via #at:put: messages (or similar Dictionary protocol),
the order in which associations are added is remembered and accessable via the #atIndex:
or #order messages.

I have one instance variable:

order <OrderedCollection>       Ordered collection of keys reflecting the order of
                                associations in the dictionary.


Related information:

    OrderedCollection
    Dictionary
    OrderedSet

Class protocol:

instance creation
o  new

o  new: anInteger


Instance protocol:

accessing
o  after: anAssociation
Return the association after anAssociation in the order.
If anAssociation is the last association in the order, return nil.
If anAssociation is not found, invoke an error notifier

o  associations
Return an OrderedCollection containing the receiver's associations.

o  at: aKey ifAbsentPut: valueBlock

o  at: key put: anObject
Set the value at key to be anObject.
If key is not found, create a new entry for key and set is value to anObject.
If key is already present, the order remains unchanged.
Return anObject.

o  atAll: indexCollection put: anObject
Put anObject into the value field of every association specified by indexCollection,
which is typically an interval.

o  atAllPut: anObject
Put anObject into the value field of every association in the dictionary

o  atIndex: index
return an element at a given index

o  atIndex: index put: anAssociation
put an association to a given index. remove the old associatioan at this index

o  before: anAssociation
Return the association before anAssociation in the order.
If anAssociation is the first association in the order, return nil.
If anAssociation is not found, invoke an error notifier

o  first
Return the first association of the receiver.
Provide an error notification if the receiver contains no elements.

o  keyAt: index
get the key at the given index

o  keys
Return a OrderedCollection containing the receiver's keys.

o  last
Return the last association of the receiver.
Provide an error notification if the receiver contains no elements.

o  order
returns the keys in the order of their appearance

o  valueAt: index
get the value at the given index

o  values
Return a OrderedCollection containing the receiver's values.

adding
o  add: anAssociation
add anAssociation to the dictionary.
If anAssociation is already present in the dictionary,
the order will not be changed. (See also: #addLast:)

o  add: anAssociation after: oldAssociation
Add the argument, anAssociation, as an element of the dictionary. Put it
in the position just succeeding oldAssociation. Return anAssociation.

o  add: anAssociation before: oldAssociation
Add the argument, anAssociation, as an element of the dictionary. Put it
in the position just preceding oldAssociation. Return anAssociation.

o  add: anAssociation beforeIndex: spot
Add the argument, anAssociation, as an element of the receiver. Put it
in the position just preceding the indexed position spot. Return newObject.

o  addAll: aCollectionOfAssociations
Add each element of anOrderedCollectionOfAssociations at my end.
We expect the argument to enumerate associations with #reverseDo:;
if it does not (i.e. it is another OD or a dictionary), use #addAllAssociationsFirst:.
Returns the argument, aCollectionOfAssociations (sigh).

o  addAllAssociations: aDictionaryOrOrderedDictionary
Add each association of aDictionaryOrOrderedDictionary to my end.
We expect the argument to respond to #associationsDo:.

o  addAllAssociationsFirst: aDictionaryOrOrderedDictionary
Add each association of aDictionaryOrOrderedDictionary at the beginning of the
receiver. We expect the argument to respond to #associationsReverseDo:.

o  addAllAssociationsLast: aDictionaryOrOrderedDictionary
Add each association of aDictionaryOrOrderedDictionary at the end of the
receiver. We expect the argument to respond to #associationsDo:.

o  addFirst: anAssociation
Add anAssociation to the beginning of the receiver.

o  addLast: anAssociation
Add anAssociation to the end of the receiver.
If anAssociation is already present in the dictionary,
it will be moved to the end. (See also: #add:)

copying
o  copyEmpty
Return a copy of the receiver that contains no elements.

o  copyEmpty: aSize
Return a copy of the receiver that contains no elements.

o  copyFrom: startIndex to: endIndex
Return a copy of the receiver that contains elements from
position startIndex to endIndex.

o  copyWith: anAssociation
Return a copy of the dictionary that is 1 bigger than the receiver and
includes the argument, anAssociation, at the end.

o  copyWithout: anAssociation
Return a copy of the dictionary that is 1 smaller than the receiver and
does not include the argument, anAssociation
No error is reported, if elementToSkip is not in the collection.

o  postCopy
have to copy the order too

enumerating
o  associationsCollect: aBlock
Evaluate aBlock with each of the associations of the dictionary as argument,
and return a new (ordered) collection with the results

o  associationsDo: aBlock
Evaluate aBlock for each of the dictionary's associations.

o  associationsDo: aBlock from: firstIndex to: secondIndex
Evaluate aBlock with each of the dictionary's associations from index
firstIndex to index secondIndex as the argument.

o  associationsReverseDo: aBlock
Evaluate aBlock for each of the dictionary's associations in reverse order.

o  associationsSelect: aBlock
Evaluate aBlock with each of the dictionary's associations as the argument.
Collect into a new OrderedDictionary only those associations for which
aBlock evaluates to true. Return the new OrderedDictionary.

o  collect: aBlock
Evaluate aBlock with each of the values of the dictionary as argument,
and return a new (ordered) collection with the results

o  do: aBlock
Evaluate aBlock for each of the dictionary's values.

o  do: aBlock from: firstIndex to: lastIndex
Evaluate aBlock with each of the dictionary's associations from index
firstIndex to index secondIndex as the argument.

o  findFirst: aBlock ifNone: exceptionalValue
Return the index of the first association in the dictionary for which aBlock
evaluates as true. If the block does not evaluate to true, return exceptionalValue

o  findLast: aBlock
Return the index of the last association in the dictionary for which aBlock
evaluates as true. If the block does not evaluate to true, return 0

o  findLast: aBlock startingAt: startIndex
Return the index of the last association in the dictionary for which aBlock
evaluates as true. Start the search at startIndex.
If the block does not evaluate to true, return 0

o  findLast: aBlock startingAt: startIndex endingAt: endIndex
Return the index of the last association in the dictionary for which aBlock
evaluates as true. Start the search at startIndex.
End the search at endIndex or when an element is found.
If the block does not evaluate to true, return 0

o  from: firstIndex to: lastIndex do: aBlock
Evaluate aBlock with each of the dictionary's associations from index
firstIndex to index secondIndex as the argument.

o  keysAndValuesDo: aBlock
perform the block for all keys in the collection.

See also:
#associationsDo: (which passes key-value associations)
#keysAndValuesDo: (which passes keys & values separately)
#do: (which passes values only)

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

o  keysDo: aBlock
perform the block for all keys in the collection.

See also:
#associationsDo: (which passes key-value associations)
#keysAndValuesDo: (which passes keys & values separately)
#do: (which passes values only)

WARNING: do not add/remove elements while iterating over the receiver.
Iterate over a copy to do this.

o  reverseDo: aBlock
Evaluate aBlock with each of the dictionary's associations as the argument,
starting with the last element and taking each in sequence up to the first.

o  reversed
Return with a new OrderedDictionary with its associations in reverse order.

o  select: aBlock
Evaluate aBlock with each of the dictionary's values as the argument.
Collect into a new OrderedDictionary only those associations for which
aBlock evaluated to true. Return the new OrderedDictionary.

initialization
o  initializeOrder

private
o  removeFromOrder: aKey

queries
o  occurrencesOfKey: aKey
Return how many of the dictionary's keys are equal to aKey.

o  occurrencesOfValue: aValue
Return how many of the dictionary's values are equal to aValue.

removing
o  removeFirst

o  removeFromIndex: fromIndex toIndex: toIndex

o  removeKey: aKey

o  removeLast

searching
o  identityIndexOfAssociation: anAssociation
Return the identity index of anAssociation within the receiver. If the receiver
does not contain anAssociation, return 0.

o  identityIndexOfAssociation: anAssociation ifAbsent: exceptionBlock
Return the identity index of anAssociation within the receiver.
If the receiver does not contain anAssociation,
return the result of evaluating the exceptionBlock.

o  identityIndexOfKey: aKey
Return the identity index of aKey within the receiver. If the receiver
does not contain aKey, return 0.

o  identityIndexOfKey: aKey ifAbsent: exceptionBlock
Return the identity index of aKey within the receiver. If the receiver does
not contain aKey, return the result of evaluating the exceptionBlock.

o  identityIndexOfValue: aValue
Return the identity index of aValue within the receiver. If the receiver
does not contain aValue, return 0.

o  identityIndexOfValue: aValue ifAbsent: exceptionBlock
Return the identity index of aValue within the receiver. If the receiver
does not contain aValue, return the result of evaluating the exceptionBlock.

o  indexOfAssociation: anAssociation
Return the index of anAssociation within the receiver. If the receiver does
not contain anAssociation, return 0.

o  indexOfAssociation: anAssociation ifAbsent: exceptionBlock
Return the identity index of anAssociation within the receiver. If the receiver
does not contain anAssociation, return the result of evaluating the exceptionBlock.

o  indexOfKey: aKey
Return the index of aKey within the receiver. If the receiver does
not contain aKey, return 0.

o  indexOfKey: aKey ifAbsent: exceptionBlock
Return the identity index of aKey within the receiver. If the receiver does
not contain aKey, return the result of evaluating the exceptionBlock.

o  indexOfValue: aValue
Return the index of aValue within the receiver.
If the receiver does not contain aValue, return 0.

o  indexOfValue: aValue ifAbsent: exceptionBlock
Return the identity index of aValue within the receiver.
If the receiver does not contain aValue, return the result of evaluating the exceptionBlock.

o  nextIndexOfAssociation: aAssociation from: startIndex to: stopIndex
Return the next index of aAssociation within the receiver between startIndex
and stopIndex. If the receiver does not contain aAssociation, return nil

o  nextIndexOfKey: aKey from: startIndex to: stopIndex
Return the next index of aKey within the receiver between startIndex and
stopIndex. If the receiver does not contain aKey, return nil

o  nextIndexOfValue: aValue from: startIndex to: stopIndex
Return the next index of aValue within the receiver between startIndex and
stopIndex. If the receiver does not contain aValue, return nil

o  prevIndexOfAssociation: aAssociation from: startIndex to: stopIndex
Return the previous index of aAssociation within the receiver between
startIndex and stopIndex working backwards through the receiver.
If the receiver does not contain aAssociation, return nil

o  prevIndexOfKey: aKey from: startIndex to: stopIndex
Return the previous index of aKey within the receiver between startIndex and
stopIndex working backwards through the receiver.
If the receiver does not contain aKey, return nil

o  prevIndexOfValue: aValue from: startIndex to: stopIndex
Return the previous index of aValue within the receiver between startIndex
and stopIndex working backwards through the receiver.
If the receiver does not contain aValue, return nil

sorting & reordering
o  reverse
Destructively reverse my order.
WARNING: this is a destructive operation, which modifies the receiver.
Please use reversed (with a d) for a functional version.

o  sort
Destructively sort my order.
WARNING: this is a destructive operation, which modifies the receiver

o  sort: aSortBlock
Destructively sort my order.
WARNING: this is a destructive operation, which modifies the receiver


Examples:


|o| o := OrderedDictionary new. o at:'one' put:1. o at:'two' put:2. o at:'three' put:3. o at:'four' put:4. o at:'five' put:5. o at:'six' put:6. o at:'seven' put:7. o at:'eight' put:8. o at:'nine' put:9. o at:'zero' put:0. o at:'eight'. o atIndex:1. o atIndex:5. o atIndex:10. o from:3 to:6 do:[:each | Transcript showCR:each ]. o collect:[:eachAssoc | eachAssoc key -> eachAssoc value squared]. o associations. o order. o reverse. o atIndex:1. o atIndex:5. o atIndex:10.

ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 20:26:55 GMT