Skip to content

Commit

Permalink
[IMP] helpers: recomputeZone handles zone and unboundedZone
Browse files Browse the repository at this point in the history
The recent refactoring of `recomputeZone` was typed such that it could
only handle unbounded zones.

Part-of: #4125
  • Loading branch information
Adrien Minne (adrm) authored and rrahir committed Apr 24, 2024
1 parent b69b816 commit 4de08fa
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/helpers/recompute_zones.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deepEqualsArray } from "../helpers/misc";
import { UnboundedZone } from "../types";
import { UnboundedZone, Zone } from "../types";

/**
* ####################################################
Expand Down Expand Up @@ -128,10 +128,10 @@ import { UnboundedZone } from "../types";
* - you will find coordinate of a cell only once among all the zones
* - the number of zones will be reduced to the minimum
*/
export function recomputeZones(
zones: UnboundedZone[],
zonesToRemove: UnboundedZone[]
): UnboundedZone[] {
export function recomputeZones<T extends Zone | UnboundedZone>(
zones: T[],
zonesToRemove: T[]
): T[] {
const profilesStartingPosition: number[] = [0];
const profiles = new Map<number, number[]>([[0, []]]);

Expand All @@ -140,10 +140,10 @@ export function recomputeZones(
return constructZonesFromProfiles(profilesStartingPosition, profiles);
}

export function modifyProfiles( // export for testing only
export function modifyProfiles<T extends Zone | UnboundedZone>( // export for testing only
profilesStartingPosition: number[],
profiles: Map<number, number[]>,
zones: UnboundedZone[],
zones: T[],
toRemove: boolean = false
) {
for (const zone of zones) {
Expand Down Expand Up @@ -298,10 +298,10 @@ function removeContiguousProfiles(
}
}

function constructZonesFromProfiles(
function constructZonesFromProfiles<T extends Zone | UnboundedZone>(
profilesStartingPosition: number[],
profiles: Map<number, number[]>
): UnboundedZone[] {
): T[] {
const mergedZone: UnboundedZone[] = [];
let pendingZones: UnboundedZone[] = [];
for (let colIndex = 0; colIndex < profilesStartingPosition.length; colIndex++) {
Expand Down Expand Up @@ -353,7 +353,7 @@ function constructZonesFromProfiles(
pendingZones = nextPendingZones;
}
mergedZone.push(...pendingZones);
return mergedZone;
return mergedZone as T[];
}

function binaryPredecessorSearch(arr: number[], val: number, start = 0, matchEqual = true) {
Expand Down

0 comments on commit 4de08fa

Please sign in to comment.