git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <bebarino@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 5/7] string-list: add unsorted_string_list_lookup()
Date: Wed, 24 Mar 2010 00:16:02 -0700	[thread overview]
Message-ID: <1269414964-9518-6-git-send-email-bebarino@gmail.com> (raw)
In-Reply-To: <1269414964-9518-1-git-send-email-bebarino@gmail.com>

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>
---
 Documentation/technical/api-string-list.txt |    6 +++++-
 string-list.c                               |   13 ++++++++++---
 string-list.h                               |    3 ++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt
index 293bb15..6d8c24b 100644
--- a/Documentation/technical/api-string-list.txt
+++ b/Documentation/technical/api-string-list.txt
@@ -104,8 +104,12 @@ write `string_list_insert(...)->util = ...;`.
 `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 1ac536e..c9ad7fc 100644
--- a/string-list.c
+++ b/string-list.c
@@ -168,12 +168,19 @@ void sort_string_list(struct string_list *list)
 	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 6569cf6..63b69c8 100644
--- a/string-list.h
+++ b/string-list.h
@@ -38,5 +38,6 @@ struct string_list_item *string_list_lookup(const char *string, struct string_li
 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 */
-- 
1.7.0.3.254.g4503b

  parent reply	other threads:[~2010-03-24  7:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-24  7:15 [PATCH 0/7] fmt-merge-msg improvements Stephen Boyd
2010-03-24  7:15 ` [PATCH 1/7] fmt-merge-msg: be quiet if nothing to merge Stephen Boyd
2010-03-25  2:39   ` Junio C Hamano
2010-03-25  3:48     ` Stephen Boyd
2010-03-24  7:15 ` [PATCH 2/7] t6200: modernize with test_tick Stephen Boyd
2010-03-24  7:16 ` [PATCH 3/7] t6200: test fmt-merge-msg more Stephen Boyd
2010-03-24  7:16 ` [PATCH 4/7] fmt-merge-msg: use pretty.c routines Stephen Boyd
2010-03-24  7:16 ` Stephen Boyd [this message]
2010-03-24  7:16 ` [PATCH 6/7] fmt-merge-msg: remove custom string_list implementation Stephen Boyd
2010-03-30  5:18   ` Junio C Hamano
2010-04-01  6:08     ` Stephen Boyd
2010-04-01  6:29     ` [PATCH 8/7] Make string_list_append() consistent with everything else Stephen Boyd
2010-04-01 20:07       ` Julian Phillips
2010-03-24  7:16 ` [PATCH 7/7] fmt-merge-msg: hide summary option Stephen Boyd
2010-03-25  2:45   ` Junio C Hamano
2010-03-25  5:19     ` Stephen Boyd
2010-03-26 19:30       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1269414964-9518-6-git-send-email-bebarino@gmail.com \
    --to=bebarino@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).