<commit_before>#include <stdlib.h>
#include "cursor.h"
#include "errhandle.h"

void olc_init(ol_database *db, ol_cursor *cursor) {
    ol_stack *stack = NULL;

    /* Initialize the stack */
    stack = malloc(sizeof(ol_stack));
    check_mem(stack);

    stack->next = NULL;
    stack->data = NULL;

    /* Init the cursor */
    cursor->current_node = NULL;
    cursor->maximum = ols_subtree_maximum(db->tree->root);
    cursor->current_node = ols_subtree_minimum(db->tree->root);

    return;

error:
    if (stack != NULL) {
        while (stack->next != NULL) {
            spop(&stack);
        }
        free(stack);
    }
    return;
}

ol_splay_tree_node *_olc_get_node(ol_cursor *cursor) {
    return cursor->current_node;
}

ol_bucket *olc_get(ol_cursor *cursor) {
    ol_bucket *bucket = (ol_bucket *)cursor->current_node->ref_obj;
    return bucket;
}

/* TODO: Make this go backwards or forwards */
int olc_step(ol_cursor *cursor) {
    ol_splay_tree_node *node = cursor->current_node;

    if (node == cursor->maximum)
        return 0;

    if (node->right != NULL) {
        cursor->current_node = ols_subtree_minimum(node->right);
        return 1;
    }

    ol_splay_tree_node *parent = node->parent;
    while(parent != NULL && node == parent->right)
    {
        node = parent;
        parent = parent->parent;
    }

    cursor->current_node = parent;
    return 1;
}
<commit_msg>Fix clang bug.<commit_after>#include <stdlib.h>
#include "cursor.h"
#include "errhandle.h"
#include "tree.h"

void olc_init(ol_database *db, ol_cursor *cursor) {
    ol_stack *stack = NULL;

    /* Initialize the stack */
    stack = malloc(sizeof(ol_stack));
    check_mem(stack);

    stack->next = NULL;
    stack->data = NULL;

    /* Init the cursor */
    cursor->current_node = NULL;
    cursor->maximum = ols_subtree_maximum(db->tree->root);
    cursor->current_node = ols_subtree_minimum(db->tree->root);

    return;

error:
    if (stack != NULL) {
        while (stack->next != NULL) {
            spop(&stack);
        }
        free(stack);
    }
    return;
}

ol_splay_tree_node *_olc_get_node(ol_cursor *cursor) {
    return cursor->current_node;
}

ol_bucket *olc_get(ol_cursor *cursor) {
    ol_bucket *bucket = (ol_bucket *)cursor->current_node->ref_obj;
    return bucket;
}

/* TODO: Make this go backwards or forwards */
int olc_step(ol_cursor *cursor) {
    ol_splay_tree_node *node = cursor->current_node;

    if (node == cursor->maximum)
        return 0;

    if (node->right != NULL) {
        cursor->current_node = ols_subtree_minimum(node->right);
        return 1;
    }

    ol_splay_tree_node *parent = node->parent;
    while(parent != NULL && node == parent->right)
    {
        node = parent;
        parent = parent->parent;
    }

    cursor->current_node = parent;
    return 1;
}

{'fraction_non_alphanumeric': 0.13689423417049876, 'fraction_numerical': 0.0021223912274495934, 'mean_word_length': 2.7959731543624162, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '2428021', 'n_tokens_mistral': 992, 'n_tokens_neox': 951, 'n_words': 200}