kernel_t *make_kernel_copy(const kernel_t *kernel, allocator_t &alc)
{
    const size_t n = kernel->size;

    kernel_t *k = make_new_kernel<stadfa>(n, alc);

    memcpy(k->state, kernel->state, n * sizeof(void*));
    memcpy(k->thist, kernel->thist, n * sizeof(hidx_t));

    prectable_t *ptbl = NULL;
    if (kernel->prectbl) {
        ptbl = alc.alloct<prectable_t>(n * n);
        memcpy(ptbl, kernel->prectbl, n * n * sizeof(prectable_t));
    }
    k->prectbl = ptbl;

    if (!stadfa) {
        memcpy(k->tvers, kernel->tvers, n * sizeof(uint32_t));
    }
    else {
        // new staDFA commands are allocated for every closure, don't copy
        k->stacmd = kernel->stacmd;
    }

    return k;
}
kernel_t *make_kernel_copy(const kernel_t *kernel, allocator_t &alc)
{
    const size_t n = kernel->size;

    kernel_t *k = make_new_kernel<stadfa>(n, alc);

    memcpy(k->state, kernel->state, n * sizeof(void*));
    memcpy(k->thist, kernel->thist, n * sizeof(hidx_t));

    prectable_t *ptbl = NULL;
    if (kernel->prectbl) {
        ptbl = alc.alloct<prectable_t>(n * n);
        memcpy(ptbl, kernel->prectbl, n * n * sizeof(prectable_t));
    }
    k->prectbl = ptbl;

    if (!stadfa) {
        memcpy(k->tvers, kernel->tvers, n * sizeof(uint32_t));
    }
    else {
         
        k->stacmd = kernel->stacmd;
    }

    return k;
}