move functions to a header file
fast graph building for dense graphs