Skip to content

Commit

Permalink
fix: remove nodejs, improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar-P-yan committed Jan 22, 2024
1 parent b87c8d4 commit e42bf9d
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 1,265 deletions.
10 changes: 2 additions & 8 deletions src/main/bun/Edgar-P-yan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ for (let i = 0; i < chunkOffsets.length; i++) {
});
}

/**
* @param {CalcResultsCont} compiledResults
*/
function printCompiledResults(compiledResults: CalcResultsCont) {
function printCompiledResults(compiledResults: CalcResultsCont): void {
const sortedStations = Array.from(compiledResults.keys()).sort();

process.stdout.write('{');
Expand All @@ -148,11 +145,8 @@ function printCompiledResults(compiledResults: CalcResultsCont) {
* round(1.2345) // "1.2"
* round(1.55) // "1.6"
* round(1) // "1.0"
*
* @param {number} num
* @returns {string}
*/
function round(num: number) {
function round(num: number): string {
const fixed = Math.round(10 * num) / 10;

return fixed.toFixed(1);
Expand Down
29 changes: 9 additions & 20 deletions src/main/bun/Edgar-P-yan/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import * as util from 'node:util';
import * as fs from 'node:fs';
import * as workerThreads from 'node:worker_threads';

declare var self: Worker;
const CHAR_SEMICOLON = ';'.charCodeAt(0);
const CHAR_NEWLINE = '\n'.charCodeAt(0);
const TOKEN_STATION_NAME = 0;
const TOKEN_TEMPERATURE = 1;

/** @type {(...args: any[]) => void} */
const debug = process.env.DEBUG ? console.error : () => {};

declare var self: Worker;
const debug: (...args: any[]) => void = process.env.DEBUG
? console.error
: () => {};

type CalcResultsCont = Map<
string,
Expand All @@ -23,7 +22,7 @@ self.addEventListener('message', (event) => {
worker(event.data.fileName, event.data.start, event.data.end);
});

function worker(fileName: string, start: number, end: number) {
function worker(fileName: string, start: number, end: number): void {
if (start > end - 1) {
postMessage(new Map());
} else {
Expand All @@ -36,10 +35,7 @@ function worker(fileName: string, start: number, end: number) {
}
}

/**
* @param {import('node:fs').ReadStream} readStream
*/
function parseStream(readStream: fs.ReadStream) {
function parseStream(readStream: fs.ReadStream): void {
let readingToken = TOKEN_STATION_NAME;

let stationName = Buffer.allocUnsafe(100);
Expand All @@ -50,16 +46,9 @@ function parseStream(readStream: fs.ReadStream) {

let rowCount = 0;

/**
* @type {CalcResultsCont}
*/
const map = new Map();
const map: CalcResultsCont = new Map();

/**
* @param {Buffer} chunk
* @returns {void}
*/
function parseChunk(chunk: Buffer) {
function parseChunk(chunk: Buffer): void {
for (let i = 0; i < chunk.length; i++) {
if (chunk[i] === CHAR_SEMICOLON) {
readingToken = TOKEN_TEMPERATURE;
Expand Down Expand Up @@ -162,6 +151,6 @@ function parseFloatBufferIntoInt(b: Buffer, length: number): number {
*
* @returns {number}
*/
function parseOneDigit(char: number) {
function parseOneDigit(char: number): number {
return char - 0x30;
}
175 changes: 0 additions & 175 deletions src/main/nodejs/Edgar-P-yan/.gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/nodejs/Edgar-P-yan/README.md

This file was deleted.

Loading

0 comments on commit e42bf9d

Please sign in to comment.