From c8470bb8dc92064212f2b5ac93d2ffe2b2eb9a6c Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Sun, 27 Nov 2022 11:43:10 -0800 Subject: [PATCH] queue --- 2018/15.cpp | 1 - 2019/15.cpp | 12 +++++++----- 2019/18.cpp | 9 +++++---- 2019/20.cpp | 14 +++++++------- CMakePresets.json | 17 ----------------- 5 files changed, 19 insertions(+), 34 deletions(-) delete mode 100644 CMakePresets.json diff --git a/2018/15.cpp b/2018/15.cpp index a11358e..5cd2430 100644 --- a/2018/15.cpp +++ b/2018/15.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/2019/15.cpp b/2019/15.cpp index 96b541b..d4a3b63 100644 --- a/2019/15.cpp +++ b/2019/15.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -70,9 +70,11 @@ auto Compute(std::map world) -> std::pair { int part1 = -1; int part2 = -1; - for (std::deque> todo {{0,start}}; - !todo.empty(); - todo.pop_front()) + for ( + std::queue> todo + {decltype(todo)::container_type{{0,start}}}; + !todo.empty(); + todo.pop()) { auto [steps, here] = todo.front(); if (Coord{0,0} == here) part1 = steps; @@ -81,7 +83,7 @@ auto Compute(std::map world) -> std::pair { for (auto fn : moves) { auto next = fn(here); if (world.erase(next)) { - todo.emplace_back(steps+1, next); + todo.emplace(steps+1, next); } } } diff --git a/2019/18.cpp b/2019/18.cpp index b11ea30..c2dcf86 100644 --- a/2019/18.cpp +++ b/2019/18.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -56,11 +56,12 @@ auto FindDistancesFrom( ) { std::map> result; - std::deque> todo {{0, start, {}}}; + std::queue> todo; + todo.push({0, start, {}}); std::set seen; - for (; !todo.empty(); todo.pop_front()) { + for (; !todo.empty(); todo.pop()) { auto [steps, here, doors] = todo.front(); // Don't visit the same coordinate twice @@ -82,7 +83,7 @@ auto FindDistancesFrom( // Visit all neighbors for (auto const fn : directions) { - todo.emplace_back(steps+1, fn(here), doors); + todo.emplace(steps+1, fn(here), doors); } } diff --git a/2019/20.cpp b/2019/20.cpp index 54d6d09..5c0321f 100644 --- a/2019/20.cpp +++ b/2019/20.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -64,12 +64,12 @@ auto FindDistancesFrom( Coord const start ) { std::vector> result; - - std::deque> todo {{0, start}}; - std::set seen; - - for (; !todo.empty(); todo.pop_front()) { + for ( + std::queue> todo + {decltype(todo)::container_type{{{0, start}}}}; + !todo.empty(); + todo.pop()) { auto const [steps, here] = todo.front(); // Don't visit the same coordinate twice @@ -86,7 +86,7 @@ auto FindDistancesFrom( // Visit all neighbors for (auto const fn : directions) { - todo.emplace_back(steps+1, fn(here)); + todo.emplace(steps+1, fn(here)); } } diff --git a/CMakePresets.json b/CMakePresets.json deleted file mode 100644 index 3571f09..0000000 --- a/CMakePresets.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": 2, - "configurePresets": [ - { - "name": "preset", - "displayName": "Configure preset using toolchain file", - "description": "Sets Ninja generator, build and install directory", - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_TOOLCHAIN_FILE": "", - "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" - } - } - ] -}