From 4f217001cd68b505b9d4820bf48e72463580c5ad Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 4 Apr 2026 11:54:40 +0100 Subject: Rename utility/map to container and prefix the difference method. --- include/utility/container.h | 84 +++++++++++++++++++++++++++++++++++++++++++++ include/utility/map.h | 84 --------------------------------------------- 2 files changed, 84 insertions(+), 84 deletions(-) create mode 100644 include/utility/container.h delete mode 100644 include/utility/map.h (limited to 'include') diff --git a/include/utility/container.h b/include/utility/container.h new file mode 100644 index 000000000..d98eaf2c2 --- /dev/null +++ b/include/utility/container.h @@ -0,0 +1,84 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2022 Sadie Powell + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#pragma once + + +namespace insp +{ + /** Compares two maps and returns a list of the differences. + * @param first The first map to compare. + * @param second The second map to compare. + * @param out The map to store the differences in. + */ + template typename Map> + void map_difference(const Map& first, const Map& second, + Map, std::optional>, Compare>& out) + { + auto fiter = first.cbegin(); + auto siter = second.cbegin(); + + while (fiter != first.end()) + { + if (siter == second.end()) + { + // Store the remaining from the first. + while (fiter != first.end()) + { + out[fiter->first] = { fiter->second, std::nullopt }; + fiter++; + } + return; + } + + if (fiter->first < siter->first) + { + // The key in first is not in second. + out[fiter->first] = { fiter->second, std::nullopt }; + fiter++; + } + else if (siter->first < fiter->first) + { + // The key in second is not in first. + out[siter->first] = { std::nullopt, siter->second }; + siter++; + } + else if (fiter->second != siter->second) + { + // The key exists in both but the value differs. + out[fiter->first] = { fiter->second, siter->second }; + fiter++; + siter++; + } + else + { + // The key/value is identical in both. + fiter++; + siter++; + } + } + + // Store the remaining from the second. + while (siter != second.end()) + { + out[siter->first] = { std::nullopt, siter->second }; + siter++; + } + } +} diff --git a/include/utility/map.h b/include/utility/map.h deleted file mode 100644 index 87d93a13b..000000000 --- a/include/utility/map.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2022 Sadie Powell - * - * This file is part of InspIRCd. InspIRCd is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#pragma once - - -namespace insp::map -{ - /** Compares two maps and returns a list of the differences. - * @param first The first map to compare. - * @param second The second map to compare. - * @param out The map to store the differences in. - */ - template typename Map> - void difference(const Map& first, const Map& second, - Map, std::optional>, Compare>& out) - { - auto fiter = first.cbegin(); - auto siter = second.cbegin(); - - while (fiter != first.end()) - { - if (siter == second.end()) - { - // Store the remaining from the first. - while (fiter != first.end()) - { - out[fiter->first] = { fiter->second, std::nullopt }; - fiter++; - } - return; - } - - if (fiter->first < siter->first) - { - // The key in first is not in second. - out[fiter->first] = { fiter->second, std::nullopt }; - fiter++; - } - else if (siter->first < fiter->first) - { - // The key in second is not in first. - out[siter->first] = { std::nullopt, siter->second }; - siter++; - } - else if (fiter->second != siter->second) - { - // The key exists in both but the value differs. - out[fiter->first] = { fiter->second, siter->second }; - fiter++; - siter++; - } - else - { - // The key/value is identical in both. - fiter++; - siter++; - } - } - - // Store the remaining from the second. - while (siter != second.end()) - { - out[siter->first] = { std::nullopt, siter->second }; - siter++; - } - } -} -- cgit v1.3.1-10-gc9f91