diff --git a/packages/heaps/src/dheap.ts b/packages/heaps/src/dheap.ts index b12ec70de3..fb6f5deeb5 100644 --- a/packages/heaps/src/dheap.ts +++ b/packages/heaps/src/dheap.ts @@ -2,6 +2,7 @@ import { compare } from "@thi.ng/api/compare"; import { DHeapOpts } from "./api"; import { Heap } from "./heap"; +import { ICopy, IEmpty } from "@thi.ng/api/api"; /** * Generic d-ary heap / priority queue with configurable arity (default @@ -12,7 +13,9 @@ import { Heap } from "./heap"; * * https://en.wikipedia.org/wiki/D-ary_heap */ -export class DHeap extends Heap { +export class DHeap extends Heap implements + ICopy>, + IEmpty> { /** * Returns index of parent node or -1 if `idx < 1`. @@ -45,6 +48,14 @@ export class DHeap extends Heap { } } + copy() { + return >super.copy(); + } + + empty() { + return new DHeap(null, { compare: this.compare, d: this.d }); + } + parent(n: number) { n = DHeap.parentIndex(n, this.d); return n >= 0 ? this.values[n] : undefined;