Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1622)

Side by Side Diff: chrome/browser/spellchecker/set_difference_container.h

Issue 1665023002: Cheer up spell-checking code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
please use gerrit instead 2016/02/03 23:59:11 no (c)
groby-ooo-7-16 2016/02/04 03:43:15 Do we have any reason to suspect a temporary set i
Kevin Bailey 2016/02/04 16:34:11 Done, and fixed in the file(s) that I copied it fr
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // A virtual container for iterating through the difference of two sets,
6 // without having to construct a set.
please use gerrit instead 2016/02/03 23:59:11 This is more of a class comment, so let's move it
Kevin Bailey 2016/02/04 16:34:11 Done.
7
8 #ifndef CHROME_BROWSER_SPELLCHECKER_SET_DIFFERENCE_CONTAINER_H_
9 #define CHROME_BROWSER_SPELLCHECKER_SET_DIFFERENCE_CONTAINER_H_
10
11 namespace spellcheck {
12
13 template <typename Container1, typename Container2>
14 class set_difference_container {
please use gerrit instead 2016/02/03 23:59:10 Class names are usually CamelCase. Is there a prec
Kevin Bailey 2016/02/04 16:34:11 Only standard C++ habit. Done.
15 public:
16 set_difference_container(
17 const Container1& container1,
18 const Container2& container2)
19 : in_beg(container1.begin()), in_end(container1.end()),
20 out_beg(container2.begin()), out_end(container2.end()) {}
please use gerrit instead 2016/02/03 23:59:10 Delegate the construction to the second constructo
Kevin Bailey 2016/02/04 16:34:11 Good idea. Done.
21
22 set_difference_container(
please use gerrit instead 2016/02/03 23:59:10 If you have a constructor, then you should have a
Kevin Bailey 2016/02/04 16:34:11 I went through 3 style guides and the only thing m
23 typename Container1::const_iterator x_beg,
24 typename Container1::const_iterator x_end,
25 typename Container2::const_iterator y_beg,
26 typename Container2::const_iterator y_end)
27 : in_beg(x_beg), in_end(x_end), out_beg(y_beg), out_end(y_end) {}
please use gerrit instead 2016/02/03 23:59:11 Do something similar to https://code.google.com/p/
Kevin Bailey 2016/02/04 16:34:11 Done.
28
29 class set_difference_iterator {
please use gerrit instead 2016/02/03 23:59:11 Internal classes usually come before constructors.
Kevin Bailey 2016/02/04 16:34:12 Done.
30 public:
31 set_difference_iterator() {}
32
33 set_difference_iterator(
please use gerrit instead 2016/02/03 23:59:11 Need a destructor too.
Kevin Bailey 2016/02/04 16:34:11 Acknowledged.
34 typename Container1::const_iterator x_beg,
35 typename Container1::const_iterator x_end,
36 typename Container2::const_iterator y_beg,
37 typename Container2::const_iterator y_end)
38 : in_beg(x_beg), in_end(x_end), out_beg(y_beg), out_end(y_end) {
39 // go to first valid value
40 MaybeIterate();
41 }
42
43 void MaybeIterate() {
44 while (in_beg != in_end && out_beg != out_end && *out_beg <= *in_beg) {
45 // skip over stuff that is equal
46 if (*in_beg == *out_beg)
47 ++in_beg;
48 // go to next in |out| that is >= |in|
49 ++out_beg;
50 }
51 }
52
53 set_difference_iterator operator++() {
please use gerrit instead 2016/02/03 23:59:10 Return a reference to avoid a copy.
Kevin Bailey 2016/02/04 16:34:11 Done.
54 // assert in_beg != in_end
please use gerrit instead 2016/02/03 23:59:10 #include "base/logging.h" DCHECK_NE(in_beg, in_en
Kevin Bailey 2016/02/04 16:34:11 Sorry, didn't work, I suspect, because it was atte
55 ++in_beg;
56 MaybeIterate();
57 return *this;
58 }
59
60 const typename Container1::value_type& operator*() {
61 // assert in_beg != in_end
62 return *in_beg;
63 }
64
65 bool operator!=(const set_difference_iterator& rhs) {
66 // This is completely cutting corners, but should work.
67 // |out| isn't really part of the state, and we just trust
68 // |end| to be correct.
69 return in_beg != rhs.in_beg;
70 }
71 private:
please use gerrit instead 2016/02/03 23:59:10 newline above private.
Kevin Bailey 2016/02/04 16:34:11 Done.
72 typename Container1::const_iterator in_beg, in_end;
73 typename Container2::const_iterator out_beg, out_end;
74 };
please use gerrit instead 2016/02/03 23:59:10 newline below };
Kevin Bailey 2016/02/04 16:34:11 Done.
75 typedef set_difference_iterator iterator;
76
77 iterator begin() const {
78 return iterator(in_beg, in_end, out_beg, out_end);
79 }
80
81 iterator end() const {
82 return iterator(in_end, in_end, out_end, out_end);
83 }
84
85 private:
86 typename Container1::const_iterator in_beg, in_end;
please use gerrit instead 2016/02/03 23:59:10 Each member variable on its own line, even if the
Kevin Bailey 2016/02/04 16:34:11 Done.
87 typename Container2::const_iterator out_beg, out_end;
please use gerrit instead 2016/02/03 23:59:10 Ditto.
Kevin Bailey 2016/02/04 16:34:11 Done.
88 };
89
90 } // namespace spellcheck
91
92 #endif // CHROME_BROWSER_SPELLCHECKER_SET_DIFFERENCE_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698