Name Date Size #Lines LOC

..23-Aug-2022-

aes/H10-Jun-2022-

aria/H24-May-2022-

asn1/H28-Jul-2022-

async/H03-May-2022-

bf/H24-May-2022-

bio/H19-Aug-2022-

bn/H17-Aug-2022-

buffer/H17-Jun-2021-

camellia/H24-May-2022-

cast/H24-May-2022-

chacha/H13-Jul-2022-

cmac/H27-May-2022-

cmp/H24-Aug-2022-

cms/H01-Aug-2022-

comp/H08-Nov-2021-

conf/H01-Jul-2022-

crmf/H24-Aug-2022-

ct/H02-Jun-2022-

des/H15-Aug-2022-

dh/H23-Aug-2022-

dsa/H01-Jul-2022-

dso/H03-May-2022-

ec/H04-Aug-2022-

encode_decode/H20-Jul-2022-

engine/H22-Jun-2022-

err/H27-Aug-2022-

ess/H26-May-2021-

evp/H22-Aug-2022-

ffc/H18-Jul-2022-

hmac/H23-Jun-2021-

http/H23-Aug-2022-

idea/H23-May-2021-

kdf/H24-Feb-2020-

lhash/H22-Jun-2022-

md2/H23-Apr-2020-

md4/H23-Apr-2020-

md5/H24-May-2022-

mdc2/H23-Apr-2020-

modes/H29-Jul-2022-

objects/H23-Aug-2022-

ocsp/H03-May-2022-

pem/H29-Jul-2022-

perlasm/H24-May-2022-

pkcs12/H24-Aug-2022-

pkcs7/H24-Aug-2022-

poly1305/H27-May-2022-

property/H10-Aug-2022-

rand/H13-Jul-2022-

rc2/H23-May-2021-

rc4/H24-May-2022-

rc5/H24-May-2022-

ripemd/H24-May-2022-

rsa/H28-Jun-2022-

seed/H17-Jun-2021-

sha/H11-Jul-2022-

siphash/H03-May-2022-

sm2/H04-May-2022-

sm3/H22-Jun-2022-

sm4/H03-May-2022-

srp/H28-Oct-2021-

stack/H17-Nov-2021-

store/H20-Jul-2022-

ts/H03-May-2022-

txt_db/H24-Feb-2020-

ui/H27-May-2022-

whrlpool/H24-May-2022-

x509/H24-Aug-2022-

LPdir_nyi.cH A D24-Feb-20202 KiB5716

LPdir_unix.cH A D03-May-20224.9 KiB170103

LPdir_vms.cH A D24-Feb-20206.2 KiB208135

LPdir_win.cH A D24-Feb-20206.9 KiB215140

LPdir_win32.cH A D24-Feb-20201.9 KiB423

LPdir_wince.cH A D24-Feb-20202 KiB452

README-sparse_array.mdH A D05-Jul-20205.6 KiB157136

alphacpuid.plH A D23-Apr-20203.9 KiB257220

arm64cpuid.plH A D03-May-20225.6 KiB271226

arm_arch.hH A D19-Jul-20226.6 KiB195140

armcap.cH A D23-May-202210.5 KiB385296

armv4cpuid.plH A D23-Apr-20205.6 KiB301264

asn1_dsa.cH A D23-May-20217.4 KiB253124

bsearch.cH A D24-Feb-20201.2 KiB4533

build.infoH A D06-Jul-20224.6 KiB143111

c64xpluscpuid.plH A D23-Apr-20205.3 KiB288259

context.cH A D03-May-202214.9 KiB593449

core_algorithm.cH A D20-Jul-20226.6 KiB200127

core_fetch.cH A D20-Jul-20225.7 KiB17298

core_namemap.cH A D22-Jun-202214 KiB533365

cpt_err.cH A D12-Jan-20223.7 KiB8974

cpuid.cH A D03-May-20225.8 KiB215129

cryptlib.cH A D03-May-20227.9 KiB283212

ctype.cH A D23-May-202215 KiB314269

cversion.cH A D24-Feb-20201.9 KiB8768

der_writer.cH A D27-Jun-20226 KiB200142

dllmain.cH A D03-May-20221.2 KiB4724

ebcdic.cH A D24-Feb-202015 KiB362232

ex_data.cH A D23-May-202113.9 KiB505361

getenv.cH A D03-May-20223.1 KiB10468

