summaryrefslogtreecommitdiff
path: root/src/strset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/strset.c')
-rw-r--r--src/strset.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/strset.c b/src/strset.c
index 8f3ffe8..3f3a855 100644
--- a/src/strset.c
+++ b/src/strset.c
@@ -1,7 +1,8 @@
#include "strset.h"
-#include "str.h"
-#include "byte.h"
+
#include "alloc.h"
+#include "byte.h"
+#include "str.h"
uint32 strset_hash(char *s)
{
@@ -24,20 +25,26 @@ int strset_init(strset *set)
set->n = 0;
set->a = 10;
- set->first = (int *) alloc(sizeof(int) * (set->mask + 1));
+ set->first = (int *)alloc(sizeof(int) * (set->mask + 1));
if (!set->first) return 0;
- set->p = (strset_list *) alloc(sizeof(strset_list) * set->a);
- if (!set->p) { alloc_free(set->first); return 0; }
- set->x = (char **) alloc(sizeof(char *) * set->a);
- if (!set->x) { alloc_free(set->p); alloc_free(set->first); return 0; }
+ set->p = (strset_list *)alloc(sizeof(strset_list) * set->a);
+ if (!set->p) {
+ alloc_free(set->first);
+ return 0;
+ }
+ set->x = (char **)alloc(sizeof(char *) * set->a);
+ if (!set->x) {
+ alloc_free(set->p);
+ alloc_free(set->first);
+ return 0;
+ }
- for (h = 0; h <= set->mask; ++h)
- set->first[h] = -1;
+ for (h = 0; h <= set->mask; ++h) set->first[h] = -1;
return 1;
}
-char *strset_in(strset *set,char *s)
+char *strset_in(strset *set, char *s)
{
uint32 h;
strset_list *sl;
@@ -51,14 +58,14 @@ char *strset_in(strset *set,char *s)
sl = set->p + i;
if (sl->h == h) {
xi = set->x[i];
- if (!str_diff(xi,s)) return xi;
+ if (!str_diff(xi, s)) return xi;
}
i = sl->next;
}
return 0;
}
-int strset_add(strset *set,char *s)
+int strset_add(strset *set, char *s)
{
uint32 h;
int n;
@@ -72,13 +79,16 @@ int strset_add(strset *set,char *s)
char **newx;
newa = n + 10 + (n >> 3);
- newp = (strset_list *) alloc(sizeof(strset_list) * newa);
+ newp = (strset_list *)alloc(sizeof(strset_list) * newa);
if (!newp) return 0;
- newx = (char **) alloc(sizeof(char *) * newa);
- if (!newx) { alloc_free(newp); return 0; }
+ newx = (char **)alloc(sizeof(char *) * newa);
+ if (!newx) {
+ alloc_free(newp);
+ return 0;
+ }
- byte_copy(newp,sizeof(strset_list) * n,set->p);
- byte_copy(newx,sizeof(char *) * n,set->x);
+ byte_copy(newp, sizeof(strset_list) * n, set->p);
+ byte_copy(newx, sizeof(char *) * n, set->x);
alloc_free(set->p);
alloc_free(set->x);
set->p = newp;
@@ -90,13 +100,12 @@ int strset_add(strset *set,char *s)
int *newfirst;
int i;
uint32 h;
-
+
newmask = set->mask + set->mask + 1;
- newfirst = (int *) alloc(sizeof(int) * (newmask + 1));
+ newfirst = (int *)alloc(sizeof(int) * (newmask + 1));
if (!newfirst) return 0;
- for (h = 0; h <= newmask; ++h)
- newfirst[h] = -1;
+ for (h = 0; h <= newmask; ++h) newfirst[h] = -1;
for (i = 0; i < n; ++i) {
sl = set->p + i;