basic/hashmap,set: move pointer symbol adjactent to the returned value

I think this is nicer in general, and here in particular we have a lot
of code like:
 static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) {
         return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h));
 }
and it's visually appealing to use the same whitespace in the function
signature and the cast in the body of the function.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-09-01 13:45:51 +02:00
parent e4126adf45
commit 8a35af80fc
4 changed files with 52 additions and 52 deletions
+22 -22
View File
@@ -323,12 +323,12 @@ static void n_entries_dec(HashmapBase *h) {
h->n_direct_entries--;
}
static void *storage_ptr(HashmapBase *h) {
static void* storage_ptr(HashmapBase *h) {
return h->has_indirect ? h->indirect.storage
: h->direct.storage;
}
static uint8_t *hash_key(HashmapBase *h) {
static uint8_t* hash_key(HashmapBase *h) {
return h->has_indirect ? h->indirect.hash_key
: shared_hash_key;
}
@@ -371,16 +371,16 @@ static void get_hash_key(uint8_t hash_key[HASH_KEY_SIZE], bool reuse_is_ok) {
memcpy(hash_key, current, sizeof(current));
}
static struct hashmap_base_entry *bucket_at(HashmapBase *h, unsigned idx) {
static struct hashmap_base_entry* bucket_at(HashmapBase *h, unsigned idx) {
return (struct hashmap_base_entry*)
((uint8_t*) storage_ptr(h) + idx * hashmap_type_info[h->type].entry_size);
}
static struct plain_hashmap_entry *plain_bucket_at(Hashmap *h, unsigned idx) {
static struct plain_hashmap_entry* plain_bucket_at(Hashmap *h, unsigned idx) {
return (struct plain_hashmap_entry*) bucket_at(HASHMAP_BASE(h), idx);
}
static struct ordered_hashmap_entry *ordered_bucket_at(OrderedHashmap *h, unsigned idx) {
static struct ordered_hashmap_entry* ordered_bucket_at(OrderedHashmap *h, unsigned idx) {
return (struct ordered_hashmap_entry*) bucket_at(HASHMAP_BASE(h), idx);
}
@@ -388,13 +388,13 @@ static struct set_entry *set_bucket_at(Set *h, unsigned idx) {
return (struct set_entry*) bucket_at(HASHMAP_BASE(h), idx);
}
static struct ordered_hashmap_entry *bucket_at_swap(struct swap_entries *swap, unsigned idx) {
static struct ordered_hashmap_entry* bucket_at_swap(struct swap_entries *swap, unsigned idx) {
return &swap->e[idx - _IDX_SWAP_BEGIN];
}
/* Returns a pointer to the bucket at index idx.
* Understands real indexes and swap indexes, hence "_virtual". */
static struct hashmap_base_entry *bucket_at_virtual(HashmapBase *h, struct swap_entries *swap,
static struct hashmap_base_entry* bucket_at_virtual(HashmapBase *h, struct swap_entries *swap,
unsigned idx) {
if (idx < _IDX_SWAP_BEGIN)
return bucket_at(h, idx);
@@ -405,7 +405,7 @@ static struct hashmap_base_entry *bucket_at_virtual(HashmapBase *h, struct swap_
assert_not_reached("Invalid index");
}
static dib_raw_t *dib_raw_ptr(HashmapBase *h) {
static dib_raw_t* dib_raw_ptr(HashmapBase *h) {
return (dib_raw_t*)
((uint8_t*) storage_ptr(h) + hashmap_type_info[h->type].entry_size * n_buckets(h));
}
@@ -503,7 +503,7 @@ static unsigned prev_idx(HashmapBase *h, unsigned idx) {
return (n_buckets(h) + idx - 1U) % n_buckets(h);
}
static void *entry_value(HashmapBase *h, struct hashmap_base_entry *e) {
static void* entry_value(HashmapBase *h, struct hashmap_base_entry *e) {
switch (h->type) {
case HASHMAP_TYPE_PLAIN:
@@ -735,7 +735,7 @@ bool _hashmap_iterate(HashmapBase *h, Iterator *i, void **value, const void **ke
(idx != IDX_NIL); \
(idx) = hashmap_iterate_entry((h), &(i)))
IteratedCache *_hashmap_iterated_cache_new(HashmapBase *h) {
IteratedCache* _hashmap_iterated_cache_new(HashmapBase *h) {
IteratedCache *cache;
assert(h);
@@ -764,7 +764,7 @@ static void reset_direct_storage(HashmapBase *h) {
memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets);
}
static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
HashmapBase *h;
const struct hashmap_type_info *hi = &hashmap_type_info[type];
bool up;
@@ -872,7 +872,7 @@ static void hashmap_free_no_clear(HashmapBase *h) {
free(h);
}
HashmapBase *_hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value) {
HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value) {
if (h) {
_hashmap_clear(h, default_free_key, default_free_value);
hashmap_free_no_clear(h);
@@ -1329,7 +1329,7 @@ int hashmap_update(Hashmap *h, const void *key, void *value) {
return 0;
}
void *_hashmap_get(HashmapBase *h, const void *key) {
void* _hashmap_get(HashmapBase *h, const void *key) {
struct hashmap_base_entry *e;
unsigned hash, idx;
@@ -1345,7 +1345,7 @@ void *_hashmap_get(HashmapBase *h, const void *key) {
return entry_value(h, e);
}
void *hashmap_get2(Hashmap *h, const void *key, void **key2) {
void* hashmap_get2(Hashmap *h, const void *key, void **key2) {
struct plain_hashmap_entry *e;
unsigned hash, idx;
@@ -1374,7 +1374,7 @@ bool _hashmap_contains(HashmapBase *h, const void *key) {
return bucket_scan(h, hash, key) != IDX_NIL;
}
void *_hashmap_remove(HashmapBase *h, const void *key) {
void* _hashmap_remove(HashmapBase *h, const void *key) {
struct hashmap_base_entry *e;
unsigned hash, idx;
void *data;
@@ -1394,7 +1394,7 @@ void *_hashmap_remove(HashmapBase *h, const void *key) {
return data;
}
void *hashmap_remove2(Hashmap *h, const void *key, void **rkey) {
void* hashmap_remove2(Hashmap *h, const void *key, void **rkey) {
struct plain_hashmap_entry *e;
unsigned hash, idx;
void *data;
@@ -1512,7 +1512,7 @@ int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_
return 0;
}
void *_hashmap_remove_value(HashmapBase *h, const void *key, void *value) {
void* _hashmap_remove_value(HashmapBase *h, const void *key, void *value) {
struct hashmap_base_entry *e;
unsigned hash, idx;
@@ -1542,7 +1542,7 @@ static unsigned find_first_entry(HashmapBase *h) {
return hashmap_iterate_entry(h, &i);
}
void *_hashmap_first_key_and_value(HashmapBase *h, bool remove, void **ret_key) {
void* _hashmap_first_key_and_value(HashmapBase *h, bool remove, void **ret_key) {
struct hashmap_base_entry *e;
void *key, *data;
unsigned idx;
@@ -1717,7 +1717,7 @@ int _hashmap_move_one(HashmapBase *h, HashmapBase *other, const void *key) {
return 0;
}
HashmapBase *_hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
HashmapBase *copy;
int r;
@@ -1745,7 +1745,7 @@ HashmapBase *_hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
return copy;
}
char **_hashmap_get_strv(HashmapBase *h) {
char** _hashmap_get_strv(HashmapBase *h) {
char **sv;
Iterator i;
unsigned idx, n;
@@ -1762,7 +1762,7 @@ char **_hashmap_get_strv(HashmapBase *h) {
return sv;
}
void *ordered_hashmap_next(OrderedHashmap *h, const void *key) {
void* ordered_hashmap_next(OrderedHashmap *h, const void *key) {
struct ordered_hashmap_entry *e;
unsigned hash, idx;
@@ -1967,7 +1967,7 @@ int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void
return 0;
}
IteratedCache *iterated_cache_free(IteratedCache *cache) {
IteratedCache* iterated_cache_free(IteratedCache *cache) {
if (cache) {
free(cache->keys.ptr);
free(cache->values.ptr);