- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
int DataBase::split(fstream& from,fstream& from0,unsigned int p){
int pos0 = static_cast<int>(from.tellp());
char *a,*b;
Data d,d0;
Index x,x0;
from.clear();
from.seekp(0,ios::end);
int PosEnd = static_cast<int>(from.tellp());
PosEnd -=static_cast<int>(p);
a = new char[PosEnd];
from.seekp(p,ios::beg);
from.read(a,PosEnd);
from.seekp(p+BlockSize,ios::beg);
from.write(a,PosEnd);
from.seekp(p+BlockSize,ios::beg);
b = a+5*RecordSize;
from.write(b,RecordSize*5);
for (int i = 0; i < 5; ++i){
from << d;
}
from.seekp(p+RecordSize*5,ios::beg);
for (int i = 0; i < 5; ++i){
from << d;
}
from.seekg(p+RecordSize*4);
from >> d;
int newmax = d.Id();
from0.seekp(0,ios::end);
int indexend =static_cast<int>(from0.tellp());
from0.seekg(0,ios::beg);
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() == p){
int oldpos = static_cast<int>(from0.tellp());
oldpos++;
int count = indexend - oldpos;
char *c = new char[count];
from0.seekg(1,ios::cur);
from0.read(c,count);
from0.seekp(oldpos,ios::beg);
x0.Max(x.Max());
x0.Num(5);
x0.Pointer(p + BlockSize);
from0 << x0;
from0.write(c,count);
from0.seekp(oldpos - IndexSize,ios::beg);
x.Max(newmax);
x.Num(5);
from0 << x;
delete c;
from.clear();
from0.seekp(0,ios::beg);
break;
}
}
from.clear();
bool first = false;
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() > p ){
if(!first){
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
first = true;
continue;
}
x.Pointer(x.Pointer()+BlockSize);
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
}
else{
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
}
}
from.clear();
from.seekp(pos0);
delete a;
//delete b;
return 0;
}