本文整理汇总了C++中KEY::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ KEY::erase方法的具体用法?C++ KEY::erase怎么用?C++ KEY::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KEY
的用法示例。
在下文中一共展示了KEY::erase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialise
void KMplex::initialise(KEY& T, KEY& S)
{
if(T.size() <= 2)
{
greedy(T, S);
return;
}
KEY::iterator a;
KEY::iterator b;
double dab = 0.0;
for(KEY::iterator t = T.begin(); t != T.end(); ++t)
for(KEY::iterator tt = t + 1; tt != T.end(); ++tt)
{
if(D_[*t][*tt] > dab)
{
dab = D_[*t][*tt];
a = t;
b = tt;
}
}
// Copy object indices a and b into sample key S
S.push_back(*a);
S.push_back(*b);
// Remove object indices from key T
T.erase(b);
T.erase(a);
}
示例2: sample
void KMplex::sample(KEY& T, KEY& S)
{
if(T.size() <= 2)
{
greedy(T, S);
return;
}
// NOTE: Cannot sample for two or less data, so copy any data to S
// Indices of points a and b
KEY::iterator a;
KEY::iterator b;
// Corresponding distances to points a and b, from c(S)
double da = 0.0;
double db = 0.0;
for(KEY::iterator t = T.begin(); t != T.end(); ++t)
{
// Find shortest distance d(t,s)
double d = large();
for(KEY::iterator s = S.begin(); s != S.end(); ++s)
{
if(D_[*t][*s] < d)
d = D_[*t][*s];
}
// Retain t if corresponds to first or second farthest from S
if(d >= da)
{
b = a; // Farthest object moves to second farthest
db = da;
a = t; // New object t is farthest from s in S
da = d;
}
else if(d >= db) // New object t is second farthest from s in S
{
b = t;
db = d;
}
else
{
; // Do nothing
}
}
// Indices a and b are moved to sample, S
S.push_back(*a);
S.push_back(*b);
// Erase items a and b, starting with last in sequence
if(a > b)
{
T.erase(a);
T.erase(b);
}
else
{
T.erase(b);
T.erase(a);
}
}