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

Side by Side Diff: chrome/common/string_ordinal.h

Issue 8236002: Create StringOrdinal to allow placement of strings in sorted lists (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Adjusting code to comply with code review comments Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_COMMON_STRING_ORDINAL_H_
6 #define CHROME_COMMON_STRING_ORDINAL_H_
7 #pragma once
8
9 #include <string>
10
11 // A StringOrdinal represents a specially-formatted string that can be used
12 // for ordering. The StringOrdinal class has an unbounded dense strict total
13 // order, which mean for any StringOrdinals a, b and c:
14 // - a < b and b < c implies a < c (transitivity);
akalin 2011/10/20 05:25:49 add extra line before, and indent each bullet 2 sp
15 // - exactly one of a < b, b < a and a = b holds (trichotomy);
16 // - if a < b, there is a StringOrdinal x such that a < x < b (density);
17 // - there are StringOrdinals x and y such that x < a < y (unboundedness).
18 //
19 // This means that when StringOrdinal is used for sorting a list, if
20 // any item changes its position in the list, only its StringOrinal value
21 // has to change to represent the new order, and all the other older values
22 // can stay the same.
23 class StringOrdinal {
24 public:
25 // Create a StringOrdinal from the given string. It may be valid or invalid.
26 explicit StringOrdinal(const std::string& string_ordinal);
27
28 // Create an invalid StringOrdinal.
29 StringOrdinal();
tfarina 2011/10/20 13:02:36 I think it would be less confusing to have an Inva
akalin 2011/10/20 18:44:30 I disagree. Negative tests are confusing.
30
31 bool IsValid() const;
32
33 // All remaining functions can only be called if IsValid() holds.
34 // It is an error to call them if IsValid() is false.
35
36 // Ordering Functions
37
38 // Returns true iff |*this| < |other|.
39 bool LessThan(const StringOrdinal& other) const;
40
41 // Return true iff |*this| == |other| (i.e. this->LessThan(other) and
42 // other.LessThan(*this) are both false).
43 bool Equal(const StringOrdinal& other) const;
44
45 // Given |*this| != |other|, returns a StringOrdinal x such that
46 // min(|*this|, |other|) < x < max(|*this|,|other|). It is an error
akalin 2011/10/20 05:25:49 space after comma
47 // to call this function with |*this| == |other|.
48 StringOrdinal CreateBetween(const StringOrdinal& other) const;
49
50 // Returns a StringOrdinal x such that x < |*this|.
51 StringOrdinal CreateBefore() const;
52
53 // Returns a StringOrdinal x such that |*this| < x.
54 StringOrdinal CreateAfter() const;
55
56 // It is guaranteed that a StringOrdinal constructed from the returned
57 // string will be valid.
58 std::string ToString() const;
59
60 // Use of copy constructor and default assignment for this class is allowed.
tfarina 2011/10/20 13:02:36 Please, move this to the end of the private sectio
akalin 2011/10/20 18:44:30 I disagree. This is part of the public interface.
61
62 private:
63 std::string string_ordinal_;
tfarina 2011/10/20 13:02:36 Can you document this two vars?
64 bool is_valid_;
tfarina 2011/10/20 13:02:36 can you make this const?
akalin 2011/10/20 18:44:30 Can't, to keep it assignable.
65 };
66 #endif // CHROME_COMMON_STRING_ORDINAL_H_
tfarina 2011/10/20 13:02:36 please add a blank line above.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698