aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-09-08 15:51:40 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-09-08 15:51:53 -0700
commitc0a7b53baf2a6e7bf9bc1fbec7ac05e43ac59154 (patch)
tree385b83f4d505da960820932f7357eb46b31abac3 /include
parent8c0475f97675245d1bcbb112dc79c9f490fad361 (diff)
checkin
Diffstat (limited to 'include')
-rw-r--r--include/libbio.h19
-rw-r--r--include/libn.h39
2 files changed, 28 insertions, 30 deletions
diff --git a/include/libbio.h b/include/libbio.h
index 558c163..b3d0426 100644
--- a/include/libbio.h
+++ b/include/libbio.h
@@ -5,15 +5,12 @@
typedef struct bio·Node
{
- string name;
- string comment;
- double dist;
- double support;
- int nnode;
- int nchild;
- struct bio·Node *parent;
- struct bio·Node *sibling;
- struct bio·Node *child;
+ string name, comment;
+ double dist, support;
+ int nnode, nchild;
+ struct bio·Node *parent, *sibling, *child;
+
+ void *data;
} bio·Node;
typedef struct bio·Tree
@@ -53,7 +50,6 @@ error bio·writenewick(bio·Tree tree, io·Putter out, void*);
/* i/o */
typedef struct bio·SeqReader bio·SeqReader;
-typedef struct bio·SeqWriter bio·SeqWriter;
typedef struct bio·Seq
{
@@ -68,3 +64,6 @@ error bio·closeseq(bio·SeqReader *rdr);
error bio·readfasta(bio·SeqReader *rdr, bio·Seq *seq);
error bio·readfastq(bio·SeqReader *rdr, bio·Seq *seq);
+
+error bio·writefasta(io·Writer io, void *wtr, bio·Seq seq);
+error bio·writefastq(io·Writer io, void *wtr, bio·Seq seq);
diff --git a/include/libn.h b/include/libn.h
index 2b8dc4c..5d557ce 100644
--- a/include/libn.h
+++ b/include/libn.h
@@ -22,34 +22,31 @@ typedef wchar_t wchar;
// ----------------------------------------------------------------------------
// dynamic array
-typedef struct bufHdr
+typedef struct BufHdr
{
vlong len;
vlong cap;
byte buf[];
-} bufHdr;
+} BufHdr;
-#define _bufHdr(s) ((bufHdr*)((uint8*)(s)-offsetof(bufHdr, buf)))
-#define buflen(s) ((s) ? (_bufHdr(s)->len) : 0)
-#define bufcap(s) ((s) ? (_bufHdr(s)->cap) : 0)
-#define bufend(s) ((s) + buflen(s))
-#define bufsize(s) ((s) ? (buflen(s) * sizeof((s)[0])) : 0)
+#define bufhdr(b) ((BufHdr*)((uint8*)(b)-offsetof(BufHdr, buf)))
+#define buflen(b) ((b) ? (bufhdr(b)->len) : 0)
+#define bufcap(b) ((b) ? (bufhdr(b)->cap) : 0)
+#define bufend(b) ((b) + buflen(b))
+#define bufsize(b) ((b) ? (buflen(b) * sizeof((b)[0])) : 0)
-#define buffree(s) ((s) ? (free(_bufHdr(s)), (s) = nil) : 0)
-#define buffit(s, n) ((n) <= bufcap(s) ? 0 : ((s) = bufgrow((s), (n), sizeof(*(s)))))
+#define buffree(b) ((b) ? (free(bufhdr(b)), (b) = nil) : 0)
+#define buffit(b, n) ((n) <= bufcap(b) ? 0 : ((b) = ·bufgrow((b), (n), sizeof(*(b)))))
-#define bufresize(s, n) \
- do { \
- (buffit(s, n)); \
- ((_bufHdr(s)->len) = (n)); \
- } while (0)
+#define bufpush(b, ...) (buffit((b), 1 + buflen(b)), (b)[bufhdr(b)->len++] = (__VA_ARGS__))
+#define bufaddn(b, n) (buffit(b, buflen(b)+n), bufhdr(b)->len += n, b+bufhdr(b)->len-n)
-#define bufpush(s, ...) (buffit((s), 1 + buflen(s)), (s)[_bufHdr(s)->len++] = (__VA_ARGS__))
+#define bufpop(b) ((b)[--bufhdr(b)->len])
+#define bufdel(b, i) bufdeln((b), (i), 1)
+#define bufdeln(b, i, n) (memmove((b)+(i), (b)+(i)+(n), sizeof(*(b))*(bufhdr(b)->len-(n)-(i)), bufhdr(b)->len -= (n))
+#define bufdelswap(b, i) ((b)[i] = bufend(b)[-1], bufhdr(b)->len-=1)
-#define bufpop(s, i) (_bufpop((s), (i), sizeof(*(s))), (s)[_bufHdr(s)->len])
-
-void* bufgrow(void*, vlong, vlong);
-void _bufpop(void*, int, vlong);
+void* ·bufgrow(void*, vlong, vlong);
// -----------------------------------------------------------------------------
// memory allocation
@@ -408,9 +405,11 @@ void sort·strings(uintptr n, byte* arr[]);
// fast random number generation
error rng·init(uint64 seed);
-double rng·random();
+double rng·random(void);
+double rng·exponential(double lambda);
bool rng·bernoulli(double f);
uint64 rng·randi(int max);
+uint64 rng·poisson(double mean);
// -----------------------------------------------------------------------------
// variable arguments