当前位置: 首页>>代码示例>>C++>>正文


C++ difference函数代码示例

本文整理汇总了C++中difference函数的典型用法代码示例。如果您正苦于以下问题:C++ difference函数的具体用法?C++ difference怎么用?C++ difference使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了difference函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: wait_until_published

 sequence_t wait_until_published(
     sequence_t sequence,
     sequence_t lastKnownPublished,
     const std::chrono::time_point<Clock, Duration>& timeoutTime) const
 {
     assert(difference(sequence, lastKnownPublished) > 0);
     
     for (sequence_t seq = lastKnownPublished + 1;
          difference(seq, sequence) <= 0;
          ++seq)
     {
         if (!is_published(seq))
         {
             const std::atomic<sequence_t>* const sequences[1] =
                 { &m_published[seq & m_indexMask] };
             sequence_t result =
                 m_waitStrategy.wait_until_published(seq, 1, sequences);
             if (difference(result, seq) < 0)
             {
                 // Timeout. seq is the first non-published sequence
                 return seq - 1;
             }
         }
     }
     return last_published_after(sequence);
 }
开发者ID:lewissbaker,项目名称:disruptorplus,代码行数:26,代码来源:multi_threaded_claim_strategy.hpp

示例2: zeroing

void PolyaevaEV::lab7()
{
    double norm, eps = 0.0001;
    double* AP = new double[N];
    double* DIS = new double[N];
	  zeroing(x);
	  zeroing(AP);

    do {
		    double *TEMP = multiplication_matrix_on_vector(A, x);
		    difference(DIS, TEMP, b);

        double tau = multiplication_of_vectors(DIS, DIS);
		    double tempTau = multiplication_of_vectors(multiplication_matrix_on_vector(A, DIS), DIS);
		    tau = tau/tempTau;
		    if (tau != tau) tau = eps;

		    for (int i = 0; i < N; i++) TEMP[i] = DIS[i]*tau;
        difference(AP, AP, TEMP);

        norm = fabs(x[0] - AP[0]);
		    for (int i = 0; i < N; i++)
        {
			       if (fabs(x[i] - AP[i]) > norm) norm = fabs(x[i] - AP[i]);
			       x[i] = AP[i];
		    }
		   delete[] TEMP;
    } while (norm > eps);
	  delete[] AP;
	  delete[] DIS;
}
开发者ID:amshegarh,项目名称:2016-203,代码行数:31,代码来源:PolyaevaEV.cpp

示例3: plumed_dbg_assert

double HistogramBead::calculateWithCutoff( double x, double& df ) const {
  plumed_dbg_assert(init && periodicity!=unset );

  double lowB, upperB, f;
  lowB = difference( x, lowb ) / width ; upperB = difference( x, highb ) / width;
  if( upperB<=-cutoff || lowB>=cutoff ) { df=0; return 0; }

  if( type==gaussian ) {
    lowB /= sqrt(2.0); upperB /= sqrt(2.0);
    df = ( exp( -lowB*lowB ) - exp( -upperB*upperB ) ) / ( sqrt(2*pi)*width );
    f = 0.5*( erf( upperB ) - erf( lowB ) );
  } else if( type==triangular ) {
    df=0;
    if( fabs(lowB)<1. ) df = (1 - fabs(lowB)) / width;
    if( fabs(upperB)<1. ) df -= (1 - fabs(upperB)) / width;
    if (upperB<=-1. || lowB >=1.) {
      f=0.;
    } else {
      double ia, ib;
      if( lowB>-1.0 ) { ia=lowB; } else { ia=-1.0; }
      if( upperB<1.0 ) { ib=upperB; } else { ib=1.0; }
      f = (ib*(2.-fabs(ib))-ia*(2.-fabs(ia)))*0.5;
    }
  } else {
    plumed_merror("function type does not exist");
  }
  return f;
}
开发者ID:JFDama,项目名称:plumed2,代码行数:28,代码来源:HistogramBead.cpp

示例4: setDefaultDeny

