ObjFW  Diff

Differences From Artifact [3e22e7bae1]:

To Artifact [4972fbd8f3]:


12
13
14
15
16
17
18

19
20
21
22
23
24
25
#import "config.h"

#include <string.h>

#import "OFDictionary.h"
#import "OFIterator.h"
#import "OFExceptions.h"


/* Reference for static linking */
void _reference_to_OFIterator_in_OFDictionary() { [OFIterator class]; }

@implementation OFDictionary
+ dictionary;
{







>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#import "config.h"

#include <string.h>

#import "OFDictionary.h"
#import "OFIterator.h"
#import "OFExceptions.h"
#import "OFMacros.h"

/* Reference for static linking */
void _reference_to_OFIterator_in_OFDictionary() { [OFIterator class]; }

@implementation OFDictionary
+ dictionary;
{
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
	return self;
}

- initWithHashSize: (int)hashsize
{
	self = [super init];

	if (hashsize < 8 || hashsize > 31) {
		Class c = isa;
		[super free];
		@throw [OFInvalidArgumentException
			newWithClass: c
			 andSelector: _cmd];
	}

	size = (size_t)1 << hashsize;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];







|


|
<
|







55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
	return self;
}

- initWithHashSize: (int)hashsize
{
	self = [super init];

	if (hashsize < 8 || hashsize >= 28) {
		Class c = isa;
		[super free];
		@throw [OFInvalidArgumentException newWithClass: c

						    andSelector: _cmd];
	}

	size = (size_t)1 << hashsize;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
171
172
173
174
175
176
177








































178
179
180
181
182
183
184
185

			return self;
		}
	}

	@throw [OFNotInSetException newWithClass: isa];
}









































/* FIXME: Implement this! */
/*
- (BOOL)isEqual
{
}
*/
@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

			return self;
		}
	}

	@throw [OFNotInSetException newWithClass: isa];
}

- changeHashSize: (int)hashsize
{
	OFList **newdata;
	size_t newsize, i;
	of_list_object_t *iter;

	if (hashsize < 8 || hashsize >= 28)
		@throw [OFInvalidArgumentException newWithClass: isa
						    andSelector: _cmd];

	newsize = (size_t)1 << hashsize;
	newdata = [self allocNItems: newsize
			   withSize: sizeof(OFList*)];
	memset(data, 0, newsize * sizeof(OFList*));

	for (i = 0; i < size; i++) {
		if (OF_LIKELY(data[i] == nil))
			continue;

		for (iter = [data[i] first]; iter != NULL;
		    iter = iter->next->next) {
			uint32_t hash = [iter->object hash] & (newsize - 1);

			if (newdata[hash] == nil)
				newdata[hash] = [[OFList alloc] init];

			[newdata[hash] append: iter->object];
			[newdata[hash] append: iter->next->object];
		}

		[data[i] release];
	}

	[self freeMem: data];
	data = newdata;
	size = newsize;

	return self;
}

/* FIXME: Implement this! */
/*
- (BOOL)isEqual
{
}
*/
@end