<!--
{
  "availability" : [
    "DriverKit: -",
    "iOS: -",
    "iPadOS: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "DriverKit",
  "identifier" : "/documentation/DriverKit/OSOrderedSet",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "DriverKit"
    ],
    "preciseIdentifier" : "c:@S@OSOrderedSet"
  },
  "title" : "OSOrderedSet"
}
-->

# OSOrderedSet

OSOrderedSet provides an ordered set store of objects.

```
class OSOrderedSet;
```

## Overview

[`OSOrderedSet`](/documentation/DriverKit/OSOrderedSet) is a container for Libkern C++ objects (those derived from [`OSMetaClassBase`](/documentation/DriverKit/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.

Note that automated ordering is performed only upon addition of objects and depends on the existing objects being properly sorted. There is no function to re-sort the contents of an OSOrderedSet or to change the ordering function. In general, you should either use the one ordered-insertion function, or the indexed-insertion functions, and not mix the two.

As with all Libkern collection classes, [`OSOrderedSet`](/documentation/DriverKit/OSOrderedSet) retains objects added to it, and releases objects removed from it. An [`OSOrderedSet`](/documentation/DriverKit/OSOrderedSet) also grows as necessary to accommodate new objects, unlike Core Foundation collections (it does not, however, shrink).

## Use Restrictions

With very few exceptions in the I/O Kit, all Libkern-based C++ classes, functions, and macros are unsafe to use in a primary interrupt context. Consult the I/O Kit documentation related to primary interrupts for more information.

OSOrderedSet provides no concurrency protection; it’s up to the usage context to provide any protection necessary. Some portions of the I/O Kit, such as `IORegistryEntry`, handle synchronization via defined member functions for setting properties.

## Topics

### Instance Methods

[`virtual void free();`](/documentation/DriverKit/OSOrderedSet/free)

[`OSObject * getFirstObject() const;`](/documentation/DriverKit/OSOrderedSet/getFirstObject)

The object at index 0 in the ordered set if there is one, otherwise `NULL`.

[`OSObject * getLastObject() const;`](/documentation/DriverKit/OSOrderedSet/getLastObject)

The last object in the ordered set if there is one, otherwise `NULL`.

[`virtual bool init();`](/documentation/DriverKit/OSOrderedSet/init)

[`int32_t orderObject(const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSOrderedSet/orderObject)

Calls the ordered set’s order function against a `NULL` object.

[`bool setFirstObject(const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSOrderedSet/setFirstObject)

Adds an object to the OSOrderedSet at index 0 if it is not already present.

[`bool setLastObject(const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSOrderedSet/setLastObject)

Adds an object at the end of the OSOrderedSet if it is not already present.

[`bool setObject(const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSOrderedSet/setObject)

Adds an object to the OSOrderedSet if it is not already present, storing it in sorted order if there is an order function.

### Type Methods

[`static OSOrderedSetPtr withCapacity(uint32_t capacity, OSOrderBlock orderBlock);`](/documentation/DriverKit/OSOrderedSet/withCapacity)

## Relationships

### Inherits From

[`OSSet`](/documentation/DriverKit/OSSet)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)