<commit_before>
/* include the enumerator headers. */
#include "enum.h"
#include "enum-thread.h"
#include "enum-write.h"

/* state_div(): divide the size of a thread state into uniform pieces,
 * storing the result into the index of the thread state.
 *
 * arguments:
 *  @state: thread state to operate on.
 *  @len: number of elements in the state.
 *  @n: value to divide the state size by.
 */
static void state_div (enum_thread_node_t *state,
                       unsigned int len,
                       unsigned int n) {
  /* @bN: base-2 log of the tree size/leaf count.
   * @bn: base-2 log of the division value.
   * @bs: base-2 log of the quotient.
   * @i: general-purpose loop counter.
   */
  double bN, bn, bs;
  unsigned int i;

  /* compute the tree size. */
  for (i = 0, bN = 0.0; i < len; i++)
    bN += log2((double) state[i].nb);

  /* compute the quotient. */
  bn = bN - log2((double) n);

  /* loop to compute the division result. */
  for (i = len - 1, bs = 0.0; i < len; i--) {
    /* sum the current node size into the "stride". */
    bs += log2((double) state[i].nb);

    /* check if the "stride" is sufficiently large. */
    if (bs == bn) {
      /* equal: amounts to one step of the parent node index. */
      state[i - 1].end = 1;
      break;
    }
    else if (bs > bn) {
      /* larger: compute the closest integer step amount based
       * on the required amount of bits in the quotient.
       */
      bs -= log2((double) state[i].nb);
      state[i].end = 1 << (unsigned int) floor(bn - bs);
      break;
    }
  }
}

/* state_add(): add the indices of two states, storing the result into
 * the index of the destination (first) state.
 *
 * arguments:
 *  @dest: destination state in the sum.
 *  @src1: source state in the sum.
 *  @len: number of elements in each state.
 */
static void state_add (enum_thread_node_t *dest,
                       enum_thread_node_t *src,
                       unsigned int len) {
  /* initialize the output values. */
  for (unsigned int i = 0; i < len; i++)
    dest[i].end = 0;

  /* loop over each index of the result. */
  for (unsigned int i = len - 1; i < len; i--) {
    /* compute the current term of the sum. */
    dest[i].end += dest[i].idx + src[i].end;

    /* perform any required carries. */
    while (i && dest[i].nb && dest[i].end >= dest[i].nb) {
      dest[i].end -= dest[i].nb;
      dest[i - 1].end++;
    }
  }
}

/* state_valid(): check whether a state is "valid", meaning that its index
 * has not yet reached its end.
 *
 * arguments:
 *  @state: state to check for validity.
 *  @len: number of nodes in the state.
 *
 * returns:
 *  integer indicating state validity (1) or non-validity (0).
 */
static inline int state_valid (enum_thread_node_t *state,
                               unsigned int len) {
  /* if any one index is less than the end value, return true. */
  for (unsigned int i = 0; i < len; i++) {
    if (state[i].idx < state[i].end)
      return 1;
  }

  /* return false. */
  return 0;
}

/* state_increment(): increment the index of a state.
 *
 * arguments:
 *  @state: state to increment.
 *  @len: number of nodes in the state.
 *  @lev: level at which to begin incrementation.
 *
 * returns:
 *  index of the most upstream node that was modified by the increment.
 */
