Martin Prikryl 6ec29a5a18 OpenSSL 3.3.5 2 周之前
..
aes 6ec29a5a18 OpenSSL 3.3.5 2 周之前
aria 513d92a184 OpenSSL 3.2.0 1 年之前
asn1 6ec29a5a18 OpenSSL 3.3.5 2 周之前
async 513d92a184 OpenSSL 3.2.0 1 年之前
bf 513d92a184 OpenSSL 3.2.0 1 年之前
bio 6ec29a5a18 OpenSSL 3.3.5 2 周之前
bn 80313efea9 OpenSSL 3.3.4 3 月之前
buffer 513d92a184 OpenSSL 3.2.0 1 年之前
camellia 3c34a35624 OpenSSL 3.1.0 2 年之前
cast 513d92a184 OpenSSL 3.2.0 1 年之前
chacha 80313efea9 OpenSSL 3.3.4 3 月之前
cmac c4c4ebb56d OpenSSL 3.3.1 1 年之前
cmp 80313efea9 OpenSSL 3.3.4 3 月之前
cms 6ec29a5a18 OpenSSL 3.3.5 2 周之前
comp 513d92a184 OpenSSL 3.2.0 1 年之前
conf 79dd2a5047 OpenSSL 3.3.2 1 年之前
crmf 513d92a184 OpenSSL 3.2.0 1 年之前
ct 513d92a184 OpenSSL 3.2.0 1 年之前
des 513d92a184 OpenSSL 3.2.0 1 年之前
dh 6ec29a5a18 OpenSSL 3.3.5 2 周之前
dsa a322da3810 OpenSSL 3.3.3 8 月之前
dso a322da3810 OpenSSL 3.3.3 8 月之前
ec 6ec29a5a18 OpenSSL 3.3.5 2 周之前
encode_decode 80313efea9 OpenSSL 3.3.4 3 月之前
engine 79dd2a5047 OpenSSL 3.3.2 1 年之前
err a322da3810 OpenSSL 3.3.3 8 月之前
ess 1254066655 OpenSSL 3.2.2 1 年之前
evp 6ec29a5a18 OpenSSL 3.3.5 2 周之前
ffc 513d92a184 OpenSSL 3.2.0 1 年之前
hmac 3c34a35624 OpenSSL 3.1.0 2 年之前
hpke a322da3810 OpenSSL 3.3.3 8 月之前
http 6ec29a5a18 OpenSSL 3.3.5 2 周之前
idea 513d92a184 OpenSSL 3.2.0 1 年之前
kdf 3c34a35624 OpenSSL 3.1.0 2 年之前
lhash c4c4ebb56d OpenSSL 3.3.1 1 年之前
md2 3c34a35624 OpenSSL 3.1.0 2 年之前
md4 3c34a35624 OpenSSL 3.1.0 2 年之前
md5 80313efea9 OpenSSL 3.3.4 3 月之前
mdc2 3c34a35624 OpenSSL 3.1.0 2 年之前
modes 6ec29a5a18 OpenSSL 3.3.5 2 周之前
objects 79dd2a5047 OpenSSL 3.3.2 1 年之前
ocsp 513d92a184 OpenSSL 3.2.0 1 年之前
pem a322da3810 OpenSSL 3.3.3 8 月之前
perlasm 80313efea9 OpenSSL 3.3.4 3 月之前
pkcs12 a322da3810 OpenSSL 3.3.3 8 月之前
pkcs7 6ec29a5a18 OpenSSL 3.3.5 2 周之前
poly1305 a322da3810 OpenSSL 3.3.3 8 月之前
property 6ec29a5a18 OpenSSL 3.3.5 2 周之前
rand 6ec29a5a18 OpenSSL 3.3.5 2 周之前
rc2 513d92a184 OpenSSL 3.2.0 1 年之前
rc4 513d92a184 OpenSSL 3.2.0 1 年之前
rc5 513d92a184 OpenSSL 3.2.0 1 年之前
ripemd 3c34a35624 OpenSSL 3.1.0 2 年之前
rsa 6ec29a5a18 OpenSSL 3.3.5 2 周之前
seed 3c34a35624 OpenSSL 3.1.0 2 年之前
sha a322da3810 OpenSSL 3.3.3 8 月之前
siphash 3c34a35624 OpenSSL 3.1.0 2 年之前
sm2 6ec29a5a18 OpenSSL 3.3.5 2 周之前
sm3 80313efea9 OpenSSL 3.3.4 3 月之前
sm4 80313efea9 OpenSSL 3.3.4 3 月之前
srp a322da3810 OpenSSL 3.3.3 8 月之前
stack c4c4ebb56d OpenSSL 3.3.1 1 年之前
store 6ec29a5a18 OpenSSL 3.3.5 2 周之前
thread a322da3810 OpenSSL 3.3.3 8 月之前
ts 80313efea9 OpenSSL 3.3.4 3 月之前
txt_db 513d92a184 OpenSSL 3.2.0 1 年之前
ui 80313efea9 OpenSSL 3.3.4 3 月之前
whrlpool 513d92a184 OpenSSL 3.2.0 1 年之前
x509 6ec29a5a18 OpenSSL 3.3.5 2 周之前
LPdir_nyi.c 3c34a35624 OpenSSL 3.1.0 2 年之前
LPdir_unix.c 57fc33d686 OpenSSL 3.1.2 2 年之前
LPdir_vms.c 3c34a35624 OpenSSL 3.1.0 2 年之前
LPdir_win.c 3c34a35624 OpenSSL 3.1.0 2 年之前
LPdir_win32.c 3c34a35624 OpenSSL 3.1.0 2 年之前
LPdir_wince.c 3c34a35624 OpenSSL 3.1.0 2 年之前
README-sparse_array.md 3c34a35624 OpenSSL 3.1.0 2 年之前
alphacpuid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前
arm64cpuid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前
arm_arch.h c4c4ebb56d OpenSSL 3.3.1 1 年之前
armcap.c 80313efea9 OpenSSL 3.3.4 3 月之前
armv4cpuid.pl a322da3810 OpenSSL 3.3.3 8 月之前
asn1_dsa.c 3c34a35624 OpenSSL 3.1.0 2 年之前
bsearch.c 3c34a35624 OpenSSL 3.1.0 2 年之前
build.info 513d92a184 OpenSSL 3.2.0 1 年之前
c64xpluscpuid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前
context.c a322da3810 OpenSSL 3.3.3 8 月之前
core_algorithm.c 513d92a184 OpenSSL 3.2.0 1 年之前
core_fetch.c a322da3810 OpenSSL 3.3.3 8 月之前
core_namemap.c 57fc33d686 OpenSSL 3.1.2 2 年之前
cpt_err.c 3c34a35624 OpenSSL 3.1.0 2 年之前
cpuid.c 513d92a184 OpenSSL 3.2.0 1 年之前
cryptlib.c 513d92a184 OpenSSL 3.2.0 1 年之前
ctype.c 513d92a184 OpenSSL 3.2.0 1 年之前
cversion.c 3c34a35624 OpenSSL 3.1.0 2 年之前
der_writer.c 513d92a184 OpenSSL 3.2.0 1 年之前
deterministic_nonce.c 1254066655 OpenSSL 3.2.2 1 年之前
dllmain.c 3c34a35624 OpenSSL 3.1.0 2 年之前
ebcdic.c 3c34a35624 OpenSSL 3.1.0 2 年之前
ex_data.c 513d92a184 OpenSSL 3.2.0 1 年之前
getenv.c 3c34a35624 OpenSSL 3.1.0 2 年之前
ia64cpuid.S 3c34a35624 OpenSSL 3.1.0 2 年之前
info.c 6ec29a5a18 OpenSSL 3.3.5 2 周之前
init.c 1254066655 OpenSSL 3.2.2 1 年之前
initthread.c a322da3810 OpenSSL 3.3.3 8 月之前
loongarch64cpuid.pl 80313efea9 OpenSSL 3.3.4 3 月之前
loongarch_arch.h d8f092ac60 OpenSSL 3.1.3 2 年之前
loongarchcap.c 57fc33d686 OpenSSL 3.1.2 2 年之前
mem.c 513d92a184 OpenSSL 3.2.0 1 年之前
mem_clr.c 3c34a35624 OpenSSL 3.1.0 2 年之前
mem_sec.c 3651ead1e8 OpenSSL 3.2.1 1 年之前
mips_arch.h 3c34a35624 OpenSSL 3.1.0 2 年之前
o_dir.c 3c34a35624 OpenSSL 3.1.0 2 年之前
o_fopen.c 513d92a184 OpenSSL 3.2.0 1 年之前
o_init.c 3c34a35624 OpenSSL 3.1.0 2 年之前
o_str.c 79dd2a5047 OpenSSL 3.3.2 1 年之前
o_time.c 3c34a35624 OpenSSL 3.1.0 2 年之前
packet.c 513d92a184 OpenSSL 3.2.0 1 年之前
param_build.c c4c4ebb56d OpenSSL 3.3.1 1 年之前
param_build_set.c c4c4ebb56d OpenSSL 3.3.1 1 年之前
params.c 1254066655 OpenSSL 3.2.2 1 年之前
params_dup.c 80313efea9 OpenSSL 3.3.4 3 月之前
params_from_text.c 3651ead1e8 OpenSSL 3.2.1 1 年之前
params_idx.c.in 513d92a184 OpenSSL 3.2.0 1 年之前
pariscid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前
passphrase.c 513d92a184 OpenSSL 3.2.0 1 年之前
ppccap.c 513d92a184 OpenSSL 3.2.0 1 年之前
ppccpuid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前
provider.c 513d92a184 OpenSSL 3.2.0 1 年之前
provider_child.c 513d92a184 OpenSSL 3.2.0 1 年之前
provider_conf.c 80313efea9 OpenSSL 3.3.4 3 月之前
provider_core.c 1254066655 OpenSSL 3.2.2 1 年之前
provider_local.h 3c34a35624 OpenSSL 3.1.0 2 年之前
provider_predefined.c 3c34a35624 OpenSSL 3.1.0 2 年之前
punycode.c 513d92a184 OpenSSL 3.2.0 1 年之前
quic_vlint.c 513d92a184 OpenSSL 3.2.0 1 年之前
rcu_internal.h c4c4ebb56d OpenSSL 3.3.1 1 年之前
riscv32cpuid.pl 6ec29a5a18 OpenSSL 3.3.5 2 周之前
riscv64cpuid.pl 6ec29a5a18 OpenSSL 3.3.5 2 周之前
riscvcap.c a322da3810 OpenSSL 3.3.3 8 月之前
s390x_arch.h a322da3810 OpenSSL 3.3.3 8 月之前
s390xcap.c a322da3810 OpenSSL 3.3.3 8 月之前
s390xcpuid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前
self_test_core.c 3c34a35624 OpenSSL 3.1.0 2 年之前
sleep.c 6ec29a5a18 OpenSSL 3.3.5 2 周之前
sparccpuid.S 3c34a35624 OpenSSL 3.1.0 2 年之前
sparcv9cap.c 3c34a35624 OpenSSL 3.1.0 2 年之前
sparse_array.c 3c34a35624 OpenSSL 3.1.0 2 年之前
threads_lib.c 513d92a184 OpenSSL 3.2.0 1 年之前
threads_none.c 80313efea9 OpenSSL 3.3.4 3 月之前
threads_pthread.c 6ec29a5a18 OpenSSL 3.3.5 2 周之前
threads_win.c 80313efea9 OpenSSL 3.3.4 3 月之前
time.c 513d92a184 OpenSSL 3.2.0 1 年之前
trace.c a322da3810 OpenSSL 3.3.3 8 月之前
uid.c 513d92a184 OpenSSL 3.2.0 1 年之前
vms_rms.h 3c34a35624 OpenSSL 3.1.0 2 年之前
x86_64cpuid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前
x86cpuid.pl 3c34a35624 OpenSSL 3.1.0 2 年之前

README-sparse_array.md

Sparse Arrays

The sparse_array.c file contains an implementation of a sparse array that attempts to be both space and time efficient.

The sparse array is represented using a tree structure. Each node in the tree contains a block of pointers to either the user supplied leaf values or to another node.

There are a number of parameters used to define the block size:

OPENSSL_SA_BLOCK_BITS   Specifies the number of bits covered by each block
SA_BLOCK_MAX            Specifies the number of pointers in each block
SA_BLOCK_MASK           Specifies a bit mask to perform modulo block size
SA_BLOCK_MAX_LEVELS     Indicates the maximum possible height of the tree

These constants are inter-related:

SA_BLOCK_MAX        = 2 ^ OPENSSL_SA_BLOCK_BITS
SA_BLOCK_MASK       = SA_BLOCK_MAX - 1
SA_BLOCK_MAX_LEVELS = number of bits in size_t divided by
                      OPENSSL_SA_BLOCK_BITS rounded up to the next multiple
                      of OPENSSL_SA_BLOCK_BITS

OPENSSL_SA_BLOCK_BITS can be defined at compile time and this overrides the built in setting.

As a space and performance optimisation, the height of the tree is usually less than the maximum possible height. Only sufficient height is allocated to accommodate the largest index added to the data structure.

The largest index used to add a value to the array determines the tree height:

    +----------------------+---------------------+
    | Largest Added Index  |   Height of Tree    |
    +----------------------+---------------------+
    | SA_BLOCK_MAX     - 1 |          1          |
    | SA_BLOCK_MAX ^ 2 - 1 |          2          |
    | SA_BLOCK_MAX ^ 3 - 1 |          3          |
    | ...                  |          ...        |
    | size_t max           | SA_BLOCK_MAX_LEVELS |
    +----------------------+---------------------+

The tree height is dynamically increased as needed based on additions.

An empty tree is represented by a NULL root pointer. Inserting a value at index 0 results in the allocation of a top level node full of null pointers except for the single pointer to the user's data (N = SA_BLOCK_MAX for brevity):

    +----+
    |Root|
    |Node|
    +-+--+
      |
      |
      |
      v
    +-+-+---+---+---+---+
    | 0 | 1 | 2 |...|N-1|
    |   |nil|nil|...|nil|
    +-+-+---+---+---+---+
      |
      |
      |
      v
    +-+--+
    |User|
    |Data|
    +----+
Index 0

Inserting at element 2N+1 creates a new root node and pushes down the old root node. It then creates a second second level node to hold the pointer to the user's new data:

    +----+
    |Root|
    |Node|
    +-+--+
      |
      |
      |
      v
    +-+-+---+---+---+---+
    | 0 | 1 | 2 |...|N-1|
    |   |nil|   |...|nil|
    +-+-+---+-+-+---+---+
      |       |
      |       +------------------+
      |                          |
      v                          v
    +-+-+---+---+---+---+      +-+-+---+---+---+---+
    | 0 | 1 | 2 |...|N-1|      | 0 | 1 | 2 |...|N-1|
    |nil|   |nil|...|nil|      |nil|   |nil|...|nil|
    +-+-+---+---+---+---+      +---+-+-+---+---+---+
      |                              |
      |                              |
      |                              |
      v                              v
    +-+--+                         +-+--+
    |User|                         |User|
    |Data|                         |Data|
    +----+                         +----+
