| 399 | } |
| 400 | |
| 401 | KeyValueDiffSet ChargeSocketsHelper::Diff(ChargeSocketDescriptors const & oldSockets) |
| 402 | { |
| 403 | KeyValueDiffSet result; |
| 404 | |
| 405 | auto oldKeys = ChargeSocketsHelper(oldSockets).GetOSMKeyValues(); |
| 406 | auto newKeys = GetOSMKeyValues(); |
| 407 | |
| 408 | ankerl::unordered_dense::map<std::string, std::string> oldMap, newMap; |
| 409 | |
| 410 | for (auto && [k, v] : oldKeys) |
| 411 | oldMap.emplace(k, v); |
| 412 | for (auto && [k, v] : newKeys) |
| 413 | newMap.emplace(k, v); |
| 414 | |
| 415 | // Handle keys that exist in old |
| 416 | for (auto && [k, oldVal] : oldMap) |
| 417 | if (auto it = newMap.find(k); it == newMap.end()) |
| 418 | result.insert({k, oldVal, ""}); // deleted |
| 419 | else if (it->second != oldVal) |
| 420 | result.insert({k, oldVal, it->second}); // updated |
| 421 | |
| 422 | // Handle keys that are only new |
| 423 | for (auto && [k, newVal] : newMap) |
| 424 | if (!oldMap.contains(k)) |
| 425 | result.insert({k, "", newVal}); // created |
| 426 | |
| 427 | return result; |
| 428 | } |
| 429 | |
| 430 | void ChargeSocketsHelper::Sort() |
| 431 | { |