Skip to content

Conversation

@Lacrit
Copy link
Collaborator

@Lacrit Lacrit commented Jul 14, 2018

No description provided.

Copy link
Collaborator

@ssancho2 ssancho2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good, several style/readability comments, and two main ones marked with '(*)'


class Dictionary {
public:
Dictionary();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep indentation consistent.

class Dictionary {
public:
Dictionary();
Dictionary(std::string);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if nod needed by the compiler, putting names for the parameters helps readers understand what parameters are.

void Fill(std::string);
bool isPrefix(const std::string&);

std::unordered_set<std::string> words;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those probably don't need to be public.

if (file.is_open()) {
while (std::getline(file, line)) {
// Add to word dictionary
this->words.insert(line);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this-> is not needed.


Dictionary::Dictionary() {};
Dictionary::Dictionary(std::string path):
path(path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It helps readability having different naming conventions for fields and parameters. On the Google Style for example, we end fields with '_'.

row = i / rows;
for ( int j = 0; j < cols; j++) {
col = j % cols;
board.push_back(cell(row, col));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*)
I think here row is 0 and col is j.
You can use i and j directly, right?

row = sq.row + row_shift;
col = sq.col + col_shift;
if (row >= 0 & row < rows & col >= 0 & col < cols & !(row_shift == 0 & col_shift == 0)) {
sq.neighbours.push_back(row * rows + col);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*)
row * rows + col should be either:
row + rows * col or row * cols + col
One way to think about it is (for the first one):
When col = 0, this goes from 0 -> rows -1, so the next available number when col = 1 is rows.
In that case, if n = row + rows * col
You can extract them back (using that row < rows, and they are both positive integers):
n / rows -> (row + rows * col) / rows -> row / rows + (rows * col) / rows -> 0 + col -> col
n % rows -> (row + rows * col) % rows -> row % rows + (rows * col) % rows -> row + 0 -> row

for (int col_shift : shift) {
row = sq.row + row_shift;
col = sq.col + col_shift;
if (row >= 0 & row < rows & col >= 0 & col < cols & !(row_shift == 0 & col_shift == 0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works, but you probably should use logical and && instead of bitwise and &

visited.insert(position);

// If the string is a word, add it to the found words
if (dict.words.find(string) != dict.words.end()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a function isWord() in the dictionary class, and the code bellow (dict.prefixes.find(string) != dict.prefixes.end()) ==> isPrefix()

private:
struct cell {
std::string value;
int row;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to store them, but they are technically not needed.
As I explain in more detail in a comment above, you can from int index to coordinates and back 'easily'
Using a int to refer to the index of a cell in the board vector is ok, but a few comments will help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants