FSTImmutableSortedSet.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. - (KeyType)predecessorObject:(KeyType)entry;
  19. /**
  20. * Returns the index of the object or NSNotFound if the object is not found.
  21. *
  22. * @param object The object to return the index for.
  23. * @return The index of the object, or NSNotFound if not found.
  24. */
  25. - (NSUInteger)indexOfObject:(KeyType)object;
  26. - (void)enumerateObjectsUsingBlock:(void (^)(KeyType obj, BOOL *stop))block;
  27. - (void)enumerateObjectsFrom:(KeyType)start
  28. to:(_Nullable KeyType)end
  29. usingBlock:(void (^)(KeyType obj, BOOL *stop))block;
  30. - (void)enumerateObjectsReverse:(BOOL)reverse usingBlock:(void (^)(KeyType obj, BOOL *stop))block;
  31. - (NSEnumerator<KeyType> *)objectEnumerator;
  32. - (NSEnumerator<KeyType> *)objectEnumeratorFrom:(KeyType)startKey;
  33. @end
  34. NS_ASSUME_NONNULL_END