Skip to content

Commit

Permalink
fix linter "no-use-before-define", move to the top of file
Browse files Browse the repository at this point in the history
  • Loading branch information
kmorcinek committed Feb 27, 2023
1 parent aca0a60 commit 6390bda
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions src/ProvinceNeighborhood.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
import { IProvinceNeighbourhoodProvider } from "./ProvinceNeighborhood/IProvinceNeighbourhoodProvider";
import { IProvinceMapValidator } from "./ProvinceNeighborhood/IProvinceMapValidator";

class Cache<T> {
dictionary: Record<string, T> = {};

getCached(source: string, target: string, getFreshData: (a: string, b: string) => T): T {
const key = Cache.concatWay(source, target);
const cachedData = this.dictionary[key];
if (cachedData !== undefined) {
return cachedData;
}

const freshData = getFreshData(source, target);
this.dictionary[key] = freshData;
return freshData;
}

// tslint:disable-next-line: member-ordering
private static concatWay(source: string, target: string) {
return source + ";" + target;
}
}

class DistanceAndPath {
static Empty = new DistanceAndPath(300, []);

static min(first: DistanceAndPath, second: DistanceAndPath) {
return first.distance < second.distance ? first : second;
}

static create(path: string[]) {
return new DistanceAndPath(path.length, path);
}

distance: number;
path: string[];

private constructor(distance: number, path: string[]) {
this.distance = distance;
this.path = path;
}
}

export class ProvinceNeighborhood {
private readonly neighbourhoodProviders: IProvinceNeighbourhoodProvider[];
private readonly provinceMapValidator: IProvinceMapValidator;
Expand Down Expand Up @@ -128,44 +169,3 @@ export class ProvinceNeighborhood {
}
}
}

class Cache<T> {
dictionary: Record<string, T> = {};

getCached(source: string, target: string, getFreshData: (a: string, b: string) => T): T {
const key = Cache.concatWay(source, target);
const cachedData = this.dictionary[key];
if (cachedData !== undefined) {
return cachedData;
}

const freshData = getFreshData(source, target);
this.dictionary[key] = freshData;
return freshData;
}

// tslint:disable-next-line: member-ordering
private static concatWay(source: string, target: string) {
return source + ";" + target;
}
}

class DistanceAndPath {
static Empty = new DistanceAndPath(300, []);

static min(first: DistanceAndPath, second: DistanceAndPath) {
return first.distance < second.distance ? first : second;
}

static create(path: string[]) {
return new DistanceAndPath(path.length, path);
}

distance: number;
path: string[];

private constructor(distance: number, path: string[]) {
this.distance = distance;
this.path = path;
}
}

0 comments on commit 6390bda

Please sign in to comment.