Skip to content

Only use Entry ID<->index maps if necessary #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions src/projections/analysis/StsReader.java
Original file line number Diff line number Diff line change
@@ -80,9 +80,9 @@ public String toString() {
/** index by Integer ID in STS file, return String name */
public Map<Integer, Chare> entryChares = new TreeMap<Integer, Chare>();
/** keys are indexes into flat arrays, values are the IDs given in STS file */
private Map<Integer, Integer> entryFlatToID = new TreeMap<Integer, Integer>();
private Map<Integer, Integer> entryFlatToID = null;
/** keys are the IDs given in STS file, values are indexes into flat arrays */
private Map<Integer, Integer> entryIDToFlat = new TreeMap<Integer, Integer>();
private Map<Integer, Integer> entryIDToFlat = null;



@@ -224,8 +224,19 @@ public StsReader(String FileName)
ChareID = Integer.parseInt(st.nextToken());
st.nextToken(); // msgid

entryFlatToID.put(entryIndex, ID);
entryIDToFlat.put(ID,entryIndex);
// In general, Entry IDs will be contiguous starting from 0, so avoid
// creating the ID<->flat maps if possible. This code creates the map
// when it detects a non-contiguous case.
if (ID != entryIndex && entryFlatToID == null) {
entryFlatToID = new TreeMap<>();
for (int i = 0; i < entryIndex; i++)
entryFlatToID.put(i, i);
entryIDToFlat = new TreeMap<>(entryFlatToID);
}
if (entryFlatToID != null) {
entryFlatToID.put(entryIndex, ID);
entryIDToFlat.put(ID, entryIndex);
}
entryIndex++;
getEntryNames().put(ID,Name);
getEntryChare().put(ID, Chares[ChareID]);
@@ -348,8 +359,13 @@ public String getEntryNameByID(int ID) {
}

public String getEntryNameByIndex(int index) {
if(entryFlatToID.containsKey(index)){
return getEntryNames().get(entryFlatToID.get(index));
// Check if the ID is valid. If entryFlatToID exists, then check if
// there's a valid mapping for index there, otherwise the index is the
// ID, so check in the entry names map directly.
final boolean isValid = (entryFlatToID != null && entryFlatToID.containsKey(index)) ||
(entryFlatToID == null && getEntryNames().containsKey(index));
if (isValid) {
return getEntryNames().get(getEntryID(index));
} else {
return "Unknown";
}
@@ -372,15 +388,15 @@ private String getEntryChareNameByID(int ID) {
}

public String getEntryChareNameByIndex(int index) {
return getEntryChare().get(entryFlatToID.get(index)).name;
return getEntryChare().get(getEntryID(index)).name;
}

public int getEntryChareDimensionsByID(int ID) {
return getEntryChare().get(ID).dimensions;
}

public int getEntryChareDimensionsByIndex(int index) {
return getEntryChare().get(entryFlatToID.get(index)).dimensions;
return getEntryChare().get(getEntryID(index)).dimensions;
}

public String getEntryFullNameByID(int ID) {
@@ -391,12 +407,16 @@ public String getEntryFullNameByIndex(int index) {
return getEntryChareNameByIndex(index) + "::" + getEntryNameByIndex(index);
}

public Integer getEntryIndex(int ID) {
if(ID<0)
return ID;
return entryIDToFlat.get(ID);
}

public int getEntryIndex(int ID) {
if(ID<0)
return ID;
return (entryIDToFlat == null) ? ID : entryIDToFlat.get(ID);
}

private int getEntryID(int index) {
return (entryFlatToID == null) ? index : entryFlatToID.get(index);
}

// *** user event accessors ***
public int getNumUserDefinedEvents() {
return userEvents.size();