proxygen
testing::internal::MaxBipartiteMatchState Class Reference

Public Member Functions

 MaxBipartiteMatchState (const MatchMatrix &graph)
 
ElementMatcherPairs Compute ()
 
 MaxBipartiteMatchState (const MatchMatrix &graph)
 
ElementMatcherPairs Compute ()
 
 MaxBipartiteMatchState (const MatchMatrix &graph)
 
ElementMatcherPairs Compute ()
 

Private Member Functions

bool TryAugment (size_t ilhs,::std::vector< char > *seen)
 
 GTEST_DISALLOW_ASSIGN_ (MaxBipartiteMatchState)
 
bool TryAugment (size_t ilhs,::std::vector< char > *seen)
 
 GTEST_DISALLOW_ASSIGN_ (MaxBipartiteMatchState)
 
bool TryAugment (size_t ilhs,::std::vector< char > *seen)
 
 GTEST_DISALLOW_ASSIGN_ (MaxBipartiteMatchState)
 

Private Attributes

const MatchMatrixgraph_
 
::std::vector< size_t > left_
 
::std::vector< size_t > right_
 

Static Private Attributes

static const size_t kUnused = static_cast<size_t>(-1)
 

Detailed Description

Definition at line 198 of file gmock-matchers.cc.

Constructor & Destructor Documentation

testing::internal::MaxBipartiteMatchState::MaxBipartiteMatchState ( const MatchMatrix graph)
inlineexplicit

Definition at line 200 of file gmock-matchers.cc.

testing::internal::MaxBipartiteMatchState::MaxBipartiteMatchState ( const MatchMatrix graph)
inlineexplicit

Definition at line 200 of file gmock-matchers.cc.

testing::internal::MaxBipartiteMatchState::MaxBipartiteMatchState ( const MatchMatrix graph)
inlineexplicit

Definition at line 200 of file gmock-matchers.cc.

Member Function Documentation

ElementMatcherPairs testing::internal::MaxBipartiteMatchState::Compute ( )
inline

Definition at line 207 of file gmock-matchers.cc.

References graph_, GTEST_CHECK_, kUnused, and seen.

Referenced by testing::internal::FindMaxBipartiteMatching(), and TryAugment().

207  {
208  // 'seen' is used for path finding { 0: unseen, 1: seen }.
209  ::std::vector<char> seen;
210  // Searches the residual flow graph for a path from each left node to
211  // the sink in the residual flow graph, and if one is found, add flow
212  // to the graph. It's okay to search through the left nodes once. The
213  // edge from the implicit source node to each previously-visited left
214  // node will have flow if that left node has any path to the sink
215  // whatsoever. Subsequent augmentations can only add flow to the
216  // network, and cannot take away that previous flow unit from the source.
217  // Since the source-to-left edge can only carry one flow unit (or,
218  // each element can be matched to only one matcher), there is no need
219  // to visit the left nodes more than once looking for augmented paths.
220  // The flow is known to be possible or impossible by looking at the
221  // node once.
222  for (size_t ilhs = 0; ilhs < graph_->LhsSize(); ++ilhs) {
223  // Reset the path-marking vector and try to find a path from
224  // source to sink starting at the left_[ilhs] node.
225  GTEST_CHECK_(left_[ilhs] == kUnused)
226  << "ilhs: " << ilhs << ", left_[ilhs]: " << left_[ilhs];
227  // 'seen' initialized to 'graph_->RhsSize()' copies of 0.
228  seen.assign(graph_->RhsSize(), 0);
229  TryAugment(ilhs, &seen);
230  }
231  ElementMatcherPairs result;
232  for (size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
233  size_t irhs = left_[ilhs];
234  if (irhs == kUnused) continue;
235  result.push_back(ElementMatcherPair(ilhs, irhs));
236  }
237  return result;
238  }
::std::vector< ElementMatcherPair > ElementMatcherPairs
std::unordered_set< std::pair< const IValidator *, const dynamic * > > seen
Definition: JSONSchema.cpp:92
bool TryAugment(size_t ilhs,::std::vector< char > *seen)
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1295
::std::pair< size_t, size_t > ElementMatcherPair
ElementMatcherPairs testing::internal::MaxBipartiteMatchState::Compute ( )
inline

Definition at line 207 of file gmock-matchers.cc.

References graph_, GTEST_CHECK_, kUnused, and seen.

207  {
208  // 'seen' is used for path finding { 0: unseen, 1: seen }.
209  ::std::vector<char> seen;
210  // Searches the residual flow graph for a path from each left node to
211  // the sink in the residual flow graph, and if one is found, add flow
212  // to the graph. It's okay to search through the left nodes once. The
213  // edge from the implicit source node to each previously-visited left
214  // node will have flow if that left node has any path to the sink
215  // whatsoever. Subsequent augmentations can only add flow to the
216  // network, and cannot take away that previous flow unit from the source.
217  // Since the source-to-left edge can only carry one flow unit (or,
218  // each element can be matched to only one matcher), there is no need
219  // to visit the left nodes more than once looking for augmented paths.
220  // The flow is known to be possible or impossible by looking at the
221  // node once.
222  for (size_t ilhs = 0; ilhs < graph_->LhsSize(); ++ilhs) {
223  // Reset the path-marking vector and try to find a path from
224  // source to sink starting at the left_[ilhs] node.
225  GTEST_CHECK_(left_[ilhs] == kUnused)
226  << "ilhs: " << ilhs << ", left_[ilhs]: " << left_[ilhs];
227  // 'seen' initialized to 'graph_->RhsSize()' copies of 0.
228  seen.assign(graph_->RhsSize(), 0);
229  TryAugment(ilhs, &seen);
230  }
231  ElementMatcherPairs result;
232  for (size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
233  size_t irhs = left_[ilhs];
234  if (irhs == kUnused) continue;
235  result.push_back(ElementMatcherPair(ilhs, irhs));
236  }
237  return result;
238  }
::std::vector< ElementMatcherPair > ElementMatcherPairs
std::unordered_set< std::pair< const IValidator *, const dynamic * > > seen
Definition: JSONSchema.cpp:92
bool TryAugment(size_t ilhs,::std::vector< char > *seen)
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1295
::std::pair< size_t, size_t > ElementMatcherPair
ElementMatcherPairs testing::internal::MaxBipartiteMatchState::Compute ( )
inline

Definition at line 207 of file gmock-matchers.cc.

References graph_, GTEST_CHECK_, kUnused, and seen.

207  {
208  // 'seen' is used for path finding { 0: unseen, 1: seen }.
209  ::std::vector<char> seen;
210  // Searches the residual flow graph for a path from each left node to
211  // the sink in the residual flow graph, and if one is found, add flow
212  // to the graph. It's okay to search through the left nodes once. The
213  // edge from the implicit source node to each previously-visited left
214  // node will have flow if that left node has any path to the sink
215  // whatsoever. Subsequent augmentations can only add flow to the
216  // network, and cannot take away that previous flow unit from the source.
217  // Since the source-to-left edge can only carry one flow unit (or,
218  // each element can be matched to only one matcher), there is no need
219  // to visit the left nodes more than once looking for augmented paths.
220  // The flow is known to be possible or impossible by looking at the
221  // node once.
222  for (size_t ilhs = 0; ilhs < graph_->LhsSize(); ++ilhs) {
223  // Reset the path-marking vector and try to find a path from
224  // source to sink starting at the left_[ilhs] node.
225  GTEST_CHECK_(left_[ilhs] == kUnused)
226  << "ilhs: " << ilhs << ", left_[ilhs]: " << left_[ilhs];
227  // 'seen' initialized to 'graph_->RhsSize()' copies of 0.
228  seen.assign(graph_->RhsSize(), 0);
229  TryAugment(ilhs, &seen);
230  }
231  ElementMatcherPairs result;
232  for (size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
233  size_t irhs = left_[ilhs];
234  if (irhs == kUnused) continue;
235  result.push_back(ElementMatcherPair(ilhs, irhs));
236  }
237  return result;
238  }
::std::vector< ElementMatcherPair > ElementMatcherPairs
std::unordered_set< std::pair< const IValidator *, const dynamic * > > seen
Definition: JSONSchema.cpp:92
bool TryAugment(size_t ilhs,::std::vector< char > *seen)
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1295
::std::pair< size_t, size_t > ElementMatcherPair
testing::internal::MaxBipartiteMatchState::GTEST_DISALLOW_ASSIGN_ ( MaxBipartiteMatchState  )
private
testing::internal::MaxBipartiteMatchState::GTEST_DISALLOW_ASSIGN_ ( MaxBipartiteMatchState  )
private
testing::internal::MaxBipartiteMatchState::GTEST_DISALLOW_ASSIGN_ ( MaxBipartiteMatchState  )
private
bool testing::internal::MaxBipartiteMatchState::TryAugment ( size_t  ilhs,
::std::vector< char > *  seen 
)
inlineprivate

Definition at line 259 of file gmock-matchers.cc.

References graph_.

259  {
260  for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
261  if ((*seen)[irhs])
262  continue;
263  if (!graph_->HasEdge(ilhs, irhs))
264  continue;
265  // There's an available edge from ilhs to irhs.
266  (*seen)[irhs] = 1;
267  // Next a search is performed to determine whether
268  // this edge is a dead end or leads to the sink.
269  //
270  // right_[irhs] == kUnused means that there is residual flow from
271  // right node irhs to the sink, so we can use that to finish this
272  // flow path and return success.
273  //
274  // Otherwise there is residual flow to some ilhs. We push flow
275  // along that path and call ourselves recursively to see if this
276  // ultimately leads to sink.
277  if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
278  // Add flow from left_[ilhs] to right_[irhs].
279  left_[ilhs] = irhs;
280  right_[irhs] = ilhs;
281  return true;
282  }
283  }
284  return false;
285  }
bool HasEdge(size_t ilhs, size_t irhs) const
bool TryAugment(size_t ilhs,::std::vector< char > *seen)
bool testing::internal::MaxBipartiteMatchState::TryAugment ( size_t  ilhs,
::std::vector< char > *  seen 
)
inlineprivate

Definition at line 259 of file gmock-matchers.cc.

References Compute(), testing::internal::FindMaxBipartiteMatching(), g(), graph_, GTEST_API_, GTEST_DISALLOW_ASSIGN_, and kUnused.

259  {
260  for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
261  if ((*seen)[irhs])
262  continue;
263  if (!graph_->HasEdge(ilhs, irhs))
264  continue;
265  // There's an available edge from ilhs to irhs.
266  (*seen)[irhs] = 1;
267  // Next a search is performed to determine whether
268  // this edge is a dead end or leads to the sink.
269  //
270  // right_[irhs] == kUnused means that there is residual flow from
271  // right node irhs to the sink, so we can use that to finish this
272  // flow path and return success.
273  //
274  // Otherwise there is residual flow to some ilhs. We push flow
275  // along that path and call ourselves recursively to see if this
276  // ultimately leads to sink.
277  if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
278  // Add flow from left_[ilhs] to right_[irhs].
279  left_[ilhs] = irhs;
280  right_[irhs] = ilhs;
281  return true;
282  }
283  }
284  return false;
285  }
bool HasEdge(size_t ilhs, size_t irhs) const
bool TryAugment(size_t ilhs,::std::vector< char > *seen)
bool testing::internal::MaxBipartiteMatchState::TryAugment ( size_t  ilhs,
::std::vector< char > *  seen 
)
inlineprivate

Definition at line 259 of file gmock-matchers.cc.

References Compute(), testing::internal::FindMaxBipartiteMatching(), g(), graph_, GTEST_API_, GTEST_DISALLOW_ASSIGN_, and kUnused.

259  {
260  for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
261  if ((*seen)[irhs])
262  continue;
263  if (!graph_->HasEdge(ilhs, irhs))
264  continue;
265  // There's an available edge from ilhs to irhs.
266  (*seen)[irhs] = 1;
267  // Next a search is performed to determine whether
268  // this edge is a dead end or leads to the sink.
269  //
270  // right_[irhs] == kUnused means that there is residual flow from
271  // right node irhs to the sink, so we can use that to finish this
272  // flow path and return success.
273  //
274  // Otherwise there is residual flow to some ilhs. We push flow
275  // along that path and call ourselves recursively to see if this
276  // ultimately leads to sink.
277  if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
278  // Add flow from left_[ilhs] to right_[irhs].
279  left_[ilhs] = irhs;
280  right_[irhs] = ilhs;
281  return true;
282  }
283  }
284  return false;
285  }
bool HasEdge(size_t ilhs, size_t irhs) const
bool TryAugment(size_t ilhs,::std::vector< char > *seen)

Member Data Documentation

const MatchMatrix * testing::internal::MaxBipartiteMatchState::graph_
private

Definition at line 287 of file gmock-matchers.cc.

const size_t testing::internal::MaxBipartiteMatchState::kUnused = static_cast<size_t>(-1)
staticprivate

Definition at line 241 of file gmock-matchers.cc.

std::vector< size_t > testing::internal::MaxBipartiteMatchState::left_
private

Definition at line 299 of file gmock-matchers.cc.

std::vector< size_t > testing::internal::MaxBipartiteMatchState::right_
private

Definition at line 300 of file gmock-matchers.cc.


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