Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
SkDeque Class Reference

#include <SkDeque.h>

Classes

struct  Block
 
class  F2BIter
 
class  Iter
 

Public Member Functions

 SkDeque (size_t elemSize, int allocCount=1)
 
 SkDeque (size_t elemSize, void *storage, size_t storageSize, int allocCount=1)
 
 ~SkDeque ()
 
bool empty () const
 
int count () const
 
size_t elemSize () const
 
const void * front () const
 
const void * back () const
 
void * front ()
 
void * back ()
 
void * push_front ()
 
void * push_back ()
 
void pop_front ()
 
void pop_back ()
 

Friends

class DequeUnitTestHelper
 

Detailed Description

Definition at line 28 of file SkDeque.h.

Constructor & Destructor Documentation

◆ SkDeque() [1/2]

SkDeque::SkDeque ( size_t  elemSize,
int  allocCount = 1 
)
explicit

elemSize specifies the size of each individual element in the deque allocCount specifies how many elements are to be allocated as a block

Definition at line 31 of file SkDeque.cpp.

32 : fElemSize(elemSize)
33 , fInitialStorage(nullptr)
34 , fCount(0)
35 , fAllocCount(allocCount) {
36 SkASSERT(allocCount >= 1);
37 fFrontBlock = fBackBlock = nullptr;
38 fFront = fBack = nullptr;
39}
#define SkASSERT(cond)
Definition SkAssert.h:116
size_t elemSize() const
Definition SkDeque.h:40

◆ SkDeque() [2/2]

SkDeque::SkDeque ( size_t  elemSize,
void *  storage,
size_t  storageSize,
int  allocCount = 1 
)

Definition at line 41 of file SkDeque.cpp.

42 : fElemSize(elemSize)
43 , fInitialStorage(storage)
44 , fCount(0)
45 , fAllocCount(allocCount) {
46 SkASSERT(storageSize == 0 || storage != nullptr);
47 SkASSERT(allocCount >= 1);
48
49 if (storageSize >= sizeof(Block) + elemSize) {
50 fFrontBlock = (Block*)storage;
51 fFrontBlock->init(storageSize);
52 } else {
53 fFrontBlock = nullptr;
54 }
55 fBackBlock = fFrontBlock;
56 fFront = fBack = nullptr;
57}
void init(size_t size)
Definition SkDeque.cpp:24

◆ ~SkDeque()

SkDeque::~SkDeque ( )

Definition at line 59 of file SkDeque.cpp.

59 {
60 Block* head = fFrontBlock;
61 Block* initialHead = (Block*)fInitialStorage;
62
63 while (head) {
64 Block* next = head->fNext;
65 if (head != initialHead) {
66 this->freeBlock(head);
67 }
68 head = next;
69 }
70}
static float next(float f)

Member Function Documentation

◆ back() [1/2]

void * SkDeque::back ( )
inline

Definition at line 46 of file SkDeque.h.

46{ return fBack; }

◆ back() [2/2]

const void * SkDeque::back ( ) const
inline

Definition at line 43 of file SkDeque.h.

43{ return fBack; }

◆ count()

int SkDeque::count ( ) const
inline

Definition at line 39 of file SkDeque.h.

39{ return fCount; }

◆ elemSize()

size_t SkDeque::elemSize ( ) const
inline

Definition at line 40 of file SkDeque.h.

40{ return fElemSize; }

◆ empty()

bool SkDeque::empty ( ) const
inline

Definition at line 38 of file SkDeque.h.

38{ return 0 == fCount; }

◆ front() [1/2]

void * SkDeque::front ( )
inline

Definition at line 45 of file SkDeque.h.

45{ return fFront; }

◆ front() [2/2]

const void * SkDeque::front ( ) const
inline

Definition at line 42 of file SkDeque.h.

42{ return fFront; }

◆ pop_back()

void SkDeque::pop_back ( )

Definition at line 187 of file SkDeque.cpp.

187 {
188 SkASSERT(fCount > 0);
189 fCount -= 1;
190
191 Block* last = fBackBlock;
192
193 SkASSERT(last != nullptr);
194
195 if (last->fEnd == nullptr) { // we were marked empty from before
196 last = last->fPrev;
197 SkASSERT(last != nullptr); // else we popped too far
198 last->fNext = nullptr;
199 this->freeBlock(fBackBlock);
200 fBackBlock = last;
201 }
202
203 char* end = last->fEnd - fElemSize;
204 SkASSERT(end >= last->fBegin);
205
206 if (end > last->fBegin) {
207 last->fEnd = end;
208 SkASSERT(last->fEnd);
209 fBack = last->fEnd - fElemSize;
210 } else {
211 last->fBegin = last->fEnd = nullptr; // mark as empty
212 if (nullptr == last->fPrev) {
213 fFront = fBack = nullptr;
214 } else {
215 SkASSERT(last->fPrev->fEnd);
216 fBack = last->fPrev->fEnd - fElemSize;
217 }
218 }
219}
glong glong end

