コード例 #1
0
ファイル: raft_consensus.cpp プロジェクト: chenbk85/raft
void RaftConsensus::handleVoteRequest(const VoteRequest& req, VoteResponse* resp) {
    std::lock_guard<std::mutex> lock(mu_);

    if (!checkTerm(req.term(), 0)) {  // term小于当前term
        resp->set_term(term_);
        resp->set_votegranted(false);
    }
    else {
        switch (state_) {
        case StateFollower:
            // TODO: check log
            if (vote_for_ == 0 || vote_for_ == req.candidateid()) {
                vote_for_ = req.candidateid();
                resp->set_term(term_);
                resp->set_votegranted(true);
            }
            else {
                resp->set_term(term_);
                resp->set_votegranted(false);
            }
            break;
        default:
            resp->set_term(term_);
            resp->set_votegranted(false);
            break;
        }
    }
}
コード例 #2
0
ファイル: lookup.cpp プロジェクト: daniel-kun/jisho
JishoLookupMode jishoGuessLookupMode(const QString &term)
{
   if (term.indexOf(QRegExp("[abcdefghijklmnopqrstuvwxyz]")) >= 0)
   {
      static QSet<QString> kana = fileLoader(":/resources/kana.txt");
      QString checkTerm(term);
      bool kanaOk = true;
      while (!checkTerm.isEmpty())
      {
         bool found = false;
         foreach(QString k, kana)
         {
            if (checkTerm.startsWith(k))
            {
               found = true;
               checkTerm.remove(0, k.size());
               break;
            }
         }
         if (!found)
         {
            kanaOk = false;
            break;
         }
      }
      if (kanaOk)
         return LookupRomaji;
      else
         return LookupNative;
   }
   return LookupJapanese;
}
コード例 #3
0
ファイル: hgGateway.c プロジェクト: davidhoover/kent
static struct dbDbMatch *searchDbDb(struct dbDb *dbDbList, char *term)
/* Search various fields of dbDb for matches to term and sort by relevance. */
{
struct dbDbMatch *matchList = NULL;
struct hash *matchHash = hashNew(0);
struct dbDb *dbDb;
for (dbDb = dbDbList;  dbDb != NULL; dbDb = dbDb->next)
    {
    checkTerm(term, dbDb->name, ddmtDb, dbDb, matchHash, &matchList);
    // Skip experimental stuff on hgwdev with bogus taxId unless the db name matches term.
    if (dbDb->taxId >= 2)
        {
        checkTerm(term, dbDb->genome, ddmtGenome, dbDb, matchHash, &matchList);
        checkTerm(term, dbDb->scientificName, ddmtSciName, dbDb, matchHash, &matchList);
        }
    // dbDb.description is a little too much for autocomplete ("br" would match dozens
    // of Broad assemblies), but we do need to recognize "GRC".
    if (startsWith("GR", term))
        checkTerm(term, dbDb->description, ddmtDescription, dbDb, matchHash, &matchList);
    }
slSort(&matchList, dbDbMatchCmp);
return matchList;
}
コード例 #4
0
ファイル: raft_consensus.cpp プロジェクト: chenbk85/raft
void RaftConsensus::handleAppendEntriesRequeset(const AppendEntriesRequest& req, AppendEntriesResponse* resp) {
    std::lock_guard<std::mutex> lock(mu_);

    if (!checkTerm(req.term(), req.leaderid())) {
        resp->set_term(term_);
        resp->set_success(false);
    }
    else {
        if (StateFollower == state_ && leaderid_ == 0)
            leaderid_ = req.leaderid();
        resp->set_term(term_);
        resp->set_success(true);
    }
}
コード例 #5
0
ファイル: raft_consensus.cpp プロジェクト: chenbk85/raft
void RaftConsensus::handleInstallSnapShotRequest(const InstallSnapShotRequest& req, InstallSnapShotResponse* resp) {
    std::lock_guard<std::mutex> lock(mu_);

    if (!checkTerm(req.term(), req.leaderid())) return;
}
コード例 #6
0
void SubPixelCorner::RefineCorner(cv::Mat image, std::vector< cv::Point2f > &corners) {

    if (enable == false)
        return;
    checkTerm();

    generateMask();
    // loop over all the corner points
    for (int k = 0; k < corners.size(); k++) {
        cv::Point2f curr_corner;
        // initial estimate
        cv::Point2f estimate_corner = corners[k];

        // cerr << 'SSS" << corners[k].x <<":" << corners[k].y << endl;

        if (estimate_corner.x < 0 || estimate_corner.y < 0 || estimate_corner.y > image.rows || estimate_corner.y > image.cols)
            continue;
        int iter = 0;
        double dist = TermCriteria::EPS;
        // loop till termination criteria is met
        do {
            iter = iter + 1;
            curr_corner = estimate_corner;

            /*
    Point cx;
    cx.x=floor(curr_corner.x);
    cx.y=floor(curr_corner.y);
    double dx=curr_corner.x-cx.x;
    double dy=curr_corner.y-cx.y;
    float vIx[2];
    float vIy[2];

    vIx[0] = dx;
    vIx[1] = 1 - dx;
    vIy[0] = dy;
    vIy[1] = 1 - dy;

    int x1=std::max((int)(cx.x-_winSize-_apertureSize/2),0);
    int y1=std::max((int)(cx.y-_winSize-_apertureSize/2),0);

    xmin = x1<0?0:x1;
    xmax = x1+_winSize<image.cols?x1+_winSize:image.cols-1;
    ymin = y1<0?0:y1;
    ymax = y1+_winSize<image.rows?y1+_winSize:image.rows-1;

    Rect roi=Rect(xmin,ymin,xmax-xmin,ymax-ymin);
    */

            Mat local;
            cv::getRectSubPix(image, Size(_winSize + 2 * (_apertureSize / 2), _winSize + 2 * (_apertureSize / 2)), curr_corner, local);



            cv::Mat Dx, Dy;
            // extracing image ROI about the corner point
            // Mat local=image(roi);
            // computing the gradients over the neighborhood about corner point
            cv::Sobel(local, Dx, CV_32FC(1), 1, 0, _apertureSize, 1, 0);
            cv::Sobel(local, Dy, CV_32FC(1), 0, 1, _apertureSize, 1, 0);

            // parameters requried for estimations
            double A = 0, B = 0, C = 0, D = 0, E = 0, F = 0;
            int lx = 0, ly = 0;
            for (int i = _apertureSize / 2; i <= _winSize; i++) {

                float *dx_ptr = Dx.ptr< float >(i);
                float *dy_ptr = Dy.ptr< float >(i);
                ly = i - _winSize / 2 - _apertureSize / 2;

                float *mask_ptr = mask.ptr< float >(ly + _winSize / 2);

                for (int j = _apertureSize / 2; j <= _winSize; j++) {

                    lx = j - _winSize / 2 - _apertureSize / 2;
                    // cerr << lx+_winSize/2 << ":" ;
                    double val = mask_ptr[lx + _winSize / 2];
                    double dxx = dx_ptr[j] * dx_ptr[j] * val;
                    double dyy = dy_ptr[j] * dy_ptr[j] * val;
                    double dxy = dx_ptr[j] * dy_ptr[j] * val;

                    A = A + dxx;
                    B = B + dxy;
                    E = E + dyy;
                    C = C + dxx * lx + dxy * ly;
                    F = F + dxy * lx + dyy * ly;
                }
            }

            // computing denominator
            double det = (A * E - B * B);
            if (fabs(det) > DBL_EPSILON * DBL_EPSILON) {
                det = 1.0 / det;
                // translating back to original corner and adding new estimates
                estimate_corner.x = curr_corner.x + ((C * E) - (B * F)) * det;
                estimate_corner.y = curr_corner.y + ((A * F) - (C * D)) * det;
            } else {
                estimate_corner.x = curr_corner.x;
                estimate_corner.y = curr_corner.y;
            }

            dist = pointDist(estimate_corner, curr_corner);


        } while (iter < _max_iters && dist > eps);

        // double dist=pointDist(corners[k],estimate_corner);
        if (fabs(corners[k].x - estimate_corner.x) > _winSize || fabs(corners[k].y - estimate_corner.y) > _winSize) {
            estimate_corner.x = corners[k].x;
            estimate_corner.y = corners[k].y;
        }
        corners[k].x = estimate_corner.x;
        corners[k].y = estimate_corner.y;
        // cerr << "EEE" << corners[k].x <<":" << corners[k].y << endl;
    }
}