mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 12:54:04 +00:00
Optimize the overall codebase and directory structure.
This commit is contained in:
parent
b0774bee5b
commit
450f051138
|
@ -13,11 +13,11 @@ By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree ->
|
|||
## install
|
||||
### npm
|
||||
```bash
|
||||
npm install data-structure-typed --save
|
||||
npm install data-structure-typed
|
||||
```
|
||||
### yarn
|
||||
```bash
|
||||
yarn add data-structure-typed -D
|
||||
yarn add data-structure-typed
|
||||
```
|
||||
### CDN
|
||||
```html
|
||||
|
|
|
@ -16,9 +16,9 @@ import type {
|
|||
BinaryTreeNodePropertyName,
|
||||
DFSOrderPattern,
|
||||
NodeOrPropertyName
|
||||
} from '../types';
|
||||
import {AbstractBinaryTreeOptions, FamilyPosition, LoopType} from '../types';
|
||||
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from '../interfaces';
|
||||
} from '../../types';
|
||||
import {AbstractBinaryTreeOptions, FamilyPosition, LoopType} from '../../types';
|
||||
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from '../../interfaces';
|
||||
|
||||
export abstract class AbstractBinaryTreeNode<T = any, NEIGHBOR extends AbstractBinaryTreeNode<T, NEIGHBOR> = AbstractBinaryTreeNodeNested<T>> implements IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* @license MIT License
|
||||
*/
|
||||
import {BST, BSTNode} from './bst';
|
||||
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId} from '../types';
|
||||
import {IAVLTree, IAVLTreeNode} from '../interfaces';
|
||||
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId} from '../../types';
|
||||
import {IAVLTree, IAVLTreeNode} from '../../interfaces';
|
||||
|
||||
export class AVLTreeNode<T = any, NEIGHBOR extends AVLTreeNode<T, NEIGHBOR> = AVLTreeNodeNested<T>> extends BSTNode<T, NEIGHBOR> implements IAVLTreeNode<T, NEIGHBOR> {
|
||||
constructor(id: BinaryTreeNodeId, val?: T) {
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* @license MIT License
|
||||
*/
|
||||
|
||||
import type {BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions} from '../types';
|
||||
import type {BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions} from '../../types';
|
||||
import {AbstractBinaryTree, AbstractBinaryTreeNode} from './abstract-binary-tree';
|
||||
import {IBinaryTree, IBinaryTreeNode} from '../interfaces';
|
||||
import {IBinaryTree, IBinaryTreeNode} from '../../interfaces';
|
||||
|
||||
export class BinaryTreeNode<T = any, NEIGHBOR extends BinaryTreeNode<T, NEIGHBOR> = BinaryTreeNodeNested<T>> extends AbstractBinaryTreeNode<T, NEIGHBOR> implements IBinaryTreeNode<T, NEIGHBOR> {
|
||||
constructor(id: BinaryTreeNodeId, val?: T) {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
||||
* @license MIT License
|
||||
*/
|
||||
import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions} from '../types';
|
||||
import {CP, LoopType} from '../types';
|
||||
import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions} from '../../types';
|
||||
import {CP, LoopType} from '../../types';
|
||||
import {BinaryTree, BinaryTreeNode} from './binary-tree';
|
||||
import {IBST, IBSTNode} from '../interfaces';
|
||||
import {IBST, IBSTNode} from '../../interfaces';
|
||||
|
||||
export class BSTNode<T = any, NEIGHBOR extends BSTNode<T, NEIGHBOR> = BSTNodeNested<T>> extends BinaryTreeNode<T, NEIGHBOR> implements IBSTNode<T, NEIGHBOR> {
|
||||
constructor(id: BinaryTreeNodeId, val?: T) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {BinaryTreeNodeId, RBColor, RBTreeNodeNested, RBTreeOptions} from '../types';
|
||||
import {IRBTree, IRBTreeNode} from '../interfaces/rb-tree';
|
||||
import {BinaryTreeNodeId, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../types';
|
||||
import {IRBTree, IRBTreeNode} from '../../interfaces/rb-tree';
|
||||
import {BST, BSTNode} from './bst';
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @license MIT License
|
||||
*/
|
||||
|
||||
import type {SegmentTreeNodeVal} from '../types';
|
||||
import type {SegmentTreeNodeVal} from '../../types';
|
||||
|
||||
export class SegmentTreeNode {
|
||||
constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null) {
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
||||
* @license MIT License
|
||||
*/
|
||||
import type {BinaryTreeNodeId, TreeMultisetNodeNested, TreeMultisetOptions} from '../types';
|
||||
import {BinaryTreeDeletedResult, CP, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName} from '../types';
|
||||
import {ITreeMultiset, ITreeMultisetNode} from '../interfaces';
|
||||
import type {BinaryTreeNodeId, TreeMultisetNodeNested, TreeMultisetOptions} from '../../types';
|
||||
import {BinaryTreeDeletedResult, CP, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName} from '../../types';
|
||||
import {ITreeMultiset, ITreeMultisetNode} from '../../interfaces';
|
||||
import {AVLTree, AVLTreeNode} from './avl-tree';
|
||||
|
||||
export class TreeMultisetNode<T = any, NEIGHBOR extends TreeMultisetNode<T, NEIGHBOR> = TreeMultisetNodeNested<T>> extends AVLTreeNode<T, NEIGHBOR> implements ITreeMultisetNode<T, NEIGHBOR> {
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
import {arrayRemove, uuidV4} from '../../utils';
|
||||
import {PriorityQueue} from '../priority-queue';
|
||||
import type {DijkstraResult, VertexId} from '../types';
|
||||
import {IAbstractGraph} from '../interfaces';
|
||||
import type {DijkstraResult, VertexId} from '../../types';
|
||||
import {IAbstractGraph} from '../../interfaces';
|
||||
|
||||
export abstract class AbstractVertex<T = any> {
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
import {arrayRemove} from '../../utils';
|
||||
import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
|
||||
import type {TopologicalStatus, VertexId} from '../types';
|
||||
import {IDirectedGraph} from '../interfaces';
|
||||
import type {TopologicalStatus, VertexId} from '../../types';
|
||||
import {IDirectedGraph} from '../../interfaces';
|
||||
|
||||
export class DirectedVertex<T = number> extends AbstractVertex<T> {
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {MapGraphCoordinate, VertexId} from '../types';
|
||||
import {MapGraphCoordinate, VertexId} from '../../types';
|
||||
import {DirectedEdge, DirectedGraph, DirectedVertex} from './directed-graph';
|
||||
|
||||
export class MapVertex<T = any> extends DirectedVertex<T> {
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
import {arrayRemove} from '../../utils';
|
||||
import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
|
||||
import type {VertexId} from '../types';
|
||||
import {IUNDirectedGraph} from '../interfaces';
|
||||
import type {VertexId} from '../../types';
|
||||
import {IUNDirectedGraph} from '../../interfaces';
|
||||
|
||||
export class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @license MIT License
|
||||
*/
|
||||
import {PriorityQueue} from '../priority-queue';
|
||||
import type {HeapOptions} from '../types';
|
||||
import type {HeapOptions} from '../../types';
|
||||
|
||||
export class HeapItem<T = number> {
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import {Heap, HeapItem} from './heap';
|
||||
import {PriorityQueue} from '../priority-queue';
|
||||
import type {HeapOptions} from '../types';
|
||||
import type {HeapOptions} from '../../types';
|
||||
|
||||
/**
|
||||
* @class MaxHeap
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import {Heap, HeapItem} from './heap';
|
||||
import {PriorityQueue} from '../priority-queue';
|
||||
import type {HeapOptions} from '../types';
|
||||
import type {HeapOptions} from '../../types';
|
||||
|
||||
/**
|
||||
* @class MinHeap
|
||||
|
|
|
@ -8,8 +8,4 @@ export * from './tree';
|
|||
export * from './heap';
|
||||
export * from './priority-queue';
|
||||
export * from './matrix';
|
||||
export * from './trie';
|
||||
export * from './interfaces';
|
||||
export * from './types';
|
||||
|
||||
|
||||
export * from './trie';
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
||||
* @license MIT License
|
||||
*/
|
||||
import type {Direction, NavigatorParams, Turning} from '../types';
|
||||
import type {Direction, NavigatorParams, Turning} from '../../types';
|
||||
|
||||
export class Character {
|
||||
direction: Direction;
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
* @license MIT License
|
||||
*/
|
||||
import {PriorityQueue} from './priority-queue';
|
||||
import type {PriorityQueueOptions} from '../types';
|
||||
import {SpecifyOptional} from '../../utils';
|
||||
import type {PriorityQueueOptions, SpecifyOptional} from '../../types';
|
||||
|
||||
export class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
|
||||
constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>)
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
* @license MIT License
|
||||
*/
|
||||
import {PriorityQueue} from './priority-queue';
|
||||
import type {PriorityQueueOptions} from '../types';
|
||||
import {SpecifyOptional} from '../../utils';
|
||||
import type {PriorityQueueOptions, SpecifyOptional} from '../../types';
|
||||
|
||||
export class MinPriorityQueue<T = number> extends PriorityQueue<T> {
|
||||
constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
||||
* @license MIT License
|
||||
*/
|
||||
import type {PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions} from '../types';
|
||||
import type {PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions} from '../../types';
|
||||
|
||||
export class PriorityQueue<T = number> {
|
||||
/**
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
export * from './data-structures';
|
||||
export * from './utils';
|
||||
export * from './utils';
|
||||
export * from './interfaces';
|
||||
export * from './types';
|
|
@ -9,7 +9,7 @@ import {
|
|||
LoopType,
|
||||
NodeOrPropertyName
|
||||
} from '../types';
|
||||
import {AbstractBinaryTreeNode} from '../binary-tree';
|
||||
import {AbstractBinaryTreeNode} from '../data-structures';
|
||||
|
||||
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
||||
|
|
@ -4,14 +4,8 @@ export interface IAbstractGraph<V, E> {
|
|||
|
||||
hasVertex(vertexOrId: V | VertexId): boolean;
|
||||
|
||||
// _getVertex(vertexOrId: VertexId | V): V | null;
|
||||
|
||||
// _getVertexId(vertexOrId: V | VertexId): VertexId;
|
||||
|
||||
addVertex(id: VertexId, val?: V): boolean;
|
||||
|
||||
// _addVertexOnly(newVertex: V): boolean;
|
||||
|
||||
removeVertex(vertexOrId: V | VertexId): boolean;
|
||||
|
||||
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
||||
|
@ -28,8 +22,6 @@ export interface IAbstractGraph<V, E> {
|
|||
|
||||
addEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
|
||||
|
||||
// _addEdgeOnly(edge: E): boolean;
|
||||
|
||||
removeEdge(edge: E): E | null;
|
||||
|
||||
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
@ -1,4 +1,4 @@
|
|||
import {AVLTreeNode} from '../binary-tree';
|
||||
import {AVLTreeNode} from '../data-structures';
|
||||
import {IBST, IBSTNode} from './bst';
|
||||
import {BinaryTreeDeletedResult, BinaryTreeNodeId} from '../types';
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import {BinaryTreeNode} from '../binary-tree';
|
||||
import {BinaryTreeNode} from '../data-structures';
|
||||
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from './abstract-binary-tree';
|
||||
|
||||
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> extends IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
|
@ -1,4 +1,4 @@
|
|||
import {BSTNode} from '../binary-tree';
|
||||
import {BSTNode} from '../data-structures';
|
||||
import {IBinaryTree, IBinaryTreeNode} from './binary-tree';
|
||||
import {BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName} from '../types';
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import {RBTreeNode} from '../binary-tree';
|
||||
import {RBTreeNode} from '../data-structures';
|
||||
import {IBST, IBSTNode} from './bst';
|
||||
import {BinaryTreeNodeId} from '../types';
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import {TreeMultisetNode} from '../binary-tree';
|
||||
import {TreeMultisetNode} from '../data-structures';
|
||||
import {IBSTNode} from './bst';
|
||||
import {IAVLTree} from './avl-tree';
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import {AbstractBinaryTreeNode} from '../binary-tree';
|
||||
import {AbstractBinaryTreeNode} from '../../data-structures/binary-tree';
|
||||
|
||||
/**
|
||||
* Enum representing different loop types.
|
|
@ -1,4 +1,4 @@
|
|||
import {AVLTreeNode} from '../binary-tree';
|
||||
import {AVLTreeNode} from '../../data-structures/binary-tree';
|
||||
import {BSTOptions} from './bst';
|
||||
|
||||
export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
@ -1,4 +1,4 @@
|
|||
import {BinaryTreeNode} from '../binary-tree';
|
||||
import {BinaryTreeNode} from '../../data-structures/binary-tree';
|
||||
import {AbstractBinaryTreeOptions} from './abstract-binary-tree';
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import {BSTNode} from '../binary-tree';
|
||||
import {BSTNode} from '../../data-structures/binary-tree';
|
||||
import type {BinaryTreeOptions} from './binary-tree';
|
||||
import {BinaryTreeNodeId} from './abstract-binary-tree';
|
||||
|
|
@ -12,5 +12,4 @@ export * from './priority-queue';
|
|||
export * from './heap';
|
||||
export * from './singly-linked-list';
|
||||
export * from './doubly-linked-list';
|
||||
export * from './navigator';
|
||||
export * from './helpers';
|
||||
export * from './navigator';
|
|
@ -1,5 +1,5 @@
|
|||
import {BinaryTreeOptions} from './binary-tree';
|
||||
import {RBTreeNode} from '../binary-tree';
|
||||
import {RBTreeNode} from '../../data-structures/binary-tree';
|
||||
|
||||
export enum RBColor { RED = 'RED', BLACK = 'BLACK'}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import {TreeMultisetNode} from '../binary-tree';
|
||||
import {TreeMultisetNode} from '../../data-structures/binary-tree';
|
||||
import {AVLTreeOptions} from './avl-tree';
|
||||
|
||||
export type TreeMultisetNodeNested<T> = TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
3
src/types/index.ts
Normal file
3
src/types/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export * from './data-structures';
|
||||
export * from './helpers';
|
||||
export * from './utils';
|
|
@ -1,3 +1,2 @@
|
|||
export * from './utils';
|
||||
export * from './types';
|
||||
export * from './validate-type';
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
||||
* @license MIT License
|
||||
*/
|
||||
import type {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types';
|
||||
import type {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from '../types';
|
||||
|
||||
export const uuidV4 = function () {
|
||||
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {z} from 'zod';
|
||||
import {NonNumberNonObjectButDefined, ObjectWithNonNumberId, ObjectWithNumberId, ObjectWithoutId} from './types';
|
||||
import {NonNumberNonObjectButDefined, ObjectWithNonNumberId, ObjectWithNumberId, ObjectWithoutId} from '../types/utils';
|
||||
|
||||
|
||||
export const nonNumberNonObjectButDefinedSchema = z.union([z.string(),
|
||||
|
|
Loading…
Reference in a new issue