• Home
Name Date Size #Lines LOC

..--

aes/07-Sep-2024-56,22748,370

aria/07-Sep-2024-1,218995

asn1/07-Sep-2024-16,15512,296

async/07-Sep-2024-1,173796

bf/07-Sep-2024-1,2461,035

bio/07-Sep-2024-12,1719,490

bn/07-Sep-2024-54,82444,218

buffer/07-Sep-2024-201153

camellia/07-Sep-2024-4,0373,177

cast/07-Sep-2024-1,4241,204

chacha/07-Sep-2024-11,4939,723

cmac/07-Sep-2024-257188

cmp/07-Sep-2024-7,7915,616

cms/07-Sep-2024-8,4776,667

comp/07-Sep-2024-818644

conf/07-Sep-2024-3,0022,295

crmf/07-Sep-2024-1,6501,052

ct/07-Sep-2024-2,3891,658

des/07-Sep-2024-6,0594,569

dh/07-Sep-2024-3,6392,714

dsa/07-Sep-2024-3,0842,257

dso/07-Sep-2024-2,4391,826

ec/07-Sep-2024-66,04353,486

encode_decode/07-Sep-2024-4,1662,941

engine/07-Sep-2024-4,6783,369

err/07-Sep-2024-3,4283,031

ess/07-Sep-2024-428330

evp/07-Sep-2024-35,49227,138

ffc/07-Sep-2024-2,0771,456

hmac/07-Sep-2024-282219

http/07-Sep-2024-1,8001,422

idea/07-Sep-2024-567423

kdf/07-Sep-2024-2310

lhash/07-Sep-2024-544407

md2/07-Sep-2024-244175

md4/07-Sep-2024-279200

md5/07-Sep-2024-1,6161,220

mdc2/07-Sep-2024-177127

modes/07-Sep-2024-20,10615,063

objects/07-Sep-2024-11,26210,536

ocsp/07-Sep-2024-2,7702,030

pem/07-Sep-2024-3,7852,964

perlasm/07-Sep-2024-8,5286,900

pkcs12/07-Sep-2024-2,7332,079

pkcs7/07-Sep-2024-3,1962,548

poly1305/07-Sep-2024-15,47312,396

property/07-Sep-2024-2,1551,673

rand/07-Sep-2024-2,1441,434

rc2/07-Sep-2024-634470

rc4/07-Sep-2024-2,7822,104

rc5/07-Sep-2024-764590

ripemd/07-Sep-2024-1,3951,172

rsa/07-Sep-2024-10,1277,254

seed/07-Sep-2024-830643

sha/07-Sep-2024-35,30629,023

siphash/07-Sep-2024-260179

sm2/07-Sep-2024-1,029788

sm3/07-Sep-2024-314250

sm4/07-Sep-2024-239185

srp/07-Sep-2024-1,112815

stack/07-Sep-2024-483364

store/07-Sep-2024-2,8402,060

ts/07-Sep-2024-3,4902,747

txt_db/07-Sep-2024-319283

ui/07-Sep-2024-2,0271,632

whrlpool/07-Sep-2024-2,2451,852

x509/07-Sep-2024-27,59320,918

LPdir_nyi.cD07-Sep-20242 KiB5716

LPdir_unix.cD07-Sep-20244.9 KiB170103

LPdir_vms.cD07-Sep-20246.2 KiB208135

LPdir_win.cD07-Sep-20246.9 KiB215140

LPdir_win32.cD07-Sep-20241.9 KiB423

LPdir_wince.cD07-Sep-20242 KiB452

README-sparse_array.mdD07-Sep-20245.6 KiB157136

alphacpuid.plD07-Sep-20243.9 KiB257220

arm64cpuid.plD07-Sep-20243.2 KiB158127

arm_arch.hD07-Sep-20244.2 KiB13091

armcap.cD07-Sep-20247.3 KiB281203

