#include #include #include #include #include #include struct AStarNode { AStarNode* parent; uint16_t x, y; }; class AStarNodes { public: AStarNodes(uint16_t x, uint16_t y); AStarNode* createNode(AStarNode* parent, uint16_t x, uint16_t y); std::vector nodes; std::unordered_map nodeMap; struct NodeCompare { bool operator()(AStarNode* a, AStarNode* b) const { return a->x > b->x; } }; std::priority_queue, NodeCompare> openSet; }; AStarNodes::AStarNodes(uint16_t x, uint16_t y) : nodes(), nodeMap() { // nodes.reserve(2); createNode(nullptr, x, y); } AStarNode* AStarNodes::createNode(AStarNode* parent, uint16_t x, uint16_t y) { uint32_t key = x + y * 255; nodes.emplace_back(AStarNode{parent, x, y}); AStarNode* node = &nodes.back(); nodeMap[key] = node; openSet.push(node); return node; } int main(int argc, const char** argv) { AStarNodes nodes(1, 1); AStarNode* node1 = &nodes.nodes.back(); std::cout << "n1:" << node1->x << "," << node1->y << std::endl; AStarNode* node2 = nodes.createNode(node1, 1, 2); std::cout << "n1:" << node1->x << "," << node1->y << std::endl; return 0; }