OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 #ifndef DoublyLinkedList_h | 26 #ifndef DoublyLinkedList_h |
27 #define DoublyLinkedList_h | 27 #define DoublyLinkedList_h |
28 | 28 |
29 namespace WTF { | 29 namespace WTF { |
30 | 30 |
31 // This class allows nodes to share code without dictating data member layout. | 31 // This class allows nodes to share code without dictating data member layout. |
32 template<typename T> class DoublyLinkedListNode { | 32 template<typename T> class DoublyLinkedListNode { |
33 public: | 33 public: |
34 DoublyLinkedListNode(); | 34 DoublyLinkedListNode(); |
35 | 35 |
36 void setPrev(T*); | 36 void setPrev(T*); |
37 void setNext(T*); | 37 void setNext(T*); |
38 | 38 |
39 T* prev() const; | 39 T* prev() const; |
40 T* next() const; | 40 T* next() const; |
41 }; | 41 }; |
42 | 42 |
43 template<typename T> inline DoublyLinkedListNode<T>::DoublyLinkedListNode() | 43 template<typename T> inline DoublyLinkedListNode<T>::DoublyLinkedListNode() |
44 { | 44 { |
45 setPrev(0); | 45 setPrev(0); |
46 setNext(0); | 46 setNext(0); |
47 } | 47 } |
48 | 48 |
(...skipping 13 matching lines...) Expand all Loading... |
62 } | 62 } |
63 | 63 |
64 template<typename T> inline T* DoublyLinkedListNode<T>::next() const | 64 template<typename T> inline T* DoublyLinkedListNode<T>::next() const |
65 { | 65 { |
66 return static_cast<const T*>(this)->m_next; | 66 return static_cast<const T*>(this)->m_next; |
67 } | 67 } |
68 | 68 |
69 template<typename T> class DoublyLinkedList { | 69 template<typename T> class DoublyLinkedList { |
70 public: | 70 public: |
71 DoublyLinkedList(); | 71 DoublyLinkedList(); |
72 | 72 |
73 bool isEmpty() const; | 73 bool isEmpty() const; |
74 size_t size() const; // This is O(n). | 74 size_t size() const; // This is O(n). |
75 void clear(); | 75 void clear(); |
76 | 76 |
77 T* head() const; | 77 T* head() const; |
78 T* removeHead(); | 78 T* removeHead(); |
79 | 79 |
80 T* tail() const; | 80 T* tail() const; |
81 | 81 |
82 void push(T*); | 82 void push(T*); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 remove(node); | 185 remove(node); |
186 return node; | 186 return node; |
187 } | 187 } |
188 | 188 |
189 } // namespace WTF | 189 } // namespace WTF |
190 | 190 |
191 using WTF::DoublyLinkedListNode; | 191 using WTF::DoublyLinkedListNode; |
192 using WTF::DoublyLinkedList; | 192 using WTF::DoublyLinkedList; |
193 | 193 |
194 #endif | 194 #endif |
OLD | NEW |