make sdust work (it didn't)
This commit is contained in:
parent
bacb7534d2
commit
0f160151c7
14
sdust.c
14
sdust.c
|
|
@ -50,11 +50,9 @@ struct sdust_buf_s {
|
||||||
void *km; // memory pool
|
void *km; // memory pool
|
||||||
};
|
};
|
||||||
|
|
||||||
sdust_buf_t *sdust_buf_init(void)
|
sdust_buf_t *sdust_buf_init(void *km)
|
||||||
{
|
{
|
||||||
sdust_buf_t *buf;
|
sdust_buf_t *buf;
|
||||||
void *km;
|
|
||||||
km = km_init();
|
|
||||||
buf = (sdust_buf_t*)kcalloc(km, 1, sizeof(sdust_buf_t));
|
buf = (sdust_buf_t*)kcalloc(km, 1, sizeof(sdust_buf_t));
|
||||||
buf->km = km;
|
buf->km = km;
|
||||||
buf->w = kdq_init(int, buf->km);
|
buf->w = kdq_init(int, buf->km);
|
||||||
|
|
@ -64,9 +62,7 @@ sdust_buf_t *sdust_buf_init(void)
|
||||||
void sdust_buf_destroy(sdust_buf_t *buf)
|
void sdust_buf_destroy(sdust_buf_t *buf)
|
||||||
{
|
{
|
||||||
if (buf == 0) return;
|
if (buf == 0) return;
|
||||||
if (buf->km == 0) { // then fall back to the default allocator for which we need free all arrays manually
|
kfree(buf->km, buf->P.a); kfree(buf->km, buf->res.a); kfree(buf->km, buf);
|
||||||
kfree(buf->km, buf->P.a); kfree(buf->km, buf->res.a); kfree(buf->km, buf);
|
|
||||||
} else km_destroy(buf->km); // This deallocate all memory allocated from buf->km
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void shift_window(int t, kdq_t(int) *w, int T, int W, int *L, int *rw, int *rv, int *cw, int *cv)
|
static inline void shift_window(int t, kdq_t(int) *w, int T, int W, int *L, int *rw, int *rv, int *cw, int *cv)
|
||||||
|
|
@ -165,11 +161,11 @@ const uint64_t *sdust_core(const uint8_t *seq, int l_seq, int T, int W, int *n,
|
||||||
return buf->res.a;
|
return buf->res.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t *sdust(const uint8_t *seq, int l_seq, int T, int W, int *n)
|
uint64_t *sdust(void *km, const uint8_t *seq, int l_seq, int T, int W, int *n)
|
||||||
{
|
{
|
||||||
uint64_t *ret;
|
uint64_t *ret;
|
||||||
sdust_buf_t *buf;
|
sdust_buf_t *buf;
|
||||||
buf = sdust_buf_init();
|
buf = sdust_buf_init(km);
|
||||||
ret = (uint64_t*)sdust_core(seq, l_seq, T, W, n, buf);
|
ret = (uint64_t*)sdust_core(seq, l_seq, T, W, n, buf);
|
||||||
buf->res.a = 0;
|
buf->res.a = 0;
|
||||||
sdust_buf_destroy(buf);
|
sdust_buf_destroy(buf);
|
||||||
|
|
@ -202,7 +198,7 @@ int main(int argc, char *argv[])
|
||||||
while (kseq_read(ks) >= 0) {
|
while (kseq_read(ks) >= 0) {
|
||||||
uint64_t *r;
|
uint64_t *r;
|
||||||
int i, n;
|
int i, n;
|
||||||
r = sdust((uint8_t*)ks->seq.s, -1, T, W, &n);
|
r = sdust(0, (uint8_t*)ks->seq.s, -1, T, W, &n);
|
||||||
for (i = 0; i < n; ++i)
|
for (i = 0; i < n; ++i)
|
||||||
printf("%s\t%d\t%d\n", ks->name.s, (int)(r[i]>>32), (int)r[i]);
|
printf("%s\t%d\t%d\n", ks->name.s, (int)(r[i]>>32), (int)r[i]);
|
||||||
free(r);
|
free(r);
|
||||||
|
|
|
||||||
4
sdust.h
4
sdust.h
|
|
@ -9,10 +9,10 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// the simple interface
|
// the simple interface
|
||||||
uint64_t *sdust(const uint8_t *seq, int l_seq, int T, int W, int *n);
|
uint64_t *sdust(void *km, const uint8_t *seq, int l_seq, int T, int W, int *n);
|
||||||
|
|
||||||
// the following interface dramatically reduce heap allocations when sdust is frequently called.
|
// the following interface dramatically reduce heap allocations when sdust is frequently called.
|
||||||
sdust_buf_t *sdust_buf_init(void);
|
sdust_buf_t *sdust_buf_init(void *km);
|
||||||
void sdust_buf_destroy(sdust_buf_t *buf);
|
void sdust_buf_destroy(sdust_buf_t *buf);
|
||||||
const uint64_t *sdust_core(const uint8_t *seq, int l_seq, int T, int W, int *n, sdust_buf_t *buf);
|
const uint64_t *sdust_core(const uint8_t *seq, int l_seq, int T, int W, int *n, sdust_buf_t *buf);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue