From 86d4b528d8a4752cc689279fb6d38c8697a507bb Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Thu, 11 Aug 2011 23:20:00 -0600 Subject: string-list: Add API to remove an item from an unsorted list Teach the string-list API how to remove an entry in O(1) runtime by moving the last entry to the vacated spot. As such, the routine works only for unsorted lists. Signed-off-by: Johannes Sixt Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- string-list.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'string-list.c') diff --git a/string-list.c b/string-list.c index 51681189e..d9810aba4 100644 --- a/string-list.c +++ b/string-list.c @@ -185,3 +185,12 @@ int unsorted_string_list_has_string(struct string_list *list, return unsorted_string_list_lookup(list, string) != NULL; } +void unsorted_string_list_delete_item(struct string_list *list, int i, int free_util) +{ + if (list->strdup_strings) + free(list->items[i].string); + if (free_util) + free(list->items[i].util); + list->items[i] = list->items[list->nr-1]; + list->nr--; +} -- cgit v1.2.1