An extension of the Hoshen-Kopelman algorithm to an arbitrary networks of nodes.
Based on Tobin Fricke's original code https://gist.github.com/tobin/909424
with an extended version of the HK algorithm added. The extension borrows some ideas from: http://gaia.pge.utexas.edu/papers/AFTWPPhysicaA.pdf