ia64cpuid.SH A D24-Feb-20206.3 KiB298258

info.cH A D03-May-20228 KiB212176

init.cH A D15-Jun-202221.2 KiB721503

initthread.cH A D03-May-202212.5 KiB461329

mem.cH A D27-Aug-20228.5 KiB357259

mem_clr.cH A D24-Feb-2020773 268

mem_sec.cH A D26-Jul-202219 KiB723551

mips_arch.hH A D24-Feb-20201.2 KiB4127

o_dir.cH A D03-May-20221.1 KiB3820

o_fopen.cH A D03-May-20224.3 KiB12775

o_init.cH A D03-May-2022525 226

o_str.cH A D23-May-20228.9 KiB367285

o_time.cH A D23-May-20215.5 KiB201133

packet.cH A D29-Jul-202213.5 KiB581405

param_build.cH A D03-May-202212 KiB407340

param_build_set.cH A D03-May-20223.7 KiB12494

params.cH A D03-May-202243 KiB1,5311,323

params_dup.cH A D03-May-20227.4 KiB242189

params_from_text.cH A D24-Nov-20217 KiB228139

pariscid.plH A D23-Apr-20204.8 KiB280237

passphrase.cH A D03-May-202211.3 KiB354284

ppccap.cH A D03-May-20228.6 KiB325251

ppccpuid.plH A D03-May-20227.4 KiB398340

provider.cH A D12-Nov-20214.2 KiB150119

provider_child.cH A D05-May-20229.6 KiB315220

provider_conf.cH A D03-May-20229.6 KiB320243

provider_core.cH A D20-Jul-202267.1 KiB2,1421,504

provider_local.hH A D24-Jun-20211 KiB3420

provider_predefined.cH A D24-Jun-20211.1 KiB3322

punycode.cH A D17-Nov-20219.2 KiB339197

quic_vlint.cH A D27-May-20222 KiB7865

riscv64cpuid.plH A D19-May-20222.4 KiB9071

riscvcap.cH A D19-May-20222.1 KiB8757

s390x_arch.hH A D03-May-20226.4 KiB178128

s390xcap.cH A D12-Apr-202229.7 KiB753645

s390xcpuid.plH A D23-Apr-202011.4 KiB562447

self_test_core.cH A D03-May-20224.4 KiB167121

sparccpuid.SH A D24-Feb-202012 KiB579535

sparcv9cap.cH A D15-Jul-20217.3 KiB232173

sparse_array.cH A D22-Jul-20225.8 KiB217154

threads_lib.cH A D14-Dec-2020510 2612

threads_none.cH A D23-May-20213.1 KiB166117

threads_pthread.cH A D03-May-20226.7 KiB287214

threads_win.cH A D12-Aug-20226 KiB264186

trace.cH A D30-May-202214.3 KiB522420

uid.cH A D02-Sep-20211.3 KiB5636

vms_rms.hH A D24-Feb-20202.1 KiB5943

x86_64cpuid.plH A D23-May-202110.4 KiB523466

x86cpuid.plH A D23-Apr-202012.2 KiB508427

README-sparse_array.md

