just checking for equality of the size of nodeMap.keys with g.nodeCount will suffice given you have already checked that every node in g belongs to nodeMap.