Cache Missing

Posted hisonsandiego

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cache Missing相关的知识,希望对你有一定的参考价值。

这是亚麻OA 题

// find all the N substring with only one duplicate character.
#include <iostream>     // std::cout
#include <algorithm>    // std::make_heap, std::pop_heap, std::push_heap, std::sort_heap
#include <vector>       // std::vector
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <sys/time.h>
#include <list>

//main point : use list to store the cached elements.
//solution : using list to store the cached elements and then iterate the input sequence.
using namespace std;

int CacheMiss ( vector<int>& nums, int size){
    std::list<int> ls;  //why use list? frequently delete and insert.
    
    int missCnt =0;
    for (auto& e: nums){
        if (ls.size() < size){
            ls.push_back (e);
            missCnt ++;
            cout<< "missing "<< e << endl;
            continue;
        }

        auto itor = find(ls.begin(),ls.end(),e);
        if (itor != ls.end()){//e exist in list. hit.  delete the exist one in the list and push_back it into list again.
            ls.erase(itor);
            ls.push_back(e);
               cout<< "hiting "<< e << endl;
        }
        else {// missing     delete  the first one in the list and push_back new one into list.
            cout<< "pop out " <<ls.front();
            ls.pop_front();
            
            ls.push_back(e);
           cout<< " missing "<< e << endl;
            missCnt ++;
        }    
    }
    return missCnt;
}
int main () { //get the start time. struct timeval tv; gettimeofday(&tv,NULL); long ts = tv.tv_sec * 1000 + tv.tv_usec / 1000; //*** call the function . vector<int> in = {1, 2, 3, 4, 5, 4, 1}; auto out = CacheMiss(in , 4); cout<< " the missing time is: " << out << endl; //*** end of the call //get the time of end. gettimeofday(&tv,NULL); long te = tv.tv_sec * 1000 + tv.tv_usec / 1000; //output the time of the running. cout<<endl<< endl<< "running tmie is : " << te - ts << endl; return 0; }

 

以上是关于Cache Missing的主要内容,如果未能解决你的问题,请参考以下文章

DELLR720服务器更换硬盘,启动系统报错:there are offline or missing virtual drivers with preserved cache

关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段

缓存ehcache启动失败missing element type

缓存ehcache启动失败missing element type

Yii2片段缓存详解

Spring Boot Starter Cache - 缺少速度?