Chromium Code Reviews| Index: base/task_scheduler/scheduler_stack.h |
| diff --git a/base/task_scheduler/scheduler_stack.h b/base/task_scheduler/scheduler_stack.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aec9ca4e9a62342e9dd494ce84d18fd65d39e4b2 |
| --- /dev/null |
| +++ b/base/task_scheduler/scheduler_stack.h |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_TASK_SCHEDULER_SCHEDULER_STACK_H_ |
| +#define BASE_TASK_SCHEDULER_SCHEDULER_STACK_H_ |
| + |
| +#include <stddef.h> |
| +#include <stdint.h> |
| + |
| +#include <vector> |
| + |
| +#include "base/base_export.h" |
| + |
| +namespace base { |
| +namespace internal { |
| + |
| +// A stack of integers in [0, 63]. Supports removal of arbitrary values. Doesn't |
| +// 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.
|
| +class BASE_EXPORT SchedulerStack { |
| + public: |
| + SchedulerStack(); |
| + ~SchedulerStack(); |
| + |
| + // Inserts |val| at the top of the stack. |val| must be in [0, 63] and must |
| + // not already be on the stack. |
| + void Push(int val); |
| + |
| + // Removes the top value from the stack and returns it. DCHECKs if the stack |
| + // is empty. |
| + int Pop(); |
| + |
| + // Removes |val| from the stack if it was on it. |
| + void Remove(int val); |
| + |
| + // Returns the number of values on the stack. |
| + size_t Size() const; |
| + |
| + // Returns true if the stack is empty. |
| + bool Empty() const; |
| + |
| + private: |
| + // Returns true if |val| is on the stack. |
| + bool Contains(int val) const; |
| + |
| + std::vector<int> stack_; |
| + |
| + // A bit field that indicates what values are in |stack_|. |
| + uint64_t bit_field_ = 0; |
| +}; |
| + |
| +} // namespace internal |
| +} // namespace base |
| + |
| +#endif // BASE_TASK_SCHEDULER_SCHEDULER_STACK_H_ |