Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jokester committed Apr 20, 2024
1 parent b69c516 commit 94dc64b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/collection/min-heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class MinHeap<T> {
this.tree[i] = value;

while (i && isBefore(this.order, value /* i.e. this.tree[i] */, this.tree[j])) {
// pop up new value
this.tree[i] = this.tree[j];
this.tree[j] = value;

Expand Down Expand Up @@ -134,7 +135,7 @@ export class MinHeap<T> {
private assertInvariants() {
for (let i = 1; i < this.tree.length; i++) {
const p = positions.parent(i);
if (!this.order.compare(this.tree[p], this.tree[i])) {
if (!isBefore(this.order, this.tree[p], this.tree[i])) {
throw new Error(`MinHeap#assertInvariants(): expected this.tree[${p} to be ordered before this.tree[${i}]`);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/collection/multiset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Multiset } from './multiset';

describe(Multiset, () => {
it('keeps elements and count', () => {
const testee = new Multiset<string>(false);
const testee = new Multiset<string>();

testee.setCount('abc', 1);
testee.setCount('abc', 2);
Expand All @@ -17,7 +17,7 @@ describe(Multiset, () => {
testee.setCount('abc', 1);
testee.setCount('abc', 1);
testee.setCount('abc', 0);
expect(testee.maxCount()).toEqual(1);
expect(testee.maxCount()).toBe(1);
expect(testee.getCount('abc')).toEqual(0);
expect(testee.getCount('abd')).toEqual(1);
expect(testee.findByCount(0)).toEqual(['abc']);
Expand Down
4 changes: 1 addition & 3 deletions src/collection/multiset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ export class Multiset<T> {
private map = new DefaultMap</* count */ number, /* objects */ Set<T>>((k) => new Set());
private countMap = new Map</* object*/ T, /* count */ number>();

constructor(readonly removeOnZeroFreq = true) {}

setCount(obj: T, count: number): void {
const existedCount = this.countMap.get(obj);

Expand All @@ -18,7 +16,7 @@ export class Multiset<T> {

const existedSet = this.map.get(existedCount)!;

Check warning on line 17 in src/collection/multiset.ts

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion
existedSet.delete(obj);
if (!existedSet.size && this.removeOnZeroFreq) {
if (!existedSet.size) {
this.map.delete(existedCount);
}
} else {
Expand Down

0 comments on commit 94dc64b

Please sign in to comment.