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

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.