diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-05-24 01:17:45 +0200 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-05-24 01:17:45 +0200 |
commit | 4d97ae66f941d9817a8b4857a34fd7ba237a2861 (patch) | |
tree | 407fc2ad430cb833ab43f1f5047df950d62a8ac5 /src/nvim/hashtab.h | |
parent | 98255c7a78d5c9ccbbc580160d13dec2978a081a (diff) | |
download | rneovim-4d97ae66f941d9817a8b4857a34fd7ba237a2861.tar.gz rneovim-4d97ae66f941d9817a8b4857a34fd7ba237a2861.tar.bz2 rneovim-4d97ae66f941d9817a8b4857a34fd7ba237a2861.zip |
Remove long_u: hashtab: Cleanup: Others.
hashtab.h:
- Add missing includes.
- Move hash_T to the top and use it to define hashtab_T.
- Move hash_removed related definitions to the top, as they are used in
the definition of hashtab_T.
- Reformat multiline expression (start continuation with operator).
- Reformat function declaration into one single line.
hashtab.c:
- Use C99 style variable declarations (move declarations as near to
first-usage point as possible).
- Simplify oldarray/newarray computation.
- Simplify unneeded else branch.
- Remove redundant casts.
Diffstat (limited to 'src/nvim/hashtab.h')
-rw-r--r-- | src/nvim/hashtab.h | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/nvim/hashtab.h b/src/nvim/hashtab.h index 8abb94b9a1..b556c6a9f3 100644 --- a/src/nvim/hashtab.h +++ b/src/nvim/hashtab.h @@ -1,6 +1,17 @@ #ifndef NVIM_HASHTAB_H #define NVIM_HASHTAB_H +#include "nvim/vim.h" + +/// Type for hash number (hash calculation result). +typedef long_u hash_T; + +/// The address of "hash_removed" is used as a magic number +/// for hi_key to indicate a removed item. +#define HI_KEY_REMOVED &hash_removed +#define HASHITEM_EMPTY(hi) ((hi)->hi_key == NULL \ + || (hi)->hi_key == &hash_removed) + /// A hastable item. /// /// Each item has a NUL terminated string key. @@ -19,7 +30,7 @@ /// This reduces the size of this item by 1/3. typedef struct hashitem_S { /// Cached hash number for hi_key. - long_u hi_hash; + hash_T hi_hash; /// Item key. /// @@ -30,12 +41,6 @@ typedef struct hashitem_S { char_u *hi_key; } hashitem_T; -/// The address of "hash_removed" is used as a magic number -/// for hi_key to indicate a removed item. -#define HI_KEY_REMOVED &hash_removed -#define HASHITEM_EMPTY(hi) ((hi)->hi_key == NULL || (hi)->hi_key == \ - &hash_removed) - /// Initial size for a hashtable. /// Our items are relatively small and growing is expensive, thus start with 16. /// Must be a power of 2. @@ -60,9 +65,6 @@ typedef struct hashtable_S { hashitem_T ht_smallarray[HT_INIT_SIZE]; /// initial array } hashtab_T; -/// Type for hash number (hash calculation result). -typedef long_u hash_T; - // hashtab.c void hash_init(hashtab_T *ht); void hash_clear(hashtab_T *ht); @@ -71,8 +73,7 @@ hashitem_T *hash_find(hashtab_T *ht, char_u *key); hashitem_T *hash_lookup(hashtab_T *ht, char_u *key, hash_T hash); void hash_debug_results(void); int hash_add(hashtab_T *ht, char_u *key); -int hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, - hash_T hash); +int hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash); void hash_remove(hashtab_T *ht, hashitem_T *hi); void hash_lock(hashtab_T *ht); void hash_unlock(hashtab_T *ht); |