2024-02-04 18:13:50 -08:00
|
|
|
#pragma once
|
2024-03-18 09:57:49 -07:00
|
|
|
|
|
|
|
// Common datastructures (arrays, tables, closures)
|
|
|
|
|
2024-08-12 22:30:25 -07:00
|
|
|
#include <gmp.h>
|
2024-08-11 11:47:34 -07:00
|
|
|
#include <pthread.h>
|
2024-09-29 17:06:09 -07:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <time.h>
|
2024-02-04 18:13:50 -08:00
|
|
|
|
2024-08-04 11:22:58 -07:00
|
|
|
#define ARRAY_LENGTH_BITS 42
|
2024-08-04 12:01:27 -07:00
|
|
|
#define ARRAY_FREE_BITS 6
|
|
|
|
#define ARRAY_REFCOUNT_BITS 3
|
2024-08-04 11:22:58 -07:00
|
|
|
#define ARRAY_STRIDE_BITS 12
|
|
|
|
|
|
|
|
#define MAX_FOR_N_BITS(N) ((1<<(N))-1)
|
|
|
|
#define ARRAY_MAX_STRIDE MAX_FOR_N_BITS(ARRAY_STRIDE_BITS-1)
|
|
|
|
#define ARRAY_MIN_STRIDE (~MAX_FOR_N_BITS(ARRAY_STRIDE_BITS-1))
|
|
|
|
#define ARRAY_MAX_DATA_REFCOUNT MAX_FOR_N_BITS(ARRAY_REFCOUNT_BITS)
|
|
|
|
#define ARRAY_MAX_FREE_ENTRIES MAX_FOR_N_BITS(ARRAY_FREE_BITS)
|
|
|
|
|
2024-08-12 22:30:25 -07:00
|
|
|
typedef union {
|
|
|
|
int64_t small;
|
|
|
|
mpz_t *big;
|
|
|
|
} Int_t;
|
|
|
|
|
2024-02-04 18:13:50 -08:00
|
|
|
typedef struct {
|
|
|
|
void *data;
|
2024-08-04 11:22:58 -07:00
|
|
|
// All of the following fields add up to 64 bits, which means that array
|
|
|
|
// structs can be passed in two 64-bit registers. C will handle doing the
|
|
|
|
// bit arithmetic to extract the necessary values, which is cheaper than
|
|
|
|
// spilling onto the stack and needing to retrieve data from the stack.
|
|
|
|
int64_t length:ARRAY_LENGTH_BITS;
|
|
|
|
uint8_t free:ARRAY_FREE_BITS;
|
2024-02-29 09:37:09 -08:00
|
|
|
bool atomic:1;
|
2024-08-04 11:22:58 -07:00
|
|
|
uint8_t data_refcount:ARRAY_REFCOUNT_BITS;
|
|
|
|
int16_t stride:ARRAY_STRIDE_BITS;
|
2024-09-05 11:56:37 -07:00
|
|
|
} Array_t;
|
2024-02-04 18:13:50 -08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t occupied:1, index:31;
|
|
|
|
uint32_t next_bucket;
|
|
|
|
} bucket_t;
|
|
|
|
|
2024-08-04 15:28:18 -07:00
|
|
|
#define TABLE_MAX_BUCKETS 0x7fffffff
|
2024-08-04 14:25:54 -07:00
|
|
|
#define TABLE_MAX_DATA_REFCOUNT 3
|
|
|
|
|
2024-02-04 18:13:50 -08:00
|
|
|
typedef struct {
|
2024-02-29 09:37:09 -08:00
|
|
|
uint32_t count:31, last_free:31;
|
|
|
|
uint8_t data_refcount:2;
|
2024-09-08 14:17:15 -07:00
|
|
|
bucket_t buckets[];
|
2024-02-04 18:13:50 -08:00
|
|
|
} bucket_info_t;
|
|
|
|
|
|
|
|
typedef struct table_s {
|
2024-09-05 11:56:37 -07:00
|
|
|
Array_t entries;
|
2024-12-26 13:52:47 -08:00
|
|
|
uint64_t hash;
|
2024-02-04 18:13:50 -08:00
|
|
|
bucket_info_t *bucket_info;
|
|
|
|
struct table_s *fallback;
|
2024-09-05 11:57:31 -07:00
|
|
|
} Table_t;
|
2024-02-04 18:13:50 -08:00
|
|
|
|
2024-03-09 11:02:19 -08:00
|
|
|
typedef struct {
|
|
|
|
void *fn, *userdata;
|
2024-09-11 10:56:39 -07:00
|
|
|
} Closure_t;
|
2024-03-09 11:02:19 -08:00
|
|
|
|
2024-08-05 11:40:28 -07:00
|
|
|
typedef struct Range_s {
|
2024-08-12 22:30:25 -07:00
|
|
|
Int_t first, last, step;
|
2024-08-05 11:40:28 -07:00
|
|
|
} Range_t;
|
|
|
|
|
2024-09-02 15:47:39 -07:00
|
|
|
enum text_type { TEXT_SHORT_ASCII, TEXT_ASCII, TEXT_SHORT_GRAPHEMES, TEXT_GRAPHEMES, TEXT_SUBTEXT };
|
|
|
|
|
|
|
|
typedef struct Text_s {
|
|
|
|
int64_t length; // Number of grapheme clusters
|
|
|
|
uint64_t hash:61;
|
|
|
|
uint8_t tag:3;
|
|
|
|
union {
|
|
|
|
char short_ascii[8];
|
|
|
|
const char *ascii;
|
|
|
|
int32_t short_graphemes[2];
|
2024-09-05 14:06:27 -07:00
|
|
|
const int32_t *graphemes;
|
2024-09-02 15:47:39 -07:00
|
|
|
struct Text_s *subtexts;
|
|
|
|
};
|
|
|
|
} Text_t;
|
|
|
|
|
2024-09-03 10:19:41 -07:00
|
|
|
#define Pattern_t Text_t
|
2024-09-27 23:07:37 -07:00
|
|
|
#define OptionalPattern_t Text_t
|
2024-09-03 10:19:41 -07:00
|
|
|
|
2024-11-17 11:49:03 -08:00
|
|
|
typedef struct timeval Moment_t;
|
|
|
|
#define OptionalMoment_t Moment_t
|
2024-09-29 17:06:09 -07:00
|
|
|
|
2024-11-03 19:37:48 -08:00
|
|
|
typedef struct RNGState_t* RNG_t;
|
|
|
|
|
2024-02-04 18:13:50 -08:00
|
|
|
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|