void PrivacyManager::setPrivacy( bool defaultIsDeny, const QStringList & allowList, const QStringList & denyList )
{
	if ( defaultIsDeny != m_defaultDeny )
		setDefaultDeny( defaultIsDeny );
	// find the DNs no longer in the allow list
	QStringList allowsToRemove = difference( m_allowList, allowList );
	// find the DNs no longer in the deny list
	QStringList denysToRemove = difference( m_denyList, denyList );
	// find the DNs new in the allow list
	QStringList allowsToAdd = difference( allowList, m_allowList );
	// find the DNs new in the deny list
	QStringList denysToAdd = difference( denyList, m_denyList );
	
	QStringList::ConstIterator end = allowsToRemove.end();
	for ( QStringList::ConstIterator it = allowsToRemove.begin(); it != end; ++it )
		removeAllow( *it );
	end = denysToRemove.end();
	for ( QStringList::ConstIterator it = denysToRemove.begin(); it != end; ++it )
		removeDeny( *it );
	end = allowsToAdd.end();
	for ( QStringList::ConstIterator it = allowsToAdd.begin(); it != end; ++it )
		addAllow( *it );
	end = denysToAdd.end();
	for ( QStringList::ConstIterator it = denysToAdd.begin(); it != end; ++it )
		addDeny( *it );
}
开发者ID:serghei,项目名称:kde3-kdenetwork,代码行数:26,代码来源:privacymanager.cpp

示例5: compute_angular_forces

void
compute_angular_forces()
{
  int i, j, k;
  struct vertex *u, *v, *w;
  struct point dvu, dvw, normal;
  double fact, s;

  s = 0.5 * sin((M_PI - bestangle) / 2.0);

  for (i = 1; i <= nvertices; i++) {
    u = &(vertices[i]);

    for (j = 0; j + 1 < u->valency; j++) {
      v = &(vertices[u->adj[j]]);

      for (k = j + 1; k < u->valency; k++) {
	w = &(vertices[u->adj[k]]);

	dvu = difference(u->pos, v->pos);
	dvw = difference(w->pos, v->pos);
	normal = crossproduct(dvw, dvu);
	normal = crossproduct(normal, dvw);
	fact = s * norm(dvw) / norm(normal);
	u->disp.x += 0.05 * (0.5 * dvw.x + fact * normal.x  - dvu.x);
	u->disp.y += 0.05 * (0.5 * dvw.y + fact * normal.y  - dvu.y);
	u->disp.z += 0.05 * (0.5 * dvw.z + fact * normal.z  - dvu.z);
      }
    }
  }
}
开发者ID:CaGe-graph,项目名称:CaGe,代码行数:31,代码来源:tkspring.c

示例6: isEar

    bool isEar(int u, int v, int w, const std::vector<uint32_t>& vertices)
    {
        PointXY p_u = toPointXY(points_.points[vertices[u]]);
        PointXY p_v = toPointXY(points_.points[vertices[v]]);
        PointXY p_w = toPointXY(points_.points[vertices[w]]);

        // Avoid flat triangles.
        // FIXME: what happens if all the triangles are flat in the X-Y axis?
        const float eps = 1e-15;
        PointXY p_uv = difference(p_v, p_u);
        PointXY p_uw = difference(p_w, p_u);
        if (crossProduct(p_uv, p_uw) < eps)
        {
            ntk_dbg(1) << cv::format("FLAT: (%d, %d, %d)", u, v, w);
            return false;
        }

        // Check if any other vertex is inside the triangle.
        for (int k = 0; k < vertices.size(); k++)
        {
            if ((k == u) || (k == v) || (k == w))
                continue;
            PointXY p = toPointXY(points_.points[vertices[k]]);
            if (isInsideTriangle(p_u, p_v, p_w, p))
                return false;
        }
        return true;
    }
开发者ID:vdavid70619,项目名称:Turtlebot,代码行数:28,代码来源:test-polygon.cpp

示例7: find_closer_key

// Check which of keys a and b is closer to the target key. If they are equally
// close, the next key from the target to the incrementing direction is
// considered closer. All arrays must be of length SHA1_DIGEST_LENGTH.
// Return: 1 if a is closer, 0 if b is closer, -1 if a and b are equal.
int find_closer_key(unsigned char *target, unsigned char *a, unsigned char *b)
{
    // Calculate differences
    unsigned char dif_a[SHA1_DIGEST_LENGTH];
    int a_bigger_t = difference(dif_a, a, target);
    unsigned char dif_b[SHA1_DIGEST_LENGTH];
    int b_bigger_t = difference(dif_b, b, target);
    int i;
    // Check if one is closer
    for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
        if (dif_b[i] > dif_a[i])
            return 1;
        if (dif_b[i] < dif_a[i])
            return 0;
    }
    // Distances are equal. Checking which one is in incremental direction.
    // N.B. in this point a and b cant be equal to the target.
    if (a_bigger_t && !b_bigger_t)
        return 1;
    if (!a_bigger_t && b_bigger_t)
        return 0;
    // Check if a or b is bigger
    for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
        if (b[i] > a[i]) {
            return 1;
        } else if (b[i] < a[i])
            return 0;
    }
    // a and b are equal
    return -1;
}
开发者ID:RikuLindholm,项目名称:adhd,代码行数:35,代码来源:sha1.c

