FSTImmutableSortedSet.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import <Foundation/Foundation.h>
  2. NS_ASSUME_NONNULL_BEGIN
  3. /**
  4. * FSTImmutableSortedSet is a set. It is immutable, but has methods to create new sets that are
  5. * mutations of it, in an efficient way.
  6. */
  7. @interface FSTImmutableSortedSet <KeyType> : NSObject
  8. + (FSTImmutableSortedSet<KeyType> *)setWithComparator:(NSComparator)comparator;
  9. + (FSTImmutableSortedSet<KeyType> *)setWithKeysFromDictionary:(NSDictionary<KeyType, id> *)array
  10. comparator:(NSComparator)comparator;
  11. - (BOOL)containsObject:(KeyType)object;
  12. - (FSTImmutableSortedSet<KeyType> *)setByAddingObject:(KeyType)object;
  13. - (FSTImmutableSortedSet<KeyType> *)setByRemovingObject:(KeyType)object;
  14. - (KeyType)firstObject;
  15. - (KeyType)lastObject;
  16. - (NSUInteger)count;
  17. - (BOOL)isEmpty;
  18. /**
  19. * Returns the index of the object or NSNotFound if the object is not found.
  20. *
  21. * @param object The object to return the index for.
  22. * @return The index of the object, or NSNotFound if not found.
  23. */
  24. - (NSUInteger)indexOfObject:(KeyType)object;
  25. - (void)enumerateObjectsUsingBlock:(void (^)(KeyType obj, BOOL *stop))block;
  26. - (void)enumerateObjectsFrom:(KeyType)start
  27. to:(_Nullable KeyType)end
  28. usingBlock:(void (^)(KeyType obj, BOOL *stop))block;
  29. - (void)enumerateObjectsReverse:(BOOL)reverse usingBlock:(void (^)(KeyType obj, BOOL *stop))block;
  30. - (NSEnumerator<KeyType> *)objectEnumerator;
  31. - (NSEnumerator<KeyType> *)objectEnumeratorFrom:(KeyType)startKey;
  32. @end
  33. NS_ASSUME_NONNULL_END