armv4cpuid.plD07-Sep-20245.6 KiB301264

asn1_dsa.cD07-Sep-20247.4 KiB253124

bsearch.cD07-Sep-20241.2 KiB4533

build.infoD07-Sep-20244.5 KiB139108

c64xpluscpuid.plD07-Sep-20245.3 KiB288259

context.cD07-Sep-202413.5 KiB511389

core_algorithm.cD07-Sep-20246.6 KiB200127

core_fetch.cD07-Sep-20245.7 KiB17298

core_namemap.cD07-Sep-202414.3 KiB532366

cpt_err.cD07-Sep-20242.7 KiB7156

cpuid.cD07-Sep-20245.7 KiB215129

cryptlib.cD07-Sep-20247.9 KiB283212

ctype.cD07-Sep-202415 KiB314269

cversion.cD07-Sep-20241.9 KiB8768

der_writer.cD07-Sep-20246 KiB200142

dllmain.cD07-Sep-20241.2 KiB4724

ebcdic.cD07-Sep-202415 KiB362232

ex_data.cD07-Sep-202413.9 KiB505361

getenv.cD07-Sep-20243.1 KiB10468

ia64cpuid.SD07-Sep-20246.3 KiB298258

info.cD07-Sep-20247.9 KiB208172

init.cD07-Sep-202421.2 KiB721503

initthread.cD07-Sep-202412.8 KiB468335

mem.cD07-Sep-20247.9 KiB338245

mem_clr.cD07-Sep-2024773 268

mem_sec.cD07-Sep-202419 KiB724552

mips_arch.hD07-Sep-20241.2 KiB4127

o_dir.cD07-Sep-20241.1 KiB3820

o_fopen.cD07-Sep-20244.3 KiB12775

o_init.cD07-Sep-2024516 226

o_str.cD07-Sep-20248.9 KiB367285

o_time.cD07-Sep-20245.5 KiB201133

packet.cD07-Sep-202411.9 KiB513358

param_build.cD07-Sep-202411.3 KiB390323

param_build_set.cD07-Sep-20243.6 KiB12292

params.cD07-Sep-202437.6 KiB1,3001,101

params_dup.cD07-Sep-20247.2 KiB236183

params_from_text.cD07-Sep-20247 KiB231141

pariscid.plD07-Sep-20244.8 KiB280237

passphrase.cD07-Sep-202411.3 KiB354284

ppccap.cD07-Sep-20248.3 KiB312240

ppccpuid.plD07-Sep-20247.3 KiB387331

provider.cD07-Sep-20244.2 KiB150119

provider_child.cD07-Sep-202410.2 KiB329233

provider_conf.cD07-Sep-20249.8 KiB317240

provider_core.cD07-Sep-202468 KiB2,1721,526

provider_local.hD07-Sep-20241 KiB3420

provider_predefined.cD07-Sep-20241.1 KiB3322

punycode.cD07-Sep-20249.1 KiB333193

s390x_arch.hD07-Sep-20246.3 KiB174124

s390xcap.cD07-Sep-202429.6 KiB746643

s390xcpuid.plD07-Sep-202411.4 KiB562447

self_test_core.cD07-Sep-20244.6 KiB173126

sparccpuid.SD07-Sep-202412 KiB579535

sparcv9cap.cD07-Sep-20247.3 KiB232173

sparse_array.cD07-Sep-20245.8 KiB217154

threads_lib.cD07-Sep-2024510 2612

threads_none.cD07-Sep-20243.1 KiB166117

threads_pthread.cD07-Sep-20246.7 KiB287214

threads_win.cD07-Sep-20246 KiB264186

trace.cD07-Sep-202414.6 KiB532421

uid.cD07-Sep-20241.3 KiB5636

vms_rms.hD07-Sep-20242.1 KiB5943

x86_64cpuid.plD07-Sep-202410.4 KiB523466

x86cpuid.plD07-Sep-202412.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