<commit_before>#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "rrb.h"

static rrb_node_t EMPTY_NODE = {.size_table = NULL,
                                .child = (rrb_node_t *) NULL};

static inline rrb_node_t *node_create(uint32_t children) {
  rrb_node_t *node = calloc(1, sizeof(uint32_t *)
                            + sizeof(rrb_node_t *) * children);
  return node;
}

rrb_t *rrb_create() {
  return NULL;
}

void rrb_destroy(rrb_t *restrict rrb) {
  return;
}

uint32_t rrb_count(const rrb_t *restrict rrb) {
  return rrb->cnt;
}

// Iffy, need to pass back the modified i somehow.
static rrb_node_t *node_for(const rrb_t *restrict rrb, uint32_t i) {
  if (i < rrb->cnt) {
    rrb_node_t *node = rrb->root;
    for (uint32_t level = rrb->shift; level >= RRB_BITS; level -= RRB_BITS) {
      uint32_t idx = (i >> level) & RRB_MASK; // TODO: don't think we need the mask

      // vv TODO: I *think* this should be sufficient, not 100% sure.
      if (node->size_table[idx] <= i) {
        idx++;
        if (node->size_table[idx] <= i) {
          idx++;
        }
      }

      if (idx) {
        i -= node->size_table[idx];
      }
      node = node->child[idx];
    }
  }
  // Index out of bounds
  else {
    return NULL; // Or some error later on
  }
}<commit_msg>Implement and return leaf node in node_for.<commit_after>#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "rrb.h"

typedef struct leaf_node_t {
  void *child[RRB_BRANCHING];
} leaf_node_t;

static rrb_node_t EMPTY_NODE = {.size_table = NULL,
                                .child = (rrb_node_t *) NULL};

static inline rrb_node_t *node_create(uint32_t children) {
  rrb_node_t *node = calloc(1, sizeof(uint32_t *)
                            + sizeof(rrb_node_t *) * children);
  return node;
}

rrb_t *rrb_create() {
  return NULL;
}

void rrb_destroy(rrb_t *restrict rrb) {
  return;
}

uint32_t rrb_count(const rrb_t *restrict rrb) {
  return rrb->cnt;
}

// Iffy, need to pass back the modified i somehow.
static leaf_node_t *node_for(const rrb_t *restrict rrb, uint32_t i) {
  if (i < rrb->cnt) {
    rrb_node_t *node = rrb->root;
    for (uint32_t level = rrb->shift; level >= RRB_BITS; level -= RRB_BITS) {
      uint32_t idx = (i >> level) & RRB_MASK; // TODO: don't think we need the mask

      // vv TODO: I *think* this should be sufficient, not 100% sure.
      if (node->size_table[idx] <= i) {
        idx++;
        if (node->size_table[idx] <= i) {
          idx++;
        }
      }

      if (idx) {
        i -= node->size_table[idx];
      }
      node = node->child[idx];
    }
    return (leaf_node_t *) node;
  }
  // Index out of bounds
  else {
    return NULL; // Or some error later on
  }
}
{'fraction_non_alphanumeric': 0.13279824881430136, 'fraction_numerical': 0.011674571324334184, 'mean_word_length': 2.414694894146949, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, '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': '1391159', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1035, 'n_words': 265}