<commit_before>/* NOTE: In this document, for a type to "act like a data type" means that it
is default-constructible, copy-constructible, copy-assignable, and destructible.
If it allocates heap memory, it must manage it on its own. */

namespace clustering {

/* `namespace_interface_t` is the main entry point that protocol parsers use to
perform reads and writes on a namespace. `protocol_t` is a config struct that
holds all the types specific to that protocol. */
template<class protocol_t>
class namespace_interface_t {

    /* This document doesn't deal with the details of how to find namespaces.
    Tim's plan is that each protocol will keep its own directory of namespaces
    organized in a protocol-specific way. Riak could have a map from strings
    to namespaces, along with a way to synchronize the creation of namespaces.
    Memcached could have a set of (namespace, port) pairs. Redis could...
    do whatever makes sense for Redis. */
    namespace_interface_t(
        mailbox_cluster_t *cluster,
        metadata_view_t<namespace_metadata_t<protocol_t> > *namespace_metadata
        );
    ~namespace_interface_t();

    /* Performs the given read query on the namespace. [May block] */
    protocol_t::read_response_t read(protocol_t::read_t query);

    /* Performs the given write query on the namespace. [May block] */
    protocol_t::write_response_t write(protocol_t::write_t query);

    /* Reads and writes configuration information for the namespace, such as the
    replication factor. */
    ... configure(...);

private:
    ...
};

}   /* namespace clustering */

/* `?` indicates that something is protocol-specific. Each protocol will define
a `?_protocol_t` for itself and all the members therein. That `?_protocol_t`
will be passed as a template parameter to the clustering code so it knows how
to work with that protocol. */

namespace ? {

struct ?_protocol_t {

    /* `region_t` is like a set (in the mathematical sense) of keys, although
    not all sets can be expressed as `region_t`s. Protocols will probably be
    implemented as a range of keys, although it could be something weirder, like
    the set of all keys whose hashes fall into a certain range.

    In this document, we talk about regions using set notation. 
    `union(regions)` refers to the union of multiple regions. And so on. */

    struct region_t {
        /* Returns true if this `region_t` is a superset of `x`. */
        bool contains(region_t x);

        /* Returns true if this `region_t` overlaps `x`. */
        bool overlaps(region_t x);

        /* Returns the `region_t` containing all keys both in this `region_t`
        and `x`. */
        region_t intersection(region_t x);

        /* Other requirements: `region_t` must be serializable. The "==" and
        "!=" operators must work on `region_t`. `region_t` must act like a data
        type. */

    private:
        ?
    };

    /* `read_t`, `read_response_t`, `write_t`, `write_response_t`, and
    `backfill_chunk_t` must all be serializable. */

    struct read_t {

        /* Indicates which keys the read depends on. */
        region_t get_region();

        /* Breaks the read into several sub-reads for individual regions.
        [Precondition] union(regions) == read.get_region()
        [Postcondition] read.shard(regions).size() == regions.size()
        [Postcondition] read.shard(regions)[i].get_region() IsSubsetOf regions[i]
        */
        std::vector<read_t> shard(std::vector<region_t> regions);

        /* Breaks the read into several sub-reads that will be run in parallel
        on different machines. `read_t` may choose how many sub-reads to create,
        but creating more than `optimal_factor` sub-reads won't help performance
        and may hurt it.
        [Postcondition] read.parallelize()[i].get_region() IsSubsetOf read.get_region()
        */
        std::vector<read_t> parallelize(int optimal_factor);

        /* Other requirements: `read_t` must be serializable. `read_t` must act
        like a data type. */
<commit_msg>Add another precondition to read_t::shard. Joe is being annoying to tim.<commit_after>/* NOTE: In this document, for a type to "act like a data type" means that it
is default-constructible, copy-constructible, copy-assignable, and destructible.
If it allocates heap memory, it must manage it on its own. */

namespace clustering {

/* `namespace_interface_t` is the main entry point that protocol parsers use to
perform reads and writes on a namespace. `protocol_t` is a config struct that
holds all the types specific to that protocol. */
template<class protocol_t>
class namespace_interface_t {

    /* This document doesn't deal with the details of how to find namespaces.
    Tim's plan is that each protocol will keep its own directory of namespaces
    organized in a protocol-specific way. Riak could have a map from strings
    to namespaces, along with a way to synchronize the creation of namespaces.
    Memcached could have a set of (namespace, port) pairs. Redis could...
    do whatever makes sense for Redis. */
    namespace_interface_t(
        mailbox_cluster_t *cluster,
        metadata_view_t<namespace_metadata_t<protocol_t> > *namespace_metadata
        );
    ~namespace_interface_t();

    /* Performs the given read query on the namespace. [May block] */
    protocol_t::read_response_t read(protocol_t::read_t query);

    /* Performs the given write query on the namespace. [May block] */
    protocol_t::write_response_t write(protocol_t::write_t query);

    /* Reads and writes configuration information for the namespace, such as the
    replication factor. */
    ... configure(...);

private:
    ...
};

}   /* namespace clustering */

/* `?` indicates that something is protocol-specific. Each protocol will define
a `?_protocol_t` for itself and all the members therein. That `?_protocol_t`
will be passed as a template parameter to the clustering code so it knows how
to work with that protocol. */

namespace ? {

struct ?_protocol_t {

    /* `region_t` is like a set (in the mathematical sense) of keys, although
    not all sets can be expressed as `region_t`s. Protocols will probably be
    implemented as a range of keys, although it could be something weirder, like
    the set of all keys whose hashes fall into a certain range.

    In this document, we talk about regions using set notation. 
    `union(regions)` refers to the union of multiple regions. And so on. */

    struct region_t {
        /* Returns true if this `region_t` is a superset of `x`. */
        bool contains(region_t x);

        /* Returns true if this `region_t` overlaps `x`. */
        bool overlaps(region_t x);

        /* Returns the `region_t` containing all keys both in this `region_t`
        and `x`. */
        region_t intersection(region_t x);

        /* Other requirements: `region_t` must be serializable. The "==" and
        "!=" operators must work on `region_t`. `region_t` must act like a data
        type. */

    private:
        ?
    };

    /* `read_t`, `read_response_t`, `write_t`, `write_response_t`, and
    `backfill_chunk_t` must all be serializable. */

    struct read_t {

        /* Indicates which keys the read depends on. */
        region_t get_region();

        /* Breaks the read into several sub-reads for individual regions.
        [Precondition] union(regions) == read.get_region()
        [Precondition] forall x,y in regions, x does not overlap y
        [Postcondition] read.shard(regions).size() == regions.size()
        [Postcondition] read.shard(regions)[i].get_region() IsSubsetOf regions[i]
        */
        std::vector<read_t> shard(std::vector<region_t> regions);

        /* Breaks the read into several sub-reads that will be run in parallel
        on different machines. `read_t` may choose how many sub-reads to create,
        but creating more than `optimal_factor` sub-reads won't help performance
        and may hurt it.
        [Postcondition] read.parallelize()[i].get_region() IsSubsetOf read.get_region()
        */
        std::vector<read_t> parallelize(int optimal_factor);

        /* Other requirements: `read_t` must be serializable. `read_t` must act
        like a data type. */

{'fraction_non_alphanumeric': 0.08705140640155189, 'fraction_numerical': 0.0, 'mean_word_length': 3.0535626535626537, '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': '5199360', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2246, 'n_words': 942}