Use linear hash ordering.
Showing
1 changed file
with
22 additions
and
10 deletions
... | @@ -135,14 +135,9 @@ alias_lookup_or_install(char *name, int install) | ... | @@ -135,14 +135,9 @@ alias_lookup_or_install(char *name, int install) |
135 | 135 | ||
136 | pos = hash(name); | 136 | pos = hash(name); |
137 | 137 | ||
138 | for (i = pos;;) | 138 | for (i = pos; aliases[i].name;) |
139 | { | 139 | { |
140 | if (aliases[i].name == NULL) | 140 | if (strcmp(aliases[i].name, name) == 0) |
141 | { | ||
142 | if (!slot && install) | ||
143 | slot = &aliases[i]; | ||
144 | } | ||
145 | else if (strcmp(aliases[i].name, name) == 0) | ||
146 | return &aliases[i]; | 141 | return &aliases[i]; |
147 | if (++i >= hash_size[hash_num]) | 142 | if (++i >= hash_size[hash_num]) |
148 | i = 0; | 143 | i = 0; |
... | @@ -153,8 +148,8 @@ alias_lookup_or_install(char *name, int install) | ... | @@ -153,8 +148,8 @@ alias_lookup_or_install(char *name, int install) |
153 | if (!install) | 148 | if (!install) |
154 | return NULL; | 149 | return NULL; |
155 | 150 | ||
156 | if (slot) | 151 | if (aliases[i].name == NULL) |
157 | return slot; | 152 | return &aliases[i]; |
158 | 153 | ||
159 | if (alias_rehash()) | 154 | if (alias_rehash()) |
160 | return NULL; | 155 | return NULL; |
... | @@ -236,12 +231,29 @@ alias_print_group(char *name, list_t list) | ... | @@ -236,12 +231,29 @@ alias_print_group(char *name, list_t list) |
236 | void | 231 | void |
237 | alias_destroy(char *name) | 232 | alias_destroy(char *name) |
238 | { | 233 | { |
234 | int i, j, r; | ||
239 | alias_t *alias = alias_lookup_or_install(name, 0); | 235 | alias_t *alias = alias_lookup_or_install(name, 0); |
240 | if (!alias) | 236 | if (!alias) |
241 | return; | 237 | return; |
242 | free(alias->name); | 238 | free(alias->name); |
243 | alias->name = NULL; | ||
244 | util_slist_destroy(&alias->list); | 239 | util_slist_destroy(&alias->list); |
240 | |||
241 | for (i = alias - aliases;;) | ||
242 | { | ||
243 | aliases[i].name = NULL; | ||
244 | j = i; | ||
245 | |||
246 | do | ||
247 | { | ||
248 | if (++i >= hash_size[hash_num]) | ||
249 | i = 0; | ||
250 | if (!aliases[i].name) | ||
251 | return; | ||
252 | r = hash(aliases[i].name); | ||
253 | } while ((j < r && r <= i) || (i < j && j < r) || (r <= i && i < j)); | ||
254 | |||
255 | aliases[j] = aliases[i]; | ||
256 | } | ||
245 | } | 257 | } |
246 | 258 | ||
247 | char * | 259 | char * | ... | ... |
-
Please register or sign in to post a comment