Advertisement
SalmaYasser

Untitled

Dec 22nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. class web_server
  2. {
  3. int limit ;
  4. list < string > history;
  5. unordered_map < string, list < string > :: iterator > website_pointer;
  6. // std::priority_queue<int, std::vector<int>, std::greater<int> > my_min_heap;
  7. priorety_queu <pair <int , string>, vector <pair <int , string>, greater<int> > top_five;
  8. unordered_map < string, int > inside_queu;
  9.  
  10. public:
  11. web_server (int capacity)
  12. {
  13. limit = capacity;
  14. }
  15.  
  16. void visit (string site)
  17. {
  18. update_top_five(site);
  19. update_history (site);
  20. }
  21. void update_history (string site)
  22. {
  23. if (history.size() == limit && website_pointer.count(site) == 0 )
  24. {
  25. string name_del = history.back();
  26. history.pop_back();
  27. website_pointer.erase(name_del);
  28. }
  29.  
  30. if (website_pointer.count(site) > 0)
  31. {
  32. list < string > :: iterator pointer_del = website_pointer[site];
  33. website_pointer.erase(site);
  34. history.erase(pointer_del);
  35. }
  36. history.push_front(site);
  37. website_pointer[site] = history.begin();
  38. }
  39. list <string> get_history()
  40. {
  41. return history;
  42. }
  43.  
  44. };
  45. /*
  46.  
  47. list of web_sites
  48. unordeed_map < web_sites, addres_list>
  49. */
  50.  
  51. int main() {
  52. std::cout << "Hello World!\n";
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement