Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -58,10 +58,17 @@ arguments: arguments]; va_end(arguments); return ret; } + +- initWithObjects: (id*)objects + count: (size_t)count +{ + return (id)[[OFCountedSet_hashtable alloc] initWithObjects: objects + count: count]; +} - initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFCountedSet_hashtable alloc] initWithObject: firstObject Index: src/OFCountedSet_hashtable.m ================================================================== --- src/OFCountedSet_hashtable.m +++ src/OFCountedSet_hashtable.m @@ -81,10 +81,28 @@ self = [self init]; @try { id *objects = [array objects]; size_t i, count = [array count]; + + for (i = 0; i < count; i++) + [self addObject: objects[i]]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithObjects: (id*)objects + count: (size_t)count +{ + self = [self init]; + + @try { + size_t i; for (i = 0; i < count; i++) [self addObject: objects[i]]; } @catch (id e) { [self release]; Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -57,10 +57,17 @@ arguments: arguments]; va_end(arguments); return ret; } + +- initWithObjects: (id*)objects + count: (size_t)count +{ + return (id)[[OFMutableSet_hashtable alloc] initWithObjects: objects + count: count]; +} - initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFMutableSet_hashtable alloc] initWithObject: firstObject Index: src/OFSet.h ================================================================== --- src/OFSet.h +++ src/OFSet.h @@ -68,10 +68,20 @@ * \param firstObject The first object for the set * \return A new, autoreleased set with the specified objects */ + setWithObjects: (id)firstObject, ...; +/** + * \brief Creates a new set with the specified objects. + * + * \param objects An array of objects for the set + * \param count The number of objects in the specified array + * \return A new, autoreleased set with the specified objects + */ ++ setWithObjects: (id*)objects + count: (size_t)count; + /** * \brief Initializes an already allocated set with the specified set. * * \param set The set to initialize the set with * \return An initialized set with the specified set @@ -92,10 +102,20 @@ * \param firstObject The first object for the set * \return An initialized set with the specified objects */ - initWithObjects: (id)firstObject, ...; +/** + * \brief Initializes an already allocated set with the specified objects. + * + * \param objects An array of objects for the set + * \param count The number of objects in the specified array + * \return An initialized set with the specified objects + */ +- initWithObjects: (id*)objects + count: (size_t)count; + /** * \brief Initializes an already allocated set with the specified object and * va_list. * * \param firstObject The first object for the set Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -57,10 +57,17 @@ arguments: arguments]; va_end(arguments); return ret; } + +- initWithObjects: (id*)objects + count: (size_t)count +{ + return (id)[[OFSet_hashtable alloc] initWithObjects: objects + count: count]; +} - initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFSet_hashtable alloc] initWithObject: firstObject @@ -134,10 +141,17 @@ arguments: arguments] autorelease]; va_end(arguments); return ret; } + ++ setWithObjects: (id*)objects + count: (size_t)count +{ + return [[[self alloc] initWithObjects: objects + count: count] autorelease]; +} - init { if (isa == [OFSet class]) { Class c = isa; @@ -163,11 +177,11 @@ [self release]; @throw [OFNotImplementedException exceptionWithClass: c selector: _cmd]; } -- (id)initWithObjects:(id)firstObject, ... +- (id)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); @@ -175,10 +189,19 @@ arguments: arguments]; va_end(arguments); return ret; } + +- initWithObjects: (id*)objects + count: (size_t)count +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException exceptionWithClass: c + selector: _cmd]; +} - initWithObject: (id)firstObject arguments: (va_list)arguments { Class c = isa; Index: src/OFSet_hashtable.m ================================================================== --- src/OFSet_hashtable.m +++ src/OFSet_hashtable.m @@ -80,10 +80,34 @@ @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFNumber *one = [OFNumber numberWithSize: 1]; id *objects = [array objects]; size_t i, count = [array count]; + + for (i = 0; i < count; i++) + [dictionary _setObject: one + forKey: objects[i] + copyKey: NO]; + + [pool release]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithObjects: (id*)objects + count: (size_t)count +{ + self = [self init]; + + @try { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFNumber *one = [OFNumber numberWithSize: 1]; + size_t i; for (i = 0; i < count; i++) [dictionary _setObject: one forKey: objects[i] copyKey: NO];