OSOrderedSet
Inheritance
Not Applicable
Conforms To
Not Applicable
Import Statement
Not Applicable
ObjectiveC
@import Kernel;
Availability
Available in OS X v10.0 and later.
OSOrderedSet provides an ordered set store of objects.
OSOrderedSet is a container for Libkern C++ objects (those derived from OSMetaClassBase, in particular OSObject). Storage and access follow ordered set logic. A given object is stored in the set only once, but you can:
Define a sorting function for automated ordering (upon addition only)
Manually insert new objects in the set (overriding sorting)
Add and remove objects in the set
Test whether the set contains a particular object
Get the object stored at a particular index.

Checks the ordered set for the presence of an object.
Declaration
C++
virtual bool containsObject( const OSMetaClassBase *
anObject
) const;Parameters
anObject
The OSMetaClassBasederived object to check for in the ordered set.
Return Value
true
ifanObject
is present within the ordered set,false
otherwise.Discussion
Pointer equality is used. This function returns
false
if passedNULL
. 
Creates a deep copy of this ordered set and its child collections.
Declaration
C++
OSCollection *copyCollection( OSDictionary *cycleDict = 0);
Parameters
cycleDict
A dictionary of all of the collections that have been copied so far, which is used to track circular references. To start the copy at the top level, pass
NULL
.Return Value
The newly copied ordered set, with a retain count of 1, or
NULL
if there is insufficient memory to do the copy.Discussion
The receiving ordered set, and any collections it contains, recursively, are copied. Objects that are not derived from OSCollection are retained rather than copied.

Ensures the set has enough space to store the requested number of distinct objects.
Declaration
C++
virtual unsigned int ensureCapacity( unsigned int
newCapacity
);Parameters
newCapacity
The total number of distinct objects the ordered set should be able to store.
Return Value
The new capacity of the ordered set, which may be different from the number requested (if smaller, reallocation of storage failed).
Discussion
This function immediately resizes the ordered set, if necessary, to accommodate at least
newCapacity
distinct objects. IfnewCapacity
is not greater than the current capacity, or if an allocation error occurs, the original capacity is returned.There is no way to reduce the capacity of an OSOrderedSet.

Removes and releases all objects within the ordered set.
Declaration
C++
virtual void flushCollection();
Discussion
The ordered set's capacity (and therefore direct memory consumption) is not reduced by this function.

Deallocatesand releases any resources used by the OSOrderedSet instance.
Declaration
C++
virtual void free();
Discussion
This function should not be called directly; use
release
instead. 
Returns the number of objects the ordered set can store without reallocating.
Declaration
C++
virtual unsigned int getCapacity() const;
Return Value
The number objects the ordered set can store without reallocating.
Discussion
OSOrderedSet objects grow when full to accommodate additional objects. See
getCapacityIncrement
andensureCapacity
. 
Returns the storage increment of the ordered set.
Declaration
C++
virtual unsigned int getCapacityIncrement() const;
Return Value
The storage increment of the ordered set.
Discussion
An OSOrderedSet allocates storage for objects in multiples of the capacity increment.

Returns the current number of objects within the ordered set.
Declaration
C++
virtual unsigned int getCount() const;
Return Value
The current number of objects within the ordered set.

