Jim,
Here's an attempt to reconcile / unify the discussions so far:
What we're attempting to do is to define a set of Collection types, suitable for use in a CIM
(Computationally Independent Model).
Accordingly, we focus only on their functionality, not any considerations of computational methods. We will attempt to define a set of properties, functionalities, capabilities, constraints and operations whereby any given combination will produce a unique name for the Collection type. Our set of Collection Types therefore will attempt to be Canonical.
In addition, where appropriate, we will apply the UML denotations regarding collections to be found in the
[size=13]Superstructure[/size] Specification 7.3.44 Property (from Kernel, AssociationClasses)
In order for the notions of isOrdered an/or isUnique to be applicable, each item in the collection must expose or provide or be associated with a
Tag for this purpose. We can liken the tag to those boards carried by advertisers on the street (such as "the End is Nigh" or "Eat at Joes") Essentially, the Tag is visible outside the Item (to the Collector - the Collection holonym).
We can thus separate Collection types into two basic categorisations:
unTagged - We can only see the Item as Opaque.
Tagged - Each opaque Item also has a visible Tag.
I'll tackle the latter one first.
[size=16]Tagged Collections[/size][/b]
Tagged Collections have Items with a Tag visible to the Collector.
Sometimes, for whatever reason, the Item
is the Tag. "The Tag, the whole Tag and nothing but the Tag". Predominantly, however,you have a Tag and the associated Item. These latter are denoted Associative Collections (for the obvious reason). Thus a Tagged Collection may be either
Associative or
nonAssociative. Associative Collections are also known as
MapsSince we have determined that isUnique and isOrdered required Tags and the UML section only discusses their interaction, then the section applies ONLY to Tagged Collections. NOTE: the UML section doesn't say anything about the Collection being Associative or not, thus the terms apply equally to both.
Once we have Tags, if the there can only be unique Tags in the Collection, then the Tag acts as a Key (uniqueness constraint). Such Collections are known as
Enumerations.
Where you do not have ordering, you can also have all the operations of unTagged Collections (see below).
The Tagged Collection Types are known as:
Set: (
unOrdered,
unique)
OrderedSet: (
ordered,
unique)
Bag: (
unOrdered,
nonUnique)
Sequence: (
ordered,
nonUnique)
[size=16]unTagged Collections[/size][/b]
UnTagged Collections have Items that are Opaque to the Collector.
We can ONLY describe (identify?) each Item by their ordinal position in the Collection. Operations such as insertion and deletion can only be carried out at certain points in the Collection:
Add to start (
addToStart)
Add in middle (
addInMiddle)
Add to end (
addToEnd)
Remove from start (i]removeFromStart[/i])
Remove from middle (
removeFromMiddle)
Remove from end (
removeFromEnd)
If all six operations are not available, then we have a Restricted Access Collection.
The unTagged Collection Types are known as:
List: (
addToStart,
addInMiddle,
addToEnd,
RemoveFromStart,
removeFromMiddle,
removeFromEnd)
Deque: (
addToStart,
addToEnd,
removeFromStart,
removeFromEnd)
Queue: (
addToStart,
removeFromEnd)
Stack: (
addToStart,
removeFromStart)
[size=16]Collection Features[/size][/b]
All collection types have two features:
Iterator: Retrieves one item at a time by applying a function over the ordinal position of the current Item.
Indexer: Retrieves one or more items at a time by applying a function some property of the Items. NOTE: an Indexer can provide similar functionality to the Tag in a Tagged Collection. The difference is that in the Tagged Collection the Collector provides a standard Indexer operation, in an unTagged collection, if no indexer is provided, then one will not exist.
In addition, where the Item contains an attribute whose values are an Enumeration one can define an:
Enumerator: Retrieves one or more items at a time by applying a filter on an Enumerable property of the Items.
The
Iterator is essentially
procedural.
Indexer and
Enumerator are essentially
declarative.
Multiple Iterators, Indexers and Enumerators may be defined for a Collection, but they must vary in their
signatures.
As far as I can tell, these are the ONLY Collection types available at the CIM level. All others are either:
PIM
(Platform Independent Model)PSM
(Platform Specific Model)applicable due to some computational or logistical internals.
HTH,
Paolo
BTW: I've uploaded a new version of the Abstractions document, consistent with these definitions.
[size=0]©2005 Paolo Cantoni, -Semantica-[/size]