<commit_before>#pragma once

#include <inttypes.h>
#include <map>
#include <set>

#include "utils.h"

namespace mdb {

typedef int64_t version_t;

template <class Value>
struct versioned_value {
    version_t created_at, removed_at;

    // const value, not modifiable
    const Value val;

    versioned_value(version_t created, const Value& v): created_at(created), removed_at(-1), val(v) {}
    bool valid_at(version_t v) const {
        return created_at <= v && (removed_at == -1 || v < removed_at);
    }
    bool invalid_at_and_before(version_t v) const {
        return v < created_at;
    }
    bool invalid_at_and_after(version_t v) const {
        return removed_at >= 0 && removed_at <= v;
    }
    void remove(version_t v) {
        verify(removed_at == -1);
        removed_at = v;
        verify(created_at < removed_at);
    }
};

template <class Key, class Value, class Iterator, class Snapshot>
class snapshot_range: public Enumerator<std::pair<const Key*, const Value*>> {
    Snapshot snapshot_;
    Iterator begin_, end_, next_;
    bool cached_;
    std::pair<const Key*, const Value*> cached_next_;
    std::pair<const Key&, const Value&> cached_next_2;
    int count_;

    bool prefetch_next() {
        verify(cached_ == false);
        while (cached_ == false && next_ != end_) {
            if (next_->second.valid_at(snapshot_.version())) {
                cached_next_.first = &(next_->first);
                cached_next_.second = &(next_->second.val);
                cached_ = true;
            }
            ++next_;
        }
        return cached_;
    }

public:

    snapshot_range(const Snapshot& snapshot, Iterator it_begin, Iterator it_end)
        : snapshot_(snapshot), begin_(it_begin), end_(it_end), next_(it_begin),
          cached_(false), cached_next_2(it_begin->first, it_begin->second.val), count_(-1) {}
<commit_msg>minor cleanup<commit_after>#pragma once

#include <inttypes.h>
#include <map>
#include <set>

#include "utils.h"

namespace mdb {

typedef int64_t version_t;

template <class Value>
struct versioned_value {
    version_t created_at, removed_at;

    // const value, not modifiable
    const Value val;

    versioned_value(version_t created, const Value& v): created_at(created), removed_at(-1), val(v) {}
    bool valid_at(version_t v) const {
        return created_at <= v && (removed_at == -1 || v < removed_at);
    }
    bool invalid_at_and_before(version_t v) const {
        return v < created_at;
    }
    bool invalid_at_and_after(version_t v) const {
        return removed_at >= 0 && removed_at <= v;
    }
    void remove(version_t v) {
        verify(removed_at == -1);
        removed_at = v;
        verify(created_at < removed_at);
    }
};

template <class Key, class Value, class Iterator, class Snapshot>
class snapshot_range: public Enumerator<std::pair<const Key*, const Value*>> {
    Snapshot snapshot_;
    Iterator begin_, end_, next_;
    bool cached_;
    std::pair<const Key*, const Value*> cached_next_;
    int count_;

    bool prefetch_next() {
        verify(cached_ == false);
        while (cached_ == false && next_ != end_) {
            if (next_->second.valid_at(snapshot_.version())) {
                cached_next_.first = &(next_->first);
                cached_next_.second = &(next_->second.val);
                cached_ = true;
            }
            ++next_;
        }
        return cached_;
    }

public:

    snapshot_range(const Snapshot& snapshot, Iterator it_begin, Iterator it_end)
        : snapshot_(snapshot), begin_(it_begin), end_(it_end), next_(it_begin), cached_(false), count_(-1) {}

{'fraction_non_alphanumeric': 0.11964631113567284, 'fraction_numerical': 0.004421110804089527, 'mean_word_length': 2.8347457627118646, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '2591760', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1133, 'n_words': 286}