1Sparse Arrays
2=============
3
4The `sparse_array.c` file contains an implementation of a sparse array that
5attempts to be both space and time efficient.
6
7The sparse array is represented using a tree structure.  Each node in the
8tree contains a block of pointers to either the user supplied leaf values or
9to another node.
10
11There are a number of parameters used to define the block size:
12
13    OPENSSL_SA_BLOCK_BITS   Specifies the number of bits covered by each block
14    SA_BLOCK_MAX            Specifies the number of pointers in each block
15    SA_BLOCK_MASK           Specifies a bit mask to perform modulo block size
16    SA_BLOCK_MAX_LEVELS     Indicates the maximum possible height of the tree
17
18These constants are inter-related:
19
20    SA_BLOCK_MAX        = 2 ^ OPENSSL_SA_BLOCK_BITS
21    SA_BLOCK_MASK       = SA_BLOCK_MAX - 1
22    SA_BLOCK_MAX_LEVELS = number of bits in size_t divided by
23                          OPENSSL_SA_BLOCK_BITS rounded up to the next multiple
24                          of OPENSSL_SA_BLOCK_BITS
25
26`OPENSSL_SA_BLOCK_BITS` can be defined at compile time and this overrides the
27built in setting.
28
29As a space and performance optimisation, the height of the tree is usually
30less than the maximum possible height.  Only sufficient height is allocated to
31accommodate the largest index added to the data structure.
32
33The largest index used to add a value to the array determines the tree height:
34
35        +----------------------+---------------------+
36        | Largest Added Index  |   Height of Tree    |
37        +----------------------+---------------------+
38        | SA_BLOCK_MAX     - 1 |          1          |
39        | SA_BLOCK_MAX ^ 2 - 1 |          2          |
40        | SA_BLOCK_MAX ^ 3 - 1 |          3          |
41        | ...                  |          ...        |
42        | size_t max           | SA_BLOCK_MAX_LEVELS |
43        +----------------------+---------------------+
44
45The tree height is dynamically increased as needed based on additions.
46
47An empty tree is represented by a NULL root pointer.  Inserting a value at
48index 0 results in the allocation of a top level node full of null pointers
49except for the single pointer to the user's data (N = SA_BLOCK_MAX for
50brevity):
51
52        +----+
53        |Root|
54        |Node|
55        +-+--+
56          |
57          |
58          |
59          v
60        +-+-+---+---+---+---+
61        | 0 | 1 | 2 |...|N-1|
62        |   |nil|nil|...|nil|
63        +-+-+---+---+---+---+
64          |
65          |
66          |
67          v
68        +-+--+
69        |User|
70        |Data|
71        +----+
72    Index 0
73
74Inserting at element 2N+1 creates a new root node and pushes down the old root
75node.  It then creates a second second level node to hold the pointer to the
76user's new data:
77
78        +----+
79        |Root|
80        |Node|
81        +-+--+
82          |
83          |
84          |
85          v
86        +-+-+---+---+---+---+
87        | 0 | 1 | 2 |...|N-1|
88        |   |nil|   |...|nil|
89        +-+-+---+-+-+---+---+
90          |       |
91          |       +------------------+
92          |                          |
93          v                          v
94        +-+-+---+---+---+---+      +-+-+---+---+---+---+
95        | 0 | 1 | 2 |...|N-1|      | 0 | 1 | 2 |...|N-1|
96        |nil|   |nil|...|nil|      |nil|   |nil|...|nil|
97        +-+-+---+---+---+---+      +---+-+-+---+---+---+
98          |                              |
99          |                              |
100          |                              |
101          v                              v
102        +-+--+                         +-+--+
103        |User|                         |User|
104        |Data|                         |Data|
105        +----+                         +----+
106    Index 0                       Index 2N+1
107
108The nodes themselves are allocated in a sparse manner.  Only nodes which exist
109along a path from the root of the tree to an added leaf will be allocated.
110The complexity is hidden and nodes are allocated on an as needed basis.
111Because the data is expected to be sparse this doesn't result in a large waste
112of space.
113
114Values can be removed from the sparse array by setting their index position to
115NULL.  The data structure does not attempt to reclaim nodes or reduce the
116height of the tree on removal.  For example, now setting index 0 to NULL would
117result in:
118
119        +----+
120        |Root|
121        |Node|
122        +-+--+
123          |
124          |
125          |
126          v
127        +-+-+---+---+---+---+
128        | 0 | 1 | 2 |...|N-1|
129        |   |nil|   |...|nil|
130        +-+-+---+-+-+---+---+
131          |       |
132          |       +------------------+
133          |                          |
134          v                          v
135        +-+-+---+---+---+---+      +-+-+---+---+---+---+
136        | 0 | 1 | 2 |...|N-1|      | 0 | 1 | 2 |...|N-1|
137        |nil|nil|nil|...|nil|      |nil|   |nil|...|nil|
138        +---+---+---+---+---+      +---+-+-+---+---+---+
139                                         |
140                                         |
141                                         |
142                                         v
143                                       +-+--+
144                                       |User|
145                                       |Data|
146                                       +----+
147                                  Index 2N+1
148
149Accesses to elements in the sparse array take O(log n) time where n is the
150largest element.  The base of the logarithm is `SA_BLOCK_MAX`, so for moderately
151small indices (e.g. NIDs), single level (constant time) access is achievable.
152Space usage is O(minimum(m, n log(n)) where m is the number of elements in the
153array.
154
155Note: sparse arrays only include pointers to types.
156Thus, `SPARSE_ARRAY_OF(char)` can be used to store a string.
157