Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 BASE_TASK_SCHEDULER_SCHEDULER_STACK_H_ | |
| 6 #define BASE_TASK_SCHEDULER_SCHEDULER_STACK_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/base_export.h" | |
| 14 | |
| 15 namespace base { | |
| 16 namespace internal { | |
| 17 | |
| 18 // A stack of integers in [0, 63]. Supports removal of arbitrary values. Doesn't | |
| 19 // allow multiple insertions of the same value. This class is NOT thread-safe. | |
|
gab
2016/04/18 18:35:40
Add a note about what makes this special (performa
fdoray
2016/04/18 20:33:12
Done.
| |
| 20 class BASE_EXPORT SchedulerStack { | |
| 21 public: | |
| 22 SchedulerStack(); | |
| 23 ~SchedulerStack(); | |
| 24 | |
| 25 // Inserts |val| at the top of the stack. |val| must be in [0, 63] and must | |
| 26 // not already be on the stack. | |
| 27 void Push(int val); | |
| 28 | |
| 29 // Removes the top value from the stack and returns it. DCHECKs if the stack | |
| 30 // is empty. | |
| 31 int Pop(); | |
| 32 | |
| 33 // Removes |val| from the stack if it was on it. | |
| 34 void Remove(int val); | |
| 35 | |
| 36 // Returns the number of values on the stack. | |
| 37 size_t Size() const; | |
| 38 | |
| 39 // Returns true if the stack is empty. | |
| 40 bool Empty() const; | |
| 41 | |
| 42 private: | |
| 43 // Returns true if |val| is on the stack. | |
| 44 bool Contains(int val) const; | |
| 45 | |
| 46 std::vector<int> stack_; | |
| 47 | |
| 48 // A bit field that indicates what values are in |stack_|. | |
| 49 uint64_t bit_field_ = 0; | |
| 50 }; | |
| 51 | |
| 52 } // namespace internal | |
| 53 } // namespace base | |
| 54 | |
| 55 #endif // BASE_TASK_SCHEDULER_SCHEDULER_STACK_H_ | |
| OLD | NEW |