Skip to content

Commit

Permalink
fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrause committed Nov 2, 2024
1 parent 242780e commit 2d753bb
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/oeis/oeis_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ void OeisManager::loadData() {
throwParseError(line);
}
total_count++;
pos = 1;
id = 0;
for (pos = 1; pos < line.length() && line[pos] >= '0' && line[pos] <= '9';
++pos) {
Expand Down Expand Up @@ -203,7 +202,6 @@ void OeisManager::loadNames() {
if (line[0] != 'A') {
throwParseError(line);
}
pos = 1;
id = 0;
for (pos = 1; pos < line.length() && line[pos] >= '0' && line[pos] <= '9';
++pos) {
Expand Down Expand Up @@ -273,8 +271,7 @@ bool OeisManager::shouldMatch(const OeisSequence &seq) const {
}

// check if program exists
const bool prog_exists = (seq.id >= 0) &&
(seq.id < stats->all_program_ids.size()) &&
const bool prog_exists = (seq.id < stats->all_program_ids.size()) &&
stats->all_program_ids[seq.id];

// program exists and protected?
Expand Down Expand Up @@ -364,9 +361,8 @@ void OeisManager::update(bool force) {
Log::get().info("Updating OEIS index (last update " +
std::to_string(oeis_age_in_days) + " days ago)");
}
std::string cmd, path;
for (auto &file : files) {
path = Setup::getOeisHome() + file;
for (const auto &file : files) {
const auto path = Setup::getOeisHome() + file;
ApiClient::getDefaultInstance().getOeisFile(file, path);
}
}
Expand Down Expand Up @@ -400,9 +396,9 @@ void OeisManager::update(bool force) {
Setup::getMiningMode() == MiningMode::MINING_MODE_CLIENT) {
Log::get().info("Cleaning up local programs directory");
int64_t num_removed = 0;
for (const auto &it : std::filesystem::directory_iterator(local_dir)) {
const auto stem = it.path().filename().stem().string();
const auto ext = it.path().filename().extension().string();
for (const auto &f : std::filesystem::directory_iterator(local_dir)) {
const auto stem = f.path().filename().stem().string();
const auto ext = f.path().filename().extension().string();
bool is_program;
try {
OeisSequence s(stem);
Expand All @@ -411,10 +407,10 @@ void OeisManager::update(bool force) {
is_program = stem.rfind("api-", 0) == 0;
}
is_program = is_program && (ext == ".asm");
const auto p = it.path().string();
const auto p = f.path().string();
if (is_program && getFileAgeInDays(p) > max_age) {
Log::get().debug("Removing \"" + p + "\"");
std::filesystem::remove(it.path());
std::filesystem::remove(f.path());
num_removed++;
}
}
Expand Down Expand Up @@ -444,7 +440,7 @@ void OeisManager::generateStats(int64_t age_in_days) {
bool has_program, has_formula;

AdaptiveScheduler notify(20); // magic number
for (auto &s : sequences) {
for (const auto &s : sequences) {
if (s.id == 0) {
continue;
}
Expand Down Expand Up @@ -524,8 +520,8 @@ void OeisManager::generateLists() {
// write lists
ensureDir(lists_home);
for (size_t i = 0; i < list_files.size(); i++) {
auto buf = list_files[i].str();
if (!buf.empty()) {
const auto f = list_files[i].str();
if (!f.empty()) {
const std::string list_path =
lists_home + "list" + std::to_string(i) + ".markdown";
OeisSequence start(std::max<int64_t>(i * list_file_size, 1));
Expand All @@ -539,7 +535,7 @@ void OeisManager::generateLists() {
list_file << "---\n";
list_file << "List of integer sequences with links to LODA programs."
<< "\n\n";
list_file << buf;
list_file << f;
list_file << "\n\n[License Info](https://github.com/loda-lang/"
"loda-programs#license)\n";
}
Expand All @@ -553,7 +549,6 @@ void OeisManager::generateLists() {
}

void OeisManager::migrate() {
Settings settings;
Interpreter interpreter(settings);
IncrementalEvaluator ie(interpreter);
for (size_t id = 0; id < 400000; id++) {
Expand Down Expand Up @@ -582,9 +577,9 @@ void OeisManager::migrate() {
op.source == Operand(Operand::Type::CONSTANT, 1)) {
Log::get().warn("Migrating " + ProgramUtil::getProgramPath(s.id));
op.type = Operation::Type::TRN;
std::ofstream out(ProgramUtil::getProgramPath(s.id));
ProgramUtil::print(p, out);
out.close();
std::ofstream fout(ProgramUtil::getProgramPath(s.id));
ProgramUtil::print(p, fout);
fout.close();
loop_started = false;
}
}
Expand Down Expand Up @@ -673,7 +668,7 @@ void OeisManager::dumpProgram(size_t id, Program &p, const std::string &file,
Comments::removeComments(p);
addSeqComments(p);
ensureDir(file);
auto &seq = sequences.at(id);
const auto &seq = sequences.at(id);
Program tmp;
Operation nop(Operation::Type::NOP);
nop.comment = seq.to_string();
Expand Down Expand Up @@ -710,7 +705,7 @@ void OeisManager::dumpProgram(size_t id, Program &p, const std::string &file,
void OeisManager::alert(Program p, size_t id, const std::string &prefix,
const std::string &color,
const std::string &submitted_by) const {
auto &seq = sequences.at(id);
const auto &seq = sequences.at(id);
std::string msg, full;
msg = prefix + " program for " + seq.to_string();
full = msg + " Terms: " + seq.getTerms(settings.num_terms).to_string();
Expand Down Expand Up @@ -936,7 +931,6 @@ std::vector<Program> OeisManager::loadAllPrograms() {
const auto num_ids = program_ids.size();
const auto num_programs = getStats().num_programs;
std::vector<Program> programs(num_ids);
Parser parser;
Log::get().info("Loading " + std::to_string(num_programs) + " programs");
AdaptiveScheduler scheduler(20);
int64_t loaded = 0;
Expand Down

0 comments on commit 2d753bb

Please sign in to comment.