diff options
Diffstat (limited to 'runtime/map-gen.c')
-rw-r--r-- | runtime/map-gen.c | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/runtime/map-gen.c b/runtime/map-gen.c index 1034b5fb..c6acb781 100644 --- a/runtime/map-gen.c +++ b/runtime/map-gen.c @@ -40,6 +40,7 @@ #define VALN s #define MAP_SET_VAL(a,b,c,d) _new_map_set_str(a,b,c,d) #define MAP_GET_VAL(n) _stp_get_str(n) +#define VAL_IS_ZERO(val,add) (val == 0 || *val == 0) #elif VALUE_TYPE == INT64 #define VALTYPE int64_t #define VSTYPE int64_t @@ -47,6 +48,7 @@ #define VALN i #define MAP_SET_VAL(a,b,c,d) _new_map_set_int64(a,b,c,d) #define MAP_GET_VAL(n) _stp_get_int64(n) +#define VAL_IS_ZERO(val,add) (val == 0) #elif VALUE_TYPE == STAT #define VALTYPE stat* #define VSTYPE int64_t @@ -54,6 +56,7 @@ #define VALN x #define MAP_SET_VAL(a,b,c,d) _new_map_set_stat(a,b,c,d) #define MAP_GET_VAL(n) _stp_get_stat(n) +#define VAL_IS_ZERO(val,add) (val == 0 && !add) #else #error Need to define VALUE_TYPE as STRING, STAT, or INT64 #endif /* VALUE_TYPE */ @@ -333,18 +336,10 @@ static unsigned int KEYSYM(hash) (ALLKEYSD(key)) } -#if VALUE_TYPE == INT64 +#if VALUE_TYPE == INT64 || VALUE_TYPE == STRING MAP KEYSYM(_stp_map_new) (unsigned max_entries) { - MAP m = _stp_map_new (max_entries, INT64, sizeof(struct KEYSYM(map_node)), 0); - if (m) - m->get_key = KEYSYM(map_get_key); - return m; -} -#elif VALUE_TYPE == STRING -MAP KEYSYM(_stp_map_new) (unsigned max_entries) -{ - MAP m = _stp_map_new (max_entries, STRING, sizeof(struct KEYSYM(map_node)), 0); + MAP m = _stp_map_new (max_entries, VALUE_TYPE, sizeof(struct KEYSYM(map_node)), 0); if (m) m->get_key = KEYSYM(map_get_key); return m; @@ -415,8 +410,9 @@ int KEYSYM(__stp_map_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add) head = &map->hashes[hv]; hlist_for_each(e, head) { - n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct hlist_node)); - dbug ("n=%lx key1=%ld n->key1=%ld\n", (long)n, key1, n->key1); + n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct list_head)); + dbug("map_node =%lx\n", (long)n); + //dbug ("n=%lx key1=%ld n->key1=%ld\n", (long)n, key1, n->key1); if (KEY1_EQ_P(n->key1, key1) #if KEY_ARITY > 1 && KEY2_EQ_P(n->key2, key2) @@ -431,32 +427,25 @@ int KEYSYM(__stp_map_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add) #endif #endif ) { -#if VALUE_TYPE == STAT - return _new_map_set_stat(map,(struct map_node *)n, val, add, 0); -#else + if VAL_IS_ZERO(val,add) { + if (!add) + _new_map_del_node(map,(struct map_node *)n); + return 0; + + } return MAP_SET_VAL(map,(struct map_node *)n, val, add); -#endif } } /* key not found */ dbug("key not found\n"); -#if VALUE_TYPE == STRING - if ((val == 0 || *val == 0) && !add) - return 0; -#else - if (val == 0 && !add) + if VAL_IS_ZERO(val,add) return 0; -#endif n = (struct KEYSYM(map_node)*)_new_map_create (map, head); if (n == NULL) return -1; KEYCPY(n); -#if VALUE_TYPE == STAT - return _new_map_set_stat(map,(struct map_node *)n, val, add, 1); -#else return MAP_SET_VAL(map,(struct map_node *)n, val, 0); -#endif } int KEYSYM(_stp_map_set) (MAP map, ALLKEYSD(key), VSTYPE val) @@ -484,8 +473,8 @@ VALTYPE KEYSYM(_stp_map_get) (MAP map, ALLKEYSD(key)) head = &map->hashes[hv]; hlist_for_each(e, head) { - n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct hlist_node)); -// dbug ("n =%lx key=" EACHKEY(%ld) "\n", (long)n, n->key1.val, n->key2.val); + n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct list_head)); + dbug("map_node =%lx\n", (long)n); if (KEY1_EQ_P(n->key1, key1) #if KEY_ARITY > 1 && KEY2_EQ_P(n->key2, key2) @@ -561,5 +550,5 @@ VALTYPE KEYSYM(_stp_map_get) (MAP map, ALLKEYSD(key)) #undef MAP_SET_VAL #undef MAP_GET_VAL - +#undef VAL_IS_ZERO |