-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecord.h
90 lines (63 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef RECORD_H
#define RECORD_H
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string>
#include "Defs.h"
#include "ParseTree.h"
#include "Record.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 class BigQ;
friend class Sum;
private:
char *GetBits();
void SetBits(char *bits);
void CopyBits(char *bits, int b_len);
public:
char *bits;
Record();
Record(Schema *schema);
~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);
// 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
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);
string ToString(Schema *mySchema);
int NumberOfAtts();
void ClearRecord();
bool IsRecordEmpty();
};
#endif