示例8: TEST

TEST(bind_with_result, return_from_function_pointer1)
{
    {
        int diff = weos::bind<int>(&difference, 1, 2) ();
        ASSERT_EQ(difference(1, 2), diff);
    }

    {
        int diff = weos::bind<int>(&difference, weos::placeholders::_2,
                                   weos::placeholders::_1) (1, 2);
        ASSERT_EQ(difference(2, 1), diff);
    }

    for (int counter = 0; counter < 100; ++counter)
    {
        int diff = weos::bind<int>(&difference, weos::placeholders::_1, 1) (
                       counter);
        ASSERT_EQ(counter - 1, diff);
    }

    for (int counter = 0; counter < 100; ++counter)
    {
        int diff = weos::bind<int>(&difference, 0, weos::placeholders::_4) (
                       0, 1, 2, counter);
        ASSERT_EQ(-counter, diff);
    }
}
开发者ID:kaidokert,项目名称:weos,代码行数:27,代码来源:tst_bind_with_result.cpp

示例9: main

int main(){
	string buffer("buffer.txt");
	string solution("solution.txt");
	
	//for (unsigned int test_number = 0; test_number <= 100000000; test_number) {

#ifdef READ
		T w, h;
		ifstream in_stream(buffer);
		in_stream >> w >> h;
		matrix<T> source(w, h);
		for (auto& i : source) {
			in_stream >> i;
		}
		in_stream.close();
#else
		const T w = 1000, h = 1000;
		matrix<T> source = gen_sourse_data(w, h, 5);
#endif
#ifdef WRITE
		ofstream out_stream(buffer);
		out_stream << w << ' ' << h;
		T j = 0;
		for (const auto& i : source) {
			if ((j++ % w) == 0) out_stream << '\n';
			out_stream << i << ' ';
		}
		out_stream.close();
#endif
#ifdef SOLVE
		cout << "w = " << w << "; h = " << h << ";" << endl;
		auto start_time = clock();
		matrix<T> source_copy(source);//эта матрица будет преобразована в такую, что в каждом квадрате 3х3 будет не больше 3 текстур
		matrix< array<pair<T, bool>, 3> > res = get_textures_arrangement(source_copy);
		double time = (clock() - start_time) / double(1000);


		auto source_from_res = res_to_source(res);
		auto diff1 = difference(source, source_from_res);
		auto diff2 = difference(source, source_copy);
		cout << "time is " << time << " second" << endl;
		cout << "full difference is " << diff1 << " = " << (diff1 / (float)(w * h)) * 100 << "%" << endl;
		cout << "difference between source and 3x3 condition source is " << diff2 << " = " << (diff2 / (float)(w * h)) * 100 << "%" << endl << endl;
#ifdef PRINT_SOLUTION
		ofstream solution_stream(solution);
		cout.rdbuf(solution_stream.rdbuf());
		cout << "w = " << w << "; h = " << h << ";" << endl;
		cout << "time is " << time << " second" << endl;
		cout << "full difference is " << diff1 << " = " << (diff1 / (float)(w * h)) * 100 << "%" << endl;
		cout << "difference between source and 3x3 condition source is " << diff2 << " = " << (diff2 / (float)(w * h)) * 100 << "%" << endl << endl;
		print(source, res);
		solution_stream.close();
#endif
#endif

	//}

	system("pause");
}
开发者ID:Sahlet,项目名称:Three_Textures,代码行数:59,代码来源:main.cpp

示例10: while

/*******************************************************************
 * 
 * NAME :               optimal_step_length()
 *
 * DESCRIPTION :        Calulates the optimal step length using
 *                      Newtons method.
 */
double MC_Brute_Force::optimal_step_length() {
    double min, max, tolerance;
    min = 0.01;
    max = 3;
    tolerance = 0.1;

    while ((max - min) > tolerance) {
        if (difference(min) * difference((min + max) / 2) < 0)
            max = (min + max) / 2;
        else
            min = (min + max) / 2;
    }
    return (min + max) / 2;
}
开发者ID:sigvebs,项目名称:VMC,代码行数:21,代码来源:MC_Brute_Force.cpp

