ObjFW  Check-in [fa52eae66a]

Overview
Comment:Neither the key nor the value in a dictionary is allowed to be nil.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fa52eae66aee98d3ba9dc3cb1ea749e80d78ea93e2af0b257ed7ce82df925896
User & Date: js on 2009-04-24 13:57:29
Other Links: manifest | tags
Context
2009-04-25
12:48
An item size of 0 is invalid for an array. check-in: 70a65567df user: js tags: trunk
2009-04-24
13:57
Neither the key nor the value in a dictionary is allowed to be nil. check-in: fa52eae66a user: js tags: trunk
2009-04-23
12:19
Add OFIterator to iterate through an OFDictionary. check-in: cd08bff565 user: js tags: trunk
Changes

Modified src/OFDictionary.m from [2b0561f376] to [4ec6bb16d4].

81
82
83
84
85
86
87
88
89
90





91
92
93
94
95
96
97

	return [super free];
}

- set: (OFObject*)key
   to: (OFObject*)obj
{
	uint32_t hash = [key hash] & (size - 1);
	of_list_object_t *iter;






	if (data[hash] == nil)
		data[hash] = [OFList new];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) {
		if ([iter->object isEqual: key]) {
			[iter->next->object release];
			[obj retain];







|


>
>
>
>
>







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

	return [super free];
}

- set: (OFObject*)key
   to: (OFObject*)obj
{
	uint32_t hash;
	of_list_object_t *iter;

	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa];

	hash = [key hash] & (size - 1);

	if (data[hash] == nil)
		data[hash] = [OFList new];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) {
		if ([iter->object isEqual: key]) {
			[iter->next->object release];
			[obj retain];
105
106
107
108
109
110
111
112
113
114





115
116
117
118
119
120
121
122
123
124
125
126
127
128
129





130
131
132
133
134
135
136
	[data[hash] append: obj];

	return self;
}

- get: (OFObject*)key
{
	uint32_t hash = [key hash] & (size - 1);
	of_list_object_t *iter;






	if (data[hash] == nil)
		@throw [OFNotInSetException newWithClass: isa];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next)
		if ([iter->object isEqual: key])
			return iter->next->object;

	@throw [OFNotInSetException newWithClass: isa];
}

- remove: (OFObject*)key
{
	uint32_t hash = [key hash] & (size - 1);
	of_list_object_t *iter;






	if (data[hash] == nil)
		@throw [OFNotInSetException newWithClass: isa];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) {
		if ([iter->object isEqual: key]) {
			[data[hash] remove: iter->next];
			[data[hash] remove: iter];







|


>
>
>
>
>












|


>
>
>
>
>







110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
	[data[hash] append: obj];

	return self;
}

- get: (OFObject*)key
{
	uint32_t hash;
	of_list_object_t *iter;

	if (key == nil)
		@throw [OFInvalidArgumentException newWithClass: isa];

	hash = [key hash] & (size - 1);

	if (data[hash] == nil)
		@throw [OFNotInSetException newWithClass: isa];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next)
		if ([iter->object isEqual: key])
			return iter->next->object;

	@throw [OFNotInSetException newWithClass: isa];
}

- remove: (OFObject*)key
{
	uint32_t hash;
	of_list_object_t *iter;

	if (key == nil)
		@throw [OFInvalidArgumentException newWithClass: isa];

	hash = [key hash] & (size - 1);

	if (data[hash] == nil)
		@throw [OFNotInSetException newWithClass: isa];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) {
		if ([iter->object isEqual: key]) {
			[data[hash] remove: iter->next];
			[data[hash] remove: iter];