本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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 );
}
示例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);
}
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
示例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 */
}
}
}