Add underscores to private data members (#898)

This is the last PR I plan to have focused on #720
This commit is contained in:
Jon Meow
2021-10-19 14:27:10 -07:00
committed by GitHub
parent dc9c36660b
commit ffa4e76ede
17 changed files with 363 additions and 356 deletions
+14 -14
View File
@@ -44,10 +44,10 @@ class Dictionary {
// NOLINTNEXTLINE(readability-identifier-naming)
using iterator_category = std::forward_iterator_tag;
explicit Iterator(std::optional<Nonnull<Node*>> x) : p(x) {}
Iterator(const Iterator& iter) : p(iter.p) {}
explicit Iterator(std::optional<Nonnull<Node*>> x) : p_(x) {}
Iterator(const Iterator& iter) : p_(iter.p_) {}
auto operator++() -> Iterator& {
p = (*p)->next;
p_ = (*p_)->next;
return *this;
}
auto operator++(int) -> Iterator {
@@ -55,17 +55,17 @@ class Dictionary {
operator++();
return tmp;
}
auto operator==(const Iterator& rhs) const -> bool { return p == rhs.p; }
auto operator!=(const Iterator& rhs) const -> bool { return p != rhs.p; }
auto operator*() -> const value_type& { return (*p)->curr; }
auto operator->() -> const value_type* { return &(*p)->curr; }
auto operator==(const Iterator& rhs) const -> bool { return p_ == rhs.p_; }
auto operator!=(const Iterator& rhs) const -> bool { return p_ != rhs.p_; }
auto operator*() -> const value_type& { return (*p_)->curr; }
auto operator->() -> const value_type* { return &(*p_)->curr; }
private:
std::optional<Nonnull<Node*>> p;
std::optional<Nonnull<Node*>> p_;
};
// Create an empty dictionary.
explicit Dictionary(Nonnull<Arena*> arena) : arena(arena) {}
explicit Dictionary(Nonnull<Arena*> arena) : arena_(arena) {}
// Return the value associated with the given key.
// Time complexity: O(n) where n is the number of times
@@ -82,21 +82,21 @@ class Dictionary {
// Associate the value v with key k in the dictionary.
// Time complexity: O(1).
auto Set(const K& k, const V& v) -> void {
head = arena->New<Node>(std::make_pair(k, v), head);
head_ = arena_->New<Node>(std::make_pair(k, v), head_);
}
auto IsEmpty() -> bool { return !head; }
auto IsEmpty() -> bool { return !head_; }
// The position of the first element of the dictionary
// or `end()` if the dictionary is empty.
auto begin() const -> Iterator { return Iterator(head); }
auto begin() const -> Iterator { return Iterator(head_); }
// The position one past that of the last element.
auto end() const -> Iterator { return Iterator(std::nullopt); }
private:
std::optional<Nonnull<Node*>> head;
Nonnull<Arena*> arena;
std::optional<Nonnull<Node*>> head_;
Nonnull<Arena*> arena_;
};
} // namespace Carbon