Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit efe3b70

Browse files
perf: use double instead of float for edge weights
The edge weight field was stored as float but every algorithm (Dijkstra, Louvain, ForceDirected, PageRank, etc.) operates on doubles internally. This caused implicit float-to-double widening on every getWeight() call in hot loops. Changes: - edge.java: weight field float -> double, getter/setter updated - GraphFileParser: Float.parseFloat -> Double.parseDouble for precision and to avoid widening on store - All existing float literal callers auto-widen safely (no source changes needed)
1 parent 0172b55 commit efe3b70

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

Gvisual/src/gvisual/GraphFileParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ public static ParseResult parse(String filePath, Predicate<String> visibleFilter
136136
continue;
137137
}
138138

139-
float weight;
139+
double weight;
140140
try {
141-
weight = Float.parseFloat(parts[3]);
141+
weight = Double.parseDouble(parts[3]);
142142
} catch (NumberFormatException e) {
143143
LOGGER.warning("Skipping edge with invalid weight: " + line);
144144
skipped++;
145145
continue;
146146
}
147-
if (Float.isNaN(weight) || Float.isInfinite(weight)) {
147+
if (Double.isNaN(weight) || Double.isInfinite(weight)) {
148148
LOGGER.warning("Skipping edge with non-finite weight: " + line);
149149
skipped++;
150150
continue;

Gvisual/src/gvisual/edge.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class edge {
1212
private String edgeType;
1313
private String vertex1;
1414
private String vertex2;
15-
private float weight;
15+
private double weight;
1616
private String label;
1717
private Long timestamp; // epoch millis (null = static/untimed edge)
1818
private Long endTimestamp; // optional: for interval-based edges
@@ -63,12 +63,12 @@ public edge(String edgeType,String vertex1,String vertex2)
6363
this.vertex2 = vertex2;
6464
}
6565

66-
public void setWeight(float weight)
66+
public void setWeight(double weight)
6767
{
6868
this.weight = weight;
6969
}
7070

71-
public float getWeight()
71+
public double getWeight()
7272
{
7373
return this.weight;
7474
}

0 commit comments

Comments
 (0)