com.sas.collection ClassesThis page provides a guide on the performance characteristics of some of the collections in the com.sas.collection
package. You can use this information to help decide which collection to use for various needs.
One important note about the com.sas.collection package is that you may not need to use it at all.
This package was written before the new Java 2 collection classes, when Java had only Vector and Hashtable. Also,
the SAS collection hierarchy was designed to meet many needs, including serving as models for many visual components.
Thus, the SAS collections are more heavyweight than the newer Java 2 collections:
Thus, in many cases, you may want to consider using Java 2 collections instead of the SAS collection framework. For example, you should avoid using the SAS collections for "internal" implementations that are hidden from your class' clients.
The below table shows some of the performance characteristics for some of the SAS collections. The performance of each operation is expressed in "big O" notation.
|
Class |
|||||||
|---|---|---|---|---|---|---|---|
| AssociationList 1 |
O(1) |
O(n) |
O(1) |
O(n) |
O(1) |
O(1) |
O(1) |
| Collection 2 |
N/A |
N/A |
O(1) |
O(n) |
O(1) |
O(1) |
O(n) |
| Dictionary |
N/A |
O(1) |
O(1) |
O(1) |
O(1) |
O(1) |
O(1) |
| OrderedCollection 3 |
O(1) |
N/A |
O(1) |
O(n) |
O(1) |
O(1) |
O(1) |
| OrderedListCollection |
O(n) |
N/A |
O(1) |
O(n) |
O(1) |
O(1) |
O(1) |
| PropertyBag 4 |
N/A |
O(n) |
N/A |
O(n) |
N/A |
O(1) |
O(n) |
| Queue |
N/A |
N/A |
N/A |
N/A |
N/A |
O(1) |
O(1) |
| Set |
O(1) |
N/A |
O(1) |
O(1) |
O(1) |
O(1) |
O(1) |
| SortedCollection |
O(1) |
N/A |
O(1) |
O(log n) |
O(log n) |
O(log n) |
O(log n) |
get(int index) operation for random
indices; for dictionaries, it is get(Object key)
index = 0
to collection.count()-1
1 AssociationList has constructors for specifying the internal implementation. These metrics assume the default, OrderedCollection, implementation.
2 Collection supports either collection semantics (allowing duplicates) or set semantics (no duplicates). These metrics assume collection semantics; the Collection is implemented with an OrderedCollection. The metrics for Set assume set semantics (implemented with a disctionary)
3 OrderedCollection also includes '
4 Although PropertyBag has O(n) behavior, the constant is extremely small and for small property bags, its O(n) behavior is often better than hashtable based collections with O(1) performance but with higher constants. Also, PropertyBag is not synchronized