<commit_before>#include <stdio.h>
#include "rbtree.h"
#include "mem.h"
#include <time.h>
#include <stdlib.h>

#define COUNT 20
#define MOD (COUNT * 2)

int cmp(const void *d1, const void *d2, void *cl) {
    return *(int *)d1 - *(int *)d2;
}

int pr(const void *d, void *cl) {
    printf("%d\n", *(int *)d);
    return 0;
}

void free_data(void *d, void *cl) {
    printf("free %d\n", *(int *)d);
    FREE(d);
}

static inline int insert(RBTree_T *t, int *n) {
    return RBTree_insert(t, n, cmp, NULL);
}

int main() {
    RBTree_T tree = NULL;
    int *n;
    int inserted;
    void *d;

    srand(time(NULL));

    for (int i = 1; i <= COUNT; i++) {
	NEW(n); *n = rand() % MOD;
	inserted = insert(&tree, n);
	printf("%d (%d)\n", *n, inserted);
	if (!inserted) FREE(n);
    }

    RBTree_traverse(tree, pr, NULL);


    int r;
    for (int i = 1; i <= COUNT; i++) {
	r = rand() % MOD;
	d = (void *)RBTree_remove(&tree, &r, cmp, NULL);
	printf("%d (%p): %d\n", r, d, d ? *(int *)d : -1);
	if (d) FREE(d);
    }

    RBTree_traverse(tree, pr, NULL);
    RBTree_traverse(tree, pr, NULL);
    RBTree_traverse(tree, pr, NULL);

    RBTree_free(&tree, free_data, NULL);

    printf("tree = %p\n", (void *)tree);

    return 0;
}<commit_msg>Small change to rbtree example<commit_after>#include <stdio.h>
#include "rbtree.h"
#include "mem.h"
#include <time.h>
#include <stdlib.h>

#define COUNT 20
#define MOD (COUNT * 2)

int cmp(const void *d1, const void *d2, void *cl) {
    return *(int *)d1 - *(int *)d2;
}

int pr(const void *d, void *cl) {
    printf("%d\n", *(int *)d);
    return 0;
}

void free_data(void *d, void *cl) {
    printf("free %d\n", *(int *)d);
    FREE(d);
}

static inline int insert(RBTree_T *t, int *n) {
    return RBTree_insert(t, n, cmp, NULL);
}

int main() {
    RBTree_T tree = NULL;
    int *n;
    int inserted;
    void *d;

    srand(time(NULL));

    for (int i = 1; i <= COUNT; i++) {
	NEW(n); *n = rand() % MOD;
	inserted = insert(&tree, n);
	printf("%d (%d)\n", *n, inserted);
	if (!inserted) FREE(n);
    }

    RBTree_traverse(tree, pr, NULL);


    int r;
    for (int i = 1; i <= COUNT; i++) {
	r = rand() % MOD;
	d = (void *)RBTree_remove(&tree, &r, cmp, NULL);
	printf("%d (%p): %d\n", r, d, d ? *(int *)d : -1);
	if (d) free_data(d, NULL);
    }

    RBTree_traverse(tree, pr, NULL);

    RBTree_free(&tree, free_data, NULL);

    printf("tree = %p\n", (void *)tree);

    return 0;
}
{'fraction_non_alphanumeric': 0.20898598516075845, 'fraction_numerical': 0.00989282769991756, 'mean_word_length': 3.045, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '574645', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1025, 'n_words': 295}