• Home
  • Annotate
  • current directory
Name Date Size #Lines LOC

..22-Aug-2025-

aes/22-Aug-2025-

aria/22-Aug-2025-

asn1/22-Aug-2025-

async/22-Aug-2025-

bf/22-Aug-2025-

bio/22-Aug-2025-

bn/22-Aug-2025-

buffer/22-Aug-2025-

camellia/22-Aug-2025-

cast/22-Aug-2025-

chacha/22-Aug-2025-

cmac/22-Aug-2025-

cmp/22-Aug-2025-

cms/22-Aug-2025-

comp/22-Aug-2025-

conf/22-Aug-2025-

crmf/22-Aug-2025-

ct/22-Aug-2025-

des/22-Aug-2025-

dh/22-Aug-2025-

dsa/22-Aug-2025-

dso/22-Aug-2025-

ec/22-Aug-2025-

encode_decode/22-Aug-2025-

engine/22-Aug-2025-

err/22-Aug-2025-

ess/22-Aug-2025-

evp/22-Aug-2025-

ffc/22-Aug-2025-

hashtable/22-Aug-2025-

hmac/22-Aug-2025-

hpke/22-Aug-2025-

http/22-Aug-2025-

idea/22-Aug-2025-

kdf/22-Aug-2025-

lhash/22-Aug-2025-

lms/22-Aug-2025-

md2/22-Aug-2025-

md4/22-Aug-2025-

md5/22-Aug-2025-

mdc2/22-Aug-2025-

ml_dsa/22-Aug-2025-

ml_kem/22-Aug-2025-

modes/22-Aug-2025-

objects/22-Aug-2025-

ocsp/22-Aug-2025-

pem/22-Aug-2025-

perlasm/22-Aug-2025-

pkcs12/22-Aug-2025-

pkcs7/22-Aug-2025-

poly1305/22-Aug-2025-

property/22-Aug-2025-

rand/22-Aug-2025-

rc2/22-Aug-2025-

rc4/22-Aug-2025-

rc5/22-Aug-2025-

ripemd/22-Aug-2025-

rsa/22-Aug-2025-

seed/22-Aug-2025-

sha/22-Aug-2025-

siphash/22-Aug-2025-

slh_dsa/22-Aug-2025-

sm2/22-Aug-2025-

sm3/22-Aug-2025-

sm4/22-Aug-2025-

srp/22-Aug-2025-

stack/22-Aug-2025-

store/22-Aug-2025-

thread/22-Aug-2025-

ts/22-Aug-2025-

txt_db/22-Aug-2025-

ui/22-Aug-2025-

whrlpool/22-Aug-2025-

x509/22-Aug-2025-

LPdir_nyi.c A D22-Aug-20252.1 KiB5716

LPdir_unix.c A D22-Aug-20255.1 KiB170103

LPdir_vms.c A D22-Aug-20256.4 KiB208135

LPdir_win.c A D22-Aug-20257.1 KiB215140

LPdir_win32.c A D22-Aug-20251.9 KiB423

LPdir_wince.c A D22-Aug-20252 KiB452

README-sparse_array.md A D22-Aug-20255.7 KiB157136

alphacpuid.pl A D22-Aug-20253.5 KiB204168

arm64cpuid.pl A D22-Aug-20255.9 KiB271226

arm_arch.h A D22-Aug-20258 KiB225167

armcap.c A D22-Aug-202515.2 KiB451333

armv4cpuid.pl A D22-Aug-20255.2 KiB260224

array_alloc.c A D22-Aug-20252.7 KiB9558

asn1_dsa.c A D22-Aug-20257.6 KiB253124

bsearch.c A D22-Aug-20251.2 KiB4533

build.info A D22-Aug-20255 KiB146115

c64xpluscpuid.pl A D22-Aug-20255.5 KiB287258

comp_methods.c A D22-Aug-20251.6 KiB6042

context.c A D22-Aug-202516.9 KiB661515

core_algorithm.c A D22-Aug-20256.7 KiB198125

core_fetch.c A D22-Aug-20256.1 KiB176102

core_namemap.c A D22-Aug-202515.8 KiB585388

cpt_err.c A D22-Aug-20253.9 KiB9075

cpuid.c A D22-Aug-20256.9 KiB230140

cryptlib.c A D22-Aug-20258.2 KiB283212

