libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Functions
crc64.h File Reference
#include <stdlib.h>
#include <stdint.h>
#include "acfutils/assert.h"
#include "acfutils/core.h"
Include dependency graph for crc64.h:

Go to the source code of this file.

Functions

API_EXPORT void crc64_init (void)
 
static void crc64_state_init (uint64_t *crc)
 
API_EXPORT void crc64_state_init_impl (uint64_t *crc)
 
API_EXPORT uint64_t crc64_append (uint64_t crc, const void *input, size_t sz)
 
API_EXPORT uint64_t crc64 (const void *input, size_t sz)
 
API_EXPORT void crc64_srand (uint64_t seed)
 
API_EXPORT uint64_t crc64_rand (void)
 
API_EXPORT double crc64_rand_fract (void)
 
API_EXPORT double crc64_rand_normal (double sigma)
 

Detailed Description

A generic CRC64 implementation from OpenSolaris. Be sure to call crc64_init() before using it. Then just call crc64() and pass it the data you want checksummed. Also includes a fast & light-weight portable pseudo random number generator.

Definition in file crc64.h.

Function Documentation

◆ crc64()

API_EXPORT uint64_t crc64 ( const void *  input,
size_t  sz 
)

Computes the CRC64 checksum of a block of input data.

Parameters
inputThe input data block for which the CRC64 checksum should be computed.
szNumber of bytes in input to be checksummed.
Returns
64-bit CRC64 checksum of the input data.

Definition at line 65 of file crc64.c.

◆ crc64_append()

API_EXPORT uint64_t crc64_append ( uint64_t  crc,
const void *  input,
size_t  sz 
)

This is similar to crc64(), but allows you to compute the checksum in pieces.

Parameters
crcPrevious state of the checksum. On first call, you must initialize this using crc64_state_init(). Then, pass the previous output of crc64_append() here, gradually updating it as the checksum process proceeds.
inputThe input data block for which the CRC64 checksum should be computed.
szNumber of bytes in input to be checksummed.
Returns
64-bit CRC64 checksum of the input data. If you plan on appending more data to this checksum, pass this return value in the crc argument of the next crc64_append() call.

Definition at line 88 of file crc64.c.

◆ crc64_init()

API_EXPORT void crc64_init ( void  )

Initializes the CRC64 tables. Must be called before calling any CRC64-related functions.

Definition at line 37 of file crc64.c.

◆ crc64_rand()

API_EXPORT uint64_t crc64_rand ( void  )

Grabs a random 64-bit number from the PRNG. This function isn't thread-safe, so take care not to rely on its output being super-duper unpredictable in multi-threade apps. You shouldn't be relying on it for anything more than lightweight randomness duties which need to be fast above everything else.

DO NOT use this for cryptographically secure randomness operations (e.g. generating encryption key material). See osrand.h for a high-quality PRNG.

Definition at line 123 of file crc64.c.

◆ crc64_rand_fract()

API_EXPORT double crc64_rand_fract ( void  )
Returns
A random number from the PRNG, but instead of returning a 64-bit integer between 0 and UINT64_MAX, this function returns a double value from 0.0 to 1.0 (inclusive). The distribution is linear.

Definition at line 135 of file crc64.c.

◆ crc64_rand_normal()

API_EXPORT double crc64_rand_normal ( double  sigma)
Returns
A random double-precision floating point number using a normal distribution instead of a linear 0-1 distribution like crc64_rand_fract().
Parameters
sigmastandard deviation of the normal distribution.

Definition at line 147 of file crc64.c.

◆ crc64_srand()

API_EXPORT void crc64_srand ( uint64_t  seed)

Initializes the CRC64-based pseudo random number generator. Obviously you only want to call this once in your app.

Parameters
seedThe random seed for the PRNG (e.g. current microclock() usually does nicely).

Definition at line 106 of file crc64.c.

◆ crc64_state_init()

static void crc64_state_init ( uint64_t *  crc)
inlinestatic

Initializes the starting CRC64 value for subsequent calls to crc64_append().

Definition at line 48 of file crc64.h.

◆ crc64_state_init_impl()

API_EXPORT void crc64_state_init_impl ( uint64_t *  crc)

Same as crc64_state_init(), but provided for linkage for Rust bridge.

Definition at line 51 of file crc64.c.