Skip to content

Commit

Permalink
Merge pull request #115 from samchon/features/esm
Browse files Browse the repository at this point in the history
Adjust prettier
  • Loading branch information
samchon authored Mar 28, 2024
2 parents b620c76 + 3369f99 commit d17ed94
Show file tree
Hide file tree
Showing 244 changed files with 20,802 additions and 21,266 deletions.
4 changes: 0 additions & 4 deletions .prettierignore

This file was deleted.

59 changes: 30 additions & 29 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "TypeScript Test using TS-NODE",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceRoot}/src/test/index.ts"
]
},
{
"type": "node",
"request": "launch",
"name": "JavaScript Test using SourceMap",
"program": "${workspaceRoot}/test/index.js",
"cwd": "${workspaceRoot}",

// TypeScript
"sourceMaps": true,
"outFiles": ["${workspaceRot}/**.js"]
}
]
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "TypeScript Test using TS-NODE",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceRoot}/src/test/index.ts"
]
},
{
"type": "node",
"request": "launch",
"name": "JavaScript Test using SourceMap",
"program": "${workspaceRoot}/test/index.js",
"cwd": "${workspaceRoot}",
// TypeScript
"sourceMaps": true,
"outFiles": [
"${workspaceRot}/**.js"
]
}
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.tabSize": 2,
"editor.formatOnSave": true,
"[typescript][javascript][json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
"benchmark": "node benchmark",
"build": "rimraf lib && tsc && rollup -c",
"dev": "rimraf lib && tsc --watch",
"prettier": "prettier --write ./src",
"prettier": "prettier --write ./src/**/*.ts",
"test": "node lib/test"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/cli": "^0.11.19",
"@types/node": "^14.6.3",
"cli": "^1.0.1",
"prettier": "^2.7.1",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"rollup": "^4.13.1",
"source-map-support": "^0.5.21",
Expand Down
12 changes: 12 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
parser: "typescript",
printWidth: 80,
semi: true,
tabWidth: 2,
trailingComma: "all",
plugins: [require.resolve("@trivago/prettier-plugin-sort-imports")],
importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
importOrderParserPlugins: ["decorators-legacy", "typescript"],
};
54 changes: 27 additions & 27 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
const typescript = require('@rollup/plugin-typescript');
const terser = require('@rollup/plugin-terser');
const typescript = require("@rollup/plugin-typescript");
const terser = require("@rollup/plugin-terser");

module.exports = {
input: './src/index.ts',
output: {
dir: 'lib',
format: 'esm',
entryFileNames: '[name].mjs',
sourcemap: true,
},
plugins: [
typescript({
tsconfig: "tsconfig.json",
module: "ES2020",
target: "ES2020",
}),
terser({
format: {
comments: 'some',
beautify: true,
ecma: '2020',
},
compress: false,
mangle: false,
module: true,
}),
]
};
input: "./src/index.ts",
output: {
dir: "lib",
format: "esm",
entryFileNames: "[name].mjs",
sourcemap: true,
},
plugins: [
typescript({
tsconfig: "tsconfig.json",
module: "ES2020",
target: "ES2020",
}),
terser({
format: {
comments: "some",
beautify: true,
ecma: "2020",
},
compress: false,
mangle: false,
module: true,
}),
],
};
116 changes: 58 additions & 58 deletions src/algorithm/binary_search.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//================================================================

/**
* @packageDocumentation
* @module std
*/
//================================================================
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IPointer } from "../functional/IPointer";
import { Pair } from "../utility/Pair";

import { Comparator } from "../internal/functional/Comparator";
import { distance, advance } from "../iterator/global";
import { less } from "../functional/comparators";
import { Comparator } from "../internal/functional/Comparator";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { advance, distance } from "../iterator/global";
import { Pair } from "../utility/Pair";

/* =========================================================
BINARY SEARCH
Expand All @@ -26,27 +26,27 @@ import { less } from "../functional/comparators";
* @return Iterator to the first element equal or after the val.
*/
export function lower_bound<
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
>(
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
): ForwardIterator {
let count: number = distance(first, last);
let count: number = distance(first, last);

while (count > 0) {
const step: number = Math.floor(count / 2);
const it: ForwardIterator = advance(first, step);
while (count > 0) {
const step: number = Math.floor(count / 2);
const it: ForwardIterator = advance(first, step);

if (comp(it.value, val)) {
first = it.next();
count -= step + 1;
} else count = step;
}
return first;
if (comp(it.value, val)) {
first = it.next();
count -= step + 1;
} else count = step;
}
return first;
}

/**
Expand All @@ -60,27 +60,27 @@ export function lower_bound<
* @return Iterator to the first element after the key.
*/
export function upper_bound<
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
>(
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
): ForwardIterator {
let count: number = distance(first, last);
let count: number = distance(first, last);

while (count > 0) {
const step: number = Math.floor(count / 2);
const it: ForwardIterator = advance(first, step);
while (count > 0) {
const step: number = Math.floor(count / 2);
const it: ForwardIterator = advance(first, step);

if (!comp(val, it.value)) {
first = it.next();
count -= step + 1;
} else count = step;
}
return first;
if (!comp(val, it.value)) {
first = it.next();
count -= step + 1;
} else count = step;
}
return first;
}

/**
Expand All @@ -94,19 +94,19 @@ export function upper_bound<
* @return Pair of {@link lower_bound} and {@link upper_bound}.
*/
export function equal_range<
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
>(
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
): Pair<ForwardIterator, ForwardIterator> {
first = lower_bound(first, last, val, comp);
const second: ForwardIterator = upper_bound(first, last, val, comp);
first = lower_bound(first, last, val, comp);
const second: ForwardIterator = upper_bound(first, last, val, comp);

return new Pair(first, second);
return new Pair(first, second);
}

/**
Expand All @@ -120,16 +120,16 @@ export function equal_range<
* @return Whether the value exists or not.
*/
export function binary_search<
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
ForwardIterator extends Readonly<
IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>
>,
>(
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
first: ForwardIterator,
last: ForwardIterator,
val: IPointer.ValueType<ForwardIterator>,
comp: Comparator<IPointer.ValueType<ForwardIterator>> = less,
): boolean {
first = lower_bound(first, last, val, comp);
first = lower_bound(first, last, val, comp);

return !first.equals(last) && !comp(val, first.value);
return !first.equals(last) && !comp(val, first.value);
}
Loading

0 comments on commit d17ed94

Please sign in to comment.