<commit_before>import { stride, offsets } from './markerArray';
import {
    BBox,
    PriorityGroup,
    Atlas,
    Marker,
    WorkerMessage,
    Job,
} from './types';

const Worker = require('worker-loader?inline&fallback=false!ts-loader!./worker');

export class General {
    private worker = new Worker();
    private queue: Job[] = [];
    private currentJob: Job | undefined = undefined;
    private markerArray = new Float32Array(1000 * stride);

    constructor() {
        this.worker.onmessage = (event) => {
            if (this.currentJob === undefined) {
                return;
            }

            const { markers, resolve } = this.currentJob;
            this.recordResult(markers, event.data);
            this.markerArray = event.data;
            this.currentJob = undefined;

            this.dequeue();
            resolve();
        };
    }

    public generalize(
        bounds: BBox,
        pixelRatio: number,
        priorityGroups: PriorityGroup[],
        atlas: Atlas,
        markers: Marker[],
    ): Promise<{}> {
        const message: WorkerMessage = {
            bounds,
            pixelRatio,
            priorityGroups,
            markerCount: markers.length,
            sprites: atlas.sprites,
            markers: this.pack(markers),
        };

        return new Promise((resolve) => {
            this.queue.push({ message, markers, resolve });
            this.dequeue();
        });
    }

    public clear() {
        this.queue = [];
    }

    private pack(markers: Marker[]): Float32Array {
        if (markers.length > this.markerArray.length) {
            this.markerArray = new Float32Array(markers.length * stride);<commit_msg>Fix array comparison bug (#10)<commit_after>import { stride, offsets } from './markerArray';
import {
    BBox,
    PriorityGroup,
    Atlas,
    Marker,
    WorkerMessage,
    Job,
} from './types';

const Worker = require('worker-loader?inline&fallback=false!ts-loader!./worker');

export class General {
    private worker = new Worker();
    private queue: Job[] = [];
    private currentJob: Job | undefined = undefined;
    private markerArray = new Float32Array(1000 * stride);

    constructor() {
        this.worker.onmessage = (event) => {
            if (this.currentJob === undefined) {
                return;
            }

            const { markers, resolve } = this.currentJob;
            this.recordResult(markers, event.data);
            this.markerArray = event.data;
            this.currentJob = undefined;

            this.dequeue();
            resolve();
        };
    }

    public generalize(
        bounds: BBox,
        pixelRatio: number,
        priorityGroups: PriorityGroup[],
        atlas: Atlas,
        markers: Marker[],
    ): Promise<{}> {
        const message: WorkerMessage = {
            bounds,
            pixelRatio,
            priorityGroups,
            markerCount: markers.length,
            sprites: atlas.sprites,
            markers: this.pack(markers),
        };

        return new Promise((resolve) => {
            this.queue.push({ message, markers, resolve });
            this.dequeue();
        });
    }

    public clear() {
        this.queue = [];
    }

    private pack(markers: Marker[]): Float32Array {
        if (markers.length * stride > this.markerArray.length) {
            this.markerArray = new Float32Array(markers.length * stride);
{'fraction_non_alphanumeric': 0.11995318899941486, 'fraction_numerical': 0.006436512580456407, 'mean_word_length': 1.9147485080988917, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3657259', 'n_tokens_mistral': 961, 'n_tokens_neox': 911, 'n_words': 210}