Purely functional graph data structure