bool isSymmetric(struct TreeNode* root) { return root ? isSame(root -> left, root -> right) : 1; }
bool Comment::operator==( const Comment& rhs ) const { return isSame(rhs); }
int ecc_isSame(const uint32_t *A, const uint32_t *B, uint8_t length) { return isSame(A, B, length); }
inline bool isSame(const AzDvect *v) const { if (v == NULL) throw new AzException("AzDvect::isSame", "null input"); return isSame(v->elm, v->num); }
void Node::disconnect(Node * n, Game * g) //only works in reverse order of connecting. { for (Node * o : d->nodes) { if (o == this) continue; o->ds.pop_back(); Q_ASSERT(o->ds.size() > 0); o->d = o->ds.back(); } if (isOccupied()) checkUnclose(g); #if PRINT_CONNECTIONS qDebug() << " disconnect:" << n->id() << "->" << id() << " BEFORE"; // for (Tile const * t : d->tiles) // qDebug() << " " << id() << t->id; // for (Tile const * t : n->d->tiles) // qDebug() << " " << n->id() << t->id; #endif if (!isSame(n)) { for (auto const & t : n->d->nodes) { auto const & i = d->nodes.find(t); Q_ASSERT(i != d->nodes.end()); d->nodes.erase(i); } d->maxMeples = 0; for (uchar * tm = d->meeples, * end = d->meeples + (g->getPlayerCount()), * nm = n->d->meeples; tm < end; ++tm, ++nm) { *tm = (uchar)(*tm - *nm); if (*tm > d->maxMeples) d->maxMeples = *tm; } for (auto const & t : n->d->tiles) d->tiles.erase(d->tiles.find(t)); #if PRINT_CONNECTIONS // qDebug() << " disconnect:" << n->id() << "->" << id(); #endif } #if PRINT_CONNECTIONS else { // qDebug() << " disconnect:" << n->id() << "->" << id() << "skipped"; qDebug() << " skipped"; return; } // qDebug() << " disconnect:" << n->id() << "->" << id() << " AFTER"; // for (Tile const * t : d->tiles) // qDebug() << " " << id() << t->id; // for (Tile const * t : n->d->tiles) // qDebug() << " " << n->id() << t->id; #endif }
void Node::connect(Node * n, Game * g) { Q_ASSERT_X(n->getTerrain() == this->getTerrain(), "Node::connect", "TerrainType does not match"); Q_ASSERT_X(typeid(*n) == typeid(*this), "Node::connect", "classes do not match"); Q_ASSERT(getScored() == NotScored); Q_ASSERT(n->getScored() == NotScored); Q_ASSERT(data.scored == NotScored); Q_ASSERT(n->data.scored == NotScored); #if PRINT_CONNECTIONS qDebug() << " connect:" << n->id() << "->" << id() << " BEFORE"; // for (Tile const * t : d->tiles) // qDebug() << " " << id() << t->id; // for (Tile const * t : n->d->tiles) // qDebug() << " " << n->id() << t->id; #endif if (!isSame(n)) { // for (Node ** & p : n->pointers) // { // *p = this; // pointers.push_back(p); //// p = 0; // } d->tiles.insert(n->d->tiles.begin(), n->d->tiles.end()); for (uchar * tm = d->meeples, * end = d->meeples + (g->getPlayerCount()), * nm = n->d->meeples; tm < end; ++tm, ++nm) { *tm = (uchar)(*tm + *nm); if (*tm > d->maxMeples) d->maxMeples = *tm; } d->nodes.insert(n->d->nodes.begin(), n->d->nodes.end()); #if PRINT_CONNECTIONS // qDebug() << " connect:" << n->id() << "->" << id(); #endif } #if PRINT_CONNECTIONS else { // qDebug() << " connect:" << n->id() << "->" << id() << "skipped"; qDebug() << " skpped"; } // qDebug() << " connect:" << n->id() << "->" << id() << " AFTER"; // for (Tile const * t : d->tiles) // qDebug() << " " << id() << t->id; // for (Tile const * t : n->d->tiles) // qDebug() << " " << n->id() << t->id; #endif // Q_ASSERT(n->d == &n->data); for (Node * o : d->nodes) { if (o == this) continue; o->ds.push_back(d); o->d = d; } if (isOccupied()) checkClose(g); }
int SoXipSFData::operator !=( const SoXipSFData& other ) const { return !isSame(other); }
bool isSymmetric(TreeNode* root) { if (!root){ return true; } return isSame(root->left, root->right); }
bool isSame(TreeNode* s,TreeNode*t) { if(!s)return t==nullptr; return t!=nullptr && s->val==t->val && isSame(s->left,t->left) && isSame(s->right,t->right); }
int getKeywordId(const char *id){ if(isSame(id,"SHORT")){ return SHORT; } if(isSame(id,"INT")){ return INT; } if(isSame(id,"FLOAT")){ return FLOAT; } if(isSame(id,"DOUBLE")){ return DOUBLE; } if(isSame(id,"BOOL")){ return BOOL; } if(isSame(id,"CHAR")){ return CHAR; } if(isSame(id,"SIGNED")){ return SIGNED; } if(isSame(id,"UNSIGNED")){ return UNSIGNED; } if(isSame(id,"FOR")){ return FOR; } if(isSame(id,"WHILE")){ return WHILE; } if(isSame(id,"DO")){ return DO; } if(isSame(id,"RETURN")){ return RETURN; } if(isSame(id,"STRUCT")){ return STRUCT; } if(isSame(id,"CONST")){ return CONST; } if(isSame(id,"VOID")){ return VOID; } if(isSame(id,"SWITCH")){ return SWITCH; } if(isSame(id,"BREAK")){ return BREAK; } if(isSame(id,"CASE")){ return CASE; } if(isSame(id,"CONTINUE")){ return CONTINUE; } if(isSame(id,"GOTO")){ return GOTO; } if(isSame(id,"LONG")){ return LONG; } if(isSame(id,"STATIC")){ return STATIC; } if(isSame(id,"UNION")){ return UNION; } if(isSame(id,"DEFAULT")){ return DEFAULT; } }
const bool ofxWidget::isActivated() const { return (sAllWidgets.empty()) ? false : isSame(mThis, sFocusedWidget); }
// ---------------------------------------------------------------------- // static method - called once for all widgets by the // WidgetEventResponder, which self- // registers to all events upon creation of the first widget. // bool ofxWidget::mouseEvent(ofMouseEventArgs& args_) { // If we register a mouse down event, we do a hit test over // all visible widgets, and re-order if necessary. // Then, and in all other cases, we do a hit-test on the // frontmost widget and, if positive, forward the event to this // widget. updateVisibleWidgetsList(); if (sVisibleWidgets.empty()) return false; // ---------| invariant: there are some widgets flying around. bool eventAttended = false; float mx = args_.x; float my = args_.y; // if we have a mouse down on a widget, we need to check which // widget was hit and potentially re-order widgets. // find the first widget that is under the mouse, that is also visible // if it is not yet up front, bring it to the front. // hit-test only visible widgets - this makes sure to only evaluate // the widgets which are visible, and whose parents are visible, too. auto itUnderMouse = std::find_if(sVisibleWidgets.begin(), sVisibleWidgets.end(), [&mx, &my](std::weak_ptr<ofxWidget>& w) ->bool { auto p = w.lock(); if (p && p->mVisible && p->mRect.inside(mx, my)) { return true; } else { return false; } }); // if we have a click, we want to make sure the widget gets to be the topmost widget. if (args_.type == ofMouseEventArgs::Pressed) { // --- now iterate over sAllWidgets instead of just the visible widgets. // we need to do this, because otherwise the reorder check won't be safe // as the number of children in sVisibleWidgets is potentially incorrect, // as the number of children there refers to all children of a widget, // and not just the visible children of the widget. auto itPressedWidget = (itUnderMouse == sVisibleWidgets.end() ? sAllWidgets.end() : findIt(*itUnderMouse, sAllWidgets.begin(), sAllWidgets.end())); if (itPressedWidget != sAllWidgets.end()) { if (!isSame(*itPressedWidget, sFocusedWidget)) { // change in focus detected. // first, let the first element know that it is losing focus if (auto previousElementInFocus = sFocusedWidget.lock()) if (previousElementInFocus->onFocusLeave) previousElementInFocus->onFocusLeave(); sFocusedWidget = *itPressedWidget; // now that the new wiget is at the front, send an activate callback. if (auto nextFocusedWidget = sFocusedWidget.lock()) if (nextFocusedWidget->onFocusEnter) nextFocusedWidget->onFocusEnter(); } bringToFront(itPressedWidget); // reorder widgets } else { // hit test was not successful, no wigets found. if (auto previousElementInFocus = sFocusedWidget.lock()) if (previousElementInFocus->onFocusLeave) previousElementInFocus->onFocusLeave(); sFocusedWidget.reset(); // no widget gets the focus, then. } } // end if (args_.type == ofMouseEventArgs::Pressed) // now, we will attempt to send the mouse event to the widget that // is in focus. if (itUnderMouse != sVisibleWidgets.end()) { // a widget is under the mouse. // is it the same as the current widget under the mouse? if (!isSame(*itUnderMouse, sWidgetUnderMouse)) { if (auto nU = itUnderMouse->lock()) { // there is a new widget under the mouse if (auto w = sWidgetUnderMouse.lock()) { // there was an old widget under the mouse if (w->onMouseLeave) w->onMouseLeave(); w->mHover = false; } if (nU->onMouseEnter) nU->onMouseEnter(); nU->mHover = true; sWidgetUnderMouse = *itUnderMouse; } } } else { if (auto w = sWidgetUnderMouse.lock()) { // there was a widget under mouse, // but now there is none. if (w->onMouseLeave) w->onMouseLeave(); w->mHover = false; sWidgetUnderMouse.reset(); } } if (auto w = sFocusedWidget.lock()) { if (w->onMouse) { w->onMouse(args_); eventAttended = true; } } // store last mouse position last thing, so that // we are able to calculate a difference. sLastMousePos.set(mx, my); return eventAttended; }
inline void testAll() { typedef Opm::H2O<Scalar> IapwsH2O; typedef Opm::TabulatedComponent<Scalar, IapwsH2O> TabulatedH2O; Scalar tempMin = 274.15; Scalar tempMax = 622.15; unsigned nTemp = static_cast<unsigned>(tempMax - tempMin) * 6/8; Scalar pMin = 10.00; Scalar pMax = IapwsH2O::vaporPressure(tempMax*1.1); unsigned nPress = 50; std::cout << "Creating tabulation with " << nTemp*nPress << " entries per quantity\n"; TabulatedH2O::init(tempMin, tempMax, nTemp, pMin, pMax, nPress); std::cout << "Checking tabulation\n"; success = true; unsigned m = nTemp*3; unsigned n = nPress*3; for (unsigned i = 0; i < m; ++i) { Scalar T = tempMin + (tempMax - tempMin)*Scalar(i)/m; if (i % std::max<unsigned>(1, m/1000) == 0) { std::cout << Scalar(i)/m*100 << "% done \r"; std::cout.flush(); } isSame("vaporPressure", TabulatedH2O::vaporPressure(T), IapwsH2O::vaporPressure(T), Scalar(1e-3)); for (unsigned j = 0; j < n; ++j) { Scalar p = pMin + (pMax - pMin)*Scalar(j)/n; if (p < IapwsH2O::vaporPressure(T) * 1.001) { Scalar tol = 1e-3; if (p > IapwsH2O::vaporPressure(T)) tol = 1e-2; Scalar rho = IapwsH2O::gasDensity(T,p); //isSame("Iapws::gasPressure", IapwsH2O::gasPressure(T,rho), p, 1e-6); //isSame("gasPressure", TabulatedH2O::gasPressure(T,rho), p, 2e-2); isSame("gasEnthalpy", TabulatedH2O::gasEnthalpy(T,p), IapwsH2O::gasEnthalpy(T,p), tol); isSame("gasInternalEnergy", TabulatedH2O::gasInternalEnergy(T,p), IapwsH2O::gasInternalEnergy(T,p), tol); isSame("gasDensity", TabulatedH2O::gasDensity(T,p), rho, tol); isSame("gasViscosity", TabulatedH2O::gasViscosity(T,p), IapwsH2O::gasViscosity(T,p), tol); } if (p > IapwsH2O::vaporPressure(T) / 1.001) { Scalar tol = 1e-3; if (p < IapwsH2O::vaporPressure(T)) tol = 1e-2; Scalar rho = IapwsH2O::liquidDensity(T,p); //isSame("Iapws::liquidPressure", IapwsH2O::liquidPressure(T,rho), p, 1e-6); //isSame("liquidPressure", TabulatedH2O::liquidPressure(T,rho), p, 2e-2); isSame("liquidEnthalpy", TabulatedH2O::liquidEnthalpy(T,p), IapwsH2O::liquidEnthalpy(T,p), tol); isSame("liquidInternalEnergy", TabulatedH2O::liquidInternalEnergy(T,p), IapwsH2O::liquidInternalEnergy(T,p), tol); isSame("liquidDensity", TabulatedH2O::liquidDensity(T,p), rho, tol); isSame("liquidViscosity", TabulatedH2O::liquidViscosity(T,p), IapwsH2O::liquidViscosity(T,p), tol); } } //std::cerr << "\n"; } if (success) std::cout << "\nsuccess\n"; }