18 EYLÜL 2008, PERŞEMBE
::std map ekleme veya std::map buldunuz mu?
Kayıtlar korumak istediğiniz bir harita varsayarsak. Zaman, eklediğiniz girişi yeni bilgiler. Orada std yapmak için bir avantajdır::map::o zaman std::map::döndürülen yineleyici kullanarak Ekle? Yoksa Ekle girişimi ve eylem ya da yineleyici kaydı olduğunu gösterir bağlı o zaman daha hızlı ya da değil takılı?
CEVAP
19 EYLÜL 2008, Cuma
Cevabı sen de öyle. Yerine bir şey Scott Meyers Effective STL Madde 24 önerdiği yapmak istiyorum:
typedef map<int, int> MapType; // Your map type may vary, just change the typedef
MapType mymap;
// Add elements to map here
int k = 4; // assume we're searching for keys equal to 4
int v = 0; // assume we want the value 0 associated with the key of 4
MapType::iterator lb = mymap.lower_bound(k);
if(lb != mymap.end() && !(mymap.key_comp()(k, lb->first)))
{
// key already exists
// update lb->second if you care to
}
else
{
// the key does not exist in the map
// add it to the map
mymap.insert(lb, MapType::value_type(k, v)); // Use lb as a hint to insert,
// so it can avoid another lookup
}
Bunu Paylaş:
MongoDB upsert yaptığı bir ekleme olma...
Güncelleştirme veya Ekleme (çoklu satı...
Ekleme Google Javascript veya jQuery i...
Bir Tema kullanmanız gerekir.AppCompat...
SERİ: Max veya Varsayılan?...