Lines Matching +full:- +full:set

1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
18 /* lookup index for each unique string in strings set */
25 const char *str = s->strs_data + key; in strset_hash_fn()
33 const char *str1 = s->strs_data + key1; in strset_equal_fn()
34 const char *str2 = s->strs_data + key2; in strset_equal_fn()
41 struct strset *set = calloc(1, sizeof(*set)); in strset__new() local
43 int err = -ENOMEM; in strset__new()
45 if (!set) in strset__new()
46 return ERR_PTR(-ENOMEM); in strset__new()
48 hash = hashmap__new(strset_hash_fn, strset_equal_fn, set); in strset__new()
52 set->strs_data_max_len = max_data_sz; in strset__new()
53 set->strs_hash = hash; in strset__new()
58 set->strs_data = malloc(init_data_sz); in strset__new()
59 if (!set->strs_data) in strset__new()
62 memcpy(set->strs_data, init_data, init_data_sz); in strset__new()
63 set->strs_data_len = init_data_sz; in strset__new()
64 set->strs_data_cap = init_data_sz; in strset__new()
66 for (off = 0; off < set->strs_data_len; off += strlen(set->strs_data + off) + 1) { in strset__new()
71 if (err == -EEXIST) in strset__new()
78 return set; in strset__new()
80 strset__free(set); in strset__new()
84 void strset__free(struct strset *set) in strset__free() argument
86 if (IS_ERR_OR_NULL(set)) in strset__free()
89 hashmap__free(set->strs_hash); in strset__free()
90 free(set->strs_data); in strset__free()
91 free(set); in strset__free()
94 size_t strset__data_size(const struct strset *set) in strset__data_size() argument
96 return set->strs_data_len; in strset__data_size()
99 const char *strset__data(const struct strset *set) in strset__data() argument
101 return set->strs_data; in strset__data()
104 static void *strset_add_str_mem(struct strset *set, size_t add_sz) in strset_add_str_mem() argument
106 return libbpf_add_mem(&set->strs_data, &set->strs_data_cap, 1, in strset_add_str_mem()
107 set->strs_data_len, set->strs_data_max_len, add_sz); in strset_add_str_mem()
112 * - >0 offset into string data, if string is found;
113 * - -ENOENT, if string is not in the string data;
114 * - <0, on any other error.
116 int strset__find_str(struct strset *set, const char *s) in strset__find_str() argument
123 p = strset_add_str_mem(set, len); in strset__find_str()
125 return -ENOMEM; in strset__find_str()
127 new_off = set->strs_data_len; in strset__find_str()
130 if (hashmap__find(set->strs_hash, new_off, &old_off)) in strset__find_str()
133 return -ENOENT; in strset__find_str()
139 * - > 0 offset into string data, on success;
140 * - < 0, on error.
142 int strset__add_str(struct strset *set, const char *s) in strset__add_str() argument
148 /* Hashmap keys are always offsets within set->strs_data, so to even in strset__add_str()
151 * until set->strs_data_len is incremented, that string is just a piece in strset__add_str()
154 * ready to be used, only a simple set->strs_data_len increment away. in strset__add_str()
157 p = strset_add_str_mem(set, len); in strset__add_str()
159 return -ENOMEM; in strset__add_str()
161 new_off = set->strs_data_len; in strset__add_str()
168 err = hashmap__insert(set->strs_hash, new_off, new_off, in strset__add_str()
170 if (err == -EEXIST) in strset__add_str()
175 set->strs_data_len += len; /* new unique string, adjust data length */ in strset__add_str()