Name Date Size #Lines LOC

..20-Nov-2024-

aes/H19-Jun-2024-

aria/H24-May-2022-

asn1/H19-Sep-2024-

async/H19-Jun-2024-

bf/H19-Jun-2024-

bio/H23-Oct-2024-

bn/H23-Oct-2024-

buffer/H19-Jun-2024-

camellia/H24-May-2022-

cast/H19-Jun-2024-

chacha/H05-Sep-2024-

cmac/H31-Jul-2024-

cmp/H13-Nov-2024-

cms/H05-Sep-2024-

comp/H19-Jun-2024-

conf/H05-Sep-2024-

crmf/H05-Sep-2024-

ct/H19-Jun-2024-

des/H05-Sep-2024-

dh/H19-Jun-2024-

dsa/H05-Sep-2024-

dso/H12-Oct-2024-

ec/H26-Sep-2024-

encode_decode/H19-Jun-2024-

engine/H05-Sep-2024-

err/H19-Sep-2024-

ess/H05-Sep-2024-

evp/H20-Nov-2024-

ffc/H05-Sep-2024-

hashtable/H22-Aug-2024-

hmac/H03-Sep-2024-

hpke/H30-Oct-2024-

http/H23-Sep-2024-

idea/H05-Sep-2024-

kdf/H24-Feb-2020-

lhash/H19-Jun-2024-

md2/H19-Jun-2024-

md4/H19-Jun-2024-

md5/H19-Jun-2024-

mdc2/H19-Jun-2024-

modes/H12-Sep-2024-

objects/H05-Sep-2024-

ocsp/H05-Sep-2024-

pem/H09-Sep-2024-

perlasm/H05-Sep-2024-

pkcs12/H07-Oct-2024-

pkcs7/H21-Oct-2024-

poly1305/H05-Sep-2024-

property/H19-Nov-2024-

rand/H09-Oct-2024-

rc2/H19-Jun-2024-

rc4/H19-Jun-2024-

rc5/H19-Jun-2024-

ripemd/H19-Jun-2024-

rsa/H05-Sep-2024-

seed/H19-Jun-2024-

sha/H05-Sep-2024-

siphash/H19-Jun-2024-

sm2/HToday-

sm3/H05-Sep-2024-

sm4/H05-Sep-2024-

srp/H11-Oct-2024-

stack/H19-Jun-2024-

store/H05-Sep-2024-

thread/H10-Sep-2024-

ts/H05-Sep-2024-

txt_db/H19-Jun-2024-

ui/H09-Sep-2024-

whrlpool/H19-Jun-2024-

x509/H20-Nov-2024-

LPdir_nyi.cH A D24-Feb-20202 KiB5716

LPdir_unix.cH A D19-Jun-20244.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-Jun-20247.7 KiB220163

armcap.cH A D02-Sep-202414.4 KiB449330

armv4cpuid.plH A D19-Jun-20245.6 KiB300263

asn1_dsa.cH A D23-May-20217.4 KiB253124

bsearch.cH A D24-Feb-20201.2 KiB4533

build.infoH A D11-Jul-20244.9 KiB146115

c64xpluscpuid.plH A D23-Apr-20205.3 KiB288259

comp_methods.cH A D19-Jun-20241.5 KiB6042

context.cH A D19-Sep-202416.7 KiB674525

core_algorithm.cH A D19-Jun-20246.5 KiB198125

core_fetch.cH A D20-Jul-20225.7 KiB17298

core_namemap.cH A D05-Sep-202414.1 KiB548369

cpt_err.cH A D21-Aug-20243.8 KiB9075

cpuid.cH A D19-Jun-20245.7 KiB215129

cryptlib.cH A D19-Jun-20247.9 KiB283212

ctype.cH A D19-Jun-202414.9 KiB314269

cversion.cH A D17-Oct-20243.5 KiB140109

defaults.cH A D07-Aug-20245 KiB201111

