OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #ifndef SkSinglyLinkedList_DEFINED | 7 #ifndef SkSinglyLinkedList_DEFINED |
8 #define SkSinglyLinkedList_DEFINED | 8 #define SkSinglyLinkedList_DEFINED |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 13 matching lines...) Expand all Loading... |
24 Node* next = node->fNext; | 24 Node* next = node->fNext; |
25 SkASSERT(next != nullptr || node == fTail); | 25 SkASSERT(next != nullptr || node == fTail); |
26 delete node; | 26 delete node; |
27 node = next; | 27 node = next; |
28 } | 28 } |
29 fHead = nullptr; | 29 fHead = nullptr; |
30 fTail = nullptr; | 30 fTail = nullptr; |
31 } | 31 } |
32 T* back() { return fTail ? &fTail->fData : nullptr; } | 32 T* back() { return fTail ? &fTail->fData : nullptr; } |
33 T* front() { return fHead ? &fHead->fData : nullptr; } | 33 T* front() { return fHead ? &fHead->fData : nullptr; } |
| 34 bool empty() const { return fHead == nullptr; } |
34 #ifdef SK_DEBUG | 35 #ifdef SK_DEBUG |
35 int count() { // O(n), debug only. | 36 int count() { // O(n), debug only. |
36 int count = 0; | 37 int count = 0; |
37 for (Node* node = fHead; node; node = node->fNext) { | 38 for (Node* node = fHead; node; node = node->fNext) { |
38 ++count; | 39 ++count; |
39 } | 40 } |
40 return count; | 41 return count; |
41 } | 42 } |
42 #endif | 43 #endif |
43 void pop_front() { | 44 void pop_front() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 Node* fNext; | 88 Node* fNext; |
88 template <class... Args> | 89 template <class... Args> |
89 Node(Args&&... args) : fData(std::forward<Args>(args)...), fNext(nullptr
) {} | 90 Node(Args&&... args) : fData(std::forward<Args>(args)...), fNext(nullptr
) {} |
90 }; | 91 }; |
91 Node* fHead; | 92 Node* fHead; |
92 Node* fTail; | 93 Node* fTail; |
93 SkSinglyLinkedList(const SkSinglyLinkedList<T>&) = delete; | 94 SkSinglyLinkedList(const SkSinglyLinkedList<T>&) = delete; |
94 SkSinglyLinkedList& operator=(const SkSinglyLinkedList<T>&) = delete; | 95 SkSinglyLinkedList& operator=(const SkSinglyLinkedList<T>&) = delete; |
95 }; | 96 }; |
96 #endif // SkSinglyLinkedList_DEFINED | 97 #endif // SkSinglyLinkedList_DEFINED |
OLD | NEW |