<commit_before>#include "c4-internal.h"
#include "operator/scancursor.h"
#include "storage/mem_table.h"

/*
 * Unpin the tuples contained in this table.
 */
static void
mem_table_cleanup(AbstractTable *a_tbl)
{
    MemTable *tbl = (MemTable *) a_tbl;
    rset_index_t *ri;

    ri = rset_iter_make(a_tbl->pool, tbl->tuples);
    while (rset_next(ri))
    {
        Tuple *t;

        t = rset_this(ri);
        tuple_unpin(t, a_tbl->def->schema);
    }
}

static bool
mem_table_insert(AbstractTable *a_tbl, Tuple *t)
{
    MemTable *tbl = (MemTable *) a_tbl;
    bool is_new;

    is_new = rset_add(tbl->tuples, t);
    if (is_new)
        tuple_pin(t);
#if 0
    c4_log(a_tbl->c4, "%s: t = %s, tbl = %s, is_new = %s, refcount = %u",
           __func__, log_tuple(a_tbl->c4, t, a_tbl->def->schema),
           a_tbl->def->name,
           is_new ? "true" : "false", rset_get(tbl->tuples, t));
#endif
    return is_new;
}

static bool
mem_table_delete(AbstractTable *a_tbl, Tuple *t)
{
    MemTable *tbl = (MemTable *) a_tbl;
    Tuple *elem;
    unsigned int new_count;

    elem = rset_remove(tbl->tuples, t, &new_count);
    if (!elem)
        return false;

#if 0
    c4_log(a_tbl->c4, "%s: t = %s, tbl = %s, new_count = %u",
           __func__, log_tuple(a_tbl->c4, t, a_tbl->def->schema),
           a_tbl->def->name,
           new_count);
#endif
    if (new_count == 0)
    {
        tuple_unpin(elem, a_tbl->def->schema);
        return true;
    }

    return false;
}

static bool
mem_table_cmp_tuple(const void *k1, const void *k2,
                    int klen, void *user_data)
{
    Tuple *t1 = (Tuple *) k1;
    Tuple *t2 = (Tuple *) k2;
    AbstractTable *tbl = (AbstractTable *) user_data;

    ASSERT(klen == sizeof(Tuple *));
    return tuple_equal(t1, t2, tbl->def->schema);
}<commit_msg>Code cleanup.<commit_after>#include "c4-internal.h"
#include "operator/scancursor.h"
#include "storage/mem_table.h"

/*
 * Unpin the tuples contained in this table.
 */
static void
mem_table_cleanup(AbstractTable *a_tbl)
{
    MemTable *tbl = (MemTable *) a_tbl;
    rset_index_t *ri;

    ri = rset_iter_make(a_tbl->pool, tbl->tuples);
    while (rset_next(ri))
    {
        Tuple *t;

        t = rset_this(ri);
        tuple_unpin(t, a_tbl->def->schema);
    }
}

static bool
mem_table_insert(AbstractTable *a_tbl, Tuple *t)
{
    MemTable *tbl = (MemTable *) a_tbl;
    bool is_new;

    is_new = rset_add(tbl->tuples, t);
    if (is_new)
        tuple_pin(t);

    return is_new;
}

static bool
mem_table_delete(AbstractTable *a_tbl, Tuple *t)
{
    MemTable *tbl = (MemTable *) a_tbl;
    Tuple *elem;
    unsigned int new_count;

    elem = rset_remove(tbl->tuples, t, &new_count);
    if (elem != NULL && new_count == 0)
    {
        tuple_unpin(elem, a_tbl->def->schema);
        return true;
    }

    /* Either not found or updated ref count > 0 */
    return false;
}

static bool
mem_table_cmp_tuple(const void *k1, const void *k2,
                    int klen, void *user_data)
{
    Tuple *t1 = (Tuple *) k1;
    Tuple *t2 = (Tuple *) k2;
    AbstractTable *tbl = (AbstractTable *) user_data;

    ASSERT(klen == sizeof(Tuple *));
    return tuple_equal(t1, t2, tbl->def->schema);
}
{'fraction_non_alphanumeric': 0.1442817076971019, 'fraction_numerical': 0.009037083203490184, 'mean_word_length': 2.7412587412587412, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '2204141', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1224, 'n_words': 279}