generated from CSED421-DBS/EduBfM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedubfm_Hash.c
196 lines (156 loc) · 6.01 KB
/
edubfm_Hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/******************************************************************************/
/* */
/* ODYSSEUS/EduCOSMOS Educational-Purpose Object Storage System */
/* */
/* Developed by Professor Kyu-Young Whang et al. */
/* */
/* Database and Multimedia Laboratory */
/* */
/* Computer Science Department and */
/* Advanced Information Technology Research Center (AITrc) */
/* Korea Advanced Institute of Science and Technology (KAIST) */
/* */
/* e-mail: kywhang@cs.kaist.ac.kr */
/* phone: +82-42-350-7722 */
/* fax: +82-42-350-8380 */
/* */
/* Copyright (c) 1995-2013 by Kyu-Young Whang */
/* */
/* All rights reserved. No part of this software may be reproduced, */
/* stored in a retrieval system, or transmitted, in any form or by any */
/* means, electronic, mechanical, photocopying, recording, or otherwise, */
/* without prior written permission of the copyright owner. */
/* */
/******************************************************************************/
/*
* Module: edubfm_Hash.c
*
* Description:
* Some functions are provided to support buffer manager.
* Each BfMHashKey is mapping to one table entry in a hash table(hTable),
* and each entry has an index which indicates a buffer in a buffer pool.
* An ordinary hashing method is used and linear probing strategy is
* used if collision has occurred.
*
* Exports:
* Four edubfm_LookUp(BfMHashKey *, Four)
* Four edubfm_Insert(BfMHaskKey *, Two, Four)
* Four edubfm_Delete(BfMHashKey *, Four)
* Four edubfm_DeleteAll(void)
*/
#include <stdlib.h> /* for malloc & free */
#include "EduBfM_common.h"
#include "EduBfM_Internal.h"
/*@
* macro definitions
*/
/* Macro: BFM_HASH(k,type)
* Description: return the hash value of the key given as a parameter
* Parameters:
* BfMHashKey *k : pointer to the key
* Four type : buffer type
* Returns: (Two) hash value
*/
#define BFM_HASH(k,type) (((k)->volNo + (k)->pageNo) % HASHTABLESIZE(type))
/*@================================
* edubfm_Insert()
*================================*/
/*
* Function: Four edubfm_Insert(BfMHashKey *, Two, Four)
*
* Description:
* (Following description is for original ODYSSEUS/COSMOS BfM.
* For ODYSSEUS/EduCOSMOS EduBfM, refer to the EduBfM project manual.)
*
* Insert a new entry into the hash table.
* If collision occurs, then use the linear probing method.
*
* Returns:
* error code
* eBADBUFINDEX_BFM - bad index value for buffer table
*/
Four edubfm_Insert(
BfMHashKey *key, /* IN a hash key in Buffer Manager */
Two index, /* IN an index used in the buffer pool */
Four type) /* IN buffer type */
{
Four i;
Two hashValue;
CHECKKEY(key); /*@ check validity of key */
if( (index < 0) || (index > BI_NBUFS(type)) )
ERR( eBADBUFINDEX_BFM );
return( eNOERROR );
} /* edubfm_Insert */
/*@================================
* edubfm_Delete()
*================================*/
/*
* Function: Four edubfm_Delete(BfMHashKey *, Four)
*
* Description:
* (Following description is for original ODYSSEUS/COSMOS BfM.
* For ODYSSEUS/EduCOSMOS EduBfM, refer to the EduBfM project manual.)
*
* Look up the entry which corresponds to `key' and
* Delete the entry from the hash table.
*
* Returns:
* error code
* eNOTFOUND_BFM - The key isn't in the hash table.
*/
Four edubfm_Delete(
BfMHashKey *key, /* IN a hash key in buffer manager */
Four type ) /* IN buffer type */
{
Two i, prev;
Two hashValue;
CHECKKEY(key); /*@ check validity of key */
ERR( eNOTFOUND_BFM );
} /* edubfm_Delete */
/*@================================
* edubfm_LookUp()
*================================*/
/*
* Function: Four edubfm_LookUp(BfMHashKey *, Four)
*
* Description:
* (Following description is for original ODYSSEUS/COSMOS BfM.
* For ODYSSEUS/EduCOSMOS EduBfM, refer to the EduBfM project manual.)
*
* Look up the given key in the hash table and return its
* corressponding index to the buffer table.
*
* Retruns:
* index on buffer table entry holding the train specified by 'key'
* (NOTFOUND_IN_HTABLE - The key don't exist in the hash table.)
*/
Four edubfm_LookUp(
BfMHashKey *key, /* IN a hash key in Buffer Manager */
Four type) /* IN buffer type */
{
Two i, j; /* indices */
Two hashValue;
CHECKKEY(key); /*@ check validity of key */
return(NOTFOUND_IN_HTABLE);
} /* edubfm_LookUp */
/*@================================
* edubfm_DeleteAll()
*================================*/
/*
* Function: Four edubfm_DeleteAll(void)
*
* Description:
* (Following description is for original ODYSSEUS/COSMOS BfM.
* For ODYSSEUS/EduCOSMOS EduBfM, refer to the EduBfM project manual.)
*
* Delete all hash entries.
*
* Returns:
* error code
*/
Four edubfm_DeleteAll(void)
{
Two i;
Four tableSize;
return(eNOERROR);
} /* edubfm_DeleteAll() */