<commit_before>//
//  binarytree.c
//  CinyTest-Sample
//
//  Created by <NAME> on 8/24/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include "binarytree.h"

#define BT_EMPTY NULL

struct bt_node {
    int value;
    struct bt_node *left;
    struct bt_node *right;
};

static struct bt_node *make_node(int value)
{
    struct bt_node *new_node = malloc(sizeof *new_node);
    new_node->value = value;
    new_node->left = BT_EMPTY;
    new_node->right = BT_EMPTY;
    return new_node;
}

static struct bt_node **find_childref(struct bt_node *parent, int value)
{
    struct bt_node **child_ref = parent->value > value ? &parent->left : &parent->right;
    if (!(*child_ref) || (*child_ref)->value == value) {
        return child_ref;
    }
    return find_childref(*child_ref, value);
}

static struct bt_node *minimum_child(struct bt_node *tree)
{
    struct bt_node *minimum_child = tree;
    while (minimum_child->left) {
        minimum_child = minimum_child->left;
    }
    return minimum_child;
}

static void remove_node(struct bt_node *tree, int value)
{
    struct bt_node **node_ref = find_childref(tree, value);
    struct bt_node *node = *node_ref;
    
    if (!node) return;
    
    if (node->left && node->right) {
        struct bt_node *successor = minimum_child(node->right);
        node->value = successor->value;
        bt_remove(&node->right, successor->value);
    } else if (node->left) {
        *node_ref = node->left;
        node->left = BT_EMPTY;
        bt_free(node);
    } else if (node->right) {
        *node_ref = node->right;
        node->right = BT_EMPTY;
        bt_free(node);
    } else {
        *node_ref = BT_EMPTY;
        bt_free(node);
    }
}

static void print_tree(struct bt_node *tree, int indent, char label)
{
    if (!tree) return;
    
    for (int indent_count = indent; indent_count > 0; --indent_count) {
        printf("\t");
    }
    printf("%c%d\n", label, tree->value);
    print_tree(tree->left, indent + 1, 'L');<commit_msg>minor change to binary tree printing<commit_after>//
//  binarytree.c
//  CinyTest-Sample
//
//  Created by <NAME> on 8/24/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include "binarytree.h"

#define BT_EMPTY NULL

struct bt_node {
    int value;
    struct bt_node *left;
    struct bt_node *right;
};

static struct bt_node *make_node(int value)
{
    struct bt_node *new_node = malloc(sizeof *new_node);
    new_node->value = value;
    new_node->left = BT_EMPTY;
    new_node->right = BT_EMPTY;
    return new_node;
}

static struct bt_node **find_childref(struct bt_node *parent, int value)
{
    struct bt_node **child_ref = parent->value > value ? &parent->left : &parent->right;
    if (!(*child_ref) || (*child_ref)->value == value) {
        return child_ref;
    }
    return find_childref(*child_ref, value);
}

static struct bt_node *minimum_child(struct bt_node *tree)
{
    struct bt_node *minimum_child = tree;
    while (minimum_child->left) {
        minimum_child = minimum_child->left;
    }
    return minimum_child;
}

static void remove_node(struct bt_node *tree, int value)
{
    struct bt_node **node_ref = find_childref(tree, value);
    struct bt_node *node = *node_ref;
    
    if (!node) return;
    
    if (node->left && node->right) {
        struct bt_node *successor = minimum_child(node->right);
        node->value = successor->value;
        bt_remove(&node->right, successor->value);
    } else if (node->left) {
        *node_ref = node->left;
        node->left = BT_EMPTY;
        bt_free(node);
    } else if (node->right) {
        *node_ref = node->right;
        node->right = BT_EMPTY;
        bt_free(node);
    } else {
        *node_ref = BT_EMPTY;
        bt_free(node);
    }
}

static void print_tree(struct bt_node *tree, int indent, char label)
{
    if (!tree) return;
    
    for (int indent_count = indent; indent_count > 0; --indent_count) {
        printf("\t");
    }
    printf("%c(%d)\n", label, tree->value);
    print_tree(tree->left, indent + 1, 'L');
{'fraction_non_alphanumeric': 0.1403759219605044, 'fraction_numerical': 0.005234356412086605, 'mean_word_length': 2.8925925925925924, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 67, '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': '4322441', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1451, 'n_words': 350}