<commit_before>
#include "assembly_arc_block.h"

#include <core/system/packer.h>

void bsal_assembly_arc_block_init(struct bsal_assembly_arc_block *self, struct bsal_memory_pool *pool,
                int kmer_length, struct bsal_dna_codec *codec)
{
    int key_length;
    struct bsal_assembly_arc arc;

    bsal_assembly_arc_init_mock(&arc, kmer_length, pool, codec);

    key_length = bsal_assembly_arc_pack_size(&arc, kmer_length, codec);

    bsal_assembly_arc_destroy(&arc, pool);

    bsal_set_init(&self->set, key_length);

    bsal_vector_init(&self->arcs, sizeof(struct bsal_assembly_arc));

    /*
     * Set the memory pool too.
     * The main use case is to generate stuff to transport between actors so
     * ephemeral memory pool is going to be used.
     */
    bsal_set_set_memory_pool(&self->set, pool);
    bsal_vector_set_memory_pool(&self->arcs, pool);

    self->enable_redundancy_check = 0;
}

void bsal_assembly_arc_block_destroy(struct bsal_assembly_arc_block *self, struct bsal_memory_pool *pool)
{
    int i;
    int size;
    struct bsal_assembly_arc *arc;

    bsal_set_destroy(&self->set);

    size = bsal_vector_size(&self->arcs);

    /*
     * Destroy arcs.
     */
    for (i = 0; i < size; i++) {

        arc = bsal_vector_at(&self->arcs, i);

        bsal_assembly_arc_destroy(arc, pool);
    }

    bsal_vector_destroy(&self->arcs);
}

void bsal_assembly_arc_block_add_arc(struct bsal_assembly_arc_block *self,
                int type, struct bsal_dna_kmer *source,
                int destination,
                int kmer_length, struct bsal_dna_codec *codec,
                struct bsal_memory_pool *pool)
{
    int key_length;
    void *buffer;
    int found;
    struct bsal_assembly_arc *arc;
    int size;

    size = bsal_vector_size(&self->arcs);
    bsal_vector_resize(&self->arcs, size + 1);

    arc = bsal_vector_at(&self->arcs, size);

    bsal_assembly_arc_init(arc, type, source,
                                destination,
                                kmer_length, pool, codec);

    /*
     * Verify if it is accepted.
     */
    if (self->enable_redundancy_check) {

        key_length = bsal_assembly_arc_pack_size(arc, kmer_length, codec);
        buffer = bsal_memory_pool_allocate(pool, key_length);

        /*
         * Generate a key to verify if this arc is already in the block.
         * Duplicates are not required anyway.
         */
        bsal_assembly_arc_pack(arc, buffer, kmer_length, codec);

        found = bsal_set_find(&self->set, buffer);

        bsal_memory_pool_free(pool, buffer);

        /*
         * Don't append it if the arc is there already
         */
        if (found) {
            bsal_vector_resize(&self->arcs, size);
        }
    }
}

int bsal_assembly_arc_block_pack_size(struct bsal_assembly_arc_block *self, int kmer_length, struct bsal_dna_codec *codec)<commit_msg>actual insert things into the redundancy set<commit_after>
#include "assembly_arc_block.h"

#include <core/system/packer.h>

void bsal_assembly_arc_block_init(struct bsal_assembly_arc_block *self, struct bsal_memory_pool *pool,
                int kmer_length, struct bsal_dna_codec *codec)
{
    int key_length;
    struct bsal_assembly_arc arc;

    bsal_assembly_arc_init_mock(&arc, kmer_length, pool, codec);

    key_length = bsal_assembly_arc_pack_size(&arc, kmer_length, codec);

    bsal_assembly_arc_destroy(&arc, pool);

    bsal_set_init(&self->set, key_length);

    bsal_vector_init(&self->arcs, sizeof(struct bsal_assembly_arc));

    /*
     * Set the memory pool too.
     * The main use case is to generate stuff to transport between actors so
     * ephemeral memory pool is going to be used.
     */
    bsal_set_set_memory_pool(&self->set, pool);
    bsal_vector_set_memory_pool(&self->arcs, pool);

    self->enable_redundancy_check = 0;
}

void bsal_assembly_arc_block_destroy(struct bsal_assembly_arc_block *self, struct bsal_memory_pool *pool)
{
    int i;
    int size;
    struct bsal_assembly_arc *arc;

    bsal_set_destroy(&self->set);

    size = bsal_vector_size(&self->arcs);

    /*
     * Destroy arcs.
     */
    for (i = 0; i < size; i++) {

        arc = bsal_vector_at(&self->arcs, i);

        bsal_assembly_arc_destroy(arc, pool);
    }

    bsal_vector_destroy(&self->arcs);
}

void bsal_assembly_arc_block_add_arc(struct bsal_assembly_arc_block *self,
                int type, struct bsal_dna_kmer *source,
                int destination,
                int kmer_length, struct bsal_dna_codec *codec,
                struct bsal_memory_pool *pool)
{
    int key_length;
    void *buffer;
    int found;
    struct bsal_assembly_arc *arc;
    int size;

    size = bsal_vector_size(&self->arcs);
    bsal_vector_resize(&self->arcs, size + 1);

    arc = bsal_vector_at(&self->arcs, size);

    bsal_assembly_arc_init(arc, type, source,
                                destination,
                                kmer_length, pool, codec);

    /*
     * Verify if it is accepted.
     */
    if (self->enable_redundancy_check) {

        key_length = bsal_assembly_arc_pack_size(arc, kmer_length, codec);
        buffer = bsal_memory_pool_allocate(pool, key_length);

        /*
         * Generate a key to verify if this arc is already in the block.
         * Duplicates are not required anyway.
         */
        bsal_assembly_arc_pack(arc, buffer, kmer_length, codec);

        found = bsal_set_find(&self->set, buffer);

        /*
         * Don't append it if the arc is there already
         */
        if (found) {
            bsal_vector_resize(&self->arcs, size);
        } else {

            /*
             * Actually add the key into the
             * set.
             */
            bsal_set_add(&self->set, buffer);
        }

        bsal_memory_pool_free(pool, buffer);
    }
}

int bsal_assembly_arc_block_pack_size(struct bsal_assembly_arc_block *self, int kmer_length, struct bsal_dna_codec *codec)
{'fraction_non_alphanumeric': 0.09339828657819586, 'fraction_numerical': 0.0010078951789013943, 'mean_word_length': 2.6415902140672785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2350404', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1939, 'n_words': 431}