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