Skip to content

Commit

Permalink
load store hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
appad committed Mar 3, 2024
1 parent 77befeb commit 5662c1b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
8 changes: 7 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ COPY --from=builder /app/build/api/asio-grpc-server /app/asio-grpc-server
# Run
CMD ["/app/asio-grpc-server"]

EXPOSE 50051
EXPOSE 50051

# Metadata
LABEL project="eternity2"
LABEL description="Eternity II Asio gRPC server"
LABEL version="1.0"
LABEL repository="https://github.com/Apoorva64/eternity2"
1 change: 0 additions & 1 deletion api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <unifex/timed_single_thread_context.hpp>
#include <unifex/when_all.hpp>
#include <unifex/with_query_value.hpp>
// Example showing some of the features of using asio-grpc with libunifex.

template<class Sender>
void run_grpc_context_for_sender(agrpc::GrpcContext &grpc_context, Sender &&sender)
Expand Down
4 changes: 1 addition & 3 deletions api/solver/solvera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,19 @@ auto handle_server_solver_request_step_by_step(agrpc::GrpcContext &grpc_context,
while (!shared_data.stop)
{
co_await delay(std::chrono::milliseconds{request.wait_time()});
mutex.lock();
std::scoped_lock lock(mutex);
for (auto &res : responses)
{
if (!co_await rpc.write(res))
{
spdlog::info("Client cancelled request");
shared_data.stop = true;
mutex.unlock();
solver_thread.join();
co_await rpc.finish(grpc::Status::CANCELLED);
co_return;
}
}
responses.clear();
mutex.unlock();
}
co_await rpc.finish(grpc::Status::OK);
});
Expand Down
4 changes: 3 additions & 1 deletion solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ add_library(solver_lib STATIC
format/format.cpp
format/format.h
solver/solver.h
solver/solver.cpp board/scan_row.cpp board/scan_row.h board/spiral.cpp board/spiral.h)
solver/solver.cpp board/scan_row.cpp board/scan_row.h board/spiral.cpp board/spiral.h
hash_load_store/hash_store_load.cpp
hash_load_store/hash_store_load.h)

target_include_directories(solver_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

Expand Down
26 changes: 26 additions & 0 deletions solver/hash_load_store/hash_store_load.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by appad on 03/03/2024.
//

#include "hash_store_load.h"
void store_hash(std::unordered_set<BoardHash> &hashes, const std::string &filename)
{
std::ofstream file;
file.open(filename);
for (const auto &hash : hashes)
{
file << hash << '\n';
}
file.close();
}
void load_hash(std::unordered_set<BoardHash> &hashes, const std::string &filename)
{
std::ifstream file;
file.open(filename);
std::string line;
while (std::getline(file, line))
{
hashes.insert(line);
}
file.close();
}
18 changes: 18 additions & 0 deletions solver/hash_load_store/hash_store_load.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by appad on 03/03/2024.
//

#ifndef ETERNITY2_HASH_STORE_LOAD_H
#define ETERNITY2_HASH_STORE_LOAD_H

#include "board/board.h"

#include <fstream>
#include <string>
#include <unordered_set>
#include <vector>

void store_hash(std::unordered_set<BoardHash> &hashes, const std::string &filename);

void load_hash(std::unordered_set<BoardHash> &hashes, const std::string &filename);
#endif //ETERNITY2_HASH_STORE_LOAD_H
2 changes: 0 additions & 2 deletions solver/solver/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ struct SharedData
unsigned int hash_length_threshold = 7;
};

SharedData create_shared_data();

auto possible_pieces(const Board &board, const std::vector<PieceWAvailability> &pieces, Index index)
-> std::vector<RotatedPiece>;

Expand Down

0 comments on commit 5662c1b

Please sign in to comment.