static inline unsigned int state_increment (enum_thread_node_t *state,
                                            const unsigned int len,
                                            const unsigned int lev) {
  /* declare required variables:
   *  @imod: index of the highest modified parent node.
   */
  unsigned int imod = lev;

  /* loop over the skipped state indices (when lev < len - 1). */
  for (unsigned int i = lev + 1; i < len; i++)
    state[i].idx = 0;

  /* loop over the state indices. */
  for (unsigned int i = lev; i < len; i--) {
    /* increment the current index. */
    state[i].idx++;<commit_msg>Fixed an issue with enumerator state validity<commit_after>
/* include the enumerator headers. */
#include "enum.h"
#include "enum-thread.h"
#include "enum-write.h"

/* state_div(): divide the size of a thread state into uniform pieces,
 * storing the result into the index of the thread state.
 *
 * arguments:
 *  @state: thread state to operate on.
 *  @len: number of elements in the state.
 *  @n: value to divide the state size by.
 */
static void state_div (enum_thread_node_t *state,
                       unsigned int len,
                       unsigned int n) {
  /* @bN: base-2 log of the tree size/leaf count.
   * @bn: base-2 log of the division value.
   * @bs: base-2 log of the quotient.
   * @i: general-purpose loop counter.
   */
  double bN, bn, bs;
  unsigned int i;

  /* compute the tree size. */
  for (i = 0, bN = 0.0; i < len; i++)
    bN += log2((double) state[i].nb);

  /* compute the quotient. */
  bn = bN - log2((double) n);

  /* loop to compute the division result. */
  for (i = len - 1, bs = 0.0; i < len; i--) {
    /* sum the current node size into the "stride". */
    bs += log2((double) state[i].nb);

    /* check if the "stride" is sufficiently large. */
    if (bs == bn) {
      /* equal: amounts to one step of the parent node index. */
      state[i - 1].end = 1;
      break;
    }
    else if (bs > bn) {
      /* larger: compute the closest integer step amount based
       * on the required amount of bits in the quotient.
       */
      bs -= log2((double) state[i].nb);
      state[i].end = 1 << (unsigned int) floor(bn - bs);
      break;
    }
  }
}

/* state_add(): add the indices of two states, storing the result into
 * the index of the destination (first) state.
 *
 * arguments:
 *  @dest: destination state in the sum.
 *  @src1: source state in the sum.
 *  @len: number of elements in each state.
 */
static void state_add (enum_thread_node_t *dest,
                       enum_thread_node_t *src,
                       unsigned int len) {
  /* initialize the output values. */
  for (unsigned int i = 0; i < len; i++)
    dest[i].end = 0;

  /* loop over each index of the result. */
  for (unsigned int i = len - 1; i < len; i--) {
    /* compute the current term of the sum. */
    dest[i].end += dest[i].idx + src[i].end;

    /* perform any required carries. */
    while (i && dest[i].nb && dest[i].end >= dest[i].nb) {
      dest[i].end -= dest[i].nb;
      dest[i - 1].end++;
    }
  }
}

/* state_valid(): check whether a state is "valid", meaning that its index
 * has not yet reached its end.
 *
 * arguments:
 *  @state: state to check for validity.
 *  @len: number of nodes in the state.
 *
 * returns:
 *  integer indicating state validity (1) or non-validity (0).
 */
static inline int state_valid (enum_thread_node_t *state,
                               unsigned int len) {
  /* if any one index has passed the end value, return false. */
  for (unsigned int i = 0; i < len; i++) {
    if (state[i].idx > state[i].end)
      return 0;
  }

  /* return true. */
  return 1;
}

/* state_increment(): increment the index of a state.
 *
 * arguments:
 *  @state: state to increment.
 *  @len: number of nodes in the state.
 *  @lev: level at which to begin incrementation.
 *
 * returns:
 *  index of the most upstream node that was modified by the increment.
 */
static inline unsigned int state_increment (enum_thread_node_t *state,
                                            const unsigned int len,
                                            const unsigned int lev) {
  /* declare required variables:
   *  @imod: index of the highest modified parent node.
   */
  unsigned int imod = lev;

  /* loop over the skipped state indices (when lev < len - 1). */
  for (unsigned int i = lev + 1; i < len; i++)
    state[i].idx = 0;

  /* loop over the state indices. */
  for (unsigned int i = lev; i < len; i--) {
    /* increment the current index. */
    state[i].idx++;
{'fraction_non_alphanumeric': 0.12890129408779497, 'fraction_numerical': 0.007358538442019792, 'mean_word_length': 2.1532, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6049183', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2428, 'n_words': 978}