Skip to content

Commit

Permalink
O(1) UUIDs lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ekuiter committed Nov 20, 2018
1 parent 165ea2f commit a8001b1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions client/src/modeling/GraphicalFeatureModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class GraphicalFeatureModel {
_actualNodes: GraphicalFeatureNode[];
_visibleNodes: GraphicalFeatureNode[];
_constraints: GraphicalConstraint[];
_UUIDsToFeatures: {[x: string]: GraphicalFeatureNode} = {};

// feature model as supplied by feature model messages from the server
static fromJSON(serializedFeatureModel: SerializedFeatureModel): GraphicalFeatureModel {
Expand Down Expand Up @@ -254,6 +255,8 @@ class GraphicalFeatureModel {

if (isVisible(node))
this._visibleNodes.push(node);

this._UUIDsToFeatures[getUUID(node)] = node;
});
}
}
Expand All @@ -279,8 +282,8 @@ class GraphicalFeatureModel {
}

getNode(featureUUID: string): GraphicalFeatureNode | undefined {
// TODO: use a map instead?
return this.actualNodes.find(node => getUUID(node) === featureUUID);
this.prepare();
return this._UUIDsToFeatures[featureUUID];
}

getFeature(featureUUID: string): GraphicalFeature | undefined {
Expand Down

0 comments on commit a8001b1

Please sign in to comment.