Collections

Several object types are designed as collections or containers for other objects. For example, an array is just a linear, possibly heterogeneous, collection of objects. You access each element by an indexing from 1 to the number of elements in the array. The types of collections you can create include array, stack, dictionary, directory, node or set.

PartsList

All objects except the basic objects consist of a collection of parts. Type PartsList is an abstract type which provides rudimentary access to these parts. All types except the basic types should be subtypes of PartsList. These methods should rarely be used since no type checking is being done. For additional functionality, refer to Type Object.

Instance Methods

This section lists methods which are available to all instances of Partslist.

at index:Integer
REPLY Object

Reply with the object at position index in the object. Index can range from 1 to the number of parts.

at index:Integer put anObject:Object

Replace the part at position index with anObject.

do aBlock:Block

Execute aBlock for each part in the object. The block variable will contain the part.

copyPartsOf aPartsList:PartsList

Replace the parts in me with the parts in aPartsList. Nothing is done if me and aPartsList are not the same type.

manage aTitle:String at aPoint:Point
REPLY Manager

Invoke the Parts Manager to allow the user to view and edit me as a list of parts. Put the manager at aPoint with title aTitle.

Array

Type Array is a linear array of objects indexed from 1 to the number of objects in the array. The objects can be heterogeneous. The maximum size of the array is about 2000 objects. For additional functionality, refer to Type PartsList.

Type Methods

This section lists methods available when Type Array is receiver.

new

Reply with a new empty array.

newSize n:Integer

Reply with an array of n NILs.

Instance Methods

This section lists methods which are available to all instances of Partslist.

remove anObject:Object

Reply with anObject deleted from me.

append anObject:Object

Reply with a list consisting of anObject added on the end of me.

appendArray anArray:Array

Reply with a new array consisting of the elements of me followed by the elements of anArray.

asString
REPLY String

Reply with a string representation of me. It is a concatenation of all of the string representation of the elements.

insert anObject:Object at index:Integer

Insert anObject at position index of me and reply with the new list.

delete index:Integer

Delete the object at position index of me and reply with the new list.

move source:Integer to dest:Integer

Move object located at position source to position dest. Move objects in between up or down as appropriate.
SIGNAL "Source out of bounds"
SIGNAL "Destination out of bounds"

swap source:Integer with dest:Integer

Swap object at position source with object at position dest.

Dictionary

Type Dictionary supports the storage of objects under names. The objects are stored alphabetically and are searched using a binary search. A dictionary can hold up to 2000 entries and they may be heterogeneous. The dictionary will automatically grow as items are added. For additional functionality, refer to Type PartsList.

Parts

entries:Array (an array of associations)
tally:Integer (the number of actual entries)

Type Methods

This section lists methods available when Type Dictionary is receiver.

new

Reply with an empty dictionary.

Instance Methods

This section lists methods which are available to all instances of Dictionary.

at name:String ifAbsentDo aBlock:Block
REPLY Object

Reply with the object stored under name. If it is not found, reply with NIL and execute aBlock.

locate name:String
REPLY Integer

Reply with the position of name in entries. If not found reply with the negative of the position where it should be inserted.

at name:String
REPLY Object

Reply with the object stored under name. Reply with NIL if not found.

at name:String put anElement:Object

Store anElement under name. If it already exists, replace it.

delete name:String

Delete the object stored under name. Do nothing if not found.

size
REPLY Integer

Reply with the number of stored objects.

do aBlock:Block

Execute aBlock for each object in the system. The block variables will be the name of the object and the object itself.

fullcopy

Make a complete copy of the dictionary but not the objects stored in it.

at loc:Integer insert assoc:Association

Insert the association assoc at position loc, expanding as needed.
SIGNAL "Dictionary size at maximum"

names
REPLY Array

Reply with an array of the names stored in the dictionary.

Directory

Type Directory is a Dictionary which also tracks when an object was last modified. For additional functionality, refer to Type Dictionary.

Instance Methods

This section lists methods which are available to all instances of Directory.

forAllDo aBlock:Block

