sped up evaluation a bit
made faster by storing edges as a hashtable