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

Public Member Functions

 Graph (int numNodesToReserve, skiatest::Reporter *reporter)
 
NodeaddNode (uint32_t id)
 
void addEdge (Node *dependedOn, Node *dependent)
 
void addEdges (SkTDArray< Node * > *dependedOn, Node *dependent)
 
void getActual (SkString *actual) const
 

Detailed Description

Definition at line 93 of file IncrTopoSortTest.cpp.

Constructor & Destructor Documentation

◆ Graph()

Graph::Graph ( int  numNodesToReserve,
skiatest::Reporter reporter 
)
inline

Definition at line 95 of file IncrTopoSortTest.cpp.

96 : fNodes(numNodesToReserve)
97 , fReporter(reporter) {
98 }
reporter

Member Function Documentation

◆ addEdge()

void Graph::addEdge ( Node dependedOn,
Node dependent 
)
inline

Definition at line 111 of file IncrTopoSortTest.cpp.

111 {
112 // TODO: this would be faster if all the SkTDArray code was stripped out of
113 // addEdges but, when used in MDB sorting, this entry point will never be used.
114 SkTDArray<Node*> tmp(&dependedOn, 1);
115 this->addEdges(&tmp, dependent);
116 }
void addEdges(SkTDArray< Node * > *dependedOn, Node *dependent)

◆ addEdges()

void Graph::addEdges ( SkTDArray< Node * > *  dependedOn,
Node dependent 
)
inline

Definition at line 133 of file IncrTopoSortTest.cpp.

133 {
134 this->validate();
135
136 // remove any of the new dependencies that are already satisfied
137 for (int i = 0; i < dependedOn->size(); ++i) {
138 if ((*dependedOn)[i]->indexInSort() < dependent->indexInSort()) {
139 dependent->addDependency((*dependedOn)[i]);
140 dependedOn->removeShuffle(i);
141 i--;
142 } else {
143 dependent->addDependency((*dependedOn)[i]);
144 }
145 }
146
147 if (dependedOn->empty()) {
148 return;
149 }
150
151 // Sort the remaining dependencies into descending order based on their indices in the
152 // sort. This means that we will be proceeding from right to left in the sort when
153 // correcting the order.
154 // TODO: QSort is waaay overkill here!
155 SkTQSort<Node*>(dependedOn->begin(), dependedOn->end(), Node::CompareIndicesGT);
156
157 // TODO: although this is the general algorithm, I think this can be simplified for our
158 // use case (i.e., the same dependent for all the new edges).
159
160 int lowerBound = fNodes.size(); // 'lowerBound' tracks the left of the affected region
161 for (int i = 0; i < dependedOn->size(); ++i) {
162 if ((*dependedOn)[i]->indexInSort() < lowerBound) {
163 this->shift(lowerBound);
164 }
165
166 if (!dependent->visited()) {
167 this->dfs(dependent, (*dependedOn)[i]->indexInSort());
168 }
169
170 lowerBound = std::min(dependent->indexInSort(), lowerBound);
171 }
172
173 this->shift(lowerBound);
174
175 this->validate();
176 }
T * end()
Definition SkTDArray.h:152
int size() const
Definition SkTDArray.h:138
bool empty() const
Definition SkTDArray.h:135
T * begin()
Definition SkTDArray.h:150
void removeShuffle(int index)
Definition SkTDArray.h:214
int size() const
Definition SkTArray.h:416
bool visited() const
int indexInSort() const
static bool CompareIndicesGT(Node *const &a, Node *const &b)

◆ addNode()

Node * Graph::addNode ( uint32_t  id)
inline

Definition at line 100 of file IncrTopoSortTest.cpp.

100 {
101 this->validate();
102 sk_sp<Node> tmp(new Node(id));
103
104 fNodes.push_back(tmp); // The graph gets the creation ref
105 tmp->setIndexInSort(fNodes.size()-1);
106 this->validate();
107 return tmp.get();
108 }
Definition dart.idl:29

◆ getActual()

void Graph::getActual ( SkString actual) const
inline

Definition at line 179 of file IncrTopoSortTest.cpp.

179 {
180 this->validate();
181
182 for (int i = 0; i < fNodes.size(); ++i) {
183 (*actual) += fNodes[i]->id();
184 if (i < fNodes.size()-1) {
185 (*actual) += ',';
186 }
187 }
188 }

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