Execute aBlock for every object in me and its subdirectories. The block variables consist of the name and object for each execution. Note that aBlock is not executed for the directories themselves.

delete pathName:String
REPLY Object

Delete the object specified in pathName.

at pathName:String ifAbsentDo aBlock:Block
REPLY Object

Reply with the object named pathName and execute aBlock if not found.

manage aTitle:String at aPoint:Point
REPLY Manager

Invoke the Directory Manager to manager me.

doByEntry aBlock:Block

Execute aBlock for each object in me. The block variable is the directory entry.

parsePath path:String
REPLY Array

Reply with an array consisting of the directory and name of the object. The pathname is of the form ``/dir/subdir/name'' where dir will be a subdirectory of me, subdir will be a subdirectory of dir and name will be an object stored in subdir.
SIGNAL "Bad name in pathname"
SIGNAL "Bad directory in pathname"

at pathName:String
REPLY Object

Reply with the object stored at pathName or NIL if not found.

at pathName:String put anElement:Object

Put anElement at pathName, replacing if it already exists.

Set

Type Set implements efficient set operations for a set of integers. For additional functionality, refer to Type PartsList.

Parts

bitset:Bits (A bit string representing whether an integer is present)
tally:Integer (The cardinality of the set)

Type Methods

This section lists methods available when Type Set is receiver.

new size:Integer

Reply with a set of size elements, initialized to FALSE.
SIGNAL "The set size must be >= 0"

Instance Methods

This section lists methods which are available to all instances of Set.

+ addset:Set

Reply with the union of me and addset.
SIGNAL "Set sizes don't match"

- diffset:Set

Reply with the difference of me and diffset.
SIGNAL "Set sizes don't match"

* intset:Set

Reply with the intersection of me and intset.
SIGNAL "Set sizes don't match"

isSubsetOf aSet:Set
REPLY Boolean

Reply TRUE if me is a subset of aSet.
SIGNAL "Set sizes don't match"

count
REPLY Integer

Reply with the number of elements which are present(i.e. TRUE).

contains element:Integer
REPLY Boolean

Reply TRUE if the integer element is contained in the set.

add element:Integer

Add the integer element to the set.

delete element:Integer

Delete the integer element from the set.

do aBlock:Block

Execute aBlock for every integer in the set. The block variable contains the integer.

asString
REPLY String

Reply with a string representation of me in the form ``{2 4 8 22}'' for example.

Stack

Type Stack implements a last-in-first-out queue. It can be heterogeneous. The maximum number of elements is 2000. The stack will grow automatically as needed. For additional functionality, refer to Type PartsList.

Parts

data:Array (contains the objects in the stack)
top:Integer (contains the number of objects in the stack)

Type Methods

This section lists methods available when Type Stack is receiver.

new

Reply with a new empty stack.

newSize initsize:Integer

Reply with a new empty stack but will initsize elements initially allocated for efficiency.

Instance Methods

This section lists methods which are available to all instances of Stack.

do aBlock:Block

Execute aBlock for each object in the stack. The block variable will contain the object.

push anElement:Object

Push anElement on the stack.

pop
REPLY Object

Reply with the top object on the stack and pop it off.

top
REPLY Object

Reply with the top object on the stack.

isEmpty
REPLY Boolean

Reply with TRUE if there are no objects in the stack.

Node

Type Node provides the functionality to produce binary trees. For additional functionality, refer to Type PartsList.

Parts

value:Object (data)
left:Node (left branch)
Right:Node (right branch)

Type Methods

This section lists methods available when Type Node is receiver.

newItem anItem:Object

Reply with a new node with anItem stored in it.

Instance Methods

This section lists methods which are available to instances of Node.

addLeft anItem:Object

Add a node to the left subtree of me with anItem as its object.

addRight anItem:Object

Add a node to the left subtree of me with anItem as its object.

doPre preBlock:Block doIn inBlock:Block doPost postBlock:Block

Traverse me and my subtrees and execute preBlock before I visit subtrees, inBlock between when I visit the left and right subtrees and postBlock after I have visited both subtrees. NIL may be specified for any of the three blocks. The block variable for each will be the current node.