strings: Add strings__find and strings__cmp

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2008-10-24 14:20:37 -02:00
parent 46a3bc4626
commit 4d615b9e01
2 changed files with 24 additions and 0 deletions

View File

@ -88,3 +88,24 @@ strings_t strings__add(struct strings *self, const char *str)
return index;
}
strings_t strings__find(struct strings *self, const char *str)
{
strings_t *s;
struct search_key key = {
.self = self,
.str = str,
};
if (str == NULL)
return 0;
s = tfind(&key, &self->tree, strings__compare);
return s ? *s : 0;
}
int strings__cmp(const struct strings *self, strings_t a, strings_t b)
{
return a == b ? 0 : strcmp(strings__ptr(self, a),
strings__ptr(self, b));
}

View File

@ -22,6 +22,9 @@ struct strings *strings__new(void);
void strings__delete(struct strings *self);
strings_t strings__add(struct strings *self, const char *str);
strings_t strings__find(struct strings *self, const char *str);
int strings__cmp(const struct strings *self, strings_t a, strings_t b);
static inline const char *strings__ptr(const struct strings *self, strings_t s)
{