What's the difference between deque and list STL containers?

前端 未结 8 1580
滥情空心
滥情空心 2020-12-07 10:08

What is the difference between the two? I mean the methods are all the same. So, for a user, they work identically.

Is that correct??

8条回答
  •  Happy的楠姐
    2020-12-07 11:00

    Here's a proof-of-concept code use of list, unorded map that gives O(1) lookup and O(1) exact LRU maintenance. Needs the (non-erased) iterators to survive erase operations. Plan to use in a O(1) arbitrarily large software managed cache for CPU pointers on GPU memory. Nods to the Linux O(1) scheduler (LRU <-> run queue per processor). The unordered_map has constant time access via hash table.

    #include  
    #include  
    #include   
    using namespace std; 
    
    struct MapEntry {
      list::iterator LRU_entry;
      uint64_t CpuPtr;
    };
    typedef unordered_map Table;
    typedef list FIFO;
    FIFO  LRU;        // LRU list at a given priority 
    Table DeviceBuffer; // Table of device buffers
    
    void Print(void){
      for (FIFO::iterator l = LRU.begin(); l != LRU.end(); l++) {
        std::cout<< "LRU    entry "<< *l << "   :    " ;
        std::cout<< "Buffer entry "<< DeviceBuffer[*l].CpuPtr <

提交回复
热议问题