Skip to content

Commit

Permalink
calling functions provide conditional checks in cache when retrieving…
Browse files Browse the repository at this point in the history
… frames by time or frame number
  • Loading branch information
interim17 committed Oct 8, 2024
1 parent 7aadb37 commit 346cf56
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/simularium/VisDataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,14 @@ class VisDataCache {
return this.tail?.data.time || -1;
}

private getFrameAtTimeOrFrameNumber(
condition: "time" | "frameNumber",
private getFrameAtCondition(
condition: (data: CacheNode) => boolean,
value: number
): CachedFrame {
if (!this.head) {
return this.frameAccessError("No data in cache.");
}
const frame = this.walkLinkedList(
(node) => node.data[condition] === value
);
const frame = this.walkLinkedList(condition);
if (frame) {
return frame.data;
}
Expand All @@ -166,11 +164,17 @@ class VisDataCache {
}

public getFrameAtTime(time: number): CachedFrame {
return this.getFrameAtTimeOrFrameNumber("time", time);
return this.getFrameAtCondition(
(node) => compareTimes(node.data.time, time, 0) === 0,
time
);
}

public getFrameAtFrameNumber(frameNumber: number): CachedFrame {
return this.getFrameAtTimeOrFrameNumber("frameNumber", frameNumber);
return this.getFrameAtCondition(
(node) => node.data["frameNumber"] === frameNumber,
frameNumber
);
}

public assignSingleFrameToCache(data: CachedFrame): void {
Expand Down

0 comments on commit 346cf56

Please sign in to comment.