Function SetNeighbors(, ):
if parent[i] != and parent[i] != then
sparseNeighbors[parent[]].insert();
sparseNeighbors[].insert(parent[]);
Function UnSetAllNeighbors():
foreach in sparseNeighbors[].activeNeighbors do
sparseNeighbors[].erase();
sparseNeighbors[].erase();
Function RebuildNeighbors():
foreach in patches[].patchIndices do
if then
foreach in edgeNeighbors[] do
SetNeighbors(, );
Algorithm 4: Helper functions for sparse neighbor handling.
Function Withdraw(, ):
count = 0;
foreach in patches[].patchIndices do
if then
withdrawn[i] = true;
distance[i] = ;
parent[i] = -1;
++count;
return count
Function UnWithdraw():
foreach in patches[].patchIndices do
withdrawn[i] = false;
Function RebuildPatches():
patches.clear();
for do
if parent[i] == -1 then
patches[parent[i]].insert(i);
Algorithm 5: Helper functions for withdrawal and building patch
information.