Arrays

Beta documentation : This document has not received a full technical review and therefore might contain inaccuracies.

A Core Foundation array--an object of opaque type CFArray--is an ordered, compact container of values. The values are in sequential order and the key for accessing these values is their index , an integer specifying an value's position in the sequence. The range of indexes is from zero to n -1 where n is the number of values in the array. An index of zero identifies the first value in the array. You can think of arrays as numbered slots.

Arrays are ideal for programmatic situations where sequential position is significant, such as lists whose items are ranked according to some scheme (priority, for example) or where there is a mapping between values in the array and items in list-type controls such as menus. However, you can use arrays as general-purpose containers for holding and iterating over collected values.

An array is said to be compact because, with mutable arrays, deleting a value does not leave a gap in the array. The values with higher-numbered indexes have their indexes decremented by one. If you insert a value, all subsequent elements have their keys incremented by one. Because of this behavior, the key for accessing a particular object may change over time as values are inserted into and deleted from an array. But the set of valid indexes is always between zero and n -1.

The access time for a value in the array is guaranteed to be at worst O(log N) for any implementation, current and future, but will often be O(1) (that is, constant time). Linear search operations similarly have a worst-case complexity of O(N*log N) , though typically the bounds will be tighter. Insertion or deletion operations are typically linear in the number of objects in the array, but may be O(N*log N) clearly in the worst case in some implementations. There are no favored positions within the array for performance; for example, it is not necessarily faster to access values with low indexes or to insert or delete values with high indexes.


© 1999 Apple Computer, Inc. – (Last Updated 07 September 99)