1 |
commit: 3d6b64ef4c4dfd0fe2e008c7cc28a94904775e1e |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jan 19 09:44:57 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jan 19 09:44:57 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3d6b64ef |
7 |
|
8 |
libq/set: change interface of contains_set to return internal key |
9 |
|
10 |
Allow to refer to the internal allocated key name, which can avoid |
11 |
another duplicate in certain cases. |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
libq/set.c | 11 ++++++----- |
16 |
libq/set.h | 3 +-- |
17 |
2 files changed, 7 insertions(+), 7 deletions(-) |
18 |
|
19 |
diff --git a/libq/set.c b/libq/set.c |
20 |
index 4529c3a..ceb6f47 100644 |
21 |
--- a/libq/set.c |
22 |
+++ b/libq/set.c |
23 |
@@ -148,23 +148,24 @@ add_set_value(const char *name, void *ptr, set *q) |
24 |
return NULL; |
25 |
} |
26 |
|
27 |
-/* returns whether s is in set */ |
28 |
-bool |
29 |
+/* returns whether name is in set, and if so, the set-internal key |
30 |
+ * representation (an internal copy of name made during addition) */ |
31 |
+const char * |
32 |
contains_set(const char *name, set *q) |
33 |
{ |
34 |
unsigned int hash; |
35 |
int pos; |
36 |
set_elem *w; |
37 |
- bool found; |
38 |
+ const char *found; |
39 |
|
40 |
hash = fnv1a32(name); |
41 |
pos = hash % _SET_HASH_SIZE; |
42 |
|
43 |
- found = false; |
44 |
+ found = NULL; |
45 |
if (q->buckets[pos] != NULL) { |
46 |
for (w = q->buckets[pos]; w != NULL; w = w->next) { |
47 |
if (w->hash == hash && strcmp(w->name, name) == 0) { |
48 |
- found = true; |
49 |
+ found = w->name; |
50 |
break; |
51 |
} |
52 |
} |
53 |
|
54 |
diff --git a/libq/set.h b/libq/set.h |
55 |
index c65eb0f..5d53f95 100644 |
56 |
--- a/libq/set.h |
57 |
+++ b/libq/set.h |
58 |
@@ -7,7 +7,6 @@ |
59 |
#define _SET_H 1 |
60 |
|
61 |
#include <stdlib.h> |
62 |
-#include <stdbool.h> |
63 |
#include <unistd.h> |
64 |
|
65 |
#include "xarray.h" |
66 |
@@ -32,7 +31,7 @@ set *create_set(void); |
67 |
set *add_set(const char *name, set *q); |
68 |
set *add_set_unique(const char *name, set *q, bool *unique); |
69 |
void *add_set_value(const char *name, void *ptr, set *q); |
70 |
-bool contains_set(const char *name, set *q); |
71 |
+const char *contains_set(const char *name, set *q); |
72 |
void *get_set(const char *name, set *q); |
73 |
void *del_set(const char *s, set *q, bool *removed); |
74 |
size_t list_set(set *q, char ***l); |