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

Side by Side Diff: third_party/WebKit/Source/wtf/HashSetTest.cpp

Issue 2386843002: reflow comments in wtf (Closed)
Patch Set: comments (heh!) Created 4 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
« no previous file with comments | « third_party/WebKit/Source/wtf/HashSet.h ('k') | third_party/WebKit/Source/wtf/HashTable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // reserveCapacityForSize should respect minimumTableSize. 52 // reserveCapacityForSize should respect minimumTableSize.
53 EXPECT_GE(initialCapacity, minimumTableSize); 53 EXPECT_GE(initialCapacity, minimumTableSize);
54 54
55 // Adding items up to size should never change the capacity. 55 // Adding items up to size should never change the capacity.
56 for (size_t i = 0; i < size; ++i) { 56 for (size_t i = 0; i < size; ++i) {
57 testSet.add(i + 1); // Avoid adding '0'. 57 testSet.add(i + 1); // Avoid adding '0'.
58 EXPECT_EQ(initialCapacity, testSet.capacity()); 58 EXPECT_EQ(initialCapacity, testSet.capacity());
59 } 59 }
60 60
61 // Adding items up to less than half the capacity should not change the capaci ty. 61 // Adding items up to less than half the capacity should not change the
62 // capacity.
62 unsigned capacityLimit = initialCapacity / 2 - 1; 63 unsigned capacityLimit = initialCapacity / 2 - 1;
63 for (size_t i = size; i < capacityLimit; ++i) { 64 for (size_t i = size; i < capacityLimit; ++i) {
64 testSet.add(i + 1); 65 testSet.add(i + 1);
65 EXPECT_EQ(initialCapacity, testSet.capacity()); 66 EXPECT_EQ(initialCapacity, testSet.capacity());
66 } 67 }
67 68
68 // Adding one more item increases the capacity. 69 // Adding one more item increases the capacity.
69 testSet.add(capacityLimit + 1); 70 testSet.add(capacityLimit + 1);
70 EXPECT_GT(testSet.capacity(), initialCapacity); 71 EXPECT_GT(testSet.capacity(), initialCapacity);
71 72
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 set = std::move(other); 269 set = std::move(other);
269 EXPECT_EQ(0, counter); 270 EXPECT_EQ(0, counter);
270 271
271 counter = 0; 272 counter = 0;
272 HashSet<CountCopy> yetAnother(std::move(set)); 273 HashSet<CountCopy> yetAnother(std::move(set));
273 EXPECT_EQ(0, counter); 274 EXPECT_EQ(0, counter);
274 } 275 }
275 276
276 class MoveOnly { 277 class MoveOnly {
277 public: 278 public:
278 // kEmpty and kDeleted have special meanings when MoveOnly is used as the key of a hash table. 279 // kEmpty and kDeleted have special meanings when MoveOnly is used as the key
280 // of a hash table.
279 enum { kEmpty = 0, kDeleted = -1, kMovedOut = -2 }; 281 enum { kEmpty = 0, kDeleted = -1, kMovedOut = -2 };
280 282
281 explicit MoveOnly(int value = kEmpty, int id = 0) 283 explicit MoveOnly(int value = kEmpty, int id = 0)
282 : m_value(value), m_id(id) {} 284 : m_value(value), m_id(id) {}
283 MoveOnly(MoveOnly&& other) : m_value(other.m_value), m_id(other.m_id) { 285 MoveOnly(MoveOnly&& other) : m_value(other.m_value), m_id(other.m_id) {
284 other.m_value = kMovedOut; 286 other.m_value = kMovedOut;
285 other.m_id = 0; 287 other.m_id = 0;
286 } 288 }
287 MoveOnly& operator=(MoveOnly&& other) { 289 MoveOnly& operator=(MoveOnly&& other) {
288 m_value = other.m_value; 290 m_value = other.m_value;
289 m_id = other.m_id; 291 m_id = other.m_id;
290 other.m_value = kMovedOut; 292 other.m_value = kMovedOut;
291 other.m_id = 0; 293 other.m_id = 0;
292 return *this; 294 return *this;
293 } 295 }
294 296
295 int value() const { return m_value; } 297 int value() const { return m_value; }
296 // id() is used for distinguishing MoveOnlys with the same value(). 298 // id() is used for distinguishing MoveOnlys with the same value().
297 int id() const { return m_id; } 299 int id() const { return m_id; }
298 300
299 private: 301 private:
300 MoveOnly(const MoveOnly&) = delete; 302 MoveOnly(const MoveOnly&) = delete;
301 MoveOnly& operator=(const MoveOnly&) = delete; 303 MoveOnly& operator=(const MoveOnly&) = delete;
302 304
303 int m_value; 305 int m_value;
304 int m_id; 306 int m_id;
305 }; 307 };
306 308
307 struct MoveOnlyHashTraits : public GenericHashTraits<MoveOnly> { 309 struct MoveOnlyHashTraits : public GenericHashTraits<MoveOnly> {
308 // This is actually true, but we pretend that it's false to disable the optimi zation. 310 // This is actually true, but we pretend that it's false to disable the
311 // optimization.
309 static const bool emptyValueIsZero = false; 312 static const bool emptyValueIsZero = false;
310 313
311 static const bool hasIsEmptyValueFunction = true; 314 static const bool hasIsEmptyValueFunction = true;
312 static bool isEmptyValue(const MoveOnly& value) { 315 static bool isEmptyValue(const MoveOnly& value) {
313 return value.value() == MoveOnly::kEmpty; 316 return value.value() == MoveOnly::kEmpty;
314 } 317 }
315 static void constructDeletedValue(MoveOnly& slot, bool) { 318 static void constructDeletedValue(MoveOnly& slot, bool) {
316 slot = MoveOnly(MoveOnly::kDeleted); 319 slot = MoveOnly(MoveOnly::kDeleted);
317 } 320 }
318 static bool isDeletedValue(const MoveOnly& value) { 321 static bool isDeletedValue(const MoveOnly& value) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 EXPECT_TRUE(oneTwoThree.contains(1)); 488 EXPECT_TRUE(oneTwoThree.contains(1));
486 EXPECT_TRUE(oneTwoThree.contains(2)); 489 EXPECT_TRUE(oneTwoThree.contains(2));
487 EXPECT_TRUE(oneTwoThree.contains(3)); 490 EXPECT_TRUE(oneTwoThree.contains(3));
488 491
489 oneTwoThree = {3, 1, 1, 2, 1, 1, 3}; 492 oneTwoThree = {3, 1, 1, 2, 1, 1, 3};
490 EXPECT_EQ(3u, oneTwoThree.size()); 493 EXPECT_EQ(3u, oneTwoThree.size());
491 EXPECT_TRUE(oneTwoThree.contains(1)); 494 EXPECT_TRUE(oneTwoThree.contains(1));
492 EXPECT_TRUE(oneTwoThree.contains(2)); 495 EXPECT_TRUE(oneTwoThree.contains(2));
493 EXPECT_TRUE(oneTwoThree.contains(3)); 496 EXPECT_TRUE(oneTwoThree.contains(3));
494 497
495 // Other ways of construction: as a function parameter and in a return stateme nt. 498 // Other ways of construction: as a function parameter and in a return
499 // statement.
496 EXPECT_TRUE(isOneTwoThree({1, 2, 3})); 500 EXPECT_TRUE(isOneTwoThree({1, 2, 3}));
497 EXPECT_TRUE(isOneTwoThree(returnOneTwoThree())); 501 EXPECT_TRUE(isOneTwoThree(returnOneTwoThree()));
498 } 502 }
499 503
500 } // anonymous namespace 504 } // anonymous namespace
501 505
502 } // namespace WTF 506 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/HashSet.h ('k') | third_party/WebKit/Source/wtf/HashTable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698