/* * CPSet.j * Foundation * * Created by Bailey Carlson. * * TODO: Needs to implement CPCoding, CPCopying, CPEnumerator. */ import "CPObject.j" import "CPArray.j" import "CPString.j" import "CPDate.j" import "CPNumber.j" //import "CPEnumerator.j" @implementation CPSet : CPObject { var _contents; unsigned _count; } /* Creates and returns an empty set. */ + (id)set { return [[self alloc] init]; } /* Creates and returns a set containing a uniqued collection of those objects contained in a given array. @param anArray array containing the objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. */ + (id)setWithArray:(CPArray)array { return [[self alloc] initWithArray:array]; } /* Creates and returns a set that contains a single given object. @param anObject The object to add to the new set. */ + (id)setWithObject:(id)anObject { return [[self alloc] initWithObjects:anObject]; } /* Creates and returns a set containing a specified number of objects from a given array of objects. @param objects A array of objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. @param count The number of objects from objects to add to the new set. */ + (id)setWithObjects:(id)objects count:(unsigned)count { return [[self alloc] initWithObjects:objects count:count]; } /* Creates and returns a set containing the objects in a given argument list. @param anObject The first object to add to the new set. @param ... A comma-separated list of objects, ending with nil, to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. */ + (id)setWithObjects:(id)anObject, ... { return [[self alloc] initWithObjects:arguments]; } /* Creates and returns a set containing the objects from another set. @param aSet A set containing the objects to add to the new set. */ + (id)setWithSet:(CPSet)set { return [[self alloc] initWithSet:set]; } /* Basic initializer, returns an empty set */ - (id)init { self = [super init]; if (self) { _count = 0; _contents = {}; } return self; } /* Initializes a newly allocated set with the objects that are contained in a given array. @param array An array of objects to add to the new set. If the same object appears more than once in array, it is represented only once in the returned set. */ - (id)initWithArray:(CPArray)array { self = [self init]; if (self) { for (var i = 0; i