Ejemplo n.º 1
0
Archivo: mime.c Proyecto: codesun/xetn
void Mime_initModule() {
	HashMap_init(&module.s2t_map);
	HashMap_init(&module.t2s_map);
	Mime p;
	for(uint32_t i = 0; i < MIME_NUM; ++i) {
		p = mime_arr + i;
		HashMap_put(&module.s2t_map, p->suffix, (void*)p->type);
		HashMap_put(&module.t2s_map, p->type,   (void*)p->suffix);
	}
}
Ejemplo n.º 2
0
void Function_clearFunctionCache(void)
{
	Entry entry;

	HashMap oldMap = s_funcMap;
	Iterator itor = Iterator_create(oldMap);

	s_funcMap = HashMap_create(59, TopMemoryContext);
	while((entry = Iterator_next(itor)) != 0)
	{
		Function func = (Function)Entry_getValue(entry);
		if(func != 0)
		{
			if(Function_inUse(func))
			{
				/* This is the replace_jar function or similar. Just
				 * move it to the new map.
				 */
				HashMap_put(s_funcMap, Entry_getKey(entry), func);
			}
			else
			{
				Entry_setValue(entry, 0);
				PgObject_free((PgObject)func);
			}
		}
	}
	PgObject_free((PgObject)itor);
	PgObject_free((PgObject)oldMap);
}
Ejemplo n.º 3
0
int insertProperty(const char *key, void* value)
{
#ifdef SDFAPIONLY
    /* SDFSetPropery may be called before loadProperties, initialize the hash here in this case */
    if (!_sdf_globalPropertiesMap) {
        initializeProperties();
    }
#endif
    if (strcmp(key, "ZS_LOG_LEVEL") == 0)
        set_log_level(value);
    return ((SDF_TRUE == HashMap_put(_sdf_globalPropertiesMap, key, value)) ? 0 : 1);
}
Ejemplo n.º 4
0
int setProperty(const char *key, void* value)
{
#ifdef SDFAPIONLY
    /* SDFSetPropery may be called before loadProperties, initialize the hash here in this case */
    if (!_sdf_globalPropertiesMap) {
        initializeProperties();
    }
#endif
    if (strcmp(key, "ZS_LOG_LEVEL") == 0)
        set_log_level(value);
    if (SDF_TRUE != HashMap_put(_sdf_globalPropertiesMap, key, value)) {
        void *p = HashMap_replace(_sdf_globalPropertiesMap, key, value);
        if (p) {
            plat_free(p);
            return 0;
        } else {
            return 1;
        }
    }
    return 0;
}
Ejemplo n.º 5
0
void HasMap_test() {
    HashMap* m = HashMap_init();

    bstring b1 = bfromcstr("1");
    bstring b2 = bfromcstr("2");
    bstring b3 = bfromcstr("3");
    bstring b4 = bfromcstr("4");
    bstring b5 = bfromcstr("5");
    bstring b6 = bfromcstr("6");
    bstring b7 = bfromcstr("7");

    HashMap_put(m, b1, 1);
    HashMap_put(m, b2, 2);
    HashMap_put(m, b3, 3);
    HashMap_put(m, b4, 4);
    HashMap_put(m, b5, 5);
    HashMap_put(m, b6, 6);

    printf("=== HashMap exists ===\n");
    printf("%d: %s\n", 1, HashMap_exists(m, b1) ? "true" : "false");
    printf("%d: %s\n", 2, HashMap_exists(m, b2) ? "true" : "false");
    printf("%d: %s\n", 3, HashMap_exists(m, b3) ? "true" : "false");
    printf("%d: %s\n", 4, HashMap_exists(m, b4) ? "true" : "false");
    printf("%d: %s\n", 5, HashMap_exists(m, b5) ? "true" : "false");
    printf("%d: %s\n", 6, HashMap_exists(m, b6) ? "true" : "false");
    printf("%d: %s\n", 7, HashMap_exists(m, b7) ? "true" : "false");

    printf("\n=== Remove 6 ===\n");
    int val = HashMap_remove(m, b6);
    printf("%d == %d\n", val, 6);
    printf("%d: %s\n", 6, HashMap_exists(m, b6) ? "true" : "false");

    printf("\n=== Get 4 ===\n");
    val = HashMap_get(m, b4);
    printf("%d == %d\n", val, 4);
    printf("%d: %s\n", 4, HashMap_exists(m, b4) ? "true" : "false");

    HashMap_destroy(m);
}
Ejemplo n.º 6
0
static void test_hashmap_put_get(void** state) {
	HashMap map = (HashMap)*state;

	variant_t v1, v2, v3, v4, v5;
	v1.inum = 1;
	v2.inum = 2;
	v3.inum = 123;
	v4.inum = 456;
	v5.inum = 999;

	String_t p1 = STRING_OF("v1");
	String_t p2 = STRING_OF("v2");
	String_t p3 = STRING_OF("v3");
	String_t p4 = STRING_OF("v4");
	String_t p5 = STRING_OF("v5");

	void* ret;
	ret = HashMap_put(map, p1, &v1);
	assert_ptr_equal(ret, &v1);
	ret = HashMap_put(map, p2, &v2);
	assert_ptr_equal(ret, &v2);
	ret = HashMap_put(map, p3, &v3);
	assert_ptr_equal(ret, &v3);
	ret = HashMap_put(map, p4, &v4);
	assert_ptr_equal(ret, &v4);
	ret = HashMap_put(map, p5, &v5);
	assert_ptr_equal(ret, &v5);
	ret = HashMap_put(map, p5, &v5);
	assert_ptr_equal(ret, NULL);

	String_t g1 = STRING_OF("v1");
	String_t g2 = STRING_OF("v2");
	String_t g3 = STRING_OF("v3");
	String_t g4 = STRING_OF("v4");
	String_t g5 = STRING_OF("v5");
	ret = HashMap_get(map, g5);
	assert_ptr_equal(ret, &v5);
	assert_int_equal(*(int*)ret, v5.inum);
	assert_int_equal(HashMap_contains(map, g5), 1);
	ret = HashMap_get(map, g4);
	assert_ptr_equal(ret, &v4);
	assert_int_equal(*(int*)ret, v4.inum);
	assert_int_equal(HashMap_contains(map, g4), 1);
	ret = HashMap_get(map, g3);
	assert_ptr_equal(ret, &v3);
	assert_int_equal(*(int*)ret, v3.inum);
	assert_int_equal(HashMap_contains(map, g3), 1);
	ret = HashMap_get(map, g2);
	assert_ptr_equal(ret, &v2);
	assert_int_equal(*(int*)ret, v2.inum);
	assert_int_equal(HashMap_contains(map, g2), 1);
	ret = HashMap_get(map, g1);
	assert_ptr_equal(ret, &v1);
	assert_int_equal(*(int*)ret, v1.inum);
	assert_int_equal(HashMap_contains(map, g1), 1);
	String_t g0 = STRING_OF("vv");
	assert_int_equal(HashMap_contains(map, g0), 0);

	ret = HashMap_delete(map, g0);
	assert_ptr_equal(ret, NULL);
	ret = HashMap_delete(map, g3);
	assert_ptr_not_equal(ret, NULL);
	ret = HashMap_get(map, g3);
	assert_ptr_equal(ret, NULL);
}