-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecord.h
75 lines (60 loc) · 2.46 KB
/
Record.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
#ifndef RECORD_H
#define RECORD_H
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "Defs.h"
#include "ParseTree.h"
#include "Schema.h"
#include "File.h"
#include "Comparison.h"
#include "ComparisonEngine.h"
using namespace std;
// Basic record data structure. Data is actually stored in "bits" field. The layout of bits is as follows:
// 1) First sizeof(int) bytes: length of the record in bytes
// 2) Next sizeof(int) bytes: byte offset to the start of the first att
// 3) Byte offset to the start of the att in position numAtts
// 4) Bits encoding the record's data
class Record {
friend class ComparisonEngine;
friend class Page;
friend void *WriteoutWorker(void*);
friend void q6();
private:
char* GetBits ();
void SetBits (char *bits);
void CopyBits(char *bits, int b_len);
public:
char *bits;
Record ();
~Record();
// suck the contents of the record fromMe into this; note that after
// this call, fromMe will no longer have anything inside of it
void Consume (Record *fromMe);
// make a copy of the record fromMe; note that this is far more
// expensive (requiring a bit-by-bit copy) than Consume, which is
// only a pointer operation
void Copy (Record *copyMe);
// reads the next record from a pointer to a text file; also requires
// that the schema be given; returns a 0 if there is no data left or
// if there is an error and returns a 1 otherwise
int SuckNextRecord (Schema *mySchema, FILE *textFile);
int ComposeRecord (Schema *mySchema, const char *src);
// this projects away various attributes...
// the array attsToKeep should be sorted, and lists all of the attributes
// that should still be in the record after Project is called. numAttsNow
// tells how many attributes are currently in the record
void Project (int *attsToKeep, int numAttsToKeep, int numAttsNow);
// takes two input records and creates a new record by concatenating them;
// this is useful for a join operation
// attsToKeep[] = {0, 1, 2, 0, 2, 4} --gets 0,1,2 records from left 0, 2, 4 recs from right and startOfRight=3
// startOfRight is the index position in attsToKeep for the first att from right rec
void MergeRecords (Record *left, Record *right, int numAttsLeft,
int numAttsRight, int *attsToKeep, int numAttsToKeep, int startOfRight);
// prints the contents of the record; this requires
// that the schema also be given so that the record can be interpreted
void Print (Schema *mySchema);
int numOfAttInRecord();
};
#endif