source: main/tags/2.10/gsdl/src/colservr/querycache.cpp@ 32704

Last change on this file since 32704 was 534, checked in by sjboddie, 25 years ago

added gpl notice

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/**********************************************************************
2 *
3 * querycache.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: querycache.cpp 534 1999-09-07 04:57:43Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.4 1999/09/07 04:57:24 sjboddie
31 added gpl notice
32
33 Revision 1.3 1999/01/19 01:38:17 rjmcnab
34
35 Made the source more portable.
36
37 Revision 1.2 1999/01/12 01:51:02 rjmcnab
38
39 Standard header.
40
41 Revision 1.1 1999/01/08 09:02:18 rjmcnab
42
43 Moved from src/library.
44
45 */
46
47
48#include "querycache.h"
49
50
51
52
53resultcacheel::resultcacheel ()
54{
55 accessnum = -1;
56}
57
58
59
60querycache::querycache (int themaxcachesize)
61{
62 if (themaxcachesize < 1) themaxcachesize = 1;
63
64 resultcache = new resultcacheel[themaxcachesize];
65
66 maxcachesize = themaxcachesize;
67 nextaccessnum = 1;
68}
69
70querycache::~querycache ()
71{
72 delete [] resultcache;
73}
74
75// returns true if the query was found in the cache
76// if the query was found then queryresults contains
77// the results
78bool querycache::find (const queryparamclass &queryparams,
79 queryresultsclass &queryresults)
80{
81 int i;
82
83 for (i=0; i < maxcachesize; i++)
84 {
85 if (resultcache[i].queryparameters == queryparams)
86 {
87 queryresults = resultcache[i].queryresults;
88 resultcache[i].accessnum = getnextaccessnum ();
89 return true;
90 }
91 }
92
93 return false;
94}
95
96
97void querycache::cache (const queryparamclass &queryparams,
98 const queryresultsclass &queryresults)
99{
100 int i = getfreecachenum();
101 resultcache[i].queryparameters = queryparams;
102 resultcache[i].queryresults = queryresults;
103 resultcache[i].accessnum = getnextaccessnum ();
104}
105
106int querycache::getnextaccessnum ()
107{
108 return nextaccessnum++;
109}
110
111int querycache::getfreecachenum ()
112{
113 int i;
114 int minaccessnum = 0;
115 int minaccessi = 0;
116
117 for (i=0; i < maxcachesize; i++)
118 {
119 if (resultcache[i].accessnum < minaccessnum) {
120 minaccessnum = resultcache[i].accessnum;
121 minaccessi = i;
122 }
123 }
124
125 return minaccessi;
126}
127
Note: See TracBrowser for help on using the repository browser.