Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / storage / lru.h
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 librararies 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
44
45 #ifndef _lru_h
46 #define _lru_h 1
47
48 #ifdef C_API
49 #include "utility/c_stream.h"
50 #else
51 #include <stream.h>
52 #endif
53
54 #include "utility/debug.h"
55 #include "dstr/dlist.h"
56 #include "storage/rep_policy.h"
57
58 class lru: public rep_policy {
59
60 protected:
61    dlist active_list;
62    dlist inactive_list;
63
64 protected:
65    void lower_last(rep_cell*& replaced);
66
67 public:
68    lru(int a_size, int i_size, Boolean remove_cells) ;
69    virtual ~lru() ;
70
71 // promotes the cell x to the active list.
72 // In the first version, the replaced is the cell dumped from the
73 // active list. It is set to zero if no dumping takes place.
74 // Boolean = true: replaced is saved in the inactive list
75
76    virtual Boolean promote(rep_cell& x, rep_cell*& replaced);
77    virtual Boolean promote(rep_cell& x);
78
79 // put x to the last of position_t list. Only from
80 //    somewhere in active list -> active list's last
81 //       or
82 //    somewhere in active list -> inactive list's last
83 //
84 // not possible:
85 //    somewhere in inactive list -> active list's last
86 //
87
88    virtual Boolean derank(rep_cell& x, position_t);
89
90 // walk through all cells in either the active or inactive list, 
91    long first(position_t = ACTIVE);
92    rep_cell* operator()(long index, position_t);
93    rep_cell* operator()(long index) { return operator()(index, ACTIVE); };
94    void next(long & index, position_t = ACTIVE);
95
96 // the last cell in either of the list
97    long last(position_t = ACTIVE);
98
99    Boolean remove(rep_cell& x); // remove a cell x
100    void remove();               // remove all cells
101    void forget();               // let go all cells, do nothing on them
102
103 // counts
104    int active_elmts()   { return active_list.count();   };
105    int inactive_elmts() { return inactive_list.count(); }; 
106
107    dlist& get_active_list()   { return active_list;   };
108    dlist& get_inactive_list() { return inactive_list; }; 
109 };
110
111 typedef lru *lruPtr;
112
113 #endif