diff --git a/src/main/bun/Edgar-P-yan/index.ts b/src/main/bun/Edgar-P-yan/index.ts index ff05089..b38ba66 100644 --- a/src/main/bun/Edgar-P-yan/index.ts +++ b/src/main/bun/Edgar-P-yan/index.ts @@ -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('{'); @@ -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); diff --git a/src/main/bun/Edgar-P-yan/worker.ts b/src/main/bun/Edgar-P-yan/worker.ts index 1eee607..6ef35fe 100644 --- a/src/main/bun/Edgar-P-yan/worker.ts +++ b/src/main/bun/Edgar-P-yan/worker.ts @@ -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, @@ -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 { @@ -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); @@ -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; @@ -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; } diff --git a/src/main/nodejs/Edgar-P-yan/.gitignore b/src/main/nodejs/Edgar-P-yan/.gitignore deleted file mode 100644 index 468f82a..0000000 --- a/src/main/nodejs/Edgar-P-yan/.gitignore +++ /dev/null @@ -1,175 +0,0 @@ -# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore - -# Logs - -logs -_.log -npm-debug.log_ -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Caches - -.cache - -# Diagnostic reports (https://nodejs.org/api/report.html) - -report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json - -# Runtime data - -pids -_.pid -_.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover - -lib-cov - -# Coverage directory used by tools like istanbul - -coverage -*.lcov - -# nyc test coverage - -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) - -.grunt - -# Bower dependency directory (https://bower.io/) - -bower_components - -# node-waf configuration - -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) - -build/Release - -# Dependency directories - -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) - -web_modules/ - -# TypeScript cache - -*.tsbuildinfo - -# Optional npm cache directory - -.npm - -# Optional eslint cache - -.eslintcache - -# Optional stylelint cache - -.stylelintcache - -# Microbundle cache - -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history - -.node_repl_history - -# Output of 'npm pack' - -*.tgz - -# Yarn Integrity file - -.yarn-integrity - -# dotenv environment variable files - -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) - -.parcel-cache - -# Next.js build output - -.next -out - -# Nuxt.js build / generate output - -.nuxt -dist - -# Gatsby files - -# Comment in the public line in if your project uses Gatsby and not Next.js - -# https://nextjs.org/blog/next-9-1#public-directory-support - -# public - -# vuepress build output - -.vuepress/dist - -# vuepress v2.x temp and cache directory - -.temp - -# Docusaurus cache and generated files - -.docusaurus - -# Serverless directories - -.serverless/ - -# FuseBox cache - -.fusebox/ - -# DynamoDB Local files - -.dynamodb/ - -# TernJS port file - -.tern-port - -# Stores VSCode versions used for testing VSCode extensions - -.vscode-test - -# yarn v2 - -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -# IntelliJ based IDEs -.idea - -# Finder (MacOS) folder config -.DS_Store diff --git a/src/main/nodejs/Edgar-P-yan/README.md b/src/main/nodejs/Edgar-P-yan/README.md deleted file mode 100644 index 578f04f..0000000 --- a/src/main/nodejs/Edgar-P-yan/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# 1brc Node.js by [@Edgar-P-yan](https://github.com/Edgar-P-yan) - -## Details: - -- Machine: MacBook Pro M1 Max 32GB; -- Best results I could get with **Node.js is 23s**; -- Utilizes all cores of the system (10 on mine) via worker threads; -- A custom input-specific and quite fast float point to integer parser; -- Byte-by-byte processing of the whole file; -- Statically typed code that gets JITed very efficiently; - -## What should be improved: - -- Custom hashmap with 2-byte hashes. Right now I just use the builtin `Map`, which is too general purpose for this task, hence quite slow, around 30% of spent time is on the Map. -- Set higher watermarks for the GC, it might save some milliseconds too. -- Do fewer allocations. Right now for each station name in each row a new string gets allocated. diff --git a/src/main/nodejs/Edgar-P-yan/index.js b/src/main/nodejs/Edgar-P-yan/index.js deleted file mode 100644 index ade6290..0000000 --- a/src/main/nodejs/Edgar-P-yan/index.js +++ /dev/null @@ -1,296 +0,0 @@ -import * as os from 'node:os'; -import * as fsp from 'node:fs/promises'; -import * as fs from 'node:fs'; -import * as workerThreads from 'worker_threads'; - -const MAX_LINE_LENGTH = 100 + 1 + 4 + 1; -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 - ? (...args) => console.error(`Thread ${workerThreads.threadId}:`, args) - : () => {}; - -/** - * @typedef {Map} CalcResultsCont - */ - -if (workerThreads.isMainThread) { - const fileName = process.argv[2]; - - const file = await fsp.open(fileName); - - const size = (await file.stat()).size; - - const threadsCount = os.cpus().length; - - const chunkSize = Math.floor(size / threadsCount); - - /** @type {number[]} */ - const chunkOffsets = []; - - let offset = 0; - const bufFindNl = Buffer.alloc(MAX_LINE_LENGTH); - - while (true) { - offset += chunkSize; - - if (offset >= size) { - chunkOffsets.push(size); - break; - } - - await file.read(bufFindNl, 0, MAX_LINE_LENGTH, offset); - - const nlPos = bufFindNl.indexOf(10); - bufFindNl.fill(0); - - if (nlPos === -1) { - chunkOffsets.push(size); - break; - } else { - offset += nlPos + 1; - chunkOffsets.push(offset); - } - } - - await file.close(); - - /** - * @type {CalcResultsCont} - */ - const compiledResults = new Map(); - - let stoppedWorkers = 0; - - for (let i = 0; i < chunkOffsets.length; i++) { - const worker = new workerThreads.Worker( - new URL(import.meta.resolve('./index.js')), - { - workerData: { - fileName, - start: i === 0 ? 0 : chunkOffsets[i - 1], - end: chunkOffsets[i], - }, - } - ); - - worker.on( - 'message', - ( - /** @type {CalcResultsCont} */ - message - ) => { - for (let [key, value] of message.entries()) { - const existing = compiledResults.get(key); - if (existing) { - existing.min = Math.min(existing.min, value.min); - existing.max = Math.max(existing.max, value.max); - existing.sum += value.sum; - existing.count += value.count; - } else { - compiledResults.set(key, value); - } - } - } - ); - - worker.on('error', (err) => { - console.error(err); - }); - - worker.on('exit', (code) => { - if (code !== 0) { - new Error(`Worker stopped with exit code ${code}`); - } else { - debug('Worker stopped'); - } - - stoppedWorkers++; - - if (stoppedWorkers === chunkOffsets.length) { - printCompiledResults(compiledResults); - } - }); - } -} else { - const { fileName, start, end } = workerThreads.workerData; - if (start > end - 1) { - workerThreads.parentPort.postMessage(new Map()); - } else { - const readStream = fs.createReadStream(fileName, { - start: start, - end: end - 1, - }); - - parseStream(readStream); - } -} - -/** - * @param {CalcResultsCont} compiledResults - */ -function printCompiledResults(compiledResults) { - const sortedStations = Array.from(compiledResults.keys()).sort(); - - process.stdout.write('{'); - for (let i = 0; i < sortedStations.length; i++) { - if (i > 0) { - process.stdout.write(', '); - } - const data = compiledResults.get(sortedStations[i]); - process.stdout.write(sortedStations[i]); - process.stdout.write('='); - process.stdout.write( - round(data.min / 10) + - '/' + - round(data.sum / 10 / data.count) + - '/' + - round(data.max / 10) - ); - } - process.stdout.write('}\n'); -} - -/** - * @example - * round(1.2345) // "1.2" - * round(1.55) // "1.6" - * round(1) // "1.0" - * - * @param {number} num - * @returns {string} - */ -function round(num) { - const fixed = Math.round(10 * num) / 10; - - return fixed.toFixed(1); -} - -/** - * @param {import('node:fs').ReadStream} readStream - */ -function parseStream(readStream) { - let readingToken = TOKEN_STATION_NAME; - - let stationName = Buffer.allocUnsafe(100); - let stationNameLen = 0; - - let temperature = Buffer.allocUnsafe(5); - let temperatureLen = 0; - - /** - * @type {CalcResultsCont} - */ - const map = new Map(); - - /** - * @param {Buffer} chunk - * @returns {void} - */ - function parseChunk(chunk) { - for (let i = 0; i < chunk.length; i++) { - if (chunk[i] === CHAR_SEMICOLON) { - readingToken = TOKEN_TEMPERATURE; - } else if (chunk[i] === CHAR_NEWLINE) { - const stationNameStr = stationName.toString('utf8', 0, stationNameLen); - - let temperatureFloat = 0 | 0; - try { - temperatureFloat = parseFloatBufferIntoInt( - temperature, - temperatureLen - ); - } catch (err) { - console.log({ temperature, temperatureLen }, err.message); - throw err; - } - - const existing = map.get(stationNameStr); - - if (existing) { - existing.min = - existing.min < temperatureFloat ? existing.min : temperatureFloat; - existing.max = - existing.max > temperatureFloat ? existing.max : temperatureFloat; - existing.sum += temperatureFloat; - existing.count++; - } else { - map.set(stationNameStr, { - min: temperatureFloat, - max: temperatureFloat, - sum: temperatureFloat, - count: 1, - }); - } - - readingToken = TOKEN_STATION_NAME; - stationNameLen = 0; - temperatureLen = 0; - } else if (readingToken === TOKEN_STATION_NAME) { - stationName[stationNameLen] = chunk[i]; - stationNameLen++; - } else { - temperature[temperatureLen] = chunk[i]; - temperatureLen++; - } - } - } - - readStream.on('data', (/** @type {Buffer} */ chunk) => { - parseChunk(chunk); - }); - - readStream.on('end', () => { - debug('Sending result to the main thread'); - workerThreads.parentPort.postMessage(map); - }); -} - -const CHAR_MINUS = '-'.charCodeAt(0); - -/** - * @param {Buffer} b - * @param {number} length 1-5 - * - * @returns {number} - */ -function parseFloatBufferIntoInt(b, length) { - if (b[0] === CHAR_MINUS) { - // b can be -1.1 or -11.1 - switch (length) { - case 4: - return -(parseOneDigit(b[1]) * 10 + parseOneDigit(b[3])); - case 5: - return -( - parseOneDigit(b[1]) * 100 + - parseOneDigit(b[2]) * 10 + - parseOneDigit(b[4]) - ); - } - } else { - // b can be 1.1 or 11.1 - switch (length) { - case 3: // b is 1.1 - return parseOneDigit(b[0]) * 10 + parseOneDigit(b[2]); - case 4: - return ( - parseOneDigit(b[0]) * 100 + - parseOneDigit(b[1]) * 10 + - parseOneDigit(b[3]) - ); - } - } -} - -/** - * @param {number} char byte number of a digit char - * - * @returns {number} - */ -function parseOneDigit(char) { - return char - 0x30; -} diff --git a/src/main/nodejs/Edgar-P-yan/package-lock.json b/src/main/nodejs/Edgar-P-yan/package-lock.json deleted file mode 100644 index fc27bc0..0000000 --- a/src/main/nodejs/Edgar-P-yan/package-lock.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "nodejs", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "devDependencies": { - "@types/node": "^20.10.6" - } - }, - "node_modules/@types/node": { - "version": "20.10.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz", - "integrity": "sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==", - "dev": true, - "dependencies": { - "undici-types": "~5.26.4" - } - }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true - } - } -} diff --git a/src/main/nodejs/Edgar-P-yan/package.json b/src/main/nodejs/Edgar-P-yan/package.json deleted file mode 100644 index cb4b32b..0000000 --- a/src/main/nodejs/Edgar-P-yan/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "module", - "module": "es2022", - "devDependencies": { - "@types/node": "^20.10.6" - } -} diff --git a/src/main/nodejs/Edgar-P-yan/result.txt b/src/main/nodejs/Edgar-P-yan/result.txt deleted file mode 100644 index 0736747..0000000 --- a/src/main/nodejs/Edgar-P-yan/result.txt +++ /dev/null @@ -1,415 +0,0 @@ -{Abha=-32.2/18.0/67.2, -Abidjan=-23.6/26.0/79.6, -Abéché=-22.9/29.4/82.2, -Accra=-23.4/26.4/75.5, -Addis Ababa=-37.9/16.0/64.6, -Adelaide=-32.0/17.3/67.3, -Aden=-19.9/29.1/78.7, -Ahvaz=-27.1/25.4/77.5, -Albuquerque=-35.2/14.0/62.1, -Alexandra=-37.9/11.0/57.2, -Alexandria=-29.4/20.0/74.8, -Algiers=-27.2/18.2/69.4, -Alice Springs=-26.7/21.0/67.9, -Almaty=-38.9/10.0/63.0, -Amsterdam=-39.4/10.2/56.5, -Anadyr=-57.3/-6.9/41.9, -Anchorage=-48.8/2.8/55.0, -Andorra la Vella=-39.4/9.8/60.7, -Ankara=-39.0/12.0/68.1, -Antananarivo=-31.3/17.9/72.0, -Antsiranana=-23.5/25.2/74.0, -Arkhangelsk=-49.8/1.3/50.9, -Ashgabat=-33.4/17.1/66.0, -Asmara=-34.1/15.6/63.6, -Assab=-23.3/30.5/85.1, -Astana=-50.6/3.5/50.0, -Athens=-33.8/19.2/69.8, -Atlanta=-33.0/17.0/63.4, -Auckland=-37.7/15.2/65.1, -Austin=-29.8/20.7/69.2, -Baghdad=-28.3/22.8/74.3, -Baguio=-32.7/19.5/65.1, -Baku=-34.5/15.1/71.7, -Baltimore=-39.0/13.1/63.8, -Bamako=-26.6/27.8/76.5, -Bangkok=-19.9/28.6/76.3, -Bangui=-22.6/26.0/75.3, -Banjul=-23.6/26.0/76.7, -Barcelona=-34.9/18.2/66.8, -Bata=-23.0/25.1/73.3, -Batumi=-33.2/14.0/65.3, -Beijing=-36.0/12.9/66.7, -Beirut=-29.0/20.9/72.3, -Belgrade=-42.2/12.5/66.3, -Belize City=-22.6/26.7/76.2, -Benghazi=-29.7/19.9/67.9, -Bergen=-41.1/7.7/58.8, -Berlin=-36.0/10.3/60.5, -Bilbao=-35.8/14.7/62.6, -Birao=-26.4/26.5/75.2, -Bishkek=-36.5/11.3/58.1, -Bissau=-22.3/27.0/82.6, -Blantyre=-25.3/22.2/70.2, -Bloemfontein=-34.0/15.6/66.5, -Boise=-36.9/11.4/60.8, -Bordeaux=-37.9/14.2/66.0, -Bosaso=-18.7/30.0/79.5, -Boston=-37.5/10.9/62.2, -Bouaké=-27.5/26.0/86.0, -Bratislava=-38.9/10.5/58.6, -Brazzaville=-25.9/25.0/73.9, -Bridgetown=-21.8/27.0/74.9, -Brisbane=-31.1/21.4/68.7, -Brussels=-38.3/10.5/58.8, -Bucharest=-37.3/10.8/61.2, -Budapest=-40.0/11.3/60.7, -Bujumbura=-23.4/23.8/71.7, -Bulawayo=-28.8/18.9/69.6, -Burnie=-35.2/13.1/65.9, -Busan=-37.6/15.0/65.7, -Cabo San Lucas=-30.6/23.9/80.5, -Cairns=-27.0/25.0/81.1, -Cairo=-25.5/21.4/74.6, -Calgary=-42.7/4.4/57.4, -Canberra=-38.4/13.1/67.4, -Cape Town=-31.2/16.2/68.7, -Changsha=-30.9/17.4/68.5, -Charlotte=-35.1/16.1/67.3, -Chiang Mai=-23.8/25.8/75.0, -Chicago=-41.8/9.8/60.5, -Chihuahua=-33.7/18.6/69.5, -Chittagong=-24.2/25.9/76.1, -Chișinău=-42.4/10.2/63.1, -Chongqing=-31.8/18.6/70.8, -Christchurch=-39.8/12.2/60.4, -City of San Marino=-38.1/11.8/60.8, -Colombo=-22.9/27.4/78.0, -Columbus=-40.2/11.7/61.0, -Conakry=-23.6/26.4/76.8, -Copenhagen=-41.4/9.1/57.6, -Cotonou=-20.6/27.2/75.9, -Cracow=-40.4/9.3/57.1, -Da Lat=-34.8/17.9/70.3, -Da Nang=-25.6/25.8/81.3, -Dakar=-24.6/24.0/74.9, -Dallas=-33.1/19.0/68.6, -Damascus=-32.9/17.0/67.4, -Dampier=-25.4/26.4/77.7, -Dar es Salaam=-23.1/25.8/75.4, -Darwin=-28.0/27.6/76.6, -Denpasar=-26.6/23.7/73.6, -Denver=-38.7/10.4/56.8, -Detroit=-39.3/10.0/60.2, -Dhaka=-24.8/25.9/76.9, -Dikson=-60.9/-11.1/38.2, -Dili=-21.4/26.6/80.8, -Djibouti=-16.8/29.9/78.8, -Dodoma=-30.3/22.7/71.5, -Dolisie=-25.1/24.0/74.8, -Douala=-22.9/26.7/76.8, -Dubai=-21.9/26.9/77.4, -Dublin=-41.0/9.8/59.2, -Dunedin=-40.5/11.1/61.3, -Durban=-30.3/20.6/71.9, -Dushanbe=-31.7/14.7/64.3, -Edinburgh=-38.7/9.3/59.6, -Edmonton=-43.6/4.2/51.7, -El Paso=-33.9/18.1/65.2, -Entebbe=-29.5/21.0/67.4, -Erbil=-29.7/19.5/70.3, -Erzurum=-45.0/5.1/58.3, -Fairbanks=-49.7/-2.3/51.0, -Fianarantsoa=-30.8/17.9/66.9, -Flores, - Petén=-21.0/26.4/79.6, -Frankfurt=-37.1/10.6/60.3, -Fresno=-33.3/17.9/67.3, -Fukuoka=-32.2/17.0/66.6, -Gaborone=-28.3/21.0/69.8, -Gabès=-29.7/19.5/68.9, -Gagnoa=-21.4/26.0/76.1, -Gangtok=-33.4/15.2/67.2, -Garissa=-20.0/29.3/79.9, -Garoua=-20.7/28.3/80.3, -George Town=-27.2/27.9/83.3, -Ghanzi=-34.3/21.4/67.2, -Gjoa Haven=-72.4/-14.4/35.4, -Guadalajara=-29.1/20.9/69.0, -Guangzhou=-26.5/22.4/72.3, -Guatemala City=-29.3/20.4/70.7, -Halifax=-42.1/7.5/58.3, -Hamburg=-41.4/9.7/57.1, -Hamilton=-35.1/13.8/64.7, -Hanga Roa=-31.7/20.5/70.3, -Hanoi=-28.1/23.6/71.4, -Harare=-28.7/18.4/66.4, -Harbin=-46.0/5.0/53.1, -Hargeisa=-28.8/21.7/72.9, -Hat Yai=-18.5/27.0/75.4, -Havana=-29.2/25.2/74.9, -Helsinki=-39.7/5.9/61.5, -Heraklion=-30.0/18.9/66.9, -Hiroshima=-37.7/16.3/65.3, -Ho Chi Minh City=-28.5/27.4/77.3, -Hobart=-37.8/12.7/60.7, -Hong Kong=-24.6/23.3/74.4, -Honiara=-30.8/26.5/77.2, -Honolulu=-23.2/25.4/73.4, -Houston=-26.6/20.8/66.8, -Ifrane=-36.0/11.4/61.2, -Indianapolis=-39.5/11.8/61.8, -Iqaluit=-58.8/-9.3/42.0, -Irkutsk=-48.6/1.0/53.8, -Istanbul=-36.7/13.9/64.6, -Jacksonville=-27.4/20.3/69.8, -Jakarta=-24.5/26.7/76.7, -Jayapura=-26.2/27.0/76.1, -Jerusalem=-33.1/18.3/67.4, -Johannesburg=-31.8/15.5/66.4, -Jos=-25.8/22.8/75.0, -Juba=-18.4/27.8/78.2, -Kabul=-38.7/12.1/62.4, -Kampala=-28.2/20.0/68.0, -Kandi=-19.7/27.7/74.8, -Kankan=-28.5/26.5/79.6, -Kano=-26.8/26.4/75.6, -Kansas City=-37.0/12.5/61.7, -Karachi=-26.0/26.0/74.2, -Karonga=-27.4/24.4/79.6, -Kathmandu=-30.2/18.3/66.6, -Khartoum=-18.8/29.9/89.3, -Kingston=-22.7/27.4/76.7, -Kinshasa=-27.2/25.3/73.9, -Kolkata=-28.7/26.7/76.4, -Kuala Lumpur=-25.8/27.3/76.1, -Kumasi=-22.2/26.0/75.2, -Kunming=-34.9/15.7/65.3, -Kuopio=-46.1/3.4/55.1, -Kuwait City=-25.6/25.7/77.9, -Kyiv=-49.4/8.4/61.4, -Kyoto=-31.6/15.8/63.2, -La Ceiba=-22.3/26.2/77.8, -La Paz=-25.4/23.7/72.5, -Lagos=-22.3/26.8/74.4, -Lahore=-23.8/24.3/72.6, -Lake Havasu City=-34.1/23.7/70.9, -Lake Tekapo=-38.9/8.7/59.4, -Las Palmas de Gran Canaria=-31.1/21.2/68.3, -Las Vegas=-27.9/20.3/74.3, -Launceston=-39.2/13.1/60.7, -Lhasa=-42.5/7.6/55.2, -Libreville=-22.6/25.9/79.2, -Lisbon=-33.0/17.5/68.8, -Livingstone=-27.5/21.8/69.2, -Ljubljana=-41.4/10.9/58.5, -Lodwar=-19.0/29.3/78.9, -Lomé=-23.4/26.9/77.7, -London=-36.9/11.3/60.8, -Los Angeles=-28.5/18.6/67.2, -Louisville=-36.3/13.9/64.6, -Luanda=-25.3/25.8/72.2, -Lubumbashi=-30.8/20.8/70.5, -Lusaka=-30.4/19.9/68.3, -Luxembourg City=-44.1/9.3/60.5, -Lviv=-43.5/7.8/67.9, -Lyon=-36.1/12.5/59.5, -Madrid=-35.0/15.0/66.2, -Mahajanga=-23.7/26.3/74.5, -Makassar=-21.4/26.7/78.2, -Makurdi=-22.3/26.0/77.4, -Malabo=-23.4/26.3/76.6, -Malé=-20.3/28.0/77.9, -Managua=-21.3/27.3/76.8, -Manama=-26.8/26.5/75.2, -Mandalay=-19.5/28.0/78.3, -Mango=-19.5/28.1/77.2, -Manila=-20.5/28.4/79.8, -Maputo=-27.6/22.8/68.8, -Marrakesh=-35.1/19.6/69.3, -Marseille=-33.8/15.8/68.7, -Maun=-29.5/22.4/74.4, -Medan=-25.1/26.5/77.4, -Mek'ele=-26.8/22.7/73.9, -Melbourne=-36.4/15.1/63.3, -Memphis=-33.2/17.2/64.6, -Mexicali=-30.3/23.1/74.2, -Mexico City=-33.8/17.5/67.5, -Miami=-22.7/24.9/71.8, -Milan=-35.7/13.0/61.3, -Milwaukee=-41.7/8.9/59.8, -Minneapolis=-41.2/7.8/58.1, -Minsk=-42.4/6.7/64.3, -Mogadishu=-27.5/27.1/76.1, -Mombasa=-21.2/26.3/73.1, -Monaco=-35.4/16.4/72.4, -Moncton=-44.8/6.1/58.6, -Monterrey=-30.2/22.3/72.6, -Montreal=-46.4/6.8/61.0, -Moscow=-47.7/5.8/55.1, -Mumbai=-21.7/27.1/76.2, -Murmansk=-47.5/0.6/49.2, -Muscat=-20.1/28.0/77.9, -Mzuzu=-34.0/17.7/69.1, -N'Djamena=-20.1/28.3/80.0, -Naha=-24.2/23.1/72.6, -Nairobi=-29.7/17.8/67.7, -Nakhon Ratchasima=-23.6/27.3/78.2, -Napier=-35.7/14.6/63.8, -Napoli=-36.5/15.9/67.6, -Nashville=-33.1/15.4/64.3, -Nassau=-23.4/24.6/77.8, -Ndola=-31.0/20.3/69.9, -New Delhi=-27.2/25.0/77.8, -New Orleans=-30.8/20.7/69.8, -New York City=-36.0/12.9/63.3, -Ngaoundéré=-28.8/22.0/71.1, -Niamey=-22.0/29.3/78.5, -Nicosia=-35.0/19.7/69.0, -Niigata=-37.8/13.9/65.0, -Nouadhibou=-36.2/21.3/68.7, -Nouakchott=-24.2/25.7/75.2, -Novosibirsk=-47.4/1.7/54.6, -Nuuk=-51.1/-1.4/46.6, -Odesa=-38.2/10.7/59.6, -Odienné=-24.9/26.0/76.9, -Oklahoma City=-33.1/15.9/64.8, -Omaha=-42.7/10.6/62.9, -Oranjestad=-21.3/28.1/78.8, -Oslo=-45.4/5.7/60.2, -Ottawa=-47.7/6.6/55.8, -Ouagadougou=-23.1/28.3/80.2, -Ouahigouya=-21.1/28.6/77.8, -Ouarzazate=-30.3/18.9/72.3, -Oulu=-46.8/2.7/52.7, -Palembang=-20.4/27.3/76.2, -Palermo=-34.7/18.5/70.1, -Palm Springs=-26.6/24.5/72.4, -Palmerston North=-39.9/13.2/61.2, -Panama City=-20.0/28.0/78.1, -Parakou=-24.6/26.8/78.2, -Paris=-38.6/12.3/61.5, -Perth=-41.6/18.7/65.5, -Petropavlovsk-Kamchatsky=-48.9/1.9/49.1, -Philadelphia=-38.0/13.2/65.2, -Phnom Penh=-21.8/28.3/77.0, -Phoenix=-26.2/23.9/77.9, -Pittsburgh=-39.3/10.8/59.4, -Podgorica=-34.6/15.3/65.2, -Pointe-Noire=-25.3/26.1/78.5, -Pontianak=-20.7/27.7/79.6, -Port Moresby=-22.7/26.9/74.6, -Port Sudan=-24.1/28.4/76.2, -Port Vila=-25.8/24.3/75.2, -Port-Gentil=-24.1/26.0/77.3, -Portland (OR)=-39.5/12.4/60.7, -Porto=-35.6/15.7/71.0, -Prague=-41.6/8.4/57.7, -Praia=-25.7/24.4/71.8, -Pretoria=-33.9/18.2/67.6, -Pyongyang=-39.9/10.8/59.0, -Rabat=-29.7/17.2/67.5, -Rangpur=-29.5/24.4/72.5, -Reggane=-22.1/28.3/80.0, -Reykjavík=-46.2/4.3/51.4, -Riga=-41.7/6.2/53.3, -Riyadh=-34.8/26.0/74.1, -Rome=-37.0/15.2/69.5, -Roseau=-28.8/26.2/77.0, -Rostov-on-Don=-42.8/9.9/62.3, -Sacramento=-31.9/16.3/64.0, -Saint Petersburg=-42.7/5.8/55.8, -Saint-Pierre=-42.7/5.7/56.4, -Salt Lake City=-37.9/11.6/61.9, -San Antonio=-26.3/20.8/72.0, -San Diego=-30.0/17.8/68.1, -San Francisco=-33.9/14.6/66.8, -San Jose=-36.2/16.4/67.2, -San José=-30.0/22.6/69.1, -San Juan=-20.6/27.2/76.2, -San Salvador=-25.3/23.1/72.4, -Sana'a=-32.6/20.0/69.1, -Santo Domingo=-30.4/25.9/75.1, -Sapporo=-40.1/8.9/59.2, -Sarajevo=-44.2/10.1/60.5, -Saskatoon=-47.4/3.3/53.9, -Seattle=-35.7/11.3/66.6, -Seoul=-34.7/12.5/66.5, -Seville=-29.9/19.2/68.7, -Shanghai=-32.1/16.7/65.8, -Singapore=-23.6/27.0/77.4, -Skopje=-35.6/12.4/60.5, -Sochi=-35.4/14.2/65.3, -Sofia=-38.0/10.6/58.2, -Sokoto=-20.4/28.0/74.8, -Split=-32.6/16.1/63.5, -St. John's=-49.0/5.0/53.5, -St. Louis=-36.1/13.9/63.5, -Stockholm=-41.9/6.6/54.6, -Surabaya=-23.9/27.1/76.4, -Suva=-27.8/25.6/77.7, -Suwałki=-44.2/7.2/66.7, -Sydney=-32.6/17.7/69.8, -Ségou=-26.1/28.0/78.1, -Tabora=-25.1/23.0/70.4, -Tabriz=-35.6/12.6/62.1, -Taipei=-28.9/23.0/78.6, -Tallinn=-42.7/6.4/61.5, -Tamale=-20.3/27.9/78.0, -Tamanrasset=-30.1/21.7/71.4, -Tampa=-28.1/22.9/75.4, -Tashkent=-34.2/14.8/64.8, -Tauranga=-33.6/14.8/65.2, -Tbilisi=-41.0/12.9/63.3, -Tegucigalpa=-30.0/21.7/77.2, -Tehran=-32.2/17.0/66.5, -Tel Aviv=-29.9/20.0/74.3, -Thessaloniki=-33.1/16.0/68.8, -Thiès=-24.9/24.0/76.4, -Tijuana=-29.2/17.8/65.2, -Timbuktu=-22.0/28.0/76.4, -Tirana=-37.5/15.2/67.2, -Toamasina=-28.0/23.4/71.6, -Tokyo=-32.1/15.4/65.4, -Toliara=-27.0/24.1/77.2, -Toluca=-35.3/12.4/63.1, -Toronto=-39.8/9.4/58.8, -Tripoli=-34.6/20.0/69.9, -Tromsø=-45.1/2.9/52.6, -Tucson=-29.5/20.9/69.2, -Tunis=-30.3/18.4/66.9, -Ulaanbaatar=-49.9/-0.4/49.8, -Upington=-29.6/20.4/71.5, -Vaduz=-37.3/10.1/61.2, -Valencia=-32.4/18.3/66.9, -Valletta=-32.4/18.8/69.0, -Vancouver=-40.3/10.4/59.7, -Veracruz=-24.0/25.4/75.9, -Vienna=-37.4/10.4/67.2, -Vientiane=-26.0/25.9/74.0, -Villahermosa=-22.7/27.1/79.2, -Vilnius=-43.1/6.0/55.1, -Virginia Beach=-32.5/15.8/66.7, -Vladivostok=-41.5/4.9/56.2, -Warsaw=-43.9/8.5/56.4, -Washington, -D.C.=-41.8/14.6/63.5, -Wau=-18.5/27.8/79.3, -Wellington=-38.9/12.9/67.2, -Whitehorse=-48.9/-0.1/50.5, -Wichita=-36.2/13.9/66.9, -Willemstad=-20.6/28.0/78.9, -Winnipeg=-48.6/3.0/52.3, -Wrocław=-36.2/9.6/62.0, -Xi'an=-36.6/14.1/61.8, -Yakutsk=-56.8/-8.8/46.8, -Yangon=-22.1/27.5/80.4, -Yaoundé=-25.1/23.8/80.3, -Yellowknife=-52.5/-4.3/41.5, -Yerevan=-36.9/12.4/63.5, -Yinchuan=-42.5/9.0/60.4, -Zagreb=-38.0/10.7/69.2, -Zanzibar City=-26.6/26.0/74.5, -Zürich=-39.7/9.3/57.2, -Ürümqi=-40.3/7.4/54.8, -İzmir=-29.2/17.9/68.8} \ No newline at end of file diff --git a/src/main/nodejs/Edgar-P-yan/tsconfig.json b/src/main/nodejs/Edgar-P-yan/tsconfig.json deleted file mode 100644 index 57fc6e6..0000000 --- a/src/main/nodejs/Edgar-P-yan/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "module": "es2022", - "target": "es2022", - "allowJs": true, - "checkJs": true, - "outDir": "dist", - "types": ["node"] - } -} diff --git a/src/main/nodejs/baseline/.gitignore b/src/main/nodejs/baseline/.gitignore deleted file mode 100644 index 468f82a..0000000 --- a/src/main/nodejs/baseline/.gitignore +++ /dev/null @@ -1,175 +0,0 @@ -# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore - -# Logs - -logs -_.log -npm-debug.log_ -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Caches - -.cache - -# Diagnostic reports (https://nodejs.org/api/report.html) - -report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json - -# Runtime data - -pids -_.pid -_.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover - -lib-cov - -# Coverage directory used by tools like istanbul - -coverage -*.lcov - -# nyc test coverage - -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) - -.grunt - -# Bower dependency directory (https://bower.io/) - -bower_components - -# node-waf configuration - -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) - -build/Release - -# Dependency directories - -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) - -web_modules/ - -# TypeScript cache - -*.tsbuildinfo - -# Optional npm cache directory - -.npm - -# Optional eslint cache - -.eslintcache - -# Optional stylelint cache - -.stylelintcache - -# Microbundle cache - -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history - -.node_repl_history - -# Output of 'npm pack' - -*.tgz - -# Yarn Integrity file - -.yarn-integrity - -# dotenv environment variable files - -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) - -.parcel-cache - -# Next.js build output - -.next -out - -# Nuxt.js build / generate output - -.nuxt -dist - -# Gatsby files - -# Comment in the public line in if your project uses Gatsby and not Next.js - -# https://nextjs.org/blog/next-9-1#public-directory-support - -# public - -# vuepress build output - -.vuepress/dist - -# vuepress v2.x temp and cache directory - -.temp - -# Docusaurus cache and generated files - -.docusaurus - -# Serverless directories - -.serverless/ - -# FuseBox cache - -.fusebox/ - -# DynamoDB Local files - -.dynamodb/ - -# TernJS port file - -.tern-port - -# Stores VSCode versions used for testing VSCode extensions - -.vscode-test - -# yarn v2 - -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -# IntelliJ based IDEs -.idea - -# Finder (MacOS) folder config -.DS_Store diff --git a/src/main/nodejs/baseline/index.js b/src/main/nodejs/baseline/index.js deleted file mode 100644 index 9ce7638..0000000 --- a/src/main/nodejs/baseline/index.js +++ /dev/null @@ -1,72 +0,0 @@ -import * as readline from 'node:readline'; -import * as fs from 'node:fs'; - -const fileName = process.argv[2]; -const stream = fs.createReadStream(fileName); -const lineStream = readline.createInterface(stream); - -const aggregations = new Map(); - -for await (const line of lineStream) { - const [stationName, temperatureStr] = line.split(';'); - - // use integers for computation to avoid loosing precision - const temperature = Math.floor(parseFloat(temperatureStr) * 10); - - const existing = aggregations.get(stationName); - - if (existing) { - existing.min = Math.min(existing.min, temperature); - existing.max = Math.max(existing.max, temperature); - existing.sum += temperature; - existing.count++; - } else { - aggregations.set(stationName, { - min: temperature, - max: temperature, - sum: temperature, - count: 1, - }); - } -} - -printCompiledResults(aggregations); - -/** - * @param {Map} aggregations - * - * @returns {void} - */ -function printCompiledResults(aggregations) { - const sortedStations = Array.from(aggregations.keys()).sort(); - - let result = - '{' + - sortedStations - .map((station) => { - const data = aggregations.get(station); - return `${station}=${round(data.min / 10)}/${round( - data.sum / 10 / data.count - )}/${round(data.max / 10)}`; - }) - .join(', ') + - '}'; - - console.log(result); -} - -/** - * @example - * round(1.2345) // "1.2" - * round(1.55) // "1.6" - * round(1) // "1.0" - * - * @param {number} num - * - * @returns {string} - */ -function round(num) { - const fixed = Math.round(10 * num) / 10; - - return fixed.toFixed(1); -} diff --git a/src/main/nodejs/baseline/package-lock.json b/src/main/nodejs/baseline/package-lock.json deleted file mode 100644 index fc27bc0..0000000 --- a/src/main/nodejs/baseline/package-lock.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "nodejs", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "devDependencies": { - "@types/node": "^20.10.6" - } - }, - "node_modules/@types/node": { - "version": "20.10.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz", - "integrity": "sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==", - "dev": true, - "dependencies": { - "undici-types": "~5.26.4" - } - }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true - } - } -} diff --git a/src/main/nodejs/baseline/package.json b/src/main/nodejs/baseline/package.json deleted file mode 100644 index cb4b32b..0000000 --- a/src/main/nodejs/baseline/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "module", - "module": "es2022", - "devDependencies": { - "@types/node": "^20.10.6" - } -} diff --git a/src/main/nodejs/baseline/tsconfig.json b/src/main/nodejs/baseline/tsconfig.json deleted file mode 100644 index 57fc6e6..0000000 --- a/src/main/nodejs/baseline/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "module": "es2022", - "target": "es2022", - "allowJs": true, - "checkJs": true, - "outDir": "dist", - "types": ["node"] - } -}