Skip to content

Commit

Permalink
fix: type error fixed. docs: Remove unnecessary 'Software Engineering…
Browse files Browse the repository at this point in the history
… Design Standards'.
  • Loading branch information
zrwusa committed Nov 20, 2023
1 parent 7c6e5d3 commit d3a6bda
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 84 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
108 changes: 47 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 5 additions & 12 deletions src/data-structures/hash/hash-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/types/data-structures/hash/coordinate-map.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/types/data-structures/hash/coordinate-set.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/types/data-structures/hash/hash-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 0 additions & 4 deletions src/types/data-structures/hash/index.ts
Original file line number Diff line number Diff line change
@@ -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 change: 0 additions & 1 deletion src/types/data-structures/hash/tree-map.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/types/data-structures/hash/tree-set.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};
Expand Down

0 comments on commit d3a6bda

Please sign in to comment.