summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 15cb500)
raw | patch | inline | side by side (parent: 15cb500)
author | Stephen Boyd <bebarino@gmail.com> | |
Wed, 24 Mar 2010 07:16:02 +0000 (00:16 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 25 Mar 2010 02:41:19 +0000 (19:41 -0700) |
Sometimes users need to lookup a string in an unsorted string_list. In
that case they should use this function instead of the version for
sorted strings.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
that case they should use this function instead of the version for
sorted strings.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/technical/api-string-list.txt | patch | blob | history | |
string-list.c | patch | blob | history | |
string-list.h | patch | blob | history |
diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt
index 293bb15d206e71f57e906b33ca27ee05e3429521..6d8c24bb1e68e86d70d4a68d02e3a4d5ccb94c2a 100644 (file)
`unsorted_string_list_has_string`::
It's like `string_list_has_string()` but for unsorted lists.
+
+`unsorted_string_list_lookup`::
+
+ It's like `string_list_lookup()` but for unsorted lists.
+
-This function needs to look through all items, as opposed to its
+The above two functions need to look through all items, as opposed to their
counterpart for sorted lists, which performs a binary search.
Data structures
diff --git a/string-list.c b/string-list.c
index 1ac536e638dbbc02deb2d4e4a607cc52f7f7c108..c9ad7fcd49669b0dff481d9ab857bf70d8a51bca 100644 (file)
--- a/string-list.c
+++ b/string-list.c
qsort(list->items, list->nr, sizeof(*list->items), cmp_items);
}
-int unsorted_string_list_has_string(struct string_list *list, const char *string)
+struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
+ const char *string)
{
int i;
for (i = 0; i < list->nr; i++)
if (!strcmp(string, list->items[i].string))
- return 1;
- return 0;
+ return list->items + i;
+ return NULL;
+}
+
+int unsorted_string_list_has_string(struct string_list *list,
+ const char *string)
+{
+ return unsorted_string_list_lookup(list, string) != NULL;
}
diff --git a/string-list.h b/string-list.h
index 6569cf607b18b84f39ebee613471f270e42cfbdc..63b69c8d75ee33120a65a23598ddf93e84831bdd 100644 (file)
--- a/string-list.h
+++ b/string-list.h
struct string_list_item *string_list_append(const char *string, struct string_list *list);
void sort_string_list(struct string_list *list);
int unsorted_string_list_has_string(struct string_list *list, const char *string);
-
+struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
+ const char *string);
#endif /* STRING_LIST_H */