summaryrefslogtreecommitdiff
path: root/lichen.h
blob: a607d2444f83281e3af6a69854907c0dc1c2d8b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef LICHEN_H
#define LICHEN_H

#include <stdlib.h>
#include <stdint.h>

/* --===== random number generation =====-- */
typedef struct li_rand32_t {
  uint32_t (*rand)(void *);
  void *state;
} li_rand32_t;


struct li_xorshift32_t {
  li_rand32_t generator;
  uint64_t state;
};

// initialize an xorshift32 struct with a specific seed
void li_xorshift32_seed(struct li_xorshift32_t *xor, uint32_t seed);
// get a pseudo-random number via the xorshift algorithm
uint32_t li_xorshift32(void *s);


/* --===== generic linked lists =====-- */


typedef struct li_llnode_t {
  int tag;
  void *data;
  struct li_llnode_t *next;
} li_llnode_t;


li_llnode_t * li_alloc_llnode();
li_llnode_t * li_copy_llnode(li_llnode_t *n);
void li_free_llnode(li_llnode_t *n, void (*free_data)(void*));


typedef struct li_ll_t {
  int tag;
  size_t count;
  li_llnode_t *head;
  li_llnode_t *end;
} li_ll_t;


// allocate a linked list
struct li_ll_t * li_alloc_ll();
// free a linked list
void li_free_ll(struct li_ll_t *list, void (*free_data)(void*));
void li_ll_append(struct li_ll_t *list, void *data);
struct li_ll_t * li_copy_list(struct li_ll_t *list);




#endif