# Simple Validation: Can the Priority Queue and Graph Detect a Crash Before CSV Load? - JoseCanova/brainz GitHub Wiki
Simple Validation: Can the Priority Queue and Graph Detect a Crash Before CSV Load?
You don't need advanced algorithms to check if your current priority queue will cause a crash when loading CSVs into the database. If you have:
- The dependency graph (edges: A → B means B depends on A)
- The priority queue/map (each entity/table has a priority value; lower = loaded earlier)
You can check for possible crashes as follows:
What Could Cause a Crash?
A crash (referential integrity error) occurs if you try to load a table before a table it depends on (i.e., a child before its parent). This happens when, for an edge A → B (B depends on A):
priority(A) >= priority(B)
This means B (the child) is loaded before or at the same time as A (the parent).
Simple Validation Algorithm
For each edge (A → B) in your graph:
- Get the priorities:
priority(A)
andpriority(B)
- Check if
priority(A) < priority(B)
- If true: safe (parent loaded before child)
- If false: possible crash (child loaded before parent)
If you find any edge where priority(A) >= priority(B)
, you have a risk of a crash.
Example Java-like Pseudocode
for (Edge edge : graph.edgeSet()) {
Node parent = graph.getEdgeSource(edge); // A
Node child = graph.getEdgeTarget(edge); // B
int parentPriority = priorityMap.get(parent).getPriority();
int childPriority = priorityMap.get(child).getPriority();
if (parentPriority >= childPriority) {
System.err.println("Potential crash: " + child + " (priority " + childPriority +
") depends on " + parent + " (priority " + parentPriority + ")");
}
}
Summary Table
What you have | What to check | What it tells you |
---|---|---|
Dependency graph | For edge A→B: | If B depends on A, |
Priority map/queue | priority(A) < priority(B) | safe to load B after A |
priority(A) >= priority(B) | possible crash |
Conclusion
- You can detect if the current priority queue is safe using just the graph and the priority map.
- If all parent→child dependencies are respected (
priority(parent) < priority(child)
), you're safe to load. - If not, flag the issue before loading to avoid database errors.
Need a code snippet for your exact class structure? Just ask!