1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-07 01:21:00 +01:00

Apply clang-format universally.

* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
This commit is contained in:
Graham Christensen 2025-07-18 12:47:27 -04:00
parent 41bf87ec70
commit e4f62e4608
587 changed files with 23258 additions and 23135 deletions

View file

@ -15,20 +15,20 @@ int levenshteinDistance(std::string_view first, std::string_view second)
int m = first.size();
int n = second.size();
auto v0 = std::vector<int>(n+1);
auto v1 = std::vector<int>(n+1);
auto v0 = std::vector<int>(n + 1);
auto v1 = std::vector<int>(n + 1);
for (auto i = 0; i <= n; i++)
v0[i] = i;
for (auto i = 0; i < m; i++) {
v1[0] = i+1;
v1[0] = i + 1;
for (auto j = 0; j < n; j++) {
auto deletionCost = v0[j+1] + 1;
auto deletionCost = v0[j + 1] + 1;
auto insertionCost = v1[j] + 1;
auto substitutionCost = first[i] == second[j] ? v0[j] : v0[j] + 1;
v1[j+1] = std::min({deletionCost, insertionCost, substitutionCost});
v1[j + 1] = std::min({deletionCost, insertionCost, substitutionCost});
}
std::swap(v0, v1);
@ -37,18 +37,17 @@ int levenshteinDistance(std::string_view first, std::string_view second)
return v0[n];
}
Suggestions Suggestions::bestMatches (
const StringSet & allMatches,
std::string_view query)
Suggestions Suggestions::bestMatches(const StringSet & allMatches, std::string_view query)
{
std::set<Suggestion> res;
for (const auto & possibleMatch : allMatches) {
res.insert(Suggestion {
.distance = levenshteinDistance(query, possibleMatch),
.suggestion = possibleMatch,
});
res.insert(
Suggestion{
.distance = levenshteinDistance(query, possibleMatch),
.suggestion = possibleMatch,
});
}
return Suggestions { res };
return Suggestions{res};
}
Suggestions Suggestions::trim(int limit, int maxDistance) const
@ -75,31 +74,29 @@ std::string Suggestion::to_string() const
std::string Suggestions::to_string() const
{
switch (suggestions.size()) {
case 0:
return "";
case 1:
return suggestions.begin()->to_string();
default: {
std::string res = "one of ";
auto iter = suggestions.begin();
res += iter->to_string(); // Iter cant be end() because the container isnt null
iter++;
auto last = suggestions.end(); last--;
for ( ; iter != suggestions.end() ; iter++) {
res += (iter == last) ? " or " : ", ";
res += iter->to_string();
}
return res;
case 0:
return "";
case 1:
return suggestions.begin()->to_string();
default: {
std::string res = "one of ";
auto iter = suggestions.begin();
res += iter->to_string(); // Iter cant be end() because the container isnt null
iter++;
auto last = suggestions.end();
last--;
for (; iter != suggestions.end(); iter++) {
res += (iter == last) ? " or " : ", ";
res += iter->to_string();
}
return res;
}
}
}
Suggestions & Suggestions::operator+=(const Suggestions & other)
{
suggestions.insert(
other.suggestions.begin(),
other.suggestions.end()
);
suggestions.insert(other.suggestions.begin(), other.suggestions.end());
return *this;
}
@ -113,4 +110,4 @@ std::ostream & operator<<(std::ostream & str, const Suggestions & suggestions)
return str << suggestions.to_string();
}
}
} // namespace nix