-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.c
More file actions
70 lines (61 loc) · 1.72 KB
/
query.c
File metadata and controls
70 lines (61 loc) · 1.72 KB
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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
// query.c ... query scan functions
// part of Multi-attribute Linear-hashed Files
// Manage creating and using Query objects
// Last modified by John Shepherd, July 2019
#include "defs.h"
#include "query.h"
#include "reln.h"
#include "tuple.h"
// A suggestion ... you can change however you like
struct QueryRep {
Reln rel; // need to remember Relation info
Bits known; // the hash value from MAH
Bits unknown; // the unknown bits from MAH
PageID curpage; // current page in scan
int is_ovflow; // are we in the overflow pages?
Offset curtup; // offset of current tuple within page
//TODO
};
// take a query string (e.g. "1234,?,abc,?")
// set up a QueryRep object for the scan
Query startQuery(Reln r, char *q)
{
Query new = malloc(sizeof(struct QueryRep));
assert(new != NULL);
// TODO
// Partial algorithm:
// form known bits from known attributes
// form unknown bits from '?' attributes
// compute PageID of first page
// using known bits and first "unknown" value
// set all values in QueryRep object
return new;
}
// get next tuple during a scan
Tuple getNextTuple(Query q)
{
// TODO
// Partial algorithm:
// if (more tuples in current page)
// get next matching tuple from current page
// else if (current page has overflow)
// move to overflow page
// grab first matching tuple from page
// else
// move to "next" bucket
// grab first matching tuple from data page
// endif
// if (current page has no matching tuples)
// go to next page (try again)
// endif
return NULL;
}
// clean up a QueryRep object and associated data
void closeQuery(Query q)
{
// TODO
}