The object at index 0 in the ordered set if there is one, otherwise
NULL
.Declaration
C++
virtual OSObject * getFirstObject() const;
Discussion
The returned object will be released if removed from the ordered set; if you plan to store the reference, you should call
retain
on that object. 
The last object in the ordered set if there is one, otherwise
NULL
.Declaration
C++
virtual OSObject * getLastObject() const;
Discussion
The returned object will be released if removed from the ordered set; if you plan to store the reference, you should call
retain
on that object. 
Gets the object at a particular index.
Declaration
C++
virtual OSObject * getObject( unsigned int
index
) const;Parameters
index
The index into the set.
Return Value
The object at the given index, or
NULL
if none exists at that location.Discussion
The returned object will be released if removed from the set; if you plan to store the reference, you should call
retain
on that object. 
Returns the ordering context the ordered set was created with.
Declaration
C++
virtual void * getOrderingRef();
Return Value
The ordered set's ordering context, or
NULL
if it doesn't have one. 
Initializes a new instance of OSOrderedSet.
Declaration
C++
virtual bool initWithCapacity( unsigned int
capacity
, OSOrderFunction orderFunc = 0, void *orderingContext = 0);Parameters
capacity
The initial storage capacity of the new ordered set object.
orderFunc
A C function that implements the sorting algorithm for the set.
orderingContext
An ordering context, which is passed to
orderFunc
.Return Value
true
on success,false
on failure.Discussion
Not for general use. Use the static instance creation method
withCapacity
instead.capacity
must be nonzero. The new set will grow as needed to accommodate more key/object pairs (unlike Core Foundation collections, for which the initial capacity is a hard limit).If
orderFunc
is provided, it is used bysetObject(const OSMetaClassBase *)
to determine where to insert a new object. Other objectsetting functions ignore ordering.orderingContext
is not retained or otherwise memorymanaged by the ordered set. If it needs to be deallocated, you must track references to it and the ordered set in order to deallocate it appropriately. SeegetOrderingRef
. 
Tests the equality of an OSOrderedSet against an arbitrary object.
Declaration
C++
virtual bool isEqualTo( const OSMetaClassBase *
anObject
) const;Parameters
anObject
The object being compared against the receiver.
Return Value
true
if the two objects are equivalent,false
otherwise.Discussion
An OSOrderedSet object is considered equal to another object if the other object is derived from OSOrderedSet and compares equal as an OSOrderedSet.

Tests the equality of two OSOrderedSet objects.
Declaration
C++
virtual bool isEqualTo( const OSOrderedSet *
anOrderedSet
) const;Parameters
anOrderedSet
The ordered set object being compared against the receiver.
Return Value
true
if the two sets are equivalent,false
otherwise.Discussion
Two OSOrderedSet objects are considered equal if they have same count and the same object pointer values in the same order.

Checks the ordered set for the presence of an object.
Declaration
C++
virtual bool member( const OSMetaClassBase *
anObject
) const;Parameters
anObject
The OSMetaClassBasederived object to check for in the ordered set.
Return Value
true
ifanObject
is present within the ordered set,false
otherwise.Discussion
Pointer equality is used. Returns
false
if passedNULL
.containsObject(const OSMetaClassBase *)
checks forNULL
before scanning the contents, and is therefore more efficient than this function. 
Calls the ordered set's order function against a
NULL
object.Declaration
C++
virtual SInt32 orderObject( const OSMetaClassBase *
anObject
);Parameters
anObject
The object to be ordered.
Return Value
The ordering value for the object.
Discussion
This function calls the ordered set's order function with
anObject
,NULL
, and the ordering context (orNULL
if none was set), and returns the result of that function. 
Removes an object from the ordered set.
Declaration
C++
virtual void removeObject( const OSMetaClassBase *
anObject
);Parameters
anObject
The OSMetaClassBasederived object to be removed from the ordered set.
Discussion
The object removed from the ordered set is released.

Sets the storage increment of the ordered set.
Declaration
C++
virtual unsigned int setCapacityIncrement( unsigned
increment
);Return Value
The new storage increment of the ordered set, which may be different from the number requested.
Discussion
An OSOrderedSet allocates storage for objects in multiples of the capacity increment. Calling this function does not immediately reallocate storage.

