本文整理汇总了C++中map::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ map::empty方法的具体用法?C++ map::empty怎么用?C++ map::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
result_t SingleDataField::create(const string id, const unsigned char length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
const string constantValue, const bool verifyValue, SingleDataField* &returnField)
{
DataType* dataType = DataTypeList::getInstance()->get(id, length==REMAIN_LEN ? (unsigned char)0 : length);
if (!dataType) {
return RESULT_ERR_NOTFOUND;
}
unsigned char bitCount = dataType->getBitCount();
unsigned char byteCount = (unsigned char)((bitCount + 7) / 8);
if (dataType->isAdjustableLength()) {
// check length
if ((bitCount % 8) != 0) {
if (length == 0) {
bitCount = 1; // default bit count: 1 bit
} else if (length <= bitCount) {
bitCount = length;
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
byteCount = (unsigned char)((bitCount + 7) / 8);
} else if (length == 0) {
byteCount = 1; //default byte count: 1 byte
} else if (length <= byteCount || length == REMAIN_LEN) {
byteCount = length;
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
}
if (!constantValue.empty()) {
returnField = new ConstantDataField(name, comment, unit, dataType, partType, byteCount, constantValue, verifyValue);
return RESULT_OK;
}
if (dataType->isNumeric()) {
NumberDataType* numType = (NumberDataType*)dataType;
if (values.empty() && numType->hasFlag(DAY)) {
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
values[numType->getMinValue() + i] = dayNames[i];
}
result_t result = numType->derive(divisor, bitCount, numType);
if (result!=RESULT_OK) {
return result;
}
if (values.empty()) {
returnField = new SingleDataField(name, comment, unit, numType, partType, byteCount);
return RESULT_OK;
}
if (values.begin()->first < numType->getMinValue() || values.rbegin()->first > numType->getMaxValue()) {
return RESULT_ERR_OUT_OF_RANGE;
}
returnField = new ValueListDataField(name, comment, unit, numType, partType, byteCount, values);
return RESULT_OK;
}
if (divisor != 0 || !values.empty()) {
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
}
returnField = new SingleDataField(name, comment, unit, (StringDataType*)dataType, partType, byteCount);
return RESULT_OK;
}
示例2: work
bool work() {
int x, y, z;
scanf("%d", &x);
if (!x) return false;
switch(x) {
case 1:
scanf("%d%d", &y, &z);
a.insert(make_pair(z, y));
break;
case 3:
if (a.empty()) {
printf("%d\n", 0);
} else {
it t = a.begin();
printf("%d\n", t -> second);
a.erase(t);
}
break;
case 2:
if (a.empty()) {
printf("%d\n", 0);
} else {
it t = a.end();
--t;
printf("%d\n", t -> second);
a.erase(t);
}
break;
}
return true;
}
示例3: derive
result_t SingleDataField::derive(string name, string comment,
string unit, const PartType partType,
int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields)
{
if (m_partType != pt_any && partType == pt_any)
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
bool numeric = m_dataType->isNumeric();
if (!numeric && (divisor != 0 || !values.empty()))
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for non-numeric field
if (name.empty())
name = m_name;
if (comment.empty())
comment = m_comment;
if (unit.empty())
unit = m_unit;
DataType* dataType = m_dataType;
if (numeric) {
NumberDataType* numType = (NumberDataType*)m_dataType;
result_t result = numType->derive(divisor, 0, numType);
if (result != RESULT_OK)
return result;
dataType = numType;
}
if (values.empty()) {
fields.push_back(new SingleDataField(name, comment, unit, dataType, partType, m_length));
} else {
fields.push_back(new ValueListDataField(name, comment, unit, (NumberDataType*)dataType, partType, m_length, values));
}
return RESULT_OK;
}
示例4: if
VecX<T>& operator+=(VecX<T> const &a) {
if (a.data.empty() && a.px.empty()) return *this;
rank = rank < a.rank ? a.rank : rank;
if (!px.empty() && !a.px.empty()) {
for (it_cmap it=a.px.begin(); it!=a.px.end(); ++it) {
if (px[it->first] + it->second == 0) continue;
px[it->first] = px[it->first] + it->second;
}
} else if(!px.empty()) {
data = a.data;
for (it_cmap it=px.begin(); it!=px.end(); ++it)
data[it->first] = data[it->first] + it->second;
px.clear();
} else if(!a.px.empty()) {
if (!data.empty()) {
for (it_cmap it=a.px.begin(); it!=a.px.end(); ++it)
data[it->first] = data[it->first] + it->second;
} else {
px = a.px;
}
} else {
if (!data.empty()) {
for (int i=0; i<rank; ++i)
data[i] = data[i] + a.data[i];
} else {
data = a.data;
}
}
return *this;
}
示例5: info
void info() {
cout<<endl<<"--------------------------------"<<endl;
cout<<" Rank:\t"<<rank<<endl;
cout<<" Contains:\t"<<(!px.empty()?px.size():data.size())<<endl;
cout<<"Size(1 el):\t"<<sizeof(T)<<" bytes"<<endl;
cout<<"Total size:\t~"<<data.size()*sizeof(typename vector<T>::value_type) + px.size()*sizeof(typename map<int_8,T>::value_type)<<" bytes"<<endl;
cout<<"Compressed:\t"<<(!px.empty()?"Yes":"No")<<endl;
if (!px.empty()) cout<<" Dense:\t"<<(double)px.size()/rank*100<<"%"<<endl;
cout<<"--------------------------------"<<endl;
}
示例6: lderr
~SharedLRU() {
contents.clear();
lru.clear();
if (!weak_refs.empty()) {
lderr(cct) << "leaked refs:\n";
dump_weak_refs(*_dout);
*_dout << dendl;
assert(weak_refs.empty());
}
}
示例7: main
int main() {
long long int opern, value, temp, highest;
char type[10];
bool homo, hetro;
cin>>opern;
while (opern--) {
scanf("%s %lld", type, &value);
value += MOD;
homo = false;
hetro = false;
if (type[0] == 'i') {
data[value]++;
temp = data[value];
save[temp * FACT + value] = true;
if (temp > 1) {
save.erase((temp - 1) * FACT + value);
}
} else {
if (data[value] > 0) {
if (data[value] == 1) {
save.erase(FACT + value);
data.erase(value);
} else {
data[value]--;
temp = data[value];
save[temp * FACT + value] = true;
save.erase((temp + 1) * FACT + value);
}
}
}
if (!save.empty() && !data.empty()) {
highest = save.rbegin()->first;
highest = highest / FACT;
} else {
highest = 0;
}
if (highest > 1) {
homo = true;
}
if (save.size() > 1 && data.size() > 1) {
hetro = true;
}
if (homo && hetro) {
printf("both\n"); // << endl;
} else if (homo && !hetro) {
printf("homo\n");
} else if (!homo && hetro) {
printf("hetero\n");
} else {
printf("neither\n");
}
}
return 0;
}
示例8: adjust
void adjust(map<int, int>& small, int& ns, map<int, int>& large, int& nl) {
if(small.empty() || large.empty()) return;
int s = small.rbegin()->first;
int l = large.begin()->first;
if(s > l) {
del(small, s);
del(large, l);
small[l]++;
large[s]++;
}
}
示例9: write
void CsvWriter::write(ostream & output, map<int, list<Rule> > rules) {
// write header
if (rules.empty()) return;
map<string, string>::iterator at;
for (at=rules.begin()->second.front().attributes.begin(); at!=rules.begin()->second.front().attributes.end(); ++at) {
output << at->first << ";";
}
output << rules.begin()->second.front().class_attribute.second << endl;
map<int, list<Rule> >::iterator im;
for (im=rules.begin(); im!=rules.end(); ++im) {
list<Rule>::iterator ir;
for (ir=im->second.begin(); ir!=im->second.end(); ++ir) {
map<string, string>::iterator ia;
for (ia=ir->attributes.begin(); ia!=ir->attributes.end(); ++ia) {
if (ia->second!="") {
output << ia->second;
}
output << ";";
}
output << ir->decision;
output << endl;
}
}
output.flush();
}
示例10: initIconCodePoints
const vector<std::string> &TulipMaterialDesignIcons::getSupportedIcons() {
if (iconCodePoint.empty()) {
initIconCodePoints();
}
return iconsNames;
}
示例11: ParseAttachment
GLenum LuaFBOs::ParseAttachment(const string& name)
{
static map<string, GLenum> attachMap;
if (attachMap.empty()) {
attachMap["depth"] = GL_DEPTH_ATTACHMENT_EXT;
attachMap["stencil"] = GL_STENCIL_ATTACHMENT_EXT;
attachMap["color0"] = GL_COLOR_ATTACHMENT0_EXT;
attachMap["color1"] = GL_COLOR_ATTACHMENT1_EXT;
attachMap["color2"] = GL_COLOR_ATTACHMENT2_EXT;
attachMap["color3"] = GL_COLOR_ATTACHMENT3_EXT;
attachMap["color4"] = GL_COLOR_ATTACHMENT4_EXT;
attachMap["color5"] = GL_COLOR_ATTACHMENT5_EXT;
attachMap["color6"] = GL_COLOR_ATTACHMENT6_EXT;
attachMap["color7"] = GL_COLOR_ATTACHMENT7_EXT;
attachMap["color8"] = GL_COLOR_ATTACHMENT8_EXT;
attachMap["color9"] = GL_COLOR_ATTACHMENT9_EXT;
attachMap["color10"] = GL_COLOR_ATTACHMENT10_EXT;
attachMap["color11"] = GL_COLOR_ATTACHMENT11_EXT;
attachMap["color12"] = GL_COLOR_ATTACHMENT12_EXT;
attachMap["color13"] = GL_COLOR_ATTACHMENT13_EXT;
attachMap["color14"] = GL_COLOR_ATTACHMENT14_EXT;
attachMap["color15"] = GL_COLOR_ATTACHMENT15_EXT;
}
map<string, GLenum>::const_iterator it = attachMap.find(name);
if (it != attachMap.end()) {
return it->second;
}
return 0;
}
示例12: labelYOrderedPoints
void Grapher::labelYOrderedPoints(map<float, float> const& _data, int _maxCount, float _minFactor) const
{
int ly = active.top() + 6;
int pc = 0;
if (_data.empty())
return;
float smallestAllowed = prev(_data.end())->first * _minFactor;
BOOST_REVERSE_FOREACH (auto peak, _data)
if ((peak.first > smallestAllowed || _minFactor == 0) && pc < _maxCount)
{
int x = xTP(peak.second);
int y = yTP(peak.first);
p->setPen(QColor::fromHsvF(float(pc) / _maxCount, 1.f, 0.5f, 0.5f));
p->drawEllipse(QPoint(x, y), 4, 4);
p->drawLine(x, y - 4, x, ly + 6);
QString f = QString::fromStdString(pLabel(xT(peak.second), yT(peak.first)));
int fw = p->fontMetrics().width(f);
p->drawLine(x + 16 + fw + 2, ly + 6, x, ly + 6);
p->setPen(QColor::fromHsvF(0, 0.f, .35f));
p->fillRect(QRect(x+12, ly-6, fw + 8, 12), QBrush(QColor(255, 255, 255, 160)));
p->drawText(QRect(x+16, ly-6, 160, 12), Qt::AlignVCenter, f);
ly += 14;
++pc;
}
}
示例13: isIconSupported
bool TulipMaterialDesignIcons::isIconSupported(const std::string &iconName) {
if (iconCodePoint.empty()) {
initIconCodePoints();
}
return iconCodePoint.find(iconName.c_str()) != iconCodePoint.end();
}
示例14: forbidden
ll forbidden(ll n) {
if (n < 4) return 0;
if (n < 9) return 1;
if (n < 13) return 2;
static map<ll,ll> memo;
if (memo.empty()) {
ll p = 1;
ll q = 0;
while (0 < p) {
memo[p] = q;
q = 8*q + 2*p;
p *= 10;
}
}
if (memo.count(n)) return memo[n];
ll m = floor_log(n);
ll a = n / m;
ll b = n - a * m;
ll result = 0;
for (auto i : range(a)) {
result += (i == 4 or i == 9) ? m : forbidden(m);
}
result += (a == 4 or a == 9) ? b+1 : forbidden(b);
return memo[n] = result;
}
示例15: InitEntities
static void InitEntities()
{
if( !g_mapEntitiesToChars.empty() )
return;
static struct Entity
{
char c;
const char *pEntity;
}
const EntityTable[] =
{
{ '&', "amp", },
{ '\"', "quot", },
{ '\'', "apos", },
{ '<', "lt", },
{ '>', "gt", }
};
for( unsigned i = 0; i < ARRAYLEN(EntityTable); ++i )
{
const Entity &ent = EntityTable[i];
g_mapEntitiesToChars[ent.pEntity] = RString(1, ent.c);
g_mapCharsToEntities[ent.c] = ent.pEntity;
}
}