Skip to content

Commit

Permalink
Adds special handling for removing last "thing"
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrosz committed Jun 18, 2024
1 parent 4d40ce9 commit 4bb3a51
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ void ClimbGraph_remove_climb(ClimbGraph graph, const ClimbNode node)
return;
}

// Case where the last climb was removed
if (graph->climbslen == 1) {
graph->climbslen = 0;
free(graph->climbs);
graph->climbs = NULL;
return;
}

for (int i = index; i < graph->climbslen - 1; i++) {
graph->climbs[i] = graph->climbs[i + 1];
}
Expand Down Expand Up @@ -189,6 +197,14 @@ void ClimbGraph_remove_variation(ClimbGraph g, const ClimbNode c, const ClimbNod
return;
}

// Case where the last variation was removed
if (g->variationslen == 1) {
g->variationslen = 0;
free(g->variations);
g->variations = NULL;
return;
}

for (int i = index; i < g->variationslen - 1; i++) {
g->variations[i] = g->variations[i + 1];
}
Expand Down Expand Up @@ -304,6 +320,14 @@ void ClimbGraph_remove_linkup(ClimbGraph g, const ClimbNode c)
return;
}

// Case where the last linkup was removed
if (g->linkupslen == 1) {
g->linkupslen = 0;
free(g->linkups);
g->linkups = NULL;
return;
}

LinkupEdge_ linkup = g->linkups[index];
free(linkup.l);

Expand Down

0 comments on commit 4bb3a51

Please sign in to comment.