示例11: manhattan

int manhattan(Node n1, Node n2){
    int diff=0; 
    for(int i=1;i<9;i++){
        diff += difference(n1,n2,i); 
    }
    return diff;
}
开发者ID:nileshkulkarni,项目名称:AI_lab,代码行数:7,代码来源:8main.cpp

示例12: compute_local_repulsive_forces

void
compute_local_repulsive_forces()
{
  int i, j, k;
  struct vertex *u, *v, *w;
  struct point delta;
  double fact;

  for (i = 1; i <= nvertices; i++) {
    w = &(vertices[i]);

    for (j = 0; j + 1 < w->valency; j++) {
      v = &(vertices[w->adj[j]]);

      for (k = j + 1; k < w->valency; k++) {
	u = &(vertices[w->adj[k]]);
	
	delta = difference(v->pos, u->pos);
	
	if (delta.x == 0.0) delta.x = 0.1 * (drand48() - 0.5);
	if (delta.y == 0.0) delta.y = 0.1 * (drand48() - 0.5);
	if (delta.z == 0.0 && !flat) delta.z = 0.1 * (drand48() - 0.5);

	fact = - 1.0 / squarednorm(delta);

	v->disp.x -= delta.x * fact;
	v->disp.y -= delta.y * fact;
	v->disp.z -= delta.z * fact;
	u->disp.x += delta.x * fact;
	u->disp.y += delta.y * fact;
	u->disp.z += delta.z * fact;
      }
    }
  }
}
开发者ID:CaGe-graph,项目名称:CaGe,代码行数:35,代码来源:tkspring.c

示例13: main

int main(int argc, char* argv[]){

	Bmp *bmpA = loadbmp("img/hello.bmp");

	// Save a copy
	bmpA->saveCopy("img/hellocopy");

	// Invert filter
	invert(bmpA);
	bmpA->saveCopy("img/helloinvert");

	Bmp *bmpB = loadbmp("img/rainbow.bmp");
	Bmp *bmpC = loadbmp("img/rainbow2.bmp");

	// Difference filter
	difference(bmpB, bmpC);
	bmpB->saveCopy("img/rainbowdifference.bmp");

	//medianFilter(bmpB, 3);

	//bmpB->saveCopy("img/median3x3");

	//medianFilter(bmpC, 7);

	//bmpC->saveCopy("img/median7x7");

	return 0;

}
开发者ID:hollyanne00,项目名称:imgeditor,代码行数:29,代码来源:test.cpp

示例14: max_adjacent_difference

ForwardIterator max_adjacent_difference(ForwardIterator first, ForwardIterator last)
{
    typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
    
    ForwardIterator result(first);
    
    if (first == last) return result;
    
    ForwardIterator previous(first);
    ++first;
    
    if (first == last) return result;
    
    value_type result_difference(*first - *previous);
    previous = first; ++first;
    
    while (first != last)
    {
        value_type difference(*first - *previous);
        
        if (result_difference < difference)
        {
            result_difference = difference;
            result = previous;
        }
        previous = first;
        ++first;
    }
    
    return result;
}
开发者ID:andyprowl,项目名称:virtual-concepts,代码行数:31,代码来源:numeric.hpp

示例15: balanceleft

void 
balanceleft (avltree ** n, short adjust)
{
  short dif;

  dif = difference ((*n)->left);
  if (dif == 0)
    {
      rotateright (n);		/* both subtrees of left child of n have same height */
      ((*n)->height) -= adjust;	/* 'decrease' height of current node */
      ((*n)->right->height) += adjust;	/* 'increase' height of right subtree */
    }
  else
    {
      if (dif > 0)
	{
	  rotateright (n);	/* left subtree of left child of n is higher */
	  (*n)->right->height -= 2;
	}
      else
	{			/* right subtree of left child of n is higher */
	  rotateleft (&(*n)->left);	/* pointer to n->left */
	  rotateright (n);
	  ++((*n)->height);	/* increase height of current node */
	  (*n)->right->height -= 2;
	  --((*n)->left->height);	/* decrease height of left subtree */
	}
    }
}
开发者ID:dex4er,项目名称:deb-z88dk,代码行数:29,代码来源:avltree.c


注:本文中的difference函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。