<commit_before>import { Node, NodeData } from "./node";

export const enum FastNodeType {
    Static = 0,
    Param = 1,
}

export class FastNode<T> {
    type: FastNodeType;
    match: boolean;
    catchAll: boolean;
    path: string;
    staticIndices: string[] | null;
    staticChildren: FastNode<T>[] | null;
    paramChild: FastNode<T> | null;
    data: NodeData<T> | null;

    constructor(
        type: FastNodeType,
        match: boolean,
        catchAll: boolean,
        path: string,
        staticIndices: string[] | null,
        staticChildren: FastNode<T>[] | null,
        paramChild: FastNode<T> | null,
        data: NodeData<T> | null,
    ) {
        this.type = type;
        this.match = match;
        this.catchAll = catchAll;
        this.path = path;
        this.staticIndices = staticIndices;
        this.staticChildren = staticChildren;
        this.paramChild = paramChild;
        this.data = data;
    }
}

export function toFast<T>(node: Node<T>): FastNode<T> {
    let type = 0;
    switch (node.type) {
        case "s":
            type = FastNodeType.Static;
            break;
        case "?":
            type = FastNodeType.Param;
            break;
        default:
            throw new Error(`Invalid node type "${node.type}".`);
    }

    const staticChildren = node.getStaticChildren();
    const paramChild = node.getParamChild();

    const newStaticChildren = staticChildren ? staticChildren.map((c) => toFast(c)) : null;
    const newStaticIndices = staticChildren ? staticChildren.map((c) => c.path[0]) : null;
    const newParamChild = paramChild ? toFast(paramChild) : null;

    return new FastNode<T>(
        type,
        node.match,
        node.catchAll,
        node.path,
        newStaticIndices,
        newStaticChildren,
        newParamChild,
        node.data ? node.data : null,
    );
}<commit_msg>Fast nodes should use the same NodeType as original nodes<commit_after>import { Node, NodeData, NodeType } from "./node";

export class FastNode<T> {
    type: NodeType;
    match: boolean;
    catchAll: boolean;
    path: string;
    staticIndices: string[] | null;
    staticChildren: FastNode<T>[] | null;
    paramChild: FastNode<T> | null;
    data: NodeData<T> | null;

    constructor(
        type: NodeType,
        match: boolean,
        catchAll: boolean,
        path: string,
        staticIndices: string[] | null,
        staticChildren: FastNode<T>[] | null,
        paramChild: FastNode<T> | null,
        data: NodeData<T> | null,
    ) {
        this.type = type;
        this.match = match;
        this.catchAll = catchAll;
        this.path = path;
        this.staticIndices = staticIndices;
        this.staticChildren = staticChildren;
        this.paramChild = paramChild;
        this.data = data;
    }
}

export function toFast<T>(node: Node<T>): FastNode<T> {
    const staticChildren = node.getStaticChildren();
    const paramChild = node.getParamChild();

    const newStaticChildren = staticChildren ? staticChildren.map((c) => toFast(c)) : null;
    const newStaticIndices = staticChildren ? staticChildren.map((c) => c.path[0]) : null;
    const newParamChild = paramChild ? toFast(paramChild) : null;

    return new FastNode<T>(
        node.type,
        node.match,
        node.catchAll,
        node.path,
        newStaticIndices,
        newStaticChildren,
        newParamChild,
        node.data ? node.data : null,
    );
}
{'fraction_non_alphanumeric': 0.11585365853658537, 'fraction_numerical': 0.0014518002322880372, 'mean_word_length': 2.3381782945736433, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 29, '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': '7173587', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1029, 'n_words': 251}