ObjFW  Diff

Differences From Artifact [4dfb42e01c]:

To Artifact [f9c1f2768d]:


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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
	}

	free(table->data);
	table->data = ndata;
	table->size = nsize;
}

static void
insert(struct objc_hashtable *table, const void *key, const void *obj)
{
	uint32_t i, hash, last;
	struct objc_hashtable_bucket *bucket;

	resize(table, table->count + 1);

	hash = table->hash(key);
	last = table->size;

	for (i = hash & (table->size - 1); i < last && table->data[i] != NULL &&
	    table->data[i] != &objc_deleted_bucket; i++);

	if (i >= last) {
		last = hash & (table->size - 1);

		for (i = 0; i < last && table->data[i] != NULL &&
		    table->data[i] != &objc_deleted_bucket; i++);
	}

	if (i >= last)
		OBJC_ERROR("No free bucket!");

	if ((bucket = malloc(sizeof(struct objc_hashtable_bucket))) == NULL)
		OBJC_ERROR("Not enough memory to allocate hash table bucket!");

	bucket->key = key;
	bucket->hash = hash;
	bucket->obj = obj;

	table->data[i] = bucket;
	table->count++;
}

static inline bool
index_for_key(struct objc_hashtable *table, const void *key, uint32_t *index)
{
	uint32_t i, hash;

	hash = table->hash(key) & (table->size - 1);








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







123
124
125
126
127
128
129



































130
131
132
133
134
135
136
	}

	free(table->data);
	table->data = ndata;
	table->size = nsize;
}




































static inline bool
index_for_key(struct objc_hashtable *table, const void *key, uint32_t *index)
{
	uint32_t i, hash;

	hash = table->hash(key) & (table->size - 1);

195
196
197
198
199
200
201
202

203
204
205
206
207
208

























209

210
211
212
213
214
215
216
	return false;
}

void
objc_hashtable_set(struct objc_hashtable *table, const void *key,
    const void *obj)
{
	uint32_t idx;


	if (!index_for_key(table, key, &idx)) {
		insert(table, key, obj);
		return;
	}


























	table->data[idx]->obj = obj;

}

void*
objc_hashtable_get(struct objc_hashtable *table, const void *key)
{
	uint32_t idx;








|
>

|
|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>







160
161
162
163
164
165
166
167
168
169
170
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
	return false;
}

void
objc_hashtable_set(struct objc_hashtable *table, const void *key,
    const void *obj)
{
	uint32_t i, hash, last;
	struct objc_hashtable_bucket *bucket;

	if (index_for_key(table, key, &i)) {
		table->data[i]->obj = obj;
		return;
	}

	resize(table, table->count + 1);

	hash = table->hash(key);
	last = table->size;

	for (i = hash & (table->size - 1); i < last && table->data[i] != NULL &&
	    table->data[i] != &objc_deleted_bucket; i++);

	if (i >= last) {
		last = hash & (table->size - 1);

		for (i = 0; i < last && table->data[i] != NULL &&
		    table->data[i] != &objc_deleted_bucket; i++);
	}

	if (i >= last)
		OBJC_ERROR("No free bucket!");

	if ((bucket = malloc(sizeof(struct objc_hashtable_bucket))) == NULL)
		OBJC_ERROR("Not enough memory to allocate hash table bucket!");

	bucket->key = key;
	bucket->hash = hash;
	bucket->obj = obj;

	table->data[i] = bucket;
	table->count++;
}

void*
objc_hashtable_get(struct objc_hashtable *table, const void *key)
{
	uint32_t idx;