-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix memory explosion in typescript variant
- Loading branch information
Showing
6 changed files
with
82 additions
and
59 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 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {NumberToNumberArray, NumberToNumberMapInterface} from "./maps"; | ||
import {AssignmentMapArray, AssignmentMapInterface} from "./maps"; | ||
|
||
export class Iteration { | ||
private points: number | null = null; | ||
assignments: AssignmentMapInterface = new AssignmentMapArray(); | ||
seminarCapacity: NumberToNumberMapInterface = new NumberToNumberArray(); | ||
pointsPerStudent: NumberToNumberMapInterface = new NumberToNumberArray(); | ||
|
||
/** | ||
* Returns the total points of this iteration. Once calculated, the value is cached. | ||
*/ | ||
totalPoints(): number { | ||
if (!this.points) { | ||
this.points = this.pointsPerStudent.getAllValues().reduce((a, b) => a + b, 0); | ||
} | ||
return this.points; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {Student} from "./student"; | ||
import {Seminar} from "./seminar"; | ||
|
||
export interface AssignmentMapInterface { | ||
get: (s: Student) => { wSeminar?: Seminar, pSeminar?: Seminar } | undefined | ||
set: (s: Student, value: { wSeminar?: Seminar, pSeminar?: Seminar }) => void | ||
} | ||
|
||
export class AssignmentMapArray implements AssignmentMapInterface { | ||
readonly a: Array<{ wSeminar?: Seminar; pSeminar?: Seminar }> = [] | ||
|
||
get(s: Student): { wSeminar?: Seminar; pSeminar?: Seminar } | undefined { | ||
return this.a[s.id]; | ||
} | ||
|
||
set(s: Student, value: { wSeminar?: Seminar; pSeminar?: Seminar }): void { | ||
this.a[s.id] = value; | ||
} | ||
} | ||
|
||
export interface NumberToNumberMapInterface { | ||
get: (id: number) => number | undefined | ||
set: (id: number, value: number) => void | ||
getAllValues: () => number[] | ||
} | ||
|
||
export class NumberToNumberArray implements NumberToNumberMapInterface { | ||
readonly a: number[] = [] | ||
get(id: number): number | undefined { | ||
return (this.a)[id]; | ||
} | ||
|
||
set(id: number, value: number): void { | ||
this.a[id] = value; | ||
} | ||
|
||
getAllValues(): number[] { | ||
return this.a; | ||
} | ||
} |
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