Adds an object to the OSOrderedSet at index 0 if it is not already present.
Declaration
C++
virtual bool setFirstObject( const OSMetaClassBase *
anObject
);Parameters
anObject
The OSMetaClassBasederived object to be added to the ordered set.
Return Value
true
ifanObject
was successfully added to the ordered set,false
otherwise (including if it was already in the ordered set at any index).Discussion
The set adds storage to accomodate the new object, if necessary. If successfully added, the object is retained.
This function ignores any ordering function of the ordered set, and can disrupt the automatic sorting mechanism. Only call this function if you are managing the ordered set directly.
A
false
return value can mean either thatanObject
is already present in the set, or that a memory allocation failure occurred. If you need to know whether the object is already present, usecontainsObject(const OSMetaClassBase *)
. 
Adds an object at the end of the OSOrderedSet if it is not already present.
Declaration
C++
virtual bool setLastObject( const OSMetaClassBase *
anObject
);Parameters
anObject
The OSMetaClassBasederived object to be added to the ordered set.
Return Value
true
ifanObject
was successfully added to the ordered set,false
otherwise (including if it was already in the ordered set at any index).Discussion
The set adds storage to accomodate the new object, if necessary. If successfully added, the object is retained.
This function ignores any ordering function of the ordered set, and can disrupt the automatic sorting mechanism. Only call this function if you are managing the ordered set directly.
A
false
return value can mean either thatanObject
is already present in the set, or that a memory allocation failure occurred. If you need to know whether the object is already present, usecontainsObject(const OSMetaClassBase *)
. 
Adds an object to the OSOrderedSet if it is not already present, storing it in sorted order if there is an order function.
Declaration
C++
virtual bool setObject( const OSMetaClassBase *
anObject
);Parameters
anObject
The OSMetaClassBasederived object to be added to the ordered set.
Return Value
true
ifanObject
was successfully added to the ordered set,false
otherwise (including if it was already in the ordered set).Discussion
The set adds storage to accomodate the new object, if necessary. If successfully added, the object is retained.
If
anObject
is not already in the ordered set and there is an order function, this function loops through the existing objects, calling the order function with arguments each existingObject,anObject
, and the ordering context (orNULL
if none was set), until the order function returns a value greater than or equal to 0. It then insertsanObject
at the index of the existing object.If there is no order function, the object is inserted at index 0.
A
false
return value can mean either thatanObject
is already present in the set, or that a memory allocation failure occurred. If you need to know whether the object is already present, usecontainsObject(const OSMetaClassBase *)
. 
Adds an object to an OSOrderedSet at a specified index if it is not already present.
Declaration
C++
virtual bool setObject( unsigned int
index
, const OSMetaClassBase *anObject
);Parameters
index
The index at which to insert the new object.
anObject
The OSMetaClassBasederived object to be added to the ordered set.
Return Value
true
if the object was successfully added to the ordered set,false
otherwise (including if it was already in the set).Discussion
The set adds storage to accomodate the new object, if necessary. If successfully added, the object is retained.
This function ignores any ordering function of the ordered set, and can disrupt the automatic sorting mechanism. Only call this function if you are managing the ordered set directly.
A
false
return value can mean either that the object is already present in the set, or that a memory allocation failure occurred. If you need to know whether the object is already present, usecontainsObject containsObject
. 
Declaration
C++
virtual unsigned setOptions( unsigned
options
, unsignedmask
, void *context = 0);Parameters
options
A bitfield whose values turn the options on (1) or off (0).
mask
A mask indicating which bits in
options
to change. Pass 0 to get the whole current options bitfield without changing any settings.context
Unused.
Return Value
The options bitfield as it was before the set operation.
Discussion
Kernel extensions should not call this function.
Child collections' options are changed only if the receiving ordered set's options actually change.

Creates and initializes an empty OSOrderedSet.
Declaration
C++
static OSOrderedSet * withCapacity( unsigned int
capacity
, OSOrderFunction orderFunc = 0, void *orderingContext = 0);Parameters
capacity
The initial storage capacity of the new ordered set object.
orderFunc
A C function that implements the sorting algorithm for the set.
orderingContext
An ordering context, which is passed to
orderFunc
.Return Value
An empty instance of OSOrderedSet with a retain count of 1;
NULL
on failure.Discussion
capacity
must be nonzero. The new OSOrderedSet will grow as needed to accommodate more key/object pairs (unlike Core Foundation collections, for which the initial capacity is a hard limit).If
orderFunc
is provided, it is used bysetObject(const OSMetaClassBase *)
to determine where to insert a new object. Other objectsetting functions ignore ordering.orderingContext
is not retained or otherwise memorymanaged by the ordered set. If it needs to be deallocated, you must track references to it and the ordered set in order to deallocate it appropriately. SeegetOrderingRef
.

The sorting function used by an OSOrderedSet to order objects.
Declaration
C++
typedef SInt32 ( *OSOrderFunction)( const OSMetaClassBase *obj1, const OSMetaClassBase *obj2, void *context);
Parameters
obj1
An object from the ordered set. May be
NULL
.obj2
The object being ordered within the ordered set. May be
NULL
.context
A pointer to a userprovided context. May be
NULL
.Return Value
A comparison result of the object:
a negative value if obj2 should precede obj1,
a positive value if obj1 should precede obj2,
and 0 if obj1 and obj2 have an equivalent ordering.
Import Statement
ObjectiveC
#include <OSOrderedSet.h>;
Availability
Available in OS X v10.0 through OS X v10.5.
Copyright © 2015 Apple Inc. All rights reserved. Terms of Use  Privacy Policy  Updated: 20131022