ObjFW  Check-in [4f18e380bf]

Overview
Comment:OFMutableDictionary: Add mutations counter.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4f18e380bf4bd4dc44d246b1126dd20fad74dc7c7b7c4888527e6de1612504e4
User & Date: js on 2010-01-03 21:03:42
Other Links: manifest | tags
Context
2010-01-03
21:08
Implement Fast Enumeration for OFDictionary. check-in: b110e218cb user: js tags: trunk
21:03
OFMutableDictionary: Add mutations counter. check-in: 4f18e380bf user: js tags: trunk
20:59
Improve Fast Enumeration test. check-in: 28543f9fd0 user: js tags: trunk
Changes

Modified src/OFMutableDictionary.h from [a6dee4def6] to [825c0561fc].

10
11
12
13
14
15
16
17





18
19
20
21
22
23
24
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28







-
+
+
+
+
+







 */

#import "OFDictionary.h"

/**
 * The OFMutableDictionary class is a class for using mutable hash tables.
 */
@interface OFMutableDictionary: OFDictionary {}
@interface OFMutableDictionary: OFDictionary
{
	unsigned long mutations;
}

/**
 * Sets a key to an object. A key can be any object.
 *
 * \param key The key to set
 * \param obj The object to set the key to
 */
- setObject: (OFObject*)obj

Modified src/OFMutableDictionary.m from [cb7126369e] to [301606f51d].

85
86
87
88
89
90
91


92
93
94
95
96
97
98
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100







+
+







	if (i >= size)
		for (i = 0; i < size && data[i].key != nil &&
		    ![data[i].key isEqual: key]; i++);

	/* Key not in dictionary */
	if (i >= size || ![data[i].key isEqual: key]) {
		resize(self, isa, count + 1, &data, &size);

		mutations++;

		i = hash & (size - 1);
		for (; i < size && data[i].key != nil; i++);

		/* In case the last bucket is already used */
		if (i >= size)
			for (i = 0; i < size && data[i].key != nil; i++);
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167







+










		return self;

	[data[i].key release];
	[data[i].object release];
	data[i].key = nil;

	count--;
	mutations++;
	resize(self, isa, count, &data, &size);

	return self;
}

- (id)copy
{
	return [[OFDictionary alloc] initWithDictionary: self];
}
@end