<commit_before>#include "nanocube_traversals.h"
#include <stack>
#include <sstream>

using namespace std;

namespace {

struct BoundedIndex {
  BoundedIndex(int64_t l, int64_t r, int64_t i, int64_t d): left(l), right(r), index(i), depth(d) {}
  BoundedIndex(const BoundedIndex &other):
      left(other.left), right(other.right), index(other.index), depth(other.depth) {};
  
  int64_t left, right, index, depth;
};

};

void query_range 
(const NCDim &dim, int starting_node, int64_t lo, int64_t up, int depth,
 vector<QueryNode> &nodes, bool insert_partial_overlap)
{
  stack<BoundedIndex> node_indices;
  //node_indices.push(BoundedIndex(0, (int64_t)1 << dim.width, starting_node, 0));
  node_indices.push(BoundedIndex(0, (int64_t)1 << depth, starting_node, 0));
  while (node_indices.size()) {
    BoundedIndex t = node_indices.top();
    const NCDimNode &node = dim.at(t.index);
    node_indices.pop();
    if (t.left >= lo && t.right <= up) {
      nodes.push_back(QueryNode(t.index, t.depth, -1));
    } else if (up <= t.left || t.right <= lo) {
      continue;
    } else if (t.depth == depth) {
      if (insert_partial_overlap) {
        nodes.push_back(QueryNode(t.index, t.depth, -1));
      }
    } else {
      // avoid underflow for large values. Remember Java's lesson..
      int64_t mid = t.left + ((t.right - t.left) / 2);
      if (node.left != -1) {
        node_indices.push(BoundedIndex(t.left, mid, node.left, t.depth+1));
      }
      if (node.right != -1) {
        node_indices.push(BoundedIndex(mid, t.right, node.right, t.depth+1));
      }
    }
  }
}<commit_msg>use correct address for range results<commit_after>#include "nanocube_traversals.h"
#include <stack>
#include <sstream>

using namespace std;

namespace {

struct BoundedIndex {
  BoundedIndex(int64_t l, int64_t r, int64_t a, int i, int d): left(l), right(r), address(a), index(i), depth(d) {}
  BoundedIndex(const BoundedIndex &other):
      left(other.left), right(other.right), address(other.address), index(other.index), depth(other.depth) {};
  
  int64_t left, right;
  int64_t address;
  int index, depth;
};

};

void query_range 
(const NCDim &dim, int starting_node, int64_t lo, int64_t up, int depth,
 vector<QueryNode> &nodes, bool insert_partial_overlap)
{
  stack<BoundedIndex> node_indices;
  //node_indices.push(BoundedIndex(0, (int64_t)1 << dim.width, starting_node, 0));
  node_indices.push(BoundedIndex(0, (int64_t)1 << depth, 0, starting_node, 0));
  while (node_indices.size()) {
    BoundedIndex t = node_indices.top();
    const NCDimNode &node = dim.at(t.index);
    node_indices.pop();
    if (t.left >= lo && t.right <= up) {
      nodes.push_back(QueryNode(t.index, t.depth, t.address));
    } else if (up <= t.left || t.right <= lo) {
      continue;
    } else if (t.depth == depth) {
      if (insert_partial_overlap) {
        nodes.push_back(QueryNode(t.index, t.depth, t.address));
      }
    } else {
      // avoid underflow for large values. Remember Java's lesson..
      int64_t mid = t.left + ((t.right - t.left) / 2);
      if (node.left != -1) {
        node_indices.push(BoundedIndex(t.left, mid, t.address << 1, node.left, t.depth+1));
      }
      if (node.right != -1) {
        node_indices.push(BoundedIndex(mid, t.right, (t.address << 1)+1, node.right, t.depth+1));
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.15890657855211776, 'fraction_numerical': 0.02042655452087714, 'mean_word_length': 3.375821287779238, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, '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': '5358503', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1222, 'n_words': 273}