Word wheel: Difference between revisions

Content added Content deleted
m (Tidied up C code a bit)
m (Tidied up C++ code a bit)
Line 124:
explicit letterset(const std::string& str) {
count_.fill(0);
for (char c : str) {
if ++count_[index(c >= 'a' && c <= 'z')];
++count_[c - 'a' + 1];
else
++count_[0];
}
}
bool contains(const letterset& set) const {
Line 139 ⟶ 135:
}
unsigned int count(char c) const {
ifreturn count_[index(c >= 'a' && c <= 'z')];
return count_[c - 'a' + 1];
return 0;
}
bool is_valid() const {
Line 147 ⟶ 141:
}
private:
static bool is_letter(char c) { return c >= 'a' && c <= 'z'; }
static int index(char c) { return is_letter(c) ? c - 'a' + 1 : 0; }
// elements 1..26 contain the number of times each lowercase
// letter occurs in the word