From d3a6bdac2598cc4bb19fdb34aeab27c3a10fb733 Mon Sep 17 00:00:00 2001 From: Revone Date: Mon, 20 Nov 2023 15:14:13 +0800 Subject: [PATCH] fix: type error fixed. docs: Remove unnecessary 'Software Engineering Design Standards'. --- CHANGELOG.md | 2 +- README.md | 108 ++++++++---------- package.json | 2 +- src/data-structures/hash/hash-map.ts | 17 +-- .../data-structures/hash/coordinate-map.ts | 1 - .../data-structures/hash/coordinate-set.ts | 1 - src/types/data-structures/hash/hash-map.ts | 6 + src/types/data-structures/hash/index.ts | 4 - src/types/data-structures/hash/tree-map.ts | 1 - src/types/data-structures/hash/tree-set.ts | 1 - src/utils/utils.ts | 2 +- 11 files changed, 61 insertions(+), 84 deletions(-) delete mode 100644 src/types/data-structures/hash/coordinate-map.ts delete mode 100644 src/types/data-structures/hash/coordinate-set.ts delete mode 100644 src/types/data-structures/hash/tree-map.ts delete mode 100644 src/types/data-structures/hash/tree-set.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 82e5ebe..5935ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.46.3](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) +## [v1.46.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) ### Changes diff --git a/README.md b/README.md index cac3c3b..72dba58 100644 --- a/README.md +++ b/README.md @@ -71,54 +71,6 @@ const { } = dataStructureTyped; ``` -## Software Engineering Design Standards - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PrincipleDescription
PracticalityFollows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names.
ExtensibilityAdheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures.
ModularizationIncludes data structure modularization and independent NPM packages.
EfficiencyAll methods provide time and space complexity, comparable to native JS performance.
MaintainabilityFollows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns.
TestabilityAutomated and customized unit testing, performance testing, and integration testing.
PortabilityPlans for porting to Java, Python, and C++, currently achieved to 80%.
ReusabilityFully decoupled, minimized side effects, and adheres to OOP.
SecurityCarefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects.
ScalabilityData structure software does not involve load issues.
- ## Vivid Examples ### Binary Tree @@ -859,16 +811,50 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', ' [//]: # (No deletion!!! End of Replace Section) -## Codebase design - -### Adhere to ES6 and ESNext standard naming conventions for APIs. - -Standardize API conventions by using 'add' and 'delete' for element manipulation methods in all data structures. - -Opt for concise and clear method names, avoiding excessive length while ensuring explicit intent. - -### Object-oriented programming(OOP) - -By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultimap), you can seamlessly -inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the -optimal approach to data structure design. +## Software Engineering Design Standards + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PrincipleDescription
PracticalityFollows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names.
ExtensibilityAdheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures.
ModularizationIncludes data structure modularization and independent NPM packages.
EfficiencyAll methods provide time and space complexity, comparable to native JS performance.
MaintainabilityFollows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns.
TestabilityAutomated and customized unit testing, performance testing, and integration testing.
PortabilityPlans for porting to Java, Python, and C++, currently achieved to 80%.
ReusabilityFully decoupled, minimized side effects, and adheres to OOP.
SecurityCarefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects.
ScalabilityData structure software does not involve load issues.
diff --git a/package.json b/package.json index 1ea67df..32f2503 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.46.3", + "version": "1.46.5", "description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.", "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", diff --git a/src/data-structures/hash/hash-map.ts b/src/data-structures/hash/hash-map.ts index 67bf244..c7a0d4d 100644 --- a/src/data-structures/hash/hash-map.ts +++ b/src/data-structures/hash/hash-map.ts @@ -7,23 +7,17 @@ */ import { isWeakKey, rangeCheck } from '../../utils'; -import { HashMapLinkedNode } from '../../types'; - -type HashMapOptions = { - elements: Iterable<[K, V]>; - hashFn: (key: K) => string; - objHashFn: (key: K) => WeakKey -} +import { HashMapLinkedNode, HashMapOptions } from '../../types'; export class HashMap { protected _noObjMap: Record> = {}; - protected _objMap = new WeakMap>(); + protected _objMap = new WeakMap>(); protected _head: HashMapLinkedNode; protected _tail: HashMapLinkedNode; protected readonly _sentinel: HashMapLinkedNode; protected _hashFn: (key: K) => string; - protected _objHashFn: (key: K) => WeakKey; + protected _objHashFn: (key: K) => object; /** * The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs. @@ -33,7 +27,7 @@ export class HashMap { constructor(options: HashMapOptions = { elements: [], hashFn: (key: K) => String(key), - objHashFn: (key: K) => (key) + objHashFn: (key: K) => (key) }) { this._sentinel = >{}; this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel; @@ -120,8 +114,7 @@ export class HashMap { let node; if (isWeakKey(key)) { - // const hash = this._objHashFn(key); - const hash = key; + const hash = this._objHashFn(key); node = this._objMap.get(hash); if (node) { diff --git a/src/types/data-structures/hash/coordinate-map.ts b/src/types/data-structures/hash/coordinate-map.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/src/types/data-structures/hash/coordinate-map.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/src/types/data-structures/hash/coordinate-set.ts b/src/types/data-structures/hash/coordinate-set.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/src/types/data-structures/hash/coordinate-set.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/src/types/data-structures/hash/hash-map.ts b/src/types/data-structures/hash/hash-map.ts index b748717..b7a4558 100644 --- a/src/types/data-structures/hash/hash-map.ts +++ b/src/types/data-structures/hash/hash-map.ts @@ -4,3 +4,9 @@ export type HashMapLinkedNode = { next: HashMapLinkedNode; prev: HashMapLinkedNode; }; + +export type HashMapOptions = { + elements: Iterable<[K, V]>; + hashFn: (key: K) => string; + objHashFn: (key: K) => object +} diff --git a/src/types/data-structures/hash/index.ts b/src/types/data-structures/hash/index.ts index 9d87f1b..bda3af6 100644 --- a/src/types/data-structures/hash/index.ts +++ b/src/types/data-structures/hash/index.ts @@ -1,8 +1,4 @@ -export * from './coordinate-map'; -export * from './coordinate-set'; export * from './hash-map'; export * from './hash-table'; -export * from './tree-map'; -export * from './tree-set'; export type HashFunction = (key: K) => number; diff --git a/src/types/data-structures/hash/tree-map.ts b/src/types/data-structures/hash/tree-map.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/src/types/data-structures/hash/tree-map.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/src/types/data-structures/hash/tree-set.ts b/src/types/data-structures/hash/tree-set.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/src/types/data-structures/hash/tree-set.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 0b676b5..471ab63 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -93,7 +93,7 @@ export const throwRangeError = (message = 'The value is off-limits.'): void => { throw new RangeError(message); }; -export const isWeakKey = (input: unknown): input is WeakKey => { +export const isWeakKey = (input: unknown): input is object => { const inputType = typeof input; return (inputType === 'object' && input !== null) || inputType === 'function'; };