本文整理汇总了C++中DList::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ DList::remove方法的具体用法?C++ DList::remove怎么用?C++ DList::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DList
的用法示例。
在下文中一共展示了DList::remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set
// This method gets called when ever there was a MISS or Cache need
// to be reorganized in case if it reached to its capacity to hold entries.
void set(Key key, Value data)
{
Entry<Key,Value>* node = hash[key];
if(node) {
// refresh the link list
entries->remove(node);
node->data = data;
entries->addInFront(node);
}
else{
if ( cacheFull() ){
node = entries->tail->prev;
entries->remove(node);
hash.erase(node->key);
node->key = key;
node->data = data;
hash[key] = node;
entries->addInFront(node);
}
else{
node = new Entry<Key,Value>;
node->key = key;
node->data = data;
hash[key] = node;
entries->addInFront(node);
}
}
}
示例2: get
// It does the respective part. It checks if the requested key is in the
// cache lookup table, if it finds, which is a HIT, it returns the userName
// if it was a MISS, it gets the data from the external data source which
// could be a database or file in real time, but an In Memory map in our case
// and updates the map with set method.
Value get(Key key) {
prnt();
if(hash.count(key)==1) {
Entry<Key,Value>* node = hash[key];
cout << "<HIT> --> requested UserID found in Cache.";
entries->remove(node);
entries->addInFront(node);
return node->data;
}
else{
// not found in cache, read from external source and create entry
cout << "<MISS> --> UserID not found in Cache, Reading from Memory\n";
string userName = externalData.getUserByID(key);
if (userName.length() > 0){
set(key, userName);
}
return userName;
}
}