-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.h
62 lines (48 loc) · 2.27 KB
/
sort.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
#ifndef SORT_H
#define SORT_H
#include <vector>
#include "heapfile.h"
// define if debug output wanted
//#define DEBUGSORT
// SORTREC is an in-memory sort record that qsort(3) sorts.
// The sort attribute as well as the associated RID are
// stored in the record. The RID is used for fetching the
// full record when it is needed.
typedef struct {
RID rid; // record id of current record
char* field; // pointer to field
int length; // length of field
} SORTREC;
class SortedFile {
public:
SortedFile(const string & fileName,
int offset,// sort source file on the given
int length, Datatype type, // attribute
int maxItems, Status& status);
Status next(Record & rec); // fetch next record in sort order
Status setMark(); // record a position in sort sequence
Status gotoMark(); // go to last recorded spot
~SortedFile(); // destroy temporary structures / files
private:
Status sortFile(); // split source file into sub-runs
Status generateRun(int numItems); // generate one sub-run of file
Status startScans(); // start a scan on each sorted run
typedef struct {
string name; // name of run file
HeapFileScan* file; // ptr to sorted run of file
int valid; // TRUE if recPtr has a record
Record rec;
RID rid; // RID of current record of run
RID mark; // last marked spot (RID) in file
} RUN;
std::vector<RUN> runs; // holds info about each sub-run
HeapFileScan* file; // source file to sort
string fileName; // name of source file to sort
Datatype type; // type of sort attribute
int offset; // offset of sort attribute
int length; // length of sort attribute
SORTREC *buffer; // in-memory sort buffer
int maxItems; // max. # of items/tuples in buffer
int numItems; // current # of items in buffer
};
#endif