<commit_before>/**
  @file splaytree.c
  @brief See header for details
*/
#include "splaytree.h"
#include <stdlib.h>

splaytree_t* splaytree_create(void)
{
    splaytree_t* splaytree = (splaytree_t*)malloc(sizeof(splaytree_t));
    splaytree->root = NULL;
    return splaytree;
}

static void destroy_tree(node_t* node) {
    if (NULL != node) {
        destroy_tree(node->left);
        destroy_tree(node->right);
    }
}

void splaytree_destroy(splaytree_t* tree)
{
    destroy_tree(tree->root);
    free(tree);
}

static node_t* create_node(node_type_t tag, void* value) {
    node_t* node = (node_t*)malloc(sizeof(node_t*));
    node->tag = tag;
    node->ptr.raw = value;
    node->left = NULL;
    node->right = NULL;
    return node;
}

static uintptr_t get_start_addr(node_t* curr) {
    if (curr->tag == SEGMENT)
        return (uintptr_t)(curr->ptr.segment->start);
    else
        return (uintptr_t)(curr->ptr.block->data);
}

static uintptr_t get_end_addr(node_t* curr) {
    if (curr->tag == SEGMENT)
        return (uintptr_t)(curr->ptr.segment->end);
    else
        return (uintptr_t)(curr->ptr.block->data + curr->ptr.block->size);
}

static node_t** next_node(node_t* curr, uintptr_t address) {
    uintptr_t curr_address = get_start_addr(curr);
    if (address < curr_address)
        return &(curr->left);
    else
        return &(curr->right);
}

void splaytree_insert(splaytree_t* tree, node_type_t tag, void* value)
{
    /* Get the address of the start of the range */
    uintptr_t address;
    if (SEGMENT == tag)
        address = (uintptr_t)((segment_t*)value)->start;
    else
        address = (uintptr_t)((block_t*)value)->data;
    /* Insert the item into the tree */
    if (tree->root == NULL)
        tree->root = create_node(tag, value);<commit_msg>make destroy_node actually free the nodes<commit_after>/**
  @file splaytree.c
  @brief See header for details
*/
#include "splaytree.h"
#include <stdlib.h>

splaytree_t* splaytree_create(void)
{
    splaytree_t* splaytree = (splaytree_t*)malloc(sizeof(splaytree_t));
    splaytree->root = NULL;
    return splaytree;
}

static void destroy_tree(node_t* node)
{
    if (NULL != node) {
        destroy_tree(node->left);
        destroy_tree(node->right);
        free(node);
    }
}

void splaytree_destroy(splaytree_t* tree)
{
    destroy_tree(tree->root);
    free(tree);
}

static node_t* create_node(node_type_t tag, void* value)
{
    node_t* node = (node_t*)malloc(sizeof(node_t*));
    node->tag = tag;
    node->ptr.raw = value;
    node->left = NULL;
    node->right = NULL;
    return node;
}

static uintptr_t get_start_addr(node_t* curr)
{
    if (curr->tag == SEGMENT)
        return (uintptr_t)(curr->ptr.segment->start);
    else
        return (uintptr_t)(curr->ptr.block->data);
}

static uintptr_t get_end_addr(node_t* curr)
{
    if (curr->tag == SEGMENT)
        return (uintptr_t)(curr->ptr.segment->end);
    else
        return (uintptr_t)(curr->ptr.block->data + curr->ptr.block->size);
}

static node_t** next_node(node_t* curr, uintptr_t address)
{
    uintptr_t curr_address = get_start_addr(curr);
    if (address < curr_address)
        return &(curr->left);
    else
        return &(curr->right);
}

void splaytree_insert(splaytree_t* tree, node_type_t tag, void* value)
{
    /* Get the address of the start of the range */
    uintptr_t address;
    if (SEGMENT == tag)
        address = (uintptr_t)((segment_t*)value)->start;
    else
        address = (uintptr_t)((block_t*)value)->data;
    /* Insert the item into the tree */
    if (tree->root == NULL)
        tree->root = create_node(tag, value);
{'fraction_non_alphanumeric': 0.1437637969094923, 'fraction_numerical': 0.0, 'mean_word_length': 3.2596944770857816, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 57, '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': '634009', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1314, 'n_words': 273}