libs-base/Headers/Foundation/NSOrderedSet.h

595 lines
16 KiB
C
Raw Permalink Normal View History

2019-05-16 17:53:15 +00:00
/** Interface for NSOrderedSet, NSMutableOrderedSet for GNUStep
2019-05-18 00:17:10 +00:00
Copyright (C) 2019 Free Software Foundation, Inc.
2019-05-16 17:53:15 +00:00
2019-05-18 00:17:10 +00:00
Written by: Gregory John Casamento <greg.casamento@gmail.com>
Created: May 17 2019
2019-05-16 17:53:15 +00:00
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
2019-05-16 17:53:15 +00:00
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
2019-05-16 17:53:15 +00:00
*/
#ifndef _NSOrderedSet_h_GNUSTEP_BASE_INCLUDE
#define _NSOrderedSet_h_GNUSTEP_BASE_INCLUDE
2019-06-27 06:00:14 +00:00
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7,GS_API_LATEST)
2019-05-16 17:53:15 +00:00
#import <GNUstepBase/GSVersionMacros.h>
#import <GNUstepBase/GSBlocks.h>
2019-05-16 17:53:15 +00:00
#import <Foundation/NSObject.h>
#import <Foundation/NSEnumerator.h>
2019-05-20 05:43:06 +00:00
#import <Foundation/NSIndexSet.h>
#import <Foundation/NSKeyedArchiver.h>
2019-05-16 17:53:15 +00:00
#if defined(__cplusplus)
extern "C" {
#endif
2024-11-16 12:06:27 +00:00
2019-05-16 17:53:15 +00:00
@class GS_GENERIC_CLASS(NSArray, ElementT);
@class GS_GENERIC_CLASS(NSEnumerator, ElementT);
@class GS_GENERIC_CLASS(NSSet, ElementT);
@class GS_GENERIC_CLASS(NSDictionary, KeyT:id<NSCopying>, ValT);
@class NSString;
2019-05-18 00:17:10 +00:00
@class NSPredicate;
2019-05-16 17:53:15 +00:00
/**
* This class provides an ordered set, a set where the order of the elements matters and
* is preserved. Once created the set cannot be modified. NSMutableOrderedSet can be
* modified.
*/
GS_EXPORT_CLASS
2019-05-16 17:53:15 +00:00
@interface GS_GENERIC_CLASS(NSOrderedSet, __covariant ElementT) : NSObject <NSCoding,
NSCopying,
NSMutableCopying,
NSFastEnumeration>
// class methods
2024-11-17 15:17:46 +00:00
/**
* Create and return an empty ordered set.
*/
2019-05-16 17:53:15 +00:00
+ (instancetype) orderedSet;
2024-11-17 15:17:46 +00:00
/**
* Create and return an empty ordered set with the provided NSArray instance.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)objects;
2024-11-17 15:17:46 +00:00
/**
* Create and return an empty ordered set with the provided NSArray instance.
* Use the range to determine which elements to use. If flag is YES copy the
* elements.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)objects
range: (NSRange)range
copyItems: (BOOL)flag;
2024-11-17 15:17:46 +00:00
/**
* Create and return an ordered set with anObject as the sole member.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithObject: (GS_GENERIC_TYPE(ElementT))anObject;
2024-11-17 15:17:46 +00:00
/**
* Create and return an ordered set with list of arguments starting with
* firstObject and terminated with nil.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithObjects: (GS_GENERIC_TYPE(ElementT))firstObject, ...;
2024-11-17 15:17:46 +00:00
/**
* Create and return an ordered set using the C array of objects with count.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithObjects: (const GS_GENERIC_TYPE(ElementT)[])objects
count: (NSUInteger) count;
2024-11-17 15:17:46 +00:00
/**
* Create and return an ordered set with the provided ordered set aSet.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithOrderedSet: (GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet;
2024-11-17 15:17:46 +00:00
/**
* Create and return an ordered set with set aSet.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet;
2024-11-17 15:17:46 +00:00
/**
* Create and return an ordered set with the elements in aSet. If flag is YES,
* copy the elements.
*/
2024-11-16 12:06:27 +00:00
+ (instancetype) orderedSetWithSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet
copyItems: (BOOL)flag;
2019-05-16 17:53:15 +00:00
// instance methods
2024-11-17 15:17:46 +00:00
/**
* Initialize and return an empty ordered set with the provided NSArray instance.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)array;
2024-11-17 15:17:46 +00:00
/**
* Initialize and return an empty ordered set with the provided NSArray instance.
* If flag is YES copy the elements.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)array copyItems: (BOOL)flag;
2024-11-17 15:17:46 +00:00
/**
* Initialize and return an empty ordered set with the provided NSArray instance.
* Use the range to determine which elements to use. If flag is YES copy the
* elements.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)array
range: (NSRange)range
copyItems: (BOOL)flag;
2024-11-17 15:17:46 +00:00
/**
* Initialize and return an ordered set with anObject as the sole member.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithObject: (id)object;
2024-11-17 15:17:46 +00:00
/**
* Initialize and return an ordered set with list of arguments starting with
* firstObject and terminated with nil.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithObjects: (GS_GENERIC_TYPE(ElementT))firstObject, ...;
- (instancetype) initWithObjects: (const GS_GENERIC_TYPE(ElementT)[])objects
count: (NSUInteger)count;
2024-11-17 15:17:46 +00:00
/**
* Initialize and return an ordered set using the C array of objects with count.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithOrderedSet: (GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet;
/**
* Initialize and return an ordered set with the elements in aSet. If flag is YES,
* copy the elements.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithOrderedSet: (GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet
copyItems: (BOOL)flag;
/**
* Initialize and return an empty ordered set with the provided NSArray instance.
* Use the range to determine which elements to use. If flag is YES copy the
* elements.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithOrderedSet: (GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet
range: (NSRange)range
copyItems: (BOOL)flag;
/**
* Initialize and return an ordered set with set aSet.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet;
/**
* Initialize and return an ordered set with set aSet. If flag is YES, then copy the elements.
*/
2024-11-16 12:06:27 +00:00
- (instancetype) initWithSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet copyItems:(BOOL)flag;
/**
* Initialize an empty ordered set.
*/
2019-05-18 00:17:10 +00:00
- (instancetype) init;
/**
* Return the number of elements in the receiver.
*/
2019-05-16 17:53:15 +00:00
- (NSUInteger) count;
/**
* Returns YES if the receiver contains anObject.
*/
2024-11-16 12:06:27 +00:00
- (BOOL)containsObject: (GS_GENERIC_TYPE(ElementT))anObject;
/**
* Enumerate over the objects whose indexes are contained in indexSet, with the opts provided
* using aBlock.
*/
2024-11-16 12:06:27 +00:00
- (void) enumerateObjectsAtIndexes: (NSIndexSet *)indexSet
options: (NSEnumerationOptions)opts
usingBlock: (GSEnumeratorBlock)aBlock;
/**
* Enumerate over all objects in the receiver using aBlock.
*/
2019-05-16 17:53:15 +00:00
- (void) enumerateObjectsUsingBlock: (GSEnumeratorBlock)aBlock;
/**
* Enumerate over all objects in the receiver with aBlock utilizing the options specified by opts.
*/
2024-11-16 12:06:27 +00:00
- (void) enumerateObjectsWithOptions: (NSEnumerationOptions)opts
usingBlock: (GSEnumeratorBlock)aBlock;
/**
* First object in the receiver.
*/
2019-05-16 17:53:15 +00:00
- (GS_GENERIC_TYPE(ElementT)) firstObject;
/**
* Last object in the receiver.
*/
2019-05-16 17:53:15 +00:00
- (GS_GENERIC_TYPE(ElementT)) lastObject;
/**
* Returns the object at index in the receiver.
*/
2019-05-16 17:53:15 +00:00
- (GS_GENERIC_TYPE(ElementT)) objectAtIndex: (NSUInteger)index;
/**
* Returns the object at index in the receiver.
*/
2024-11-16 12:06:27 +00:00
- (GS_GENERIC_TYPE(ElementT)) objectAtIndexedSubscript: (NSUInteger)index;
/**
* Returns objects at the indexes specified in the receiver.
*/
2024-11-16 12:06:27 +00:00
- (GS_GENERIC_CLASS(NSArray, ElementT)*) objectsAtIndexes: (NSIndexSet *)indexes;
/**
* Returns the index of anObject in the receiver.
*/
- (NSUInteger) indexOfObject: (GS_GENERIC_TYPE(ElementT))anObject;
/**
* Returns the index of object key, contained within range, using options, and the provided comparator.
*/
2019-05-16 17:53:15 +00:00
- (NSUInteger) indexOfObject: (id)key
2024-11-16 12:06:27 +00:00
inSortedRange: (NSRange)range
options: (NSBinarySearchingOptions)options
usingComparator: (NSComparator)comparator;
/**
* Returns the index of objects at indexSet that pass the test in predicate with enumeration options opts.
*/
2024-11-16 12:06:27 +00:00
- (NSUInteger) indexOfObjectAtIndexes: (NSIndexSet *)indexSet
options: (NSEnumerationOptions)opts
passingTest: (GSPredicateBlock)predicate;
/**
* Returns the index of the first object passing test predicate.
*/
2024-11-16 12:06:27 +00:00
- (NSUInteger) indexOfObjectPassingTest: (GSPredicateBlock)predicate;
/**
* Returns the index of the first object passing test predicate using enumeration options opts.
*/
2024-11-16 12:06:27 +00:00
- (NSUInteger) indexOfObjectWithOptions: (NSEnumerationOptions)opts
passingTest: (GSPredicateBlock)predicate;
/**
* Returns an NSIndexSet containing indexes of object at indexes in indexSet matching predicate
* with enumeration options opts.
*/
2024-11-16 12:06:27 +00:00
- (NSIndexSet *) indexesOfObjectsAtIndexes: (NSIndexSet *)indexSet
options: (NSEnumerationOptions)opts
passingTest: (GSPredicateBlock)predicate;
/**
* Returns an NSIndexSet containing indexes that match predicate.
*/
- (NSIndexSet *) indexesOfObjectsPassingTest: (GSPredicateBlock)predicate;
/**
* Returns an NSIndexSet containing indexes that match predicate using opts.
*/
2024-11-16 12:06:27 +00:00
- (NSIndexSet *) indexesOfObjectsWithOptions: (NSEnumerationOptions)opts
passingTest: (GSPredicateBlock)predicate;
/**
* Returns an NSEnumerator to iterate over each object in the receiver.
*/
2019-05-16 17:53:15 +00:00
- (GS_GENERIC_CLASS(NSEnumerator, ElementT)*) objectEnumerator;
/**
* Returns an NSEnumerator to iterate over each object in the receiver in reverse order.
*/
2019-05-16 17:53:15 +00:00
- (GS_GENERIC_CLASS(NSEnumerator, ElementT)*) reverseObjectEnumerator;
/**
* Returns an NSOrderedSet that contains the same objects as the receiver, but in reverse order.
*/
2019-05-18 07:56:11 +00:00
- (NSOrderedSet *)reversedOrderedSet;
/**
* Returns a C array of objects in aBuffer at indexes specified by aRange.
*/
2019-05-16 17:53:15 +00:00
- (void) getObjects: (__unsafe_unretained GS_GENERIC_TYPE(ElementT)[])aBuffer
2024-11-16 12:06:27 +00:00
range: (NSRange)aRange;
2019-05-16 17:53:15 +00:00
// Key value coding support
/**
* Set value for key.
*/
- (void) setValue: (id)value forKey: (NSString*)key;
/**
* Returns the value for a given key.
*/
2024-11-16 12:06:27 +00:00
- (id) valueForKey: (NSString*)key;
2019-05-16 17:53:15 +00:00
// Comparing Sets
/**
* Returns YES if the receiver is equal to aSet.
*/
2019-05-16 17:53:15 +00:00
- (BOOL) isEqualToOrderedSet: (NSOrderedSet *)aSet;
2024-11-16 12:06:27 +00:00
2019-05-16 17:53:15 +00:00
// Set operations
/**
* Returns YES if the receiver intersects with ordered set aSet.
*/
2019-05-16 17:53:15 +00:00
- (BOOL) intersectsOrderedSet: (NSOrderedSet *)aSet;
/**
* Returns YES if the receiver intersects with set aSet.
*/
2019-05-27 11:40:18 +00:00
- (BOOL) intersectsSet: (NSSet *)aSet;
/**
* Returns YES if the receiver is a subset of ordered set aSet.
*/
2019-05-16 17:53:15 +00:00
- (BOOL) isSubsetOfOrderedSet: (NSOrderedSet *)aSet;
/**
* Returns YES if the receiver is a subset of set aSet.
*/
2019-05-27 11:40:18 +00:00
- (BOOL) isSubsetOfSet:(NSSet *)aSet;
2019-05-16 17:53:15 +00:00
// Creating a Sorted Array
/**
* Returns an NSArray instance containing the elements from the receiver sorted using sortDescriptors.
*/
2024-11-16 12:06:27 +00:00
- (GS_GENERIC_CLASS(NSArray, ElementT) *) sortedArrayUsingDescriptors: (NSArray *)sortDescriptors;
/**
* Returns an NSArray instance containing the elements from the receiver sorted using comparator.
*/
2019-05-16 17:53:15 +00:00
- (GS_GENERIC_CLASS(NSArray, ElementT) *) sortedArrayUsingComparator:
(NSComparator)comparator;
/**
* Returns an NSArray instance containing the elements from the receiver using options, sorted
* using comparator.
*/
2019-05-16 17:53:15 +00:00
- (GS_GENERIC_CLASS(NSArray, ElementT) *)
sortedArrayWithOptions: (NSSortOptions)options
2024-11-16 12:06:27 +00:00
usingComparator: (NSComparator)comparator;
2019-05-16 17:53:15 +00:00
// Filtering Ordered Sets
/**
* Returns an NSOrderedSet instance containing elements filtered using predicate.
*/
- (NSOrderedSet *) filteredOrderedSetUsingPredicate: (NSPredicate *)predicate;
2019-05-16 17:53:15 +00:00
// Describing a set
/**
* Description of this NSOrderedSet.
*/
2019-05-16 17:53:15 +00:00
- (NSString *) description;
/**
* Localized description of this NSOrderedSet.
*/
2019-05-16 17:53:15 +00:00
- (NSString *) descriptionWithLocale: (NSLocale *)locale;
/**
* Localized description, indented if flag is YES.
*/
2019-05-20 08:01:20 +00:00
- (NSString *) descriptionWithLocale: (NSLocale *)locale indent: (BOOL)flag;
// Convert to other types
/**
* Returns an NSArray instance with the objects contained in the receiver.
*/
- (GS_GENERIC_CLASS(NSArray, ElementT) *) array;
/**
* Returns an NSSet instance with the objects contained in the receiver.
*/
- (GS_GENERIC_CLASS(NSSet, ElementT) *) set;
2019-05-16 17:53:15 +00:00
@end
// Mutable Ordered Set
/**
* This class provides a mutable ordered set.
*/
GS_EXPORT_CLASS
@interface GS_GENERIC_CLASS(NSMutableOrderedSet, ElementT) : GS_GENERIC_CLASS(NSOrderedSet, ElementT)
2019-05-18 00:17:10 +00:00
// Creating a Mutable Ordered Set
/**
* Returns an ordered set with capacity.
*/
+ (instancetype) orderedSetWithCapacity: (NSUInteger)capacity;
/**
* Initializes an ordered set with capacity.
*/
- (instancetype) initWithCapacity: (NSUInteger)capacity;
/**
* Initializes an empty ordered set.
*/
2019-05-18 00:17:10 +00:00
- (instancetype) init;
/**
* Adds an object to the receiver.
*/
- (void) addObject: (GS_GENERIC_TYPE(ElementT))anObject;
/**
* Adds items in the C array whose length is indicated by count to the receiver.
*/
- (void) addObjects: (const GS_GENERIC_TYPE(ElementT)[])objects count: (NSUInteger)count;
/**
* Adds objects from otherArray to the receiver.
*/
- (void) addObjectsFromArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)otherArray;
/**
* Inserts object into the receiver at index.
*/
- (void) insertObject: (GS_GENERIC_TYPE(ElementT))object atIndex: (NSUInteger)index;
/**
* Sets the object at index/
*/
- (void) setObject: (GS_GENERIC_TYPE(ElementT))object atIndexedSubscript: (NSUInteger)index;
/**
* Inserts objects at indexes from array. The number of elements in indexes must be the same as the number of
* elements in array.
*/
- (void) insertObjects: (GS_GENERIC_CLASS(NSArray, ElementT)*)array atIndexes: (NSIndexSet *)indexes;
/**
* Remove object from receiver.
*/
- (void) removeObject: (GS_GENERIC_TYPE(ElementT))object;
/**
* Remove object at index.
*/
- (void) removeObjectAtIndex: (NSUInteger)index;
/**
* Remove objects at indexes.
*/
- (void) removeObjectsAtIndexes: (NSIndexSet *)indexes;
/**
* Remove objects matching items in otherArray.
*/
- (void) removeObjectsInArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)otherArray;
/**
* Remove objects at indexes matching range.
*/
- (void) removeObjectsInRange: (NSRange)range;
/**
* Remove all objects from the set.
*/
- (void) removeAllObjects;
/**
* Replace the object at index with object.
*/
- (void) replaceObjectAtIndex: (NSUInteger)index
withObject: (GS_GENERIC_TYPE(ElementT))object;
/**
* Replace objects at indexes with objects. The number of objects must correspond to the number of indexes.
*/
2019-05-18 00:17:10 +00:00
- (void) replaceObjectsAtIndexes: (NSIndexSet *)indexes
2024-11-16 12:06:27 +00:00
withObjects: (GS_GENERIC_CLASS(NSArray, ElementT)*)objects;
/**
* Replace objects in the given range with items from the C array objects.
*/
2024-11-16 12:06:27 +00:00
- (void) replaceObjectsInRange: (NSRange)range
withObjects: (const GS_GENERIC_TYPE(ElementT)[])objects
count: (NSUInteger)count;
/**
* Set object at index.
*/
- (void) setObject: (GS_GENERIC_TYPE(ElementT))object atIndex: (NSUInteger)index;
/**
* Move objects at indexes to index.
*/
- (void) moveObjectsAtIndexes: (NSIndexSet *)indexes toIndex: (NSUInteger)index;
/**
* Exchange object at index with object at otherIndex.
*/
2024-11-16 12:06:27 +00:00
- (void) exchangeObjectAtIndex: (NSUInteger)index withObjectAtIndex: (NSUInteger)otherIndex;
/**
* Filter objects using predicate.
*/
- (void) filterUsingPredicate: (NSPredicate *)predicate;
/**
* Sort using descriptors.
*/
2024-11-16 12:06:27 +00:00
- (void) sortUsingDescriptors: (NSArray *)descriptors;
/**
* Sort using comparator
*/
2019-05-18 00:17:10 +00:00
- (void) sortUsingComparator: (NSComparator)comparator;
/**
* Sort with options and comparator.
*/
2019-05-18 00:17:10 +00:00
- (void) sortWithOptions: (NSSortOptions)options
2024-11-16 12:06:27 +00:00
usingComparator: (NSComparator)comparator;
/**
* Sort the given range using options and comparator.
*/
2019-05-18 00:17:10 +00:00
- (void) sortRange: (NSRange)range
2024-11-16 12:06:27 +00:00
options: (NSSortOptions)options
2019-05-18 00:17:10 +00:00
usingComparator: (NSComparator)comparator;
/**
* This method leaves only objects that interesect with ordered set aSet in the receiver.
*/
2024-11-16 12:06:27 +00:00
- (void) intersectOrderedSet: (GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet;
/**
* This method leaves only objects that intersect with set aSet in the receiver.
*/
2024-11-16 12:06:27 +00:00
- (void) intersectSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet;
/**
* Receiver contains itself minus those elements in ordered set aSet.
*/
2024-11-16 12:06:27 +00:00
- (void) minusOrderedSet: (GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet;
/**
* Receiver contains itself minus those elements in aSet.
*/
2024-11-16 12:06:27 +00:00
- (void) minusSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet;
/**
* Receiver contains the union of itself and ordered set aSet.
*/
2024-11-16 12:06:27 +00:00
- (void) unionOrderedSet: (GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet;
/**
* Receiver contains the union of itself and aSet.
*/
2024-11-16 12:06:27 +00:00
- (void) unionSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet;
/**
* Implementation of NSCopying protocol.
*/
2019-05-18 00:17:10 +00:00
- (instancetype) initWithCoder: (NSCoder *)coder;
@end
2019-05-18 00:17:10 +00:00
2019-06-13 22:58:50 +00:00
#if defined(__cplusplus)
}
2019-05-18 00:17:10 +00:00
#endif
2019-06-13 22:58:50 +00:00
2019-06-27 06:00:14 +00:00
#endif /* OS_API_VERSION check */
2019-06-13 22:58:50 +00:00
#endif /* _NSOrderedSet_h_GNUSTEP_BASE_INCLUDE */