lru.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * $XConsortium: lru.h /main/5 1996/08/21 15:53:46 drk $
  25. *
  26. * Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
  27. * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
  28. * States. Use of a copyright notice is precautionary only and does not
  29. * imply publication or disclosure.
  30. *
  31. * This software contains confidential information and trade secrets of HaL
  32. * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
  33. * without the prior express written permission of HaL Computer Systems, Inc.
  34. *
  35. * RESTRICTED RIGHTS LEGEND
  36. * Use, duplication, or disclosure by the Government is subject to
  37. * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
  38. * Technical Data and Computer Software clause at DFARS 252.227-7013.
  39. * HaL Computer Systems, Inc.
  40. * 1315 Dell Avenue, Campbell, CA 95008
  41. *
  42. */
  43. #ifndef _lru_h
  44. #define _lru_h 1
  45. #ifdef C_API
  46. #include "utility/c_stream.h"
  47. #else
  48. #include <sstream>
  49. #endif
  50. #include "utility/debug.h"
  51. #include "dstr/dlist.h"
  52. #include "storage/rep_policy.h"
  53. class lru: public rep_policy {
  54. protected:
  55. dlist active_list;
  56. dlist inactive_list;
  57. protected:
  58. void lower_last(rep_cell*& replaced);
  59. public:
  60. lru(int a_size, int i_size, Boolean remove_cells) ;
  61. virtual ~lru() ;
  62. // promotes the cell x to the active list.
  63. // In the first version, the replaced is the cell dumped from the
  64. // active list. It is set to zero if no dumping takes place.
  65. // Boolean = true: replaced is saved in the inactive list
  66. virtual Boolean promote(rep_cell& x, rep_cell*& replaced);
  67. virtual Boolean promote(rep_cell& x);
  68. // put x to the last of position_t list. Only from
  69. // somewhere in active list -> active list's last
  70. // or
  71. // somewhere in active list -> inactive list's last
  72. //
  73. // not possible:
  74. // somewhere in inactive list -> active list's last
  75. //
  76. virtual Boolean derank(rep_cell& x, position_t);
  77. // walk through all cells in either the active or inactive list,
  78. long first(position_t = ACTIVE);
  79. rep_cell* operator()(long index, position_t);
  80. rep_cell* operator()(long index) { return operator()(index, ACTIVE); };
  81. void next(long & index, position_t = ACTIVE);
  82. // the last cell in either of the list
  83. long last(position_t = ACTIVE);
  84. Boolean remove(rep_cell& x); // remove a cell x
  85. void remove(); // remove all cells
  86. void forget(); // let go all cells, do nothing on them
  87. // counts
  88. int active_elmts() { return active_list.count(); };
  89. int inactive_elmts() { return inactive_list.count(); };
  90. dlist& get_active_list() { return active_list; };
  91. dlist& get_inactive_list() { return inactive_list; };
  92. };
  93. typedef lru *lruPtr;
  94. #endif