//{{{ CellSet Cell::getNetCells() CellSet Cell::getNetCells(const size_t &i, const bool &input) const { CellSet cells; if (i >= nets_.size()) return cells; NetSet eqv = getEqvNets(i); for (NetSet::iterator it = eqv.begin(); it != eqv.end(); ++it) { for (size_t i = 0; i < (*it)->getNPort(); ++i) { Port *p = (*it)->getPort(i); if (p->top_ != this && input && p->type_ == Port::INPUT) cells.insert(p->top_); else if (p->top_ != this && !input && p->type_ == Port::OUTPUT) cells.insert(p->top_); } } return cells; } //}}}
//{{{ CellSet Cell::getNetCells() CellSet Cell::getNetCells(const size_t &i) const { CellSet cells; if (i >= nets_.size()) return cells; NetSet eqv = getEqvNets(i); for (NetSet::iterator it = eqv.begin(); it != eqv.end(); ++it) for (size_t i = 0; i < (*it)->getNPort(); ++i) if ((*it)->getPort(i)->top_ != this) cells.insert((*it)->getPort(i)->top_); return cells; } //}}}
void GameBoard::Update() { CellSet nextLiveCells; CellQueue processQueue(_liveCells); while (!processQueue.Empty()) { Cell& cell = processQueue.Front(); if (nextLiveCells.count(cell) == 0) { // Add neighbours if necessary if (cell.isAlive) { // TODO: Check for dupes? Worth it? if (cell.x < ULONG_MAX) { processQueue.Push(Cell(cell.x+1, cell.y, false)); if (cell.y < ULONG_MAX) { processQueue.Push(Cell(cell.x+1, cell.y+1, false)); } if (cell.y > 0) { processQueue.Push(Cell(cell.x+1, cell.y-1, false)); } } if (cell.y < ULONG_MAX) { processQueue.Push(Cell(cell.x, cell.y+1, false)); } if (cell.x > 0) { processQueue.Push(Cell(cell.x-1, cell.y, false)); if (cell.y < ULONG_MAX) { processQueue.Push(Cell(cell.x-1, cell.y+1, false)); } if (cell.y > 0) { processQueue.Push(Cell(cell.x-1, cell.y-1, false)); } } if (cell.y > 0) { processQueue.Push(Cell(cell.x, cell.y-1, false)); } } int numNeighbours = NumNeighbours(cell); if (numNeighbours == 3 || (cell.isAlive && numNeighbours == 2)) { cell.isAlive = true; nextLiveCells.insert(cell); } processQueue.Pop(); } } _liveCells = nextLiveCells; MarkAlive(_liveCells, _quadTree); }
//{{{ CellSet Cell::getPortCells() CellSet Cell::getPortCells(const size_t &i) const { CellSet cells; if (i >= ports_.size()) return cells; Net *n = ports_[i]->inNet_; if (!n) return cells; NetSet eqv = getEqvNets(n->id_); for (NetSet::iterator it = eqv.begin() ; it != eqv.end(); ++it) { Net *n = *it; for (size_t i = 0; i < n->getNPort(); ++i) { Port *p = n->getPort(i); if (p->top_ != this) cells.insert(p->top_); } } return cells; } //}}}
void QuadTree::FindPoints(const BoundingBox& bound, CellSet& out) const { if (_boundary.Intersects(bound)) { if (_upperLeft == NULL) { // This is a leaf node. Check it! for (vector<Cell>::const_iterator it = _cells.begin(); it != _cells.end(); ++it) { if (bound.ContainsGreedy(it->x, it->y)) { out.insert(*it); } } } else { // This is a parent node. assert(_cells.empty()); _upperLeft->FindPoints(bound, out); _upperRight->FindPoints(bound, out); _lowerLeft->FindPoints(bound, out); _lowerRight->FindPoints(bound, out); } } }
//{{{ CellSet Cell::getFanin() CellSet Cell::getFanin(const size_t &i) const { CellSet fi; if (i >= cells_.size()) return fi; Cell *c = cells_[i]; NetSet eqvs; for (size_t i = 0; i < c->getNPort(); ++i) { if (c->getPort(i)->type_ != Port::INPUT || !c->getPort(i)->exNet_) continue; NetSet eqv = getEqvNets(c->getPort(i)->exNet_->id_); eqvs.insert(eqv.begin(), eqv.end()); } NetSet::iterator it = eqvs.begin(); for ( ; it != eqvs.end(); ++it) { Net *n = *it; for (size_t j = 0; j < n->getNPort(); ++j) { Port *p = n->getPort(j); if (p->top_ != this && p->type_ == Port::OUTPUT) fi.insert(p->top_); } } return fi; } //}}}