当前位置: 首页>>代码示例>>C++>>正文


C++ DList::addInFront方法代码示例

本文整理汇总了C++中DList::addInFront方法的典型用法代码示例。如果您正苦于以下问题:C++ DList::addInFront方法的具体用法?C++ DList::addInFront怎么用?C++ DList::addInFront使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DList的用法示例。


在下文中一共展示了DList::addInFront方法的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);
			}
		}
	}
开发者ID:nchikkam,项目名称:projects,代码行数:30,代码来源:cache.cpp

示例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;
		}
	}
开发者ID:nchikkam,项目名称:projects,代码行数:24,代码来源:cache.cpp


注:本文中的DList::addInFront方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。