◆ pop_front()

void SkDeque::pop_front ( )

Definition at line 153 of file SkDeque.cpp.

153 {
154 SkASSERT(fCount > 0);
155 fCount -= 1;
156
157 Block* first = fFrontBlock;
158
159 SkASSERT(first != nullptr);
160
161 if (first->fBegin == nullptr) { // we were marked empty from before
162 first = first->fNext;
163 SkASSERT(first != nullptr); // else we popped too far
164 first->fPrev = nullptr;
165 this->freeBlock(fFrontBlock);
166 fFrontBlock = first;
167 }
168
169 char* begin = first->fBegin + fElemSize;
170 SkASSERT(begin <= first->fEnd);
171
172 if (begin < fFrontBlock->fEnd) {
173 first->fBegin = begin;
174 SkASSERT(first->fBegin);
175 fFront = first->fBegin;
176 } else {
177 first->fBegin = first->fEnd = nullptr; // mark as empty
178 if (nullptr == first->fNext) {
179 fFront = fBack = nullptr;
180 } else {
181 SkASSERT(first->fNext->fBegin);
182 fFront = first->fNext->fBegin;
183 }
184 }
185}
static const char * begin(const StringSlice &s)
Definition editor.cpp:252

◆ push_back()

void * SkDeque::push_back ( )

Definition at line 112 of file SkDeque.cpp.

112 {
113 fCount += 1;
114
115 if (nullptr == fBackBlock) {
116 fBackBlock = this->allocateBlock(fAllocCount);
117 fFrontBlock = fBackBlock; // update our linklist
118 }
119
120 Block* last = fBackBlock;
121 char* end;
122
123 if (nullptr == last->fBegin) {
124 INIT_CHUNK:
125 last->fBegin = last->start();
126 end = last->fBegin + fElemSize;
127 } else {
128 end = last->fEnd + fElemSize;
129 if (end > last->fStop) { // no more room in this chunk
130 // should we alloc more as we accumulate more elements?
131 last = this->allocateBlock(fAllocCount);
132 last->fPrev = fBackBlock;
133 fBackBlock->fNext = last;
134 fBackBlock = last;
135 goto INIT_CHUNK;
136 }
137 }
138
139 last->fEnd = end;
140 end -= fElemSize;
141
142 if (nullptr == fBack) {
143 SkASSERT(nullptr == fFront);
144 fFront = fBack = end;
145 } else {
146 SkASSERT(fFront);
147 fBack = end;
148 }
149
150 return end;
151}
Block * fNext
Definition SkDeque.cpp:15

◆ push_front()

void * SkDeque::push_front ( )

push_front and push_back return a pointer to the memory space for the new element

Definition at line 72 of file SkDeque.cpp.

72 {
73 fCount += 1;
74
75 if (nullptr == fFrontBlock) {
76 fFrontBlock = this->allocateBlock(fAllocCount);
77 fBackBlock = fFrontBlock; // update our linklist
78 }
79
80 Block* first = fFrontBlock;
81 char* begin;
82
83 if (nullptr == first->fBegin) {
84 INIT_CHUNK:
85 first->fEnd = first->fStop;
86 begin = first->fStop - fElemSize;
87 } else {
88 begin = first->fBegin - fElemSize;
89 if (begin < first->start()) { // no more room in this chunk
90 // should we alloc more as we accumulate more elements?
91 first = this->allocateBlock(fAllocCount);
92 first->fNext = fFrontBlock;
93 fFrontBlock->fPrev = first;
94 fFrontBlock = first;
95 goto INIT_CHUNK;
96 }
97 }
98
99 first->fBegin = begin;
100
101 if (nullptr == fFront) {
102 SkASSERT(nullptr == fBack);
103 fFront = fBack = begin;
104 } else {
105 SkASSERT(fBack);
106 fFront = begin;
107 }
108
109 return begin;
110}
Block * fPrev
Definition SkDeque.cpp:16

Friends And Related Symbol Documentation

◆ DequeUnitTestHelper

friend class DequeUnitTestHelper
friend

Definition at line 113 of file SkDeque.h.


The documentation for this class was generated from the following files: