diff --git a/.gitignore b/.gitignore index 2f375a2..f8d6c46 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ dist/ __tests__/ notes/ +docs/ #.expo/* #web-build/ #.idea/ diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts index dcfb432..2bb0789 100644 --- a/src/data-structures/binary-tree/avl-tree.ts +++ b/src/data-structures/binary-tree/avl-tree.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {BST, BSTNode} from './bst'; diff --git a/src/data-structures/binary-tree/binary-indexed-tree.ts b/src/data-structures/binary-tree/binary-indexed-tree.ts index d7ab75a..e00a651 100644 --- a/src/data-structures/binary-tree/binary-indexed-tree.ts +++ b/src/data-structures/binary-tree/binary-indexed-tree.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ export class BinaryIndexedTree { diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index edb770c..5ed6018 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index 1abb12e..a7e73bd 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult} from '../types'; diff --git a/src/data-structures/binary-tree/segment-tree.ts b/src/data-structures/binary-tree/segment-tree.ts index ae0e1b9..7604f9f 100644 --- a/src/data-structures/binary-tree/segment-tree.ts +++ b/src/data-structures/binary-tree/segment-tree.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ diff --git a/src/data-structures/binary-tree/tree-multiset.ts b/src/data-structures/binary-tree/tree-multiset.ts index c72bff5..6b348ba 100644 --- a/src/data-structures/binary-tree/tree-multiset.ts +++ b/src/data-structures/binary-tree/tree-multiset.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {BST, BSTNode} from './bst'; diff --git a/src/data-structures/graph/abstract-graph.ts b/src/data-structures/graph/abstract-graph.ts index de6d339..5572d1d 100644 --- a/src/data-structures/graph/abstract-graph.ts +++ b/src/data-structures/graph/abstract-graph.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {arrayRemove, uuidV4} from '../../utils'; @@ -540,7 +540,7 @@ export abstract class AbstractGraph({comparator: (a, b) => a.id - b.id}); - heap.offer({id: 0, val: srcVertex}); + heap.add({id: 0, val: srcVertex}); distMap.set(srcVertex, 0); preMap.set(srcVertex, null); @@ -587,7 +587,7 @@ export abstract class AbstractGraph + * @copyright Tyler Zeng * @license MIT */ import {arrayRemove} from '../../utils'; diff --git a/src/data-structures/graph/undirected-graph.ts b/src/data-structures/graph/undirected-graph.ts index 63af3a2..6cc47c6 100644 --- a/src/data-structures/graph/undirected-graph.ts +++ b/src/data-structures/graph/undirected-graph.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {arrayRemove} from '../../utils'; diff --git a/src/data-structures/hash/coordinate-map.ts b/src/data-structures/hash/coordinate-map.ts index 8a7d3f6..1347aa1 100644 --- a/src/data-structures/hash/coordinate-map.ts +++ b/src/data-structures/hash/coordinate-map.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ export class CoordinateMap extends Map { diff --git a/src/data-structures/hash/coordinate-set.ts b/src/data-structures/hash/coordinate-set.ts index 072d4a0..17a5bde 100644 --- a/src/data-structures/hash/coordinate-set.ts +++ b/src/data-structures/hash/coordinate-set.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ export class CoordinateSet extends Set { diff --git a/src/data-structures/heap/heap.ts b/src/data-structures/heap/heap.ts index e9f2f38..2ccfc45 100644 --- a/src/data-structures/heap/heap.ts +++ b/src/data-structures/heap/heap.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {PriorityQueue} from '../priority-queue'; @@ -59,37 +59,37 @@ export abstract class Heap { } /** - * The `offer` function adds an element to a priority queue with an optional priority value. + * The `add` function adds an element to a priority queue with an optional priority value. * @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any * type. * @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the - * element being offered to the heap. If the `element` parameter is a number, then the `priority` parameter is set to + * element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to * the value of `element`. If the `element` parameter is not a number, then the - * @returns The `offer` method returns the instance of the `Heap` class. + * @returns The `add` method returns the instance of the `Heap` class. * @throws {Error} if priority is not a valid number */ - offer(element: T, priority?: number): Heap { + add(element: T, priority?: number): Heap { if (typeof element === 'number') { priority = element; } else { if (priority === undefined) { - throw new Error('.offer expects a numeric priority'); + throw new Error('.add expects a numeric priority'); } } if (priority && Number.isNaN(+priority)) { - throw new Error('.offer expects a numeric priority'); + throw new Error('.add expects a numeric priority'); } if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) { throw new Error( - '.offer expects a numeric priority ' + '.add expects a numeric priority ' + 'or a constructor callback that returns a number' ); } const _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element); - this._pq.offer({priority: _priority, element}); + this._pq.add({priority: _priority, element}); return this; } diff --git a/src/data-structures/heap/max-heap.ts b/src/data-structures/heap/max-heap.ts index 52ac777..c270fda 100644 --- a/src/data-structures/heap/max-heap.ts +++ b/src/data-structures/heap/max-heap.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ diff --git a/src/data-structures/heap/min-heap.ts b/src/data-structures/heap/min-heap.ts index e712ad5..6edf9c9 100644 --- a/src/data-structures/heap/min-heap.ts +++ b/src/data-structures/heap/min-heap.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ diff --git a/src/data-structures/linked-list/doubly-linked-list.ts b/src/data-structures/linked-list/doubly-linked-list.ts index fc9a13a..3dc6ced 100644 --- a/src/data-structures/linked-list/doubly-linked-list.ts +++ b/src/data-structures/linked-list/doubly-linked-list.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import type {DoublyLinkedListGetBy} from '../types'; @@ -34,7 +34,7 @@ export class DoublyLinkedList { * the doubly linked list. * @returns A boolean value is being returned. */ - offerFirst(val: T): boolean { + addFirst(val: T): boolean { const newNode = new DoublyLinkedListNode(val); if (this._size === 0) { this._first = newNode; @@ -54,7 +54,7 @@ export class DoublyLinkedList { * doubly linked list. * @returns a boolean value, which is always true. */ - offerLast(val: T): boolean { + addLast(val: T): boolean { const newNode = new DoublyLinkedListNode(val); if (this._size === 0) { this._first = newNode; @@ -247,8 +247,8 @@ export class DoublyLinkedList { */ insert(index: number, val: T): boolean { if (index < 0 || index > this._size) return false; - if (index === 0) return !!this.offerFirst(val); - if (index === this._size) return !!this.offerLast(val); + if (index === 0) return !!this.addFirst(val); + if (index === this._size) return !!this.addLast(val); const newNode = new DoublyLinkedListNode(val); const prevNode = this.get(index - 1, 'node'); diff --git a/src/data-structures/linked-list/singly-linked-list.ts b/src/data-structures/linked-list/singly-linked-list.ts index d7d757d..8971d59 100644 --- a/src/data-structures/linked-list/singly-linked-list.ts +++ b/src/data-structures/linked-list/singly-linked-list.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ diff --git a/src/data-structures/matrix/matrix.ts b/src/data-structures/matrix/matrix.ts index b255fdc..5f65e1e 100644 --- a/src/data-structures/matrix/matrix.ts +++ b/src/data-structures/matrix/matrix.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ // todo need to be improved diff --git a/src/data-structures/matrix/matrix2d.ts b/src/data-structures/matrix/matrix2d.ts index 6372bb5..9204110 100644 --- a/src/data-structures/matrix/matrix2d.ts +++ b/src/data-structures/matrix/matrix2d.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import Vector2D from './vector2d' diff --git a/src/data-structures/matrix/navigator.ts b/src/data-structures/matrix/navigator.ts index c52bfd8..fb00720 100644 --- a/src/data-structures/matrix/navigator.ts +++ b/src/data-structures/matrix/navigator.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import type {Direction, NavigatorParams, Turning} from '../types'; diff --git a/src/data-structures/matrix/vector2d.ts b/src/data-structures/matrix/vector2d.ts index 38390bf..b23213b 100644 --- a/src/data-structures/matrix/vector2d.ts +++ b/src/data-structures/matrix/vector2d.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ export class Vector2D { diff --git a/src/data-structures/priority-queue/max-priority-queue.ts b/src/data-structures/priority-queue/max-priority-queue.ts index 329952f..4ff881c 100644 --- a/src/data-structures/priority-queue/max-priority-queue.ts +++ b/src/data-structures/priority-queue/max-priority-queue.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {PriorityQueue} from './priority-queue'; diff --git a/src/data-structures/priority-queue/min-priority-queue.ts b/src/data-structures/priority-queue/min-priority-queue.ts index b0a7539..9e3c9d7 100644 --- a/src/data-structures/priority-queue/min-priority-queue.ts +++ b/src/data-structures/priority-queue/min-priority-queue.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {PriorityQueue} from './priority-queue'; diff --git a/src/data-structures/priority-queue/priority-queue.ts b/src/data-structures/priority-queue/priority-queue.ts index 36bf1b0..c25da51 100644 --- a/src/data-structures/priority-queue/priority-queue.ts +++ b/src/data-structures/priority-queue/priority-queue.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import type {PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions} from '../types'; @@ -52,11 +52,11 @@ export class PriorityQueue { } /** - * The "offer" function adds a node to the heap and ensures that the heap property is maintained. + * The "add" function adds a node to the heap and ensures that the heap property is maintained. * @param {T} node - The parameter "node" is of type T, which means it can be any data type. It represents the node * that needs to be added to the heap. */ - offer(node: T) { + add(node: T) { this.nodes.push(node); this._heapifyUp(this.size - 1); } diff --git a/src/data-structures/queue/deque.ts b/src/data-structures/queue/deque.ts index 96dae61..02b3a1d 100644 --- a/src/data-structures/queue/deque.ts +++ b/src/data-structures/queue/deque.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {DoublyLinkedList} from '../linked-list'; @@ -28,7 +28,7 @@ export class ObjectDeque { return this._size; } - offerFirst(value: T) { + addFirst(value: T) { if (this._size === 0) { const mid = Math.floor(this._capacity / 2); this._first = mid; @@ -40,7 +40,7 @@ export class ObjectDeque { this._size++; } - offerLast(value: T) { + addLast(value: T) { if (this._size === 0) { const mid = Math.floor(this._capacity / 2); this._first = mid; @@ -98,11 +98,11 @@ export class ArrayDeque { } /** - * The function "offerLast" adds a value to the end of an array. + * The function "addLast" adds a value to the end of an array. * @param {T} value - The value parameter represents the value that you want to add to the end of the array. * @returns The return value is the new length of the array after the value has been added. */ - offerLast(value: T) { + addLast(value: T) { return this._nodes.push(value); } @@ -124,12 +124,12 @@ export class ArrayDeque { } /** - * The function "offerFirst" adds a value to the beginning of an array. + * The function "addFirst" adds a value to the beginning of an array. * @param {T} value - The value parameter represents the value that you want to add to the beginning of the array. - * @returns The return value of the `offerFirst` function is the new length of the array `_nodes` after adding the + * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the * `value` at the beginning. */ - offerFirst(value: T) { + addFirst(value: T) { return this._nodes.unshift(value); } diff --git a/src/data-structures/queue/queue.ts b/src/data-structures/queue/queue.ts index 2eba8f9..a709f14 100644 --- a/src/data-structures/queue/queue.ts +++ b/src/data-structures/queue/queue.ts @@ -1,6 +1,6 @@ /** * @license MIT - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @class */ export class Queue { @@ -31,11 +31,11 @@ export class Queue { } /** - * The offer function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue. + * The add function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue. * @param {T} element - The `element` parameter represents the element that you want to add to the queue. - * @returns The `offer` method is returning a `Queue` object. + * @returns The `add` method is returning a `Queue` object. */ - offer(element: T): Queue { + add(element: T): Queue { this._nodes.push(element); return this; } diff --git a/src/data-structures/stack/stack.ts b/src/data-structures/stack/stack.ts index 19405ca..3ad714f 100644 --- a/src/data-structures/stack/stack.ts +++ b/src/data-structures/stack/stack.ts @@ -1,6 +1,6 @@ /** * @license MIT - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @class */ export class Stack { diff --git a/src/data-structures/trie/trie.ts b/src/data-structures/trie/trie.ts index d162535..638ec91 100644 --- a/src/data-structures/trie/trie.ts +++ b/src/data-structures/trie/trie.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ export class TrieNode { diff --git a/src/utils/trampoline.ts b/src/utils/trampoline.ts index 9b5f306..c3649c4 100644 --- a/src/utils/trampoline.ts +++ b/src/utils/trampoline.ts @@ -1,5 +1,5 @@ /** - * @copyright 2030 Tyler Zeng + * @copyright Tyler Zeng * @license MIT */ import {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types'; diff --git a/tests/unit/data-structures/graph/directed-graph.test.ts b/tests/unit/data-structures/graph/directed-graph.test.ts index c5c1ef2..7d034df 100644 --- a/tests/unit/data-structures/graph/directed-graph.test.ts +++ b/tests/unit/data-structures/graph/directed-graph.test.ts @@ -1,5 +1,6 @@ import { DirectedGraph, DirectedVertex, DirectedEdge } from '../../../../src'; +// TODO too few unit tests describe('DirectedGraph', () => { let graph: DirectedGraph;