1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

Merge pull request #289 from michich/hashmap-small-cleanup

a tiny hashmap cleanup
This commit is contained in:
Lennart Poettering 2015-06-18 18:29:11 +02:00
commit 39765e5f92
3 changed files with 10 additions and 34 deletions

View File

@ -1798,8 +1798,6 @@ void *ordered_hashmap_next(OrderedHashmap *h, const void *key) {
struct ordered_hashmap_entry *e; struct ordered_hashmap_entry *e;
unsigned hash, idx; unsigned hash, idx;
assert(key);
if (!h) if (!h)
return NULL; return NULL;

View File

@ -65,7 +65,6 @@ typedef struct {
} Iterator; } Iterator;
#define _IDX_ITERATOR_FIRST (UINT_MAX - 1) #define _IDX_ITERATOR_FIRST (UINT_MAX - 1)
#define _IDX_ITERATOR_NIL (UINT_MAX)
#define ITERATOR_FIRST ((Iterator) { .idx = _IDX_ITERATOR_FIRST, .next_key = NULL }) #define ITERATOR_FIRST ((Iterator) { .idx = _IDX_ITERATOR_FIRST, .next_key = NULL })
typedef unsigned long (*hash_func_t)(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]); typedef unsigned long (*hash_func_t)(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);

View File

@ -24,38 +24,17 @@ void test_hashmap_funcs(void);
void test_ordered_hashmap_funcs(void); void test_ordered_hashmap_funcs(void);
static void test_ordered_hashmap_next(void) { static void test_ordered_hashmap_next(void) {
OrderedHashmap *m; _cleanup_ordered_hashmap_free_ OrderedHashmap *m = NULL;
char *val1, *val2, *val3, *val4, *r; int i;
m = ordered_hashmap_new(&string_hash_ops); assert_se(m = ordered_hashmap_new(NULL));
val1 = strdup("val1"); for (i = -2; i <= 2; i++)
assert_se(val1); assert_se(ordered_hashmap_put(m, INT_TO_PTR(i), INT_TO_PTR(i+10)) == 1);
val2 = strdup("val2"); for (i = -2; i <= 1; i++)
assert_se(val2); assert_se(ordered_hashmap_next(m, INT_TO_PTR(i)) == INT_TO_PTR(i+11));
val3 = strdup("val3"); assert_se(!ordered_hashmap_next(m, INT_TO_PTR(2)));
assert_se(val3); assert_se(!ordered_hashmap_next(NULL, INT_TO_PTR(1)));
val4 = strdup("val4"); assert_se(!ordered_hashmap_next(m, INT_TO_PTR(3)));
assert_se(val4);
ordered_hashmap_put(m, "key 1", val1);
ordered_hashmap_put(m, "key 2", val2);
ordered_hashmap_put(m, "key 3", val3);
ordered_hashmap_put(m, "key 4", val4);
r = ordered_hashmap_next(m, "key 1");
assert_se(streq(r, val2));
r = ordered_hashmap_next(m, "key 2");
assert_se(streq(r, val3));
r = ordered_hashmap_next(m, "key 3");
assert_se(streq(r, val4));
r = ordered_hashmap_next(m, "key 4");
assert_se(!r);
r = ordered_hashmap_next(NULL, "key 1");
assert_se(!r);
r = ordered_hashmap_next(m, "key 5");
assert_se(!r);
ordered_hashmap_free_free(m);
} }
static void test_uint64_compare_func(void) { static void test_uint64_compare_func(void) {