From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0D398138350 for ; Sun, 19 Jan 2020 09:49:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3E5FFE091A; Sun, 19 Jan 2020 09:49:47 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 224FEE091A for ; Sun, 19 Jan 2020 09:49:47 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 39C2134E270 for ; Sun, 19 Jan 2020 09:49:46 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 767D8AC for ; Sun, 19 Jan 2020 09:49:44 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1579427097.3d6b64ef4c4dfd0fe2e008c7cc28a94904775e1e.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/set.c libq/set.h X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 3d6b64ef4c4dfd0fe2e008c7cc28a94904775e1e X-VCS-Branch: master Date: Sun, 19 Jan 2020 09:49:44 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: b3d93452-d8d3-4013-81fe-b76d2f3452b0 X-Archives-Hash: 33dcd4d3cdbfd4cae03c287fbe526f54 commit: 3d6b64ef4c4dfd0fe2e008c7cc28a94904775e1e Author: Fabian Groffen gentoo org> AuthorDate: Sun Jan 19 09:44:57 2020 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sun Jan 19 09:44:57 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3d6b64ef libq/set: change interface of contains_set to return internal key Allow to refer to the internal allocated key name, which can avoid another duplicate in certain cases. Signed-off-by: Fabian Groffen gentoo.org> libq/set.c | 11 ++++++----- libq/set.h | 3 +-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libq/set.c b/libq/set.c index 4529c3a..ceb6f47 100644 --- a/libq/set.c +++ b/libq/set.c @@ -148,23 +148,24 @@ add_set_value(const char *name, void *ptr, set *q) return NULL; } -/* returns whether s is in set */ -bool +/* returns whether name is in set, and if so, the set-internal key + * representation (an internal copy of name made during addition) */ +const char * contains_set(const char *name, set *q) { unsigned int hash; int pos; set_elem *w; - bool found; + const char *found; hash = fnv1a32(name); pos = hash % _SET_HASH_SIZE; - found = false; + found = NULL; if (q->buckets[pos] != NULL) { for (w = q->buckets[pos]; w != NULL; w = w->next) { if (w->hash == hash && strcmp(w->name, name) == 0) { - found = true; + found = w->name; break; } } diff --git a/libq/set.h b/libq/set.h index c65eb0f..5d53f95 100644 --- a/libq/set.h +++ b/libq/set.h @@ -7,7 +7,6 @@ #define _SET_H 1 #include -#include #include #include "xarray.h" @@ -32,7 +31,7 @@ set *create_set(void); set *add_set(const char *name, set *q); set *add_set_unique(const char *name, set *q, bool *unique); void *add_set_value(const char *name, void *ptr, set *q); -bool contains_set(const char *name, set *q); +const char *contains_set(const char *name, set *q); void *get_set(const char *name, set *q); void *del_set(const char *s, set *q, bool *removed); size_t list_set(set *q, char ***l);