<commit_before>import { MuWriteStream, MuReadStream } from '../stream';

import { MuSchema } from './schema';
import { isMuPrimitiveType } from './type';

function defaultCompare<T> (a:T, b:T) {
    if (a < b) {
        return -1;
    } else if (a > b) {
        return 1;
    } else {
        return 0;
    }
}

enum SortedOp {
    NONE = -1,
    SKIP = 0,
    PATCH = 1,
    INSERT = 2,
    INSERT_IDENTITY = 3,
    COPY = 4,
}

export class MuSortedArray<ValueSchema extends MuSchema<any>>
        implements MuSchema<ValueSchema['identity'][]> {
    public readonly muType = 'sorted-array';

    public readonly identity:ValueSchema['identity'][];
    public readonly muData:ValueSchema;
    public readonly json:object;
    public readonly compare:(a:ValueSchema['identity'], b:ValueSchema['identity']) => number;
    public readonly capacity:number;

    public pool:ValueSchema['identity'][][] = [];

    constructor (
        schema:ValueSchema,
        capacity:number,
        compare?:(a:ValueSchema['identity'], b:ValueSchema['identity']) => number,
        identity?:ValueSchema['identity'][],
    ) {
        this.muData = schema;
        this.capacity = capacity;
        this.compare = compare || defaultCompare;
        if (identity) {
            const a = identity.slice().sort(this.compare);
            for (let i = 0; i < a.length; ++i) {
                a[i] = schema.clone(a[i]);
            }
            this.identity = a;
        } else {
            this.identity = [];
        }
        this.json = {<commit_msg>improve sortedArray.identity initialization<commit_after>import { MuWriteStream, MuReadStream } from '../stream';

import { MuSchema } from './schema';
import { isMuPrimitiveType } from './type';

function defaultCompare<T> (a:T, b:T) {
    if (a < b) {
        return -1;
    } else if (a > b) {
        return 1;
    } else {
        return 0;
    }
}

enum SortedOp {
    NONE = -1,
    SKIP = 0,
    PATCH = 1,
    INSERT = 2,
    INSERT_IDENTITY = 3,
    COPY = 4,
}

export class MuSortedArray<ValueSchema extends MuSchema<any>>
        implements MuSchema<ValueSchema['identity'][]> {
    public readonly muType = 'sorted-array';

    public readonly identity:ValueSchema['identity'][];
    public readonly muData:ValueSchema;
    public readonly json:object;
    public readonly compare:(a:ValueSchema['identity'], b:ValueSchema['identity']) => number;
    public readonly capacity:number;

    public pool:ValueSchema['identity'][][] = [];

    constructor (
        schema:ValueSchema,
        capacity:number,
        compare?:(a:ValueSchema['identity'], b:ValueSchema['identity']) => number,
        identity?:ValueSchema['identity'][],
    ) {
        this.muData = schema;
        this.capacity = capacity;
        this.compare = compare || defaultCompare;
        this.identity = [];
        if (identity) {
            for (let i = 0; i < identity.length; ++i) {
                this.identity[i] = schema.clone(identity[i]);
            }
            this.identity.sort(this.compare);
        }
        this.json = {
{'fraction_non_alphanumeric': 0.14057923852912463, 'fraction_numerical': 0.006508298080052067, 'mean_word_length': 2.4578177727784025, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '634337', 'n_tokens_mistral': 928, 'n_tokens_neox': 897, 'n_words': 213}