Lines Matching refs:sk
99 size_t sk_num(const _STACK *sk) { in sk_num() argument
100 if (sk == NULL) { in sk_num()
103 return sk->num; in sk_num()
106 void sk_zero(_STACK *sk) { in sk_zero() argument
107 if (sk == NULL || sk->num == 0) { in sk_zero()
110 OPENSSL_memset(sk->data, 0, sizeof(void*) * sk->num); in sk_zero()
111 sk->num = 0; in sk_zero()
112 sk->sorted = 0; in sk_zero()
115 void *sk_value(const _STACK *sk, size_t i) { in sk_value() argument
116 if (!sk || i >= sk->num) { in sk_value()
119 return sk->data[i]; in sk_value()
122 void *sk_set(_STACK *sk, size_t i, void *value) { in sk_set() argument
123 if (!sk || i >= sk->num) { in sk_set()
126 return sk->data[i] = value; in sk_set()
129 void sk_free(_STACK *sk) { in sk_free() argument
130 if (sk == NULL) { in sk_free()
133 OPENSSL_free(sk->data); in sk_free()
134 OPENSSL_free(sk); in sk_free()
137 void sk_pop_free_ex(_STACK *sk, void (*call_free_func)(stack_free_func, void *), in sk_pop_free_ex() argument
139 if (sk == NULL) { in sk_pop_free_ex()
143 for (size_t i = 0; i < sk->num; i++) { in sk_pop_free_ex()
144 if (sk->data[i] != NULL) { in sk_pop_free_ex()
145 call_free_func(free_func, sk->data[i]); in sk_pop_free_ex()
148 sk_free(sk); in sk_pop_free_ex()
158 void sk_pop_free(_STACK *sk, stack_free_func free_func) { in sk_pop_free() argument
159 sk_pop_free_ex(sk, call_free_func_legacy, free_func); in sk_pop_free()
162 size_t sk_insert(_STACK *sk, void *p, size_t where) { in sk_insert() argument
163 if (sk == NULL) { in sk_insert()
167 if (sk->num_alloc <= sk->num + 1) { in sk_insert()
169 size_t new_alloc = sk->num_alloc << 1; in sk_insert()
174 if (new_alloc < sk->num_alloc || alloc_size / sizeof(void *) != new_alloc) { in sk_insert()
175 new_alloc = sk->num_alloc + 1; in sk_insert()
180 if (new_alloc < sk->num_alloc || alloc_size / sizeof(void *) != new_alloc) { in sk_insert()
184 data = OPENSSL_realloc(sk->data, alloc_size); in sk_insert()
189 sk->data = data; in sk_insert()
190 sk->num_alloc = new_alloc; in sk_insert()
193 if (where >= sk->num) { in sk_insert()
194 sk->data[sk->num] = p; in sk_insert()
196 OPENSSL_memmove(&sk->data[where + 1], &sk->data[where], in sk_insert()
197 sizeof(void *) * (sk->num - where)); in sk_insert()
198 sk->data[where] = p; in sk_insert()
201 sk->num++; in sk_insert()
202 sk->sorted = 0; in sk_insert()
204 return sk->num; in sk_insert()
207 void *sk_delete(_STACK *sk, size_t where) { in sk_delete() argument
210 if (!sk || where >= sk->num) { in sk_delete()
214 ret = sk->data[where]; in sk_delete()
216 if (where != sk->num - 1) { in sk_delete()
217 OPENSSL_memmove(&sk->data[where], &sk->data[where + 1], in sk_delete()
218 sizeof(void *) * (sk->num - where - 1)); in sk_delete()
221 sk->num--; in sk_delete()
225 void *sk_delete_ptr(_STACK *sk, const void *p) { in sk_delete_ptr() argument
226 if (sk == NULL) { in sk_delete_ptr()
230 for (size_t i = 0; i < sk->num; i++) { in sk_delete_ptr()
231 if (sk->data[i] == p) { in sk_delete_ptr()
232 return sk_delete(sk, i); in sk_delete_ptr()
239 int sk_find(const _STACK *sk, size_t *out_index, const void *p, in sk_find() argument
242 if (sk == NULL) { in sk_find()
246 if (sk->comp == NULL) { in sk_find()
248 for (size_t i = 0; i < sk->num; i++) { in sk_find()
249 if (sk->data[i] == p) { in sk_find()
263 if (!sk_is_sorted(sk)) { in sk_find()
264 for (size_t i = 0; i < sk->num; i++) { in sk_find()
265 const void *elem = sk->data[i]; in sk_find()
266 if (call_cmp_func(sk->comp, &p, &elem) == 0) { in sk_find()
280 size_t lo = 0, hi = sk->num; in sk_find()
285 const void *elem = sk->data[mid]; in sk_find()
286 int r = call_cmp_func(sk->comp, &p, &elem); in sk_find()
311 void *sk_shift(_STACK *sk) { in sk_shift() argument
312 if (sk == NULL) { in sk_shift()
315 if (sk->num == 0) { in sk_shift()
318 return sk_delete(sk, 0); in sk_shift()
321 size_t sk_push(_STACK *sk, void *p) { return (sk_insert(sk, p, sk->num)); } in sk_push() argument
323 void *sk_pop(_STACK *sk) { in sk_pop() argument
324 if (sk == NULL) { in sk_pop()
327 if (sk->num == 0) { in sk_pop()
330 return sk_delete(sk, sk->num - 1); in sk_pop()
333 _STACK *sk_dup(const _STACK *sk) { in sk_dup() argument
337 if (sk == NULL) { in sk_dup()
341 ret = sk_new(sk->comp); in sk_dup()
346 s = (void **)OPENSSL_realloc(ret->data, sizeof(void *) * sk->num_alloc); in sk_dup()
352 ret->num = sk->num; in sk_dup()
353 OPENSSL_memcpy(ret->data, sk->data, sizeof(void *) * sk->num); in sk_dup()
354 ret->sorted = sk->sorted; in sk_dup()
355 ret->num_alloc = sk->num_alloc; in sk_dup()
356 ret->comp = sk->comp; in sk_dup()
364 void sk_sort(_STACK *sk) { in sk_sort() argument
365 if (sk == NULL || sk->comp == NULL || sk->sorted) { in sk_sort()
378 if (sk->num >= 2) { in sk_sort()
380 (int (*)(const void *, const void *))(sk->comp); in sk_sort()
381 qsort(sk->data, sk->num, sizeof(void *), comp_func); in sk_sort()
383 sk->sorted = 1; in sk_sort()
386 int sk_is_sorted(const _STACK *sk) { in sk_is_sorted() argument
387 if (!sk) { in sk_is_sorted()
390 return sk->sorted; in sk_is_sorted()
393 stack_cmp_func sk_set_cmp_func(_STACK *sk, stack_cmp_func comp) { in sk_set_cmp_func() argument
394 stack_cmp_func old = sk->comp; in sk_set_cmp_func()
396 if (sk->comp != comp) { in sk_set_cmp_func()
397 sk->sorted = 0; in sk_set_cmp_func()
399 sk->comp = comp; in sk_set_cmp_func()
404 _STACK *sk_deep_copy(const _STACK *sk, in sk_deep_copy() argument
409 _STACK *ret = sk_dup(sk); in sk_deep_copy()