generic A* implementation in scala