CoreFW  Check-in [082d69b467]

Overview
Comment:Add cfw_map_{get,set}_c() for convenience.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 082d69b467afb957d270d0e55173efdb299375ac82468463aba18b18eb674c82
User & Date: js on 2012-09-30 02:21:50
Other Links: manifest | tags
Context
2012-09-30
02:56
Fix a leak in map. check-in: 01129bb203 user: js tags: trunk
02:21
Add cfw_map_{get,set}_c() for convenience. check-in: 082d69b467 user: js tags: trunk
01:46
Add a few new string functions. check-in: 499faa2771 user: js tags: trunk
Changes

Modified src/map.c from [30449aad8d] to [6c8dd7f75d].

25
26
27
28
29
30
31

32
33
34
35
36
37
38
 */

#include <stdlib.h>

#include "object.h"
#include "map.h"
#include "hash.h"


static struct bucket {
	CFWObject *key, *obj;
	uint32_t hash;
} deleted = { NULL, NULL, 0 };

struct CFWMap {







>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 */

#include <stdlib.h>

#include "object.h"
#include "map.h"
#include "hash.h"
#include "string.h"

static struct bucket {
	CFWObject *key, *obj;
	uint32_t hash;
} deleted = { NULL, NULL, 0 };

struct CFWMap {
247
248
249
250
251
252
253
















254
255
256
257
258
259
260

		if (cfw_equal(map->data[i]->key, key))
			return map->data[i]->obj;
	}

	return NULL;
}

















bool
cfw_map_set(CFWMap *map, void *key, void *obj)
{
	uint32_t i, hash, last;

	if (key == NULL)







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







248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

		if (cfw_equal(map->data[i]->key, key))
			return map->data[i]->obj;
	}

	return NULL;
}

void*
cfw_map_get_c(CFWMap *map, const char *key)
{
	CFWString *str;
	void *ret;

	if ((str = cfw_new(cfw_string, key)) == NULL)
		return NULL;

	ret = cfw_map_get(map, str);

	cfw_unref(str);

	return ret;
}

bool
cfw_map_set(CFWMap *map, void *key, void *obj)
{
	uint32_t i, hash, last;

	if (key == NULL)
351
352
353
354
355
356
357
















358
359
360
361
362
363
364

		if (!resize(map, map->items))
			return false;
	}

	return true;
}

















void
cfw_map_iter(CFWMap *map, cfw_map_iter_t *iter)
{
	iter->_map = map;
	iter->_pos = 0;








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







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

		if (!resize(map, map->items))
			return false;
	}

	return true;
}

bool
cfw_map_set_c(CFWMap *map, const char *key, void *obj)
{
	CFWString *str;
	bool ret;

	if ((str = cfw_new(cfw_string, key)) == NULL)
		return false;

	ret = cfw_map_set(map, str, obj);

	cfw_unref(str);

	return ret;
}

void
cfw_map_iter(CFWMap *map, cfw_map_iter_t *iter)
{
	iter->_map = map;
	iter->_pos = 0;

Modified src/map.h from [1c28d70477] to [29511f679d].

37
38
39
40
41
42
43

44

45
46
47
48
	CFWMap *_map;
	uint32_t _pos;
} cfw_map_iter_t;

extern CFWClass *cfw_map;
extern size_t cfw_map_size(CFWMap*);
extern void* cfw_map_get(CFWMap*, void*);

extern bool cfw_map_set(CFWMap*, void*, void*);

extern void cfw_map_iter(CFWMap*, cfw_map_iter_t*);
extern void cfw_map_iter_next(cfw_map_iter_t*);

#endif







>

>




37
38
39
40
41
42
43
44
45
46
47
48
49
50
	CFWMap *_map;
	uint32_t _pos;
} cfw_map_iter_t;

extern CFWClass *cfw_map;
extern size_t cfw_map_size(CFWMap*);
extern void* cfw_map_get(CFWMap*, void*);
extern void* cfw_map_get_c(CFWMap*, const char*);
extern bool cfw_map_set(CFWMap*, void*, void*);
extern bool cfw_map_set_c(CFWMap*, const char*, void*);
extern void cfw_map_iter(CFWMap*, cfw_map_iter_t*);
extern void cfw_map_iter_next(cfw_map_iter_t*);

#endif