types.c File Reference


Detailed Description

Source code.

Definition in file types.c.

Go to the source code of this file.

Data Structures

struct  zom_t
 Bit-parallel arithmetic on numbers 0, 1, more. More...
struct  input_t
 Input. More...
struct  output_t
 Output. More...
struct  bounds_t
 Bounds for values. More...

Defines

#define VERSION   "2007-05-15"
 Version number.
#define YEAR   "2007"
 Year for the copyright.
#define LEVELS_LIST   0.0001, 0.001, 0.01, 0.05, 0.10
 The significance levels to report.
#define WORD_BITS   32
 The size of the words that are used to store the bit vectors.
#define BITCOUNT_BITS   11
 The size of the precomputed arrays of bit counts.
#define WORD_ONE   UINT32_C(1)
 Value 1 in the type word_t.
#define MSB_SHIFT   5
 Base-2 logarithm of WORD_BITS.
#define LSB_MASK   ((WORD_ONE << MSB_SHIFT) - WORD_ONE)
 A bitmask for extracting the least significant bits of an index.
#define STRINGIFY2(x)   #x
 Used to implement STRINGIFY.
#define STRINGIFY(x)   STRINGIFY2(x)
 Stringify x.
#define MIN(x, y)   ((x) < (y) ? (x) : (y))
 Minimum of x and y.
#define MAX(x, y)   ((x) > (y) ? (x) : (y))
 Maximum of x and y.
#define MYMALLOC(target, type, count)
 Allocate count elements of type type and store the pointer to target.
#define MYMALLOCZ(target, type, count, init)
 Allocate count elements of type type, initialise each element to init, and store the pointer to target.
#define MYMALLOC2Z(target, type, count1, count2, init)   MYMALLOCZ(target, type, size_multiply(count1, count2), init)
 Allocate count1 times count2 elements of type type, initialise each element to init, and store the pointer to target.
#define BUILTIN_RNG_BITS   15
 The number of random bits returned by builtin_rng.
#define BUILTIN_RNG_MAX   ((1U << BUILTIN_RNG_BITS) - 1)
 The maximum value returned by builtin_rng.
#define BUILTIN_RNG_LARGE_BITS   (BUILTIN_RNG_BITS * 2)
 The number of random bits returned by builtin_rng_large.
#define BUILTIN_RNG_LARGE_MAX   ((1U << BUILTIN_RNG_LARGE_BITS) - 1)
 The maximum value returned by builtin_rng_large.
#define DEF_CALCULATE_STATISTICS(suffix, representation)
 A macro for constructing calculate_statistics_normal and calculate_statistics_hapax.
#define DEF_CALCULATE_RAW_DATA(suffix, representation)
 A macro for constructing calculate_raw_data_normal and calculate_raw_data_hapax.
#define NLEVELS   (sizeof LEVELS / sizeof LEVELS[0])
 The number of elements in LEVELS.

Typedefs

typedef unsigned bitcount_t
 The type which is used to store the bit counts.
typedef uint_fast32_t word_t
 The type which is used to store the bit vectors.
typedef uint_fast32_t builtin_rng_state_t
 The internal state of builtin_rng.

Functions

static size_t get_msb_index (size_t i)
 Get the most significant bits of the index i.
static word_t get_lsb_bit (size_t i)
 Get the least significant bits of the index i.
static size_t size_multiply (size_t a, size_t b)
 Multiply a by b; exit with failure if an overflow occurs.
static void * mymalloc (size_t s)
 Allocate s bytes; exit with failure if out of memory.
static void myfscanf (int expected, const char *description, FILE *stream, const char *format,...)
 A wrapper of fscanf.
static void bad_uint (const char *s)
 Report an error; exit with failure.
static unsigned get_uint (const char *s)
 Parse an unsigned integer in the string s; exit with failure if unsuccessful.
static void builtin_rng_init (builtin_rng_state_t *state)
 Initialise the state used by builtin_rng.
static uint_fast16_t builtin_rng (builtin_rng_state_t *state)
 Builtin pseudorandom number generator.
static uint_fast32_t builtin_rng_large (builtin_rng_state_t *state)
 Builtin pseudorandom number generator.
static unsigned builtin_rng_n (builtin_rng_state_t *state, unsigned n)
 Return a random unsigned integer between 0 and n-1.
static unsigned myrand_n (unsigned n)
 Return a random unsigned integer between 0 and n-1.
static void myswap (unsigned i, unsigned j, unsigned *restrict table)
 Swap i and j in table.
static void identity_permutation (unsigned n, unsigned *restrict table)
 Store the identity permutation of n elements into table.