Index 0                       Index 2N+1

The nodes themselves are allocated in a sparse manner. Only nodes which exist along a path from the root of the tree to an added leaf will be allocated. The complexity is hidden and nodes are allocated on an as needed basis. Because the data is expected to be sparse this doesn't result in a large waste of space.

Values can be removed from the sparse array by setting their index position to NULL. The data structure does not attempt to reclaim nodes or reduce the height of the tree on removal. For example, now setting index 0 to NULL would result in:

    +----+
    |Root|
    |Node|
    +-+--+
      |
      |
      |
      v
    +-+-+---+---+---+---+
    | 0 | 1 | 2 |...|N-1|
    |   |nil|   |...|nil|
    +-+-+---+-+-+---+---+
      |       |
      |       +------------------+
      |                          |
      v                          v
    +-+-+---+---+---+---+      +-+-+---+---+---+---+
    | 0 | 1 | 2 |...|N-1|      | 0 | 1 | 2 |...|N-1|
    |nil|nil|nil|...|nil|      |nil|   |nil|...|nil|
    +---+---+---+---+---+      +---+-+-+---+---+---+
                                     |
                                     |
                                     |
                                     v
                                   +-+--+
                                   |User|
                                   |Data|
                                   +----+
                              Index 2N+1

Accesses to elements in the sparse array take O(log n) time where n is the largest element. The base of the logarithm is SA_BLOCK_MAX, so for moderately small indices (e.g. NIDs), single level (constant time) access is achievable. Space usage is O(minimum(m, n log(n)) where m is the number of elements in the array.

Note: sparse arrays only include pointers to types. Thus, SPARSE_ARRAY_OF(char) can be used to store a string.