@@ -31,10 +31,17 @@ + dictionaryWithHashSize: (int)hashsize { return [[[self alloc] initWithHashSize: hashsize] autorelease]; } + ++ dictionaryWithKey: (OFObject *)key + andObject: (OFObject*)obj +{ + return [[[self alloc] initWithKey: key + andObject: obj] autorelease]; +} + dictionaryWithKeysAndObjects: (OFObject *)first, ... { id ret; va_list args; @@ -97,10 +104,49 @@ } memset(data, 0, size * sizeof(OFList*)); return self; } + +- initWithKey: (OFObject *)key + andObject: (OFObject*)obj +{ + Class c; + uint32_t hash; + + self = [self init]; + + if (key == nil || obj == nil) { + c = isa; + [self dealloc]; + @throw [OFInvalidArgumentException newWithClass: isa + andSelector: _cmd]; + } + + hash = [key hash] & (size - 1); + + @try { + key = [key copy]; + } @catch (OFException *e) { + [self dealloc]; + @throw e; + } + + @try { + data[hash] = [[OFList alloc] init]; + + [data[hash] append: key]; + [data[hash] append: obj]; + } @catch (OFException *e) { + [self dealloc]; + @throw e; + } @finally { + [key release]; + } + + return self; +} - initWithKeysAndObjects: (OFObject *)first, ... { id ret; va_list args; @@ -121,19 +167,25 @@ uint32_t hash; self = [self init]; obj = va_arg(args, id); - if (obj == nil) { + if (first == nil || obj == nil) { c = isa; [self dealloc]; @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; } hash = [first hash] & (size - 1); - key = [first copy]; + + @try { + key = [first copy]; + } @catch (OFException *e) { + [self dealloc]; + @throw e; + } @try { if (data[hash] == nil) data[hash] = [[OFList alloc] init];