static void rand_permutation (unsigned n, unsigned *restrict table)
 Store a random permutation of n elements into table.
static void builtin_rng_permutation (builtin_rng_state_t *restrict state, unsigned n, unsigned *restrict table)
 Store a random permutation of n elements into table.
static unsigned naive_bitcount (unsigned w)
 Compute the number of ones in the binary representation of w.
static void init_bitcount (void)
 Initialise the array bitcount.
static unsigned bitcount (word_t w)
 Compute the number of ones in the binary representation of w.
static zom_t zom_add (zom_t x, zom_t y)
 Calculate x + y in zom_t.
static word_t zom_exactly_1 (zom_t x)
 Return a bit vector where a bit is set if the value is exactly 1.
static void word_clear (word_t *restrict array, size_t n)
 Zero an array of word_t.
static void zom_clear (zom_t *restrict array, size_t n)
 Zero an array of zom_t.
static void usage (const char *name)
 Print documentation and exit.
static void version (void)
 Print version information and exit.
static void parse_command_line (input_t *restrict pinput, int argc, char **argv)
 Parse the command line.
static void process_input (input_t *restrict pinput)
 Read the input file.
static void free_input (const input_t *pinput)
 Frees the memory allocated for the fields of input_t.
static void prepare_slots (input_t *restrict pinput, output_t *restrict poutput)
 Prepare output_t::slot_threshold.
static void next_permutation (builtin_rng_state_t *restrict rng_state, const input_t *pinput, unsigned *restrict sample_order)
 Construct the next permutation in sample_order, based on the user's choice on how to compute the permutations.
static void calculate_bounds_normal (const input_t *pinput, unsigned sample, word_t *restrict accum, unsigned *restrict p_accum_types, bounds_t *restrict pb_sample)
 Process the sample number sample. Update type accumulation vector accum and type accumulation count in p_accum_types. Calculate type accumulation bounds for this sample and store the result in pb_sample.
static void calculate_bounds_hapax (const input_t *pinput, unsigned sample, zom_t *restrict accum, unsigned *restrict p_accum_hapaxes, bounds_t *restrict pb_sample)
 Process the sample number sample. Update hapax accumulation vector accum and hapax accumulation count in p_accum_hapaxes. Calculate hapax accumulation bounds for this sample and store the result in pb_sample.
static void update_bounds_normal (bounds_t *restrict pb_this_gap, const bounds_t *pb_sample)
 Use the bounds for this sample in pb_sample and use it to update the bounds for this gap in pg_this_gap.
static void update_bounds_hapax (bounds_t *restrict pb_this_gap, const bounds_t *pb_sample)
 Use the bounds for this sample in pb_sample and use it to update the bounds for this gap in pg_this_gap.
static void record (unsigned slots, const output_t *poutput, bounds_t b_slot, unsigned current_slot)
 Store new per-slot bounds.
static void record_normal (unsigned slots, const output_t *poutput, bounds_t b_prev_gap, bounds_t b_this_gap, unsigned current_slot)
 Store new per-slot bounds based on per-gap bounds.
static void record_hapax (unsigned slots, const output_t *poutput, bounds_t b_prev_gap, bounds_t b_this_gap, unsigned current_slot)
 Store new per-slot bounds based on per-gap bounds.
static void calculate_statistics_normal (const input_t *restrict pinput, const output_t *poutput)
 Calculate the bounds for type accumulation.
static void calculate_statistics_hapax (const input_t *restrict pinput, const output_t *poutput)
 Calculate the bounds for hapax accumulation.
static void calculate_statistics (const input_t *pinput, output_t *restrict poutput)
 Calculate the bounds for type or hapax accumulation.
static void free_output (const output_t *poutput)
 Frees the memory allocated for the fields of output_t.
static void print_raw_data (unsigned accum_items, unsigned accum_value)
 Print a row of raw data.
static void calculate_raw_data_normal (const input_t *pinput)
 Print raw data for type accumulation.
static void calculate_raw_data_hapax (const input_t *pinput)
 Print raw data for hapax accumulation.
static void calculate_raw_data (const input_t *pinput)
 Print raw data for type or hapax accumulation.
static void print_row (unsigned slot_threshold, const unsigned *lower_bounds, const unsigned *upper_bounds)
 Prints a row of output.
static void print_result (const input_t *pinput, const output_t *poutput)
 Prints the results.
int main (int argc, char **argv)
 Main program.

Variables

static bitcount_t bitcounts [1U<< BITCOUNT_BITS]
 A lookup table where precomputed bit counts are stored.
const double LEVELS [] = { LEVELS_LIST }
 The significance levels to report.