der_writer.cH A D27-Jun-20226 KiB200142

deterministic_nonce.cH A D05-Sep-20247.5 KiB241132

dllmain.cH A D03-May-20221.2 KiB4724

ebcdic.cH A D24-Feb-202015 KiB362232

ex_data.cH A D19-Jun-202414 KiB509363

getenv.cH A D03-May-20223.1 KiB10468

ia64cpuid.SH A D24-Feb-20206.3 KiB298258

indicator_core.cH A D11-Jul-20241.4 KiB5637

info.cH A D16-Oct-20249.6 KiB254212

init.cH A D19-Jun-202421.4 KiB732511

initthread.cH A D05-Sep-202413.3 KiB481336

loongarch64cpuid.plH A D19-Jun-20243.2 KiB11493

loongarch_arch.hH A D19-Jun-2024577 208

loongarchcap.cH A D19-Jun-2024517 187

mem.cH A D16-Oct-202410.6 KiB424288

mem_clr.cH A D24-Feb-2020773 268

mem_sec.cH A D05-Sep-202419.6 KiB750575

mips_arch.hH A D24-Feb-20201.2 KiB4127

o_dir.cH A D03-May-20221.1 KiB3820

o_fopen.cH A D05-Sep-20244.3 KiB13178

o_init.cH A D03-May-2022525 226

o_str.cH A D07-Aug-202411.4 KiB435303

o_time.cH A D23-May-20215.5 KiB201133

packet.cH A D19-Jun-202413.8 KiB591413

param_build.cH A D19-Jun-202411.5 KiB392323

param_build_set.cH A D19-Jun-20243.8 KiB12596

params.cH A D19-Jun-202446.6 KiB1,6881,445

params_dup.cH A D19-Jun-20247.2 KiB237184

params_from_text.cH A D19-Nov-202410.5 KiB338220

params_idx.c.inH A D19-Jun-2024626 2219

pariscid.plH A D23-Apr-20204.8 KiB280237

passphrase.cH A D19-Jun-202411 KiB347277

ppccap.cH A D05-Sep-20248.7 KiB326252

ppccpuid.plH A D03-May-20227.4 KiB398340

provider.cH A D19-Jun-20244.6 KiB159126

provider_child.cH A D19-Jun-20249.7 KiB317222

provider_conf.cH A D19-Jun-202413.2 KiB431309

provider_core.cH A D19-Nov-202481.5 KiB2,5331,752

provider_local.hH A D24-Jun-20211 KiB3420

provider_predefined.cH A D24-Jun-20211.1 KiB3322

punycode.cH A D19-Jun-20248.7 KiB313183

quic_vlint.cH A D19-Jun-20242 KiB8267

rcu_internal.hH A D19-Jun-2024527 2310

riscv32cpuid.plH A D05-Sep-20242.8 KiB10687

riscv64cpuid.plH A D19-Jun-20242.8 KiB10687

riscvcap.cH A D10-Oct-20243.7 KiB142102

s390x_arch.hH A D23-Oct-20247.3 KiB207153

s390xcap.cH A D23-Oct-202430.9 KiB802686

s390xcpuid.plH A D05-Sep-202411.5 KiB562447

self_test_core.cH A D05-Sep-20244.4 KiB165119

sleep.cH A D19-Jun-20243.1 KiB11762

sparccpuid.SH A D24-Feb-202012 KiB579535

sparcv9cap.cH A D15-Jul-20217.3 KiB232173

sparse_array.cH A D05-Sep-20245.8 KiB217154

threads_lib.cH A D19-Jun-2024543 2814

threads_none.cH A D05-Sep-20245 KiB276203

threads_pthread.cH A D05-Sep-202430.4 KiB1,046680

threads_win.cH A D05-Sep-202419.3 KiB749509

time.cH A D05-Sep-20241.3 KiB5035

trace.cH A D19-Nov-202415.6 KiB560447

uid.cH A D19-Jun-20241.4 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