<commit_before>// Copyright 2010-2014 RethinkDB, all rights reserved.
#ifndef RDB_PROTOCOL_BTREE_HPP_
#define RDB_PROTOCOL_BTREE_HPP_

#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "backfill_progress.hpp"
#include "concurrency/auto_drainer.hpp"
#include "rdb_protocol/datum.hpp"
#include "rdb_protocol/changes.hpp"
#include "rdb_protocol/protocol.hpp"
#include "rdb_protocol/store.hpp"

class btree_slice_t;
class deletion_context_t;
class key_tester_t;
class parallel_traversal_progress_t;
template <class> class promise_t;
struct rdb_value_t;
struct sindex_disk_info_t;

class parallel_traversal_progress_t;

bool btree_value_fits(max_block_size_t bs, int data_length, const rdb_value_t *value);

class rdb_value_sizer_t : public value_sizer_t {
public:
    explicit rdb_value_sizer_t(max_block_size_t bs);

    static const rdb_value_t *as_rdb(const void *p);

    int size(const void *value) const;

    bool fits(const void *value, int length_available) const;

    int max_possible_size() const;

    static block_magic_t leaf_magic();

    block_magic_t btree_leaf_magic() const;

    max_block_size_t block_size() const;

private:
    // The block size.  It's convenient for leaf node code and for
    // some subclasses, too.
    max_block_size_t block_size_;

    DISABLE_COPYING(rdb_value_sizer_t);
};

struct rdb_modification_info_t;
struct rdb_modification_report_t;
class rdb_modification_report_cb_t;

void rdb_get(
    const store_key_t &key,
    btree_slice_t *slice,
    superblock_t *superblock,
    point_read_response_t *response,
    profile::trace_t *trace);

struct btree_info_t {
    btree_info_t(btree_slice_t *_slice,
                 repli_timestamp_t _timestamp,
                 const wire_string_t &_primary_key)
        : slice(_slice), timestamp(_timestamp),
          primary_key(_primary_key) {
        guarantee(slice != NULL);
        guarantee(primary_key != NULL);
    }
    btree_slice_t *const slice;
    const repli_timestamp_t timestamp;
    const wire_string_t primary_key;
};

struct btree_loc_info_t {
    btree_loc_info_t(const btree_info_t *_btree,
                     superblock_t *_superblock,
                     const store_key_t *_key)
        : btree(_btree), superblock(_superblock), key(_key) {
        guarantee(btree != NULL);
        guarantee(superblock != NULL);
        guarantee(key != NULL);
    }
    const btree_info_t *const btree;
    superblock_t *const superblock;<commit_msg>Fixes a memory corruption caused by an implicit cast from NULL to char *<commit_after>// Copyright 2010-2014 RethinkDB, all rights reserved.
#ifndef RDB_PROTOCOL_BTREE_HPP_
#define RDB_PROTOCOL_BTREE_HPP_

#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "backfill_progress.hpp"
#include "concurrency/auto_drainer.hpp"
#include "rdb_protocol/datum.hpp"
#include "rdb_protocol/changes.hpp"
#include "rdb_protocol/protocol.hpp"
#include "rdb_protocol/store.hpp"

class btree_slice_t;
class deletion_context_t;
class key_tester_t;
class parallel_traversal_progress_t;
template <class> class promise_t;
struct rdb_value_t;
struct sindex_disk_info_t;

class parallel_traversal_progress_t;

bool btree_value_fits(max_block_size_t bs, int data_length, const rdb_value_t *value);

class rdb_value_sizer_t : public value_sizer_t {
public:
    explicit rdb_value_sizer_t(max_block_size_t bs);

    static const rdb_value_t *as_rdb(const void *p);

    int size(const void *value) const;

    bool fits(const void *value, int length_available) const;

    int max_possible_size() const;

    static block_magic_t leaf_magic();

    block_magic_t btree_leaf_magic() const;

    max_block_size_t block_size() const;

private:
    // The block size.  It's convenient for leaf node code and for
    // some subclasses, too.
    max_block_size_t block_size_;

    DISABLE_COPYING(rdb_value_sizer_t);
};

struct rdb_modification_info_t;
struct rdb_modification_report_t;
class rdb_modification_report_cb_t;

void rdb_get(
    const store_key_t &key,
    btree_slice_t *slice,
    superblock_t *superblock,
    point_read_response_t *response,
    profile::trace_t *trace);

struct btree_info_t {
    btree_info_t(btree_slice_t *_slice,
                 repli_timestamp_t _timestamp,
                 const wire_string_t &_primary_key)
        : slice(_slice), timestamp(_timestamp),
          primary_key(_primary_key) {
        guarantee(slice != NULL);
    }
    btree_slice_t *const slice;
    const repli_timestamp_t timestamp;
    const wire_string_t primary_key;
};

struct btree_loc_info_t {
    btree_loc_info_t(const btree_info_t *_btree,
                     superblock_t *_superblock,
                     const store_key_t *_key)
        : btree(_btree), superblock(_superblock), key(_key) {
        guarantee(btree != NULL);
        guarantee(superblock != NULL);
        guarantee(key != NULL);
    }
    const btree_info_t *const btree;
    superblock_t *const superblock;
{'fraction_non_alphanumeric': 0.08138839018551765, 'fraction_numerical': 0.003191701575902653, 'mean_word_length': 4.100712105798576, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4410141', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1733, 'n_words': 380}