1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos OPENSSL_SA, ossl_sa_TYPE_new, ossl_sa_TYPE_free, 6 1.1 christos ossl_sa_TYPE_free_leaves, ossl_sa_TYPE_num, ossl_sa_TYPE_doall, 7 1.1 christos ossl_sa_TYPE_doall_arg, ossl_sa_TYPE_get, ossl_sa_TYPE_set 8 1.1 christos - sparse array container 9 1.1 christos 10 1.1 christos =head1 SYNOPSIS 11 1.1 christos 12 1.1 christos #include "crypto/sparse_array.h" 13 1.1 christos 14 1.1 christos typedef struct sparse_array_st OPENSSL_SA; 15 1.1 christos 16 1.1 christos SPARSE_ARRAY_OF(TYPE) 17 1.1 christos DEFINE_SPARSE_ARRAY_OF(TYPE) 18 1.1 christos 19 1.1 christos SPARSE_ARRAY_OF(TYPE) *ossl_sa_TYPE_new(void); 20 1.1 christos void ossl_sa_TYPE_free(const SPARSE_ARRAY_OF(TYPE) *sa); 21 1.1 christos void ossl_sa_TYPE_free_leaves(const SPARSE_ARRAY_OF(TYPE) *sa); 22 1.1 christos size_t ossl_sa_TYPE_num(const SPARSE_ARRAY_OF(TYPE) *sa); 23 1.1 christos void ossl_sa_TYPE_doall(const OPENSSL_SA *sa, void (*leaf)(ossl_uintmax_t, 24 1.1 christos void *)); 25 1.1 christos void ossl_sa_TYPE_doall_arg(const OPENSSL_SA *sa, 26 1.1 christos void (*leaf)(ossl_uintmax_t, void *, void *), 27 1.1 christos void *arg); 28 1.1 christos TYPE *ossl_sa_TYPE_get(const SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx); 29 1.1 christos int ossl_sa_TYPE_set(SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx, 30 1.1 christos TYPE *value); 31 1.1 christos 32 1.1 christos =head1 DESCRIPTION 33 1.1 christos 34 1.1 christos =begin comment 35 1.1 christos 36 1.1 christos POD is pretty good at recognising function names and making them appropriately 37 1.1 christos bold... however, when part of the function name is variable, we have to help 38 1.1 christos the processor along 39 1.1 christos 40 1.1 christos =end comment 41 1.1 christos 42 1.1 christos SPARSE_ARRAY_OF() returns the name for a sparse array of the specified 43 1.1 christos B<I<TYPE>>. DEFINE_SPARSE_ARRAY_OF() creates set of functions for a sparse 44 1.1 christos array of B<I<TYPE>>. This will mean that a pointer to type B<I<TYPE>> 45 1.1 christos is stored in each element of a sparse array, the type is referenced by 46 1.1 christos B<SPARSE_ARRAY_OF>(B<I<TYPE>>) and each function name begins with 47 1.1 christos B<ossl_sa_I<TYPE>_>. For example: 48 1.1 christos 49 1.1 christos TYPE *ossl_sa_TYPE_get(SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx); 50 1.1 christos 51 1.1 christos B<ossl_sa_I<TYPE>_num>() returns the number of elements in I<sa> or 0 if I<sa> 52 1.1 christos is NULL. 53 1.1 christos 54 1.1 christos B<ossl_sa_I<TYPE>_get>() returns element I<idx> in I<sa>, where I<idx> starts 55 1.1 christos at zero. If I<idx> refers to a value that has not been set then NULL is 56 1.1 christos returned. 57 1.1 christos 58 1.1 christos B<ossl_sa_I<TYPE>_set>() sets element I<idx> in I<sa> to I<value>, where I<idx> 59 1.1 christos starts at zero. The sparse array will be resized as required. 60 1.1 christos 61 1.1 christos B<ossl_sa_I<TYPE>_new>() allocates a new empty sparse array. 62 1.1 christos 63 1.1 christos B<ossl_sa_I<TYPE>_free>() frees up the I<sa> structure. It does I<not> free up any 64 1.1 christos elements of I<sa>. After this call I<sa> is no longer valid. 65 1.1 christos 66 1.1 christos B<ossl_sa_I<TYPE>_free_leaves>() frees up the I<sa> structure and all of its 67 1.1 christos elements. After this call I<sa> is no longer valid. 68 1.1 christos 69 1.1 christos B<ossl_sa_I<TYPE>_doall>() calls the function I<leaf> for each element in I<sa> 70 1.1 christos in ascending index order. The index position, within the sparse array, 71 1.1 christos of each item is passed as the first argument to the leaf function and a 72 1.1 christos pointer to the associated value is passed as the second argument. 73 1.1 christos 74 1.1 christos B<ossl_sa_I<TYPE>_doall_arg>() calls the function I<leaf> for each element in 75 1.1 christos I<sa> in ascending index order. The index position, within the sparse 76 1.1 christos array, of each item is passed as the first argument to the leaf function, 77 1.1 christos a pointer to the associated value is passed as the second argument and 78 1.1 christos the third argument is the user supplied I<arg>. 79 1.1 christos 80 1.1 christos 81 1.1 christos =head1 NOTES 82 1.1 christos 83 1.1 christos Sparse arrays are an internal data structure and should B<not> be used by user 84 1.1 christos applications. 85 1.1 christos 86 1.1 christos Care should be taken when accessing sparse arrays in multi-threaded 87 1.1 christos environments. The B<ossl_sa_I<TYPE>_set>() operation can cause the internal 88 1.1 christos structure of the sparse array to change which causes race conditions if the 89 1.1 christos sparse array is accessed in a different thread. 90 1.1 christos 91 1.1 christos SPARSE_ARRAY_OF() and DEFINE_SPARSE_ARRAY_OF() are implemented as macros. 92 1.1 christos 93 1.1 christos The underlying utility B<OPENSSL_SA_> API should not be used directly. It 94 1.1 christos defines these functions: OPENSSL_SA_doall, OPENSSL_SA_doall_arg, 95 1.1 christos OPENSSL_SA_free, OPENSSL_SA_free_leaves, OPENSSL_SA_get, OPENSSL_SA_new, 96 1.1 christos OPENSSL_SA_num and OPENSSL_SA_set. 97 1.1 christos 98 1.1 christos =head1 RETURN VALUES 99 1.1 christos 100 1.1 christos B<ossl_sa_I<TYPE>_num>() returns the number of elements in the sparse array or 101 1.1 christos B<0> if the passed sparse array is NULL. 102 1.1 christos 103 1.1 christos B<ossl_sa_I<TYPE>_get>() returns a pointer to a sparse array element or NULL if 104 1.1 christos the element has not be set. 105 1.1 christos 106 1.1 christos B<ossl_sa_I<TYPE>_set>() return B<1> on success and B<0> on error. In the latter 107 1.1 christos case, the elements of the sparse array remain unchanged, although the internal 108 1.1 christos structures might have. 109 1.1 christos 110 1.1 christos B<ossl_sa_I<TYPE>_new>() returns an empty sparse array or NULL if an error 111 1.1 christos occurs. 112 1.1 christos 113 1.1 christos B<ossl_sa_I<TYPE>_doall>(), B<ossl_sa_I<TYPE>_doall_arg>(), 114 1.1 christos B<ossl_sa_I<TYPE>_free>() and B<ossl_sa_I<TYPE>_free_leaves>() 115 1.1 christos do not return values. 116 1.1 christos 117 1.1 christos =head1 HISTORY 118 1.1 christos 119 1.1 christos This functionality was added to OpenSSL 3.0. 120 1.1 christos 121 1.1 christos =head1 COPYRIGHT 122 1.1 christos 123 1.1 christos Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. Copyright 124 1.1 christos (c) 2019, Oracle and/or its affiliates. All rights reserved. 125 1.1 christos 126 1.1 christos Licensed under the Apache License 2.0 (the "License"). You may not use this 127 1.1 christos file except in compliance with the License. You can obtain a copy in the file 128 1.1 christos LICENSE in the source distribution or at 129 1.1 christos L<https://www.openssl.org/source/license.html>. 130 1.1 christos 131 1.1 christos =cut 132