add function names

This commit is contained in:
Revone 2023-08-16 01:35:16 +08:00
parent 4da59257e8
commit 02bc7c4b8f
32 changed files with 207 additions and 129 deletions

View file

@ -15,6 +15,13 @@ yarn add data-structure-typed
```bash
npm install data-structure-typed
```
## Online examples
[Online Examples](https://data-structure-typed-examples.vercel.app)
## Examples Repository
[Example Repository](https://github.com/zrwusa/data-structure-typed-examples)
## api docs

View file

@ -39,8 +39,8 @@
"Min Priority Queue",
"Trie"
],
"author": "Tyler Zeng",
"license": "ISC",
"author": "Tyler Zeng zrwusa@gmail.com",
"license": "MIT",
"bugs": {
"url": "https://github.com/zrwusa/data-structure-typed/issues"
},

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {BST, BSTNode} from './bst';
import type {AVLTreeDeleted, BinaryTreeNodeId} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
export class BinaryIndexedTree {
private readonly _sumTree: number[];

View file

@ -1,9 +1,12 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {trampoline} from '../../utils/trampoline';
import {trampoline} from '../../utils';
import type {
BinaryTreeDeleted,
BinaryTreeNodeId,

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult} from '../types';
import {BinaryTree, BinaryTreeNode, FamilyPosition, LoopType,} from './binary-tree';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import type {SegmentTreeNodeVal} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {BST, BSTNode} from './bst';
import type {BinaryTreeNodeId, TreeMultiSetDeletedResult} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {arrayRemove, uuidV4} from '../../utils';
import {PriorityQueue} from '../priority-queue';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {arrayRemove} from '../../utils';
import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
@ -184,7 +187,7 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
const destInEdges = this._inEdgeMap.get(dest);
if (destInEdges && destInEdges.length > 0) {
removed = arrayRemove(destInEdges, (edge: DirectedEdge) => edge.dest === dest.id)[0];
removed = arrayRemove(destInEdges, (edge: E) => edge.dest === dest.id)[0];
}
}

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {arrayRemove} from '../../utils';
import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
export class CoordinateMap<V> extends Map<any, V> {
private readonly _joint: string = '_';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
export class CoordinateSet extends Set {
private readonly _joint: string = '_';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {PriorityQueue} from '../priority-queue';
import type {HeapItem, HeapOptions} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {Heap} from './heap';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {Heap} from './heap';

View file

@ -8,4 +8,6 @@ export * from './heap';
export * from './priority-queue';
export * from './matrix';
export * from './trie';
export * from './types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import type {DoublyLinkedListGetBy} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
/**

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
// todo need to be improved
export class MatrixNTI2D<T = number> {

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import Vector2D from './vector2d'

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import type {Direction, NavigatorParams, Turning} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
export class Vector2D {
constructor(

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {PriorityQueue} from './priority-queue';
import type {PriorityQueueOptions} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {PriorityQueue} from './priority-queue';
import type {PriorityQueueOptions} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import type {PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions} from '../types';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {DoublyLinkedList} from '../linked-list';

View file

@ -1,6 +1,9 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
export class TrieNode {
protected _value;

View file

@ -1 +1,2 @@
export * from './utils';
export * from './utils';
export * from './types';

View file

@ -1,51 +0,0 @@
/**
* @copyright Tyler Zeng <zrwusa@gmail.com>
* @license MIT
*/
import {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types';
export const THUNK_SYMBOL = Symbol('thunk')
export const isThunk = (fnOrValue: any) => {
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === THUNK_SYMBOL
}
export const toThunk = (fn: ToThunkFn): Thunk => {
const thunk = () => fn()
thunk.__THUNK__ = THUNK_SYMBOL
return thunk
}
export const trampoline = (fn: TrlFn) => {
const cont = (...args: [...Parameters<TrlFn>]) => toThunk(() => fn(...args))
return Object.assign(
(...args: [...Parameters<TrlFn>]) => {
let result = fn(...args)
while (isThunk(result) && typeof result === 'function') {
result = result()
}
return result
},
{cont}
)
}
export const trampolineAsync = (fn: TrlAsyncFn) => {
const cont = (...args: [...Parameters<TrlAsyncFn>]) => toThunk(() => fn(...args))
return Object.assign(
async (...args: [...Parameters<TrlAsyncFn>]) => {
let result = await fn(...args)
while (isThunk(result) && typeof result === 'function') {
result = await result()
}
return result
},
{cont}
)
}

View file

@ -1,3 +1,12 @@
export type JSONSerializable = {
[key: string]: any
}
export type JSONValue = string | number | boolean | undefined | JSONObject;
export interface JSONObject {
[key: string]: JSONValue;
}
export type AnyFunction<A extends any[] = any[], R = any> = (...args: A) => R;
export type Primitive =
| number
@ -32,16 +41,6 @@ export type DeepLeavesWrap<T, TComplex> =
type Json = null | string | number | boolean | Json [] | { [name: string]: Json }
export type JSONSerializable = {
[key: string]: any
}
export type JSONValue = string | number | boolean | undefined | JSONObject;
export interface JSONObject {
[key: string]: JSONValue;
}
export type TypeName<T> = T extends string
? 'string'
: T extends number
@ -173,8 +172,7 @@ export type CurryFunc<T> = T extends (...args: infer Args) => infer R
export type ToThunkFn = () => ReturnType<TrlFn>;
const THUNK_SYMBOL = Symbol('thunk')
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: typeof THUNK_SYMBOL };
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: Symbol };
export type TrlFn = (...args: any[]) => any;
export type TrlAsyncFn = (...args: any[]) => any;

View file

@ -1,14 +1,5 @@
import * as _ from 'lodash';
import {AnyFunction} from './types';
export type JSONSerializable = {
[key: string]: any
}
export type JSONValue = string | number | boolean | undefined | JSONObject;
export interface JSONObject {
[key: string]: JSONValue;
}
import _ from 'lodash';
import type {AnyFunction, JSONObject, JSONSerializable} from './types';
export function randomText(length: number) {
let result = '';
@ -512,4 +503,59 @@ export function zip<T = number, T1 = number>(array1: T[], array2: T1[], options?
}
}
return isToObj ? zippedObjCoords : zipped;
}
/**
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types';
export const THUNK_SYMBOL = Symbol('thunk')
export const isThunk = (fnOrValue: any) => {
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === THUNK_SYMBOL
}
export const toThunk = (fn: ToThunkFn): Thunk => {
const thunk = () => fn()
thunk.__THUNK__ = THUNK_SYMBOL
return thunk
}
export const trampoline = (fn: TrlFn) => {
const cont = (...args: [...Parameters<TrlFn>]) => toThunk(() => fn(...args))
return Object.assign(
(...args: [...Parameters<TrlFn>]) => {
let result = fn(...args)
while (isThunk(result) && typeof result === 'function') {
result = result()
}
return result
},
{cont}
)
}
export const trampolineAsync = (fn: TrlAsyncFn) => {
const cont = (...args: [...Parameters<TrlAsyncFn>]) => toThunk(() => fn(...args))
return Object.assign(
async (...args: [...Parameters<TrlAsyncFn>]) => {
let result = await fn(...args)
while (isThunk(result) && typeof result === 'function') {
result = await result()
}
return result
},
{cont}
)
}