ctype.c A D22-Aug-202515.3 KiB314269

cversion.c A D22-Aug-20253.6 KiB140109

defaults.c A D22-Aug-20255.5 KiB205110

der_writer.c A D22-Aug-20256.2 KiB200142

deterministic_nonce.c A D22-Aug-20257.8 KiB241132

dllmain.c A D22-Aug-20251.2 KiB4623

ebcdic.c A D22-Aug-202515.3 KiB362232

ex_data.c A D22-Aug-202514.5 KiB509363

getenv.c A D22-Aug-20253.2 KiB10468

ia64cpuid.S A D22-Aug-20254.7 KiB208180

indicator_core.c A D22-Aug-20251.4 KiB5637

info.c A D22-Aug-202510.2 KiB261218

init.c A D22-Aug-202523.3 KiB765534

initthread.c A D22-Aug-202513.9 KiB495351

loongarch64cpuid.pl A D22-Aug-20253.3 KiB11392

loongarch_arch.h A D22-Aug-2025596 208

loongarchcap.c A D22-Aug-2025537 187

mem.c A D22-Aug-202512 KiB461317

mem_clr.c A D22-Aug-2025798 268

mem_sec.c A D22-Aug-202520.4 KiB750575

mips_arch.h A D22-Aug-20251.3 KiB4127

o_dir.c A D22-Aug-20251.1 KiB3820

o_fopen.c A D22-Aug-20254.4 KiB13178

o_init.c A D22-Aug-2025546 226

o_str.c A D22-Aug-202511.8 KiB438305

o_time.c A D22-Aug-20255.7 KiB201133

packet.c A D22-Aug-202514.4 KiB591413

param_build.c A D22-Aug-202511.9 KiB392323

param_build_set.c A D22-Aug-20253.9 KiB12596

params.c A D22-Aug-202549.6 KiB1,7241,482

params_dup.c A D22-Aug-20257.7 KiB244190

params_from_text.c A D22-Aug-202510.9 KiB338220

pariscid.pl A D22-Aug-20254.3 KiB240198

passphrase.c A D22-Aug-202511.4 KiB347277

ppccap.c A D22-Aug-20259 KiB323249

ppccpuid.pl A D22-Aug-20257.3 KiB364308

provider.c A D22-Aug-20254.7 KiB159126

provider_child.c A D22-Aug-202510 KiB317222

provider_conf.c A D22-Aug-202513.6 KiB431309

provider_core.c A D22-Aug-202589.1 KiB2,6661,847

provider_local.h A D22-Aug-20251.1 KiB3420

provider_predefined.c A D22-Aug-20251.1 KiB3322

punycode.c A D22-Aug-20259.1 KiB316186

quic_vlint.c A D22-Aug-20252.1 KiB8267

rcu_internal.h A D22-Aug-2025549 2310

riscv32cpuid.pl A D22-Aug-20252.9 KiB10687

riscv64cpuid.pl A D22-Aug-20252.9 KiB10687

riscvcap.c A D22-Aug-20254 KiB146105

s390x_arch.h A D22-Aug-20257.5 KiB207153

s390xcap.c A D22-Aug-202537 KiB908787

s390xcpuid.pl A D22-Aug-202511.6 KiB537424

self_test_core.c A D22-Aug-20254.6 KiB165119

sleep.c A D22-Aug-20253.9 KiB13678

sparccpuid.S A D22-Aug-20259.6 KiB425387

sparcv9cap.c A D22-Aug-20257.5 KiB232173

sparse_array.c A D22-Aug-20256 KiB217154

ssl_err.c A D22-Aug-202533.7 KiB636621

sslerr.h A D22-Aug-2025651 2813

threads_common.c A D22-Aug-202514.7 KiB41390

threads_lib.c A D22-Aug-2025570 2814

threads_none.c A D22-Aug-20255.8 KiB291216

threads_pthread.c A D22-Aug-202534.4 KiB1,199815

threads_win.c A D22-Aug-202519.5 KiB751518

time.c A D22-Aug-20251.4 KiB5035

trace.c A D22-Aug-202516.1 KiB560447

uid.c A D22-Aug-20251.4 KiB5636

vms_rms.h A D22-Aug-20252.2 KiB5943

x86_64cpuid.pl A D22-Aug-202511.2 KiB489430

x86cpuid.pl A D22-Aug-202513.1 KiB502419

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