func NewQueue(EventTTL *time.Duration) *EventQueue { queue := &EventQueue{eventTTL: EventTTL} queue.events = lane.NewPQueue(lane.MAXPQ) queue.done = make(chan struct{}) return queue }
// Creates a new A* object from one point to another, which can be queried to // find routing information. func NewAStar(fromX, fromY, toX, toY int, g interfaces.Game) *AStar { me := &AStar{} // TODO handle costs of start/goal tiles OR unreachable goal me.start = tile{fromX, fromY} me.goal = tile{toX, toY} me.frontier = lane.NewPQueue(lane.MINPQ) me.cameFrom = make(map[tile]tile) me.costSoFar = make(map[tile]int) me.game = g me.frontier.Push(me.start, 0) me.cameFrom[me.start] = nilTile me.costSoFar[me.start] = 0 for me.frontier.Size() != 0 { currentInterface, _ := me.frontier.Pop() current := currentInterface.(tile) if current == me.goal { break } for _, next := range me.getNeighbors(current.X, current.Y) { newCost := me.costSoFar[current] + me.getTileCost(next) if me.costSoFar[next] == 0 || newCost < me.costSoFar[next] { me.costSoFar[next] = newCost priority := newCost + me.heuristic(me.goal, next) me.frontier.Push(next, priority) me.cameFrom[next] = current } } } return me }
func NewPriorityQueue() Source { var pq *lane.PQueue = lane.NewPQueue(lane.MINPQ) return &PriorityQueue{ queue: pq, } }