Generic graph implementation