Index: src/OFMutableSet.h ================================================================== --- src/OFMutableSet.h +++ src/OFMutableSet.h @@ -29,10 +29,28 @@ # ifndef DOXYGEN # define ObjectType id # endif @interface OFMutableSet: OFSet #endif +/*! + * @brief Creates a new OFMutableSet with enough memory to hold the specified + * number of objects. + * + * @param capacity The initial capacity for the OFMutableSet + * @return A new autoreleased OFMutableSet + */ ++ (instancetype)setWithCapacity: (size_t)capacity; + +/*! + * @brief Initializes an already allocated OFMutableSet with enough memory to + * hold the specified number of objects. + * + * @param capacity The initial capacity for the OFMutableSet + * @return An initialized OFMutableSet + */ +- initWithCapacity: (size_t)capacity; + /*! * @brief Adds the specified object to the set. * * @param object The object to add to the set */ Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -76,10 +76,15 @@ - initWithSerialization: (OFXMLElement*)element { return (id)[[OFMutableSet_hashtable alloc] initWithSerialization: element]; } + +- initWithCapacity: (size_t)capacity +{ + return (id)[[OFMutableSet_hashtable alloc] initWithCapacity: capacity]; +} - retain { return self; } @@ -114,10 +119,15 @@ if (self == [OFMutableSet class]) return (id)&placeholder; return [super alloc]; } + ++ (instancetype)setWithCapacity: (size_t)capacity +{ + return [[[self alloc] initWithCapacity: capacity] autorelease]; +} - init { if (object_getClass(self) == [OFMutableSet class]) { @try { @@ -129,10 +139,15 @@ } } return [super init]; } + +- initWithCapacity: (size_t)capacity +{ + OF_INVALID_INIT_METHOD +} - (void)addObject: (id)object { OF_UNRECOGNIZED_SELECTOR }