-
Notifications
You must be signed in to change notification settings - Fork 2
/
calcl2.h
138 lines (127 loc) · 2.31 KB
/
calcl2.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef __EXT_H_
#define __EXT_H_
#include <sys/time.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
class Extary
{
public:
int bufsz;
int bufpos;
int *buf;
int filepos;
int endpos;
char readall;
Extary(int sz=0)
{
bufsz = sz;
readall = 0;
bufpos = 0;
endpos = 0;
if (bufsz > 0) buf = (int *) malloc (sizeof(int)*bufsz);
else buf = NULL;
filepos = 0;
}
~Extary()
{
if (buf) free(buf);
}
void additem(int ival)
{
buf[0] = ival;
bufpos++;
}
void setitem(int pos, int val)
{
buf[pos] = val;
}
void set_buf(int *bufadd)
{
buf = bufadd;
}
void reset()
{
bufpos = 0;
filepos = 0;
endpos = 0;
}
int check_empty()
{
if (filepos >= endpos){
filepos = -1;
return 1;
}
return 0;
}
int isempty()
{
return (filepos == -1);
}
void set_filepos(int fpos)
{
filepos = fpos;
}
int custid()
{
return buf[bufpos];
}
int get_min_max(int &mmin, int &mmax)
{
mmin = -1;
mmax = -1;
if (bufpos < bufsz){
int pos = bufpos;
int fpos = filepos;
mmin = buf[pos];
mmax = buf[pos];
fpos += (buf[pos+1]+2);
pos += (buf[pos+1]+2);
while(pos < bufsz && fpos < endpos){
//ensure that entire cust fits in buf
if (pos+buf[pos+1]+2 > bufsz) break;
mmax = buf[pos];
fpos += (buf[pos+1]+2);
pos += (buf[pos+1]+2);
}
if (fpos >= endpos) return 1;
}
return 0;
}
//to be used only for partitioned L2
// int next_custid(int idx=1)
// {
// int i, pos;
// pos = bufpos;
// for (i=0; i < idx; i++){
// pos += (pntid(pos)+2);
// if (pos >= endpos)
// return -1;
// }
// return buf[pos];
// }
int next_custid(int pos)
{
if (pos >= endpos) return -1;
return buf[pos];
}
int pntid(int pos)
{
return buf[pos+1];
}
int ntid()
{
return buf[bufpos+1];
}
int *buff()
{
return (&buf[bufpos]);
}
int fbuf()
{
return buf[bufpos+2];
}
int lbuf()
{
return buf[bufpos+ntid()+1];
}
};
#endif //__EXT_H_