Name Date Size #Lines LOC

..06-May-2025-

aes/H06-May-2025-56,29748,428

aria/H06-May-2025-1,218995

asn1/H06-May-2025-16,19712,329

async/H06-May-2025-1,173796

bf/H06-May-2025-1,2461,035

bio/H06-May-2025-12,1969,506

bn/H06-May-2025-55,04044,371

buffer/H06-May-2025-201153

camellia/H06-May-2025-4,0373,177

cast/H06-May-2025-1,4241,204

chacha/H06-May-2025-11,4959,725

cmac/H06-May-2025-257188

cmp/H06-May-2025-7,7975,621

cms/H06-May-2025-8,5516,728

comp/H06-May-2025-818644

conf/H06-May-2025-3,0182,307

crmf/H06-May-2025-1,6501,052

ct/H06-May-2025-2,3891,658

des/H06-May-2025-6,0594,569

dh/H06-May-2025-3,6422,716

dsa/H06-May-2025-3,1292,291

dso/H06-May-2025-2,4351,822

ec/H06-May-2025-66,07053,510

encode_decode/H06-May-2025-4,1802,952

engine/H06-May-2025-4,6943,382

err/H06-May-2025-3,4333,036

ess/H06-May-2025-428330

evp/H06-May-2025-35,66327,258

ffc/H06-May-2025-2,0711,450

hmac/H06-May-2025-282219

http/H06-May-2025-1,8441,461

idea/H06-May-2025-567423

kdf/H06-May-2025-2310

lhash/H06-May-2025-544407

md2/H06-May-2025-244175

md4/H06-May-2025-279200

md5/H06-May-2025-1,6161,220

mdc2/H06-May-2025-177127

modes/H06-May-2025-20,12615,081

objects/H06-May-2025-11,26310,537

ocsp/H06-May-2025-2,7702,030

pem/H06-May-2025-3,7942,968

perlasm/H06-May-2025-8,5326,904

pkcs12/H06-May-2025-2,7652,108

pkcs7/H06-May-2025-3,2042,556

poly1305/H06-May-2025-15,48612,409

property/H06-May-2025-2,2291,731

rand/H06-May-2025-2,1531,441

rc2/H06-May-2025-634470

rc4/H06-May-2025-2,7872,108

rc5/H06-May-2025-764590

ripemd/H06-May-2025-1,3951,172

rsa/H06-May-2025-10,1767,290

seed/H06-May-2025-830643

sha/H06-May-2025-35,32029,036

siphash/H06-May-2025-260179

sm2/H06-May-2025-1,068819

sm3/H06-May-2025-314250

sm4/H06-May-2025-239185

srp/H06-May-2025-1,115818

stack/H06-May-2025-483364

store/H06-May-2025-2,8422,062

ts/H06-May-2025-3,4902,747

txt_db/H06-May-2025-319283

ui/H06-May-2025-2,0311,636

whrlpool/H06-May-2025-2,2451,852

x509/H06-May-2025-27,74621,038

LPdir_nyi.cH A D06-May-20252 KiB5716

LPdir_unix.cH A D06-May-20254.9 KiB170103

LPdir_vms.cH A D06-May-20256.2 KiB208135

LPdir_win.cH A D06-May-20256.9 KiB215140

LPdir_win32.cH A D06-May-20251.9 KiB423

LPdir_wince.cH A D06-May-20252 KiB452

README-sparse_array.mdH A D06-May-20255.6 KiB157136

alphacpuid.plH A D06-May-20253.9 KiB257220

arm64cpuid.plH A D06-May-20253.5 KiB168137

arm_arch.hH A D06-May-20256.2 KiB183129

armcap.cH A D06-May-20257.3 KiB281203

armv4cpuid.plH A D06-May-20255.6 KiB301264

asn1_dsa.cH A D06-May-20257.4 KiB253124

bsearch.cH A D06-May-20251.2 KiB4533

build.infoH A D06-May-20254.4 KiB137107

c64xpluscpuid.plH A D06-May-20255.3 KiB288259

context.cH A D06-May-202513.5 KiB511389

core_algorithm.cH A D06-May-20256.6 KiB200127

core_fetch.cH A D06-May-20255.8 KiB17399

core_namemap.cH A D06-May-202514.4 KiB535368

cpt_err.cH A D06-May-20252.7 KiB7156

cpuid.cH A D06-May-20255.7 KiB215129

cryptlib.cH A D06-May-20257.9 KiB283212

ctype.cH A D06-May-202515 KiB314269

cversion.cH A D06-May-20251.9 KiB8768

der_writer.cH A D06-May-20256 KiB200142

dllmain.cH A D06-May-20251.2 KiB4724

ebcdic.cH A D06-May-202515 KiB362232

ex_data.cH A D06-May-202514 KiB507363

getenv.cH A D06-May-20253.1 KiB10468

ia64cpuid.SH A D06-May-20256.3 KiB298258

info.cH A D06-May-20257.9 KiB208172

init.cH A D06-May-202521.2 KiB723505

initthread.cH A D06-May-202512.8 KiB468335

mem.cH A D06-May-20258.2 KiB343247

mem_clr.cH A D06-May-2025773 268

mem_sec.cH A D06-May-202519.1 KiB730555

mips_arch.hH A D06-May-20251.2 KiB4127

o_dir.cH A D06-May-20251.1 KiB3820

o_fopen.cH A D06-May-20254.3 KiB12775

o_init.cH A D06-May-2025516 226

o_str.cH A D06-May-20258.9 KiB369287

o_time.cH A D06-May-20255.5 KiB201133

packet.cH A D06-May-202511.9 KiB513358

param_build.cH A D06-May-202511.3 KiB390323

param_build_set.cH A D06-May-20253.7 KiB12394

params.cH A D06-May-202537.9 KiB1,3201,121

params_dup.cH A D06-May-20257.2 KiB236183

params_from_text.cH A D06-May-20257.3 KiB237146

pariscid.plH A D06-May-20254.8 KiB280237

passphrase.cH A D06-May-202511.3 KiB354284

ppccap.cH A D06-May-20258.4 KiB316244

ppccpuid.plH A D06-May-20257.3 KiB387331

provider.cH A D06-May-20254.2 KiB150119

provider_child.cH A D06-May-202510.2 KiB329233

provider_conf.cH A D06-May-202511.7 KiB383272

provider_core.cH A D06-May-202568.4 KiB2,1811,533

provider_local.hH A D06-May-20251 KiB3420

provider_predefined.cH A D06-May-20251.1 KiB3322

punycode.cH A D06-May-20259.1 KiB333193

s390x_arch.hH A D06-May-20256.3 KiB174124

s390xcap.cH A D06-May-202529.6 KiB746643

s390xcpuid.plH A D06-May-202511.4 KiB562447

self_test_core.cH A D06-May-20254.6 KiB173126

sparccpuid.SH A D06-May-202512 KiB579535

sparcv9cap.cH A D06-May-20257.3 KiB232173

sparse_array.cH A D06-May-20255.8 KiB217154

threads_lib.cH A D06-May-2025510 2612

threads_none.cH A D06-May-20253.1 KiB166117

threads_pthread.cH A D06-May-20256.6 KiB285212

threads_win.cH A D06-May-20256 KiB265187

trace.cH A D06-May-202514.6 KiB532421

uid.cH A D06-May-20251.3 KiB5636

vms_rms.hH A D06-May-20252.1 KiB5943

x86_64cpuid.plH A D06-May-202510.4 KiB523466

x86cpuid.plH A D06-May-202512.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