JSR?
This commit is contained in:
25 files changed
+186
-94
No files matched your search
@@ -24,7 +24,7 @@ export class BinaryHeap<T> implements Iterable<T> {
|
||||
for (const el of initials) this.push(el)
|
||||
}
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
*[Symbol.iterator](): Generator<NonNullable<T>, void, unknown> {
|
||||
while (this.length !== 0) yield this.pop()!
|
||||
}
|
||||
|
||||
@@ -112,5 +112,5 @@ export class BinaryHeap<T> implements Iterable<T> {
|
||||
}
|
||||
|
||||
/** The number of elements in the heap */
|
||||
get length() { return this.#elements.length }
|
||||
get length(): number { return this.#elements.length }
|
||||
}
|
||||
@@ -69,11 +69,11 @@ export class Memo<A extends unknown[], R extends unknown> {
|
||||
return result
|
||||
}
|
||||
|
||||
get ratio() {
|
||||
get ratio(): number {
|
||||
return this.hits / (this.hits + this.misses)
|
||||
}
|
||||
|
||||
get fn() {
|
||||
get fn(): (...args: A) => R {
|
||||
return this.#memoHandler.bind(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,11 @@ export class Queue<T> implements Iterable<T> {
|
||||
}
|
||||
|
||||
/** The number of elements remaining in the queue */
|
||||
get length() { return this.#tail - this.#head }
|
||||
get length(): number {
|
||||
return this.#tail - this.#head
|
||||
}
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
*[Symbol.iterator](): Generator<NonNullable<T>, void, unknown> {
|
||||
while (this.length !== 0) yield this.pop()!
|
||||
}
|
||||
}
|
||||
@@ -35,9 +35,9 @@ export class Stack<T> implements Iterable<T> {
|
||||
}
|
||||
|
||||
/** The number of elements remaining in the stack */
|
||||
get length() { return this.#head }
|
||||
get length(): number { return this.#head }
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
*[Symbol.iterator](): Generator<NonNullable<T>, void, unknown> {
|
||||
while (this.length !== 0) yield this.pop()!
|
||||
}
|
||||
}
|
||||
@@ -25,26 +25,28 @@ export class StateMachine<State extends string | number | symbol = 0, InputAlpha
|
||||
this.reset()
|
||||
}
|
||||
|
||||
runWithInput(elements: Iterable<InputAlphabet>) {
|
||||
runWithInput(elements: Iterable<InputAlphabet>): this {
|
||||
for (const element of elements) {
|
||||
this.transitionWith(element)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
transitionWith(input: InputAlphabet) {
|
||||
transitionWith(input: InputAlphabet): this {
|
||||
const fn = this.#transitionTable[this.currentState]
|
||||
if (!fn) throw new Error(`No transition function for state ${String(this.currentState)}`)
|
||||
fn.call(this, input, this)
|
||||
return this
|
||||
}
|
||||
|
||||
goto(state: State) {
|
||||
goto(state: State): this {
|
||||
this.currentState = state
|
||||
return this
|
||||
}
|
||||
|
||||
accepts(state = this.currentState) { return this.#acceptStates.has(state) }
|
||||
accepts(state = this.currentState): boolean {
|
||||
return this.#acceptStates.has(state)
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.currentState = this.#initialState
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export * as DisjointSet from './DisjointSet.ts'
|
||||
export * as Heap from './Heap.ts'
|
||||
export * as Memo from './Memo.ts'
|
||||
export * as Queue from './Queue.ts'
|
||||
export * as Stack from './Stack.ts'
|
||||
export * as StateMachine from './StateMachine.ts'
|
||||
Reference in new issue
Block a user