<commit_before>/*
 * Copyright (C) 2021 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

package grakn.core.graph.util;

import grakn.core.common.collection.Bytes;
import grakn.core.common.exception.GraknException;
import grakn.core.common.parameters.Label;
import graql.lang.common.GraqlArg;

import javax.annotation.Nullable;
import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static grakn.common.collection.Collections.map;
import static grakn.common.collection.Collections.pair;
import static grakn.common.collection.Collections.set;
import static grakn.common.util.Objects.className;
import static grakn.core.common.exception.ErrorMessage.Internal.ILLEGAL_CAST;
import static grakn.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE;
import static java.nio.charset.StandardCharsets.UTF_8;

public class Encoding {

    public static final String ROCKS_DATA = "data";
    public static final String ROCKS_SCHEMA = "schema";

    public enum Key {
        PERSISTED(0, true),
        BUFFERED(-1, false);
        private final int initialValue;

        private final boolean isIncrement;

        Key(int initialValue, boolean isIncrement) {
            this.initialValue = initialValue;
            this.isIncrement = isIncrement;
        }

        public int initialValue() {
            return initialValue;
        }

        public boolean isIncrement() {
            return isIncrement;
        }
    }

    public enum Status {
        BUFFERED(0),
        COMMITTED(1),
        PERSISTED(2),
        IMMUTABLE(3);

        private int status;

        Status(int status) {
            this.status = status;
        }

        public int status() {
            return status;
        }
    }

    public interface Direction {

        enum Adjacency implements Direction {
            OUT(true),
            IN(false);

            private final boolean isOut;

            Adjacency(boolean isOut) {
                this.isOut = isOut;
            }

            public boolean isOut() {
                return isOut;
            }

            public boolean isIn() {
                return !isOut;
            }
        }

        enum Edge implements Direction {
            FORWARD(true),
            BACKWARD(false);

            private final boolean isForward;

            Edge(boolean isForward) {
                this.isForward = isForward;
            }

            public boolean isForward() {
                return isForward;
            }

            public boolean isBackward() {
                return !isForward;
            }
        }
    }

    public enum PrefixType {
        INDEX(0),
        STATISTICS(1),
        TYPE(2),
        THING(3),
        RULE(4);

        private final int key;

        PrefixType(int key) {
            this.key = key;
        }

    }

    /**
     * The values in this class will be used as 'prefixes' within an IID in the
     * of every object database, and must not overlap with each other.
     *
     * The size of a prefix is 1 byte; i.e. min-value = 0 and max-value = 255.
     */
    public enum Prefix {
        // leave large open range for future indices
        INDEX_TYPE(0, PrefixType.INDEX),
        INDEX_RULE(10, PrefixType.INDEX),
        INDEX_ATTRIBUTE(20, PrefixType.INDEX),
        STATISTICS_THINGS(50, PrefixType.STATISTICS),
        STATISTICS_COUNT_JOB(51, PrefixType.STATISTICS),
        STATISTICS_COUNTED(52, PrefixType.STATISTICS),
        STATISTICS_SNAPSHOT(53, PrefixType.STATISTICS),
        VERTEX_THING_TYPE(100, PrefixType.TYPE),
        VERTEX_ENTITY_TYPE(110, PrefixType.TYPE),
        VERTEX_ATTRIBUTE_TYPE(120, PrefixType.TYPE),
        VERTEX_RELATION_TYPE(130, PrefixType.TYPE),
        VERTEX_ROLE_TYPE(140, PrefixType.TYPE),
        VERTEX_ENTITY(150, PrefixType.THING),
        VERTEX_ATTRIBUTE(160, PrefixType.THING),
        VERTEX_RELATION(170, PrefixType.THING),
        VERTEX_ROLE(180, PrefixType.THING),
        STRUCTURE_RULE(190, PrefixType.RULE);

        private final byte key;
        private final PrefixType type;

        Prefix(int key, PrefixType type) {
            this.key = (byte) key;
            this.type = type;
        }<commit_msg>Fixed byte masking of Encoding.Prefix<commit_after>/*
 * Copyright (C) 2021 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

package grakn.core.graph.util;

import grakn.core.common.collection.Bytes;
import grakn.core.common.exception.GraknException;
import grakn.core.common.parameters.Label;
import graql.lang.common.GraqlArg;

import javax.annotation.Nullable;
import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static grakn.common.collection.Collections.map;
import static grakn.common.collection.Collections.pair;
import static grakn.common.collection.Collections.set;
import static grakn.common.util.Objects.className;
import static grakn.core.common.exception.ErrorMessage.Internal.ILLEGAL_CAST;
import static grakn.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE;
import static java.nio.charset.StandardCharsets.UTF_8;

public class Encoding {

    public static final String ROCKS_DATA = "data";
    public static final String ROCKS_SCHEMA = "schema";

    public enum Key {
        PERSISTED(0, true),
        BUFFERED(-1, false);
        private final int initialValue;

        private final boolean isIncrement;

        Key(int initialValue, boolean isIncrement) {
            this.initialValue = initialValue;
            this.isIncrement = isIncrement;
        }

        public int initialValue() {
            return initialValue;
        }

        public boolean isIncrement() {
            return isIncrement;
        }
    }

    public enum Status {
        BUFFERED(0),
        COMMITTED(1),
        PERSISTED(2),
        IMMUTABLE(3);

        private int status;

        Status(int status) {
            this.status = status;
        }

        public int status() {
            return status;
        }
    }

    public interface Direction {

        enum Adjacency implements Direction {
            OUT(true),
            IN(false);

            private final boolean isOut;

            Adjacency(boolean isOut) {
                this.isOut = isOut;
            }

            public boolean isOut() {
                return isOut;
            }

            public boolean isIn() {
                return !isOut;
            }
        }

        enum Edge implements Direction {
            FORWARD(true),
            BACKWARD(false);

            private final boolean isForward;

            Edge(boolean isForward) {
                this.isForward = isForward;
            }

            public boolean isForward() {
                return isForward;
            }

            public boolean isBackward() {
                return !isForward;
            }
        }
    }

    public enum PrefixType {
        INDEX(0),
        STATISTICS(1),
        TYPE(2),
        THING(3),
        RULE(4);

        private final int key;

        PrefixType(int key) {
            this.key = key;
        }

    }

    /**
     * The values in this class will be used as 'prefixes' within an IID in the
     * of every object database, and must not overlap with each other.
     *
     * The size of a prefix is 1 byte; i.e. min-value = 0 and max-value = 255.
     */
    public enum Prefix {
        // leave large open range for future indices
        INDEX_TYPE(0, PrefixType.INDEX),
        INDEX_RULE(10, PrefixType.INDEX),
        INDEX_ATTRIBUTE(20, PrefixType.INDEX),
        STATISTICS_THINGS(50, PrefixType.STATISTICS),
        STATISTICS_COUNT_JOB(51, PrefixType.STATISTICS),
        STATISTICS_COUNTED(52, PrefixType.STATISTICS),
        STATISTICS_SNAPSHOT(53, PrefixType.STATISTICS),
        VERTEX_THING_TYPE(100, PrefixType.TYPE),
        VERTEX_ENTITY_TYPE(110, PrefixType.TYPE),
        VERTEX_ATTRIBUTE_TYPE(120, PrefixType.TYPE),
        VERTEX_RELATION_TYPE(130, PrefixType.TYPE),
        VERTEX_ROLE_TYPE(140, PrefixType.TYPE),
        VERTEX_ENTITY(150, PrefixType.THING),
        VERTEX_ATTRIBUTE(160, PrefixType.THING),
        VERTEX_RELATION(170, PrefixType.THING),
        VERTEX_ROLE(180, PrefixType.THING),
        STRUCTURE_RULE(190, PrefixType.RULE);

        private final byte key;
        private final PrefixType type;

        Prefix(int key, PrefixType type) {
            this.key = (byte) (key & 0xff);
            this.type = type;
        }
{'fraction_non_alphanumeric': 0.08265295837113194, 'fraction_numerical': 0.01320431408124181, 'mean_word_length': 2.204780361757106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4116836', 'n_tokens_mistral': 2998, 'n_tokens_neox': 2782, 'n_words': 779}