-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbtproj.h
101 lines (82 loc) · 4.66 KB
/
dbtproj.h
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
#ifndef _DBTPROJ_H
#define _DBTPROJ_H
/*
* ==========================================================================================
* Database Technology 2012-2013
* Header file dbtproj.h to be used by your code.
* It is not permitted to change this file. You can make changes to perform tests,
* but please rely on the values and typedefs shown below.
*
* ==========================================================================================
*
*/
#include <iostream>
using namespace std;
#define STR_LENGTH 120
#define MAX_RECORDS_PER_BLOCK 100
// This is the definition of a record of the input file. Contains three fields, recid, num and str
typedef struct {
unsigned int recid;
unsigned int num;
char str[STR_LENGTH];
bool valid; // if set, then this record is valid
} record_t;
// This is the definition of a block, which contains a number of fixed-sized records
typedef struct {
unsigned int blockid;
unsigned int nreserved; // how many reserved entries
record_t entries[MAX_RECORDS_PER_BLOCK]; // array of records
bool valid; // if set, then this block is valid
unsigned char misc;
unsigned int next_blockid;
unsigned int dummy;
} block_t;
// Functions that must be implemented in your code
/* ----------------------------------------------------------------------------------------------------------------------
infile: the name of the input file
field: which field will be used for sorting: 0 is for recid, 1 is for num, 2 is for str and 3 is for both num and str
buffer: pointer to memory buffer
nmem_blocks: number of blocks in memory
outfile: the name of the output file
nsorted_segs: number of sorted segments produced (this should be set by you)
npasses: number of passes required for sorting (this should be set by you)
nios: number of IOs performed (this should be set by you)
----------------------------------------------------------------------------------------------------------------------
*/
void MergeSort (char *infile, unsigned char field, block_t *buffer, unsigned int nmem_blocks, char *outfile, unsigned int *nsorted_segs, unsigned int *npasses, unsigned int *nios);
/* ----------------------------------------------------------------------------------------------------------------------
infile: the name of the input file
field: which field will be used for sorting: 0 is for recid, 1 is for num, 2 is for str and 3 is for both num and str
buffer: pointer to memory buffer
nmem_blocks: number of blocks in memory
outfile: the name of the output file
nunique: number of unique records in file (this should be set by you)
nios: number of IOs performed (this should be set by you)
----------------------------------------------------------------------------------------------------------------------
*/
void EliminateDuplicates (char *infile, unsigned char field, block_t *buffer, unsigned int nmem_blocks, char *outfile, unsigned int *nunique, unsigned int *nios);
/* ----------------------------------------------------------------------------------------------------------------------
infile1: the name of the first input file
infile2: the name of the second input file
field: which field will be used for the join: 0 is for recid, 1 is for num, 2 is for str and 3 is for both num and str
buffer: pointer to memory buffer
nmem_blocks: number of blocks in memory
outfile: the name of the output file
nres: number of pairs in output (this should be set by you)
nios: number of IOs performed (this should be set by you)
----------------------------------------------------------------------------------------------------------------------
*/
void MergeJoin (char *infile1, char *infile2, unsigned char field, block_t *buffer, unsigned int nmem_blocks, char *outfile, unsigned int *nres, unsigned int *nios);
/*--------------------------------------------------------------------------------------------------------------------------------
infile1: the name of the first input file
infile2: the name of the second input file
field: which field will be used for the join: 0 is for recid, 1 is for num, 2 is for str and 3 is for both num and str
buffer: pointer to memory buffer
nmem_blocks: number of blocks in memory
outfile: the name of the output file
nres: number of pairs in output (this should be set by you)
nios: number of IOs performed (this should be set by you)
--------------------------------------------------------------------------------------------------------------------------------
* */
void HashJoin (char *infile1, char *infile2, unsigned char field, block_t *buffer, unsigned int nmem_blocks, char *outfile, unsigned int *nres, unsigned int *nios);
#endif