/* NSOrderedSet.h Copyright (c) 2007-2019, Apple Inc. All rights reserved. */ #import #import #import #import #import @class NSArray, NSIndexSet, NSSet, NSString; /**************** Immutable Ordered Set ****************/ NS_HEADER_AUDIT_BEGIN(nullability, sendability) API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0)) @interface NSOrderedSet<__covariant ObjectType> : NSObject @property (readonly) NSUInteger count; - (ObjectType)objectAtIndex:(NSUInteger)idx; - (NSUInteger)indexOfObject:(ObjectType)object; - (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)initWithObjects:(const ObjectType _Nonnull [_Nullable])objects count:(NSUInteger)cnt NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; @end @interface NSOrderedSet (NSExtendedOrderedSet) - (void)getObjects:(ObjectType _Nonnull __unsafe_unretained [_Nullable])objects range:(NSRange)range NS_SWIFT_UNAVAILABLE("Use 'array' instead"); - (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes; @property (nullable, nonatomic, readonly) ObjectType firstObject; @property (nullable, nonatomic, readonly) ObjectType lastObject; - (BOOL)isEqualToOrderedSet:(NSOrderedSet *)other; - (BOOL)containsObject:(ObjectType)object; - (BOOL)intersectsOrderedSet:(NSOrderedSet *)other; - (BOOL)intersectsSet:(NSSet *)set; - (BOOL)isSubsetOfOrderedSet:(NSOrderedSet *)other; - (BOOL)isSubsetOfSet:(NSSet *)set; - (ObjectType)objectAtIndexedSubscript:(NSUInteger)idx API_AVAILABLE(macos(10.8), ios(6.0), watchos(2.0), tvos(9.0)); - (NSEnumerator *)objectEnumerator; - (NSEnumerator *)reverseObjectEnumerator; @property (readonly, copy) NSOrderedSet *reversedOrderedSet; // These two methods return a facade object for the receiving ordered set, // which acts like an immutable array or set (respectively). Note that // while you cannot mutate the ordered set through these facades, mutations // to the original ordered set will "show through" the facade and it will // appear to change spontaneously, since a copy of the ordered set is not // being made. @property (readonly, strong) NSArray *array; @property (readonly, strong) NSSet *set; - (void)enumerateObjectsUsingBlock:(void (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))block; - (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))block; - (void)enumerateObjectsAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts usingBlock:(void (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))block; - (NSUInteger)indexOfObjectPassingTest:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate; - (NSUInteger)indexOfObjectWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate; - (NSUInteger)indexOfObjectAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts passingTest:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate; - (NSIndexSet *)indexesOfObjectsPassingTest:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate; - (NSIndexSet *)indexesOfObjectsWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate; - (NSIndexSet *)indexesOfObjectsAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts passingTest:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate; - (NSUInteger)indexOfObject:(ObjectType)object inSortedRange:(NSRange)range options:(NSBinarySearchingOptions)opts usingComparator:(NSComparator NS_NOESCAPE)cmp; // binary search - (NSArray *)sortedArrayUsingComparator:(NSComparator NS_NOESCAPE)cmptr; - (NSArray *)sortedArrayWithOptions:(NSSortOptions)opts usingComparator:(NSComparator NS_NOESCAPE)cmptr; @property (readonly, copy) NSString *description; - (NSString *)descriptionWithLocale:(nullable id)locale; - (NSString *)descriptionWithLocale:(nullable id)locale indent:(NSUInteger)level; @end @interface NSOrderedSet (NSOrderedSetCreation) + (instancetype)orderedSet; + (instancetype)orderedSetWithObject:(ObjectType)object; + (instancetype)orderedSetWithObjects:(const ObjectType _Nonnull [_Nonnull])objects count:(NSUInteger)cnt; + (instancetype)orderedSetWithObjects:(ObjectType)firstObj, ... NS_REQUIRES_NIL_TERMINATION; + (instancetype)orderedSetWithOrderedSet:(NSOrderedSet *)set; + (instancetype)orderedSetWithOrderedSet:(NSOrderedSet *)set range:(NSRange)range copyItems:(BOOL)flag; + (instancetype)orderedSetWithArray:(NSArray *)array; + (instancetype)orderedSetWithArray:(NSArray *)array range:(NSRange)range copyItems:(BOOL)flag; + (instancetype)orderedSetWithSet:(NSSet *)set; + (instancetype)orderedSetWithSet:(NSSet *)set copyItems:(BOOL)flag; - (instancetype)initWithObject:(ObjectType)object; - (instancetype)initWithObjects:(ObjectType)firstObj, ... NS_REQUIRES_NIL_TERMINATION; - (instancetype)initWithOrderedSet:(NSOrderedSet *)set; - (instancetype)initWithOrderedSet:(NSOrderedSet *)set copyItems:(BOOL)flag; - (instancetype)initWithOrderedSet:(NSOrderedSet *)set range:(NSRange)range copyItems:(BOOL)flag; - (instancetype)initWithArray:(NSArray *)array; - (instancetype)initWithArray:(NSArray *)set copyItems:(BOOL)flag; - (instancetype)initWithArray:(NSArray *)set range:(NSRange)range copyItems:(BOOL)flag; - (instancetype)initWithSet:(NSSet *)set; - (instancetype)initWithSet:(NSSet *)set copyItems:(BOOL)flag; @end API_AVAILABLE(macosx(10.15), ios(13.0), watchos(6.0), tvos(13.0)) NS_SWIFT_UNAVAILABLE("NSOrderedSet diffing methods are not available in Swift, use Collection.difference(from:) instead") @interface NSOrderedSet (NSOrderedSetDiffing) - (NSOrderedCollectionDifference *)differenceFromOrderedSet:(NSOrderedSet *)other withOptions:(NSOrderedCollectionDifferenceCalculationOptions)options usingEquivalenceTest:(BOOL (NS_NOESCAPE ^)(ObjectType obj1, ObjectType obj2))block; - (NSOrderedCollectionDifference *)differenceFromOrderedSet:(NSOrderedSet *)other withOptions:(NSOrderedCollectionDifferenceCalculationOptions)options; // Uses isEqual: to determine the difference between the parameter and the receiver - (NSOrderedCollectionDifference *)differenceFromOrderedSet:(NSOrderedSet *)other; - (nullable NSOrderedSet *)orderedSetByApplyingDifference:(NSOrderedCollectionDifference *)difference; @end /**************** Mutable Ordered Set ****************/ API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0)) @interface NSMutableOrderedSet : NSOrderedSet - (void)insertObject:(ObjectType)object atIndex:(NSUInteger)idx; - (void)removeObjectAtIndex:(NSUInteger)idx; - (void)replaceObjectAtIndex:(NSUInteger)idx withObject:(ObjectType)object; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)initWithCapacity:(NSUInteger)numItems NS_DESIGNATED_INITIALIZER; @end @interface NSMutableOrderedSet (NSExtendedMutableOrderedSet) - (void)addObject:(ObjectType)object; - (void)addObjects:(const ObjectType _Nonnull [_Nullable])objects count:(NSUInteger)count; - (void)addObjectsFromArray:(NSArray *)array; - (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2; - (void)moveObjectsAtIndexes:(NSIndexSet *)indexes toIndex:(NSUInteger)idx; - (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes; - (void)setObject:(ObjectType)obj atIndex:(NSUInteger)idx; - (void)setObject:(ObjectType)obj atIndexedSubscript:(NSUInteger)idx API_AVAILABLE(macos(10.8), ios(6.0), watchos(2.0), tvos(9.0)); - (void)replaceObjectsInRange:(NSRange)range withObjects:(const ObjectType _Nonnull [_Nullable])objects count:(NSUInteger)count; - (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects; - (void)removeObjectsInRange:(NSRange)range; - (void)removeObjectsAtIndexes:(NSIndexSet *)indexes; - (void)removeAllObjects; - (void)removeObject:(ObjectType)object; - (void)removeObjectsInArray:(NSArray *)array; - (void)intersectOrderedSet:(NSOrderedSet *)other; - (void)minusOrderedSet:(NSOrderedSet *)other; - (void)unionOrderedSet:(NSOrderedSet *)other; - (void)intersectSet:(NSSet *)other; - (void)minusSet:(NSSet *)other; - (void)unionSet:(NSSet *)other; - (void)sortUsingComparator:(NSComparator NS_NOESCAPE)cmptr; - (void)sortWithOptions:(NSSortOptions)opts usingComparator:(NSComparator NS_NOESCAPE)cmptr; - (void)sortRange:(NSRange)range options:(NSSortOptions)opts usingComparator:(NSComparator NS_NOESCAPE)cmptr; @end @interface NSMutableOrderedSet (NSMutableOrderedSetCreation) + (instancetype)orderedSetWithCapacity:(NSUInteger)numItems; @end API_AVAILABLE(macosx(10.15), ios(13.0), watchos(6.0), tvos(13.0)) NS_SWIFT_UNAVAILABLE("NSMutableOrderedSet diffing methods are not available in Swift") @interface NSMutableOrderedSet (NSMutableOrderedSetDiffing) - (void)applyDifference:(NSOrderedCollectionDifference *)difference; @end NS_HEADER_AUDIT_END(nullability, sendability)