<commit_before>#include <stdlib.h>

#include "libreset/hash.h"

#include "util/likely.h"
#include "util/macros.h"
#include "util/debug.h"

#include "ll/ll.h"
#include "avl.h"
#include "common.h"
#include "util/macros.h"

/**
 * Debug print helper for avl implementation code
 *
 * @note No #ifdef DEBUG here, because if dbg() evaluates to nothing, this code
 * gets removed by the compiler anyways.
 */
#define avl_dbg(fmt,...) do { dbg("avl: "fmt, __VA_ARGS__); } while (0)

struct avl_el*
new_avl_el(
    rs_hash h
) {
    struct avl_el* el = calloc(1, sizeof(*el));
    if (el) {
        el->hash = h;
    }
    return el;
}

void
destroy_subtree(
    struct avl_el* node, //!< A node to destroy
    struct r_set_cfg const* cfg
) {
    avl_dbg("Destroying subtree from node %p", node);
    if (node->l) {
        destroy_subtree(node->l, cfg);
    }
    if (node->r) {
        destroy_subtree(node->r, cfg);
    }

    // TODO: clear linked list
    free(node);
}

struct avl_el*
rebalance_subtree(
    struct avl_el* root
) {
    avl_dbg("Rebalance subtree for %p", root);
    // check whether the root node is NULL<commit_msg>Destroy the linked list before removing the node<commit_after>#include <stdlib.h>

#include "libreset/hash.h"

#include "util/likely.h"
#include "util/macros.h"
#include "util/debug.h"

#include "ll/ll.h"
#include "avl.h"
#include "common.h"
#include "util/macros.h"

/**
 * Debug print helper for avl implementation code
 *
 * @note No #ifdef DEBUG here, because if dbg() evaluates to nothing, this code
 * gets removed by the compiler anyways.
 */
#define avl_dbg(fmt,...) do { dbg("avl: "fmt, __VA_ARGS__); } while (0)

struct avl_el*
new_avl_el(
    rs_hash h
) {
    struct avl_el* el = calloc(1, sizeof(*el));
    if (el) {
        el->hash = h;
    }
    return el;
}

void
destroy_subtree(
    struct avl_el* node, //!< A node to destroy
    struct r_set_cfg const* cfg
) {
    avl_dbg("Destroying subtree from node %p", node);
    if (node->l) {
        destroy_subtree(node->l, cfg);
    }
    if (node->r) {
        destroy_subtree(node->r, cfg);
    }

    ll_destroy(&node->ll, cfg);
    free(node);
}

struct avl_el*
rebalance_subtree(
    struct avl_el* root
) {
    avl_dbg("Rebalance subtree for %p", root);
    // check whether the root node is NULL
{'fraction_non_alphanumeric': 0.144473455178416, 'fraction_numerical': 0.0017406440382941688, 'mean_word_length': 3.0618374558303887, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, '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': '2941870', 'n_tokens_mistral': 870, 'n_tokens_neox': 863, 'n_words': 240}