mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 12:54:04 +00:00
fix: type error fixed. docs: Remove unnecessary 'Software Engineering Design Standards'.
This commit is contained in:
parent
7c6e5d3b1c
commit
d3a6bdac25
|
@ -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
|
||||
|
||||
|
|
108
README.md
108
README.md
|
@ -71,54 +71,6 @@ const {
|
|||
} = dataStructureTyped;
|
||||
```
|
||||
|
||||
## Software Engineering Design Standards
|
||||
<table>
|
||||
<tr>
|
||||
<th>Principle</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Practicality</td>
|
||||
<td>Follows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Extensibility</td>
|
||||
<td>Adheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Modularization</td>
|
||||
<td>Includes data structure modularization and independent NPM packages.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Efficiency</td>
|
||||
<td>All methods provide time and space complexity, comparable to native JS performance.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Maintainability</td>
|
||||
<td>Follows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Testability</td>
|
||||
<td>Automated and customized unit testing, performance testing, and integration testing.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Portability</td>
|
||||
<td>Plans for porting to Java, Python, and C++, currently achieved to 80%.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Reusability</td>
|
||||
<td>Fully decoupled, minimized side effects, and adheres to OOP.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Security</td>
|
||||
<td>Carefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Scalability</td>
|
||||
<td>Data structure software does not involve load issues.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## 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
|
||||
<table>
|
||||
<tr>
|
||||
<th>Principle</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Practicality</td>
|
||||
<td>Follows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Extensibility</td>
|
||||
<td>Adheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Modularization</td>
|
||||
<td>Includes data structure modularization and independent NPM packages.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Efficiency</td>
|
||||
<td>All methods provide time and space complexity, comparable to native JS performance.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Maintainability</td>
|
||||
<td>Follows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Testability</td>
|
||||
<td>Automated and customized unit testing, performance testing, and integration testing.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Portability</td>
|
||||
<td>Plans for porting to Java, Python, and C++, currently achieved to 80%.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Reusability</td>
|
||||
<td>Fully decoupled, minimized side effects, and adheres to OOP.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Security</td>
|
||||
<td>Carefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Scalability</td>
|
||||
<td>Data structure software does not involve load issues.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -7,23 +7,17 @@
|
|||
*/
|
||||
|
||||
import { isWeakKey, rangeCheck } from '../../utils';
|
||||
import { HashMapLinkedNode } from '../../types';
|
||||
|
||||
type HashMapOptions<K, V> = {
|
||||
elements: Iterable<[K, V]>;
|
||||
hashFn: (key: K) => string;
|
||||
objHashFn: (key: K) => WeakKey
|
||||
}
|
||||
import { HashMapLinkedNode, HashMapOptions } from '../../types';
|
||||
|
||||
export class HashMap<K = any, V = any> {
|
||||
|
||||
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>> = {};
|
||||
protected _objMap = new WeakMap<WeakKey, HashMapLinkedNode<K, V | undefined>>();
|
||||
protected _objMap = new WeakMap<object, HashMapLinkedNode<K, V | undefined>>();
|
||||
protected _head: HashMapLinkedNode<K, V | undefined>;
|
||||
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
||||
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
||||
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<K = any, V = any> {
|
|||
constructor(options: HashMapOptions<K, V> = {
|
||||
elements: [],
|
||||
hashFn: (key: K) => String(key),
|
||||
objHashFn: (key: K) => (<WeakKey>key)
|
||||
objHashFn: (key: K) => (<object>key)
|
||||
}) {
|
||||
this._sentinel = <HashMapLinkedNode<K, V>>{};
|
||||
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
||||
|
@ -120,8 +114,7 @@ export class HashMap<K = any, V = any> {
|
|||
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) {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export {};
|
|
@ -1 +0,0 @@
|
|||
export {};
|
|
@ -4,3 +4,9 @@ export type HashMapLinkedNode<K, V> = {
|
|||
next: HashMapLinkedNode<K, V>;
|
||||
prev: HashMapLinkedNode<K, V>;
|
||||
};
|
||||
|
||||
export type HashMapOptions<K, V> = {
|
||||
elements: Iterable<[K, V]>;
|
||||
hashFn: (key: K) => string;
|
||||
objHashFn: (key: K) => object
|
||||
}
|
||||
|
|
|
@ -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<K> = (key: K) => number;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export {};
|
|
@ -1 +0,0 @@
|
|||
export {};
|
|
@ -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';
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue