-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Heap interface - Add BinaryHeap implementation - Add tests for BinaryHeap - Refactor list util methods - Refactor heap util methods
- Loading branch information
1 parent
c9baa64
commit dba59a5
Showing
18 changed files
with
671 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,77 @@ | ||
import { Sorted } from '..'; | ||
|
||
/** | ||
* | ||
*/ | ||
export interface Heap<T> extends Iterable<T>, Sorted<T> { | ||
/** | ||
* | ||
*/ | ||
clear(): void; | ||
comparator(): Comparator<T>; | ||
heapify(...iterables: Iterable<T>[]): Heap<T>; | ||
merge(heap: Heap<T>): Heap<T>; | ||
/** | ||
* | ||
* @param element | ||
*/ | ||
contains(element: T): boolean; | ||
/** | ||
* | ||
* Aka extract, remove | ||
* @param element | ||
* | ||
* @returns | ||
*/ | ||
delete(element: T): boolean; | ||
/** | ||
* | ||
*/ | ||
dump(): Iterable<T>; | ||
/** | ||
* | ||
* @param elements | ||
* @returns | ||
*/ | ||
merge(elements: Iterable<T>): number; | ||
/** | ||
* | ||
* @returns | ||
*/ | ||
peek(): T | undefined; | ||
pop(): T | undefined; // Aka extract, delete | ||
/** | ||
* | ||
* @returns | ||
*/ | ||
pop(): T | undefined; | ||
/** | ||
* | ||
* @param element | ||
* | ||
* @returns | ||
*/ | ||
push(element: T): number; // Aka insert, add | ||
/** | ||
* | ||
* @param element | ||
* | ||
* @returns | ||
*/ | ||
pushPop(element: T): T; | ||
replace(element: T): T; // Aka popPush | ||
/** | ||
* | ||
* @param element | ||
* | ||
* @returns | ||
*/ | ||
replace(element: T): T | undefined; // Aka popPush | ||
/** | ||
* | ||
*/ | ||
readonly size: number; | ||
} | ||
|
||
export interface Comparator<T> { | ||
compare: CompareFn<T>; | ||
} | ||
|
||
export interface CompareFn<T> { | ||
(a: T, b: T): number; | ||
} | ||
|
||
export interface Sortable<T> { | ||
sort: SortFn<T>; | ||
} | ||
|
||
export interface SortFn<T> { | ||
(compare: CompareFn<T>): void; | ||
} | ||
|
||
export interface Sorted<T> { | ||
comparator(): Comparator<T>; | ||
/** | ||
* | ||
* @param curElement | ||
* @param newElement | ||
* | ||
* @returns | ||
*/ | ||
update(curElement: T, newElement: T): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
export * from './binaryHeap'; | ||
export * from './binaryMaxHeap'; | ||
export * from './binaryMinHeap'; | ||
export * from './heap'; |
Oops, something went wrong.