Commit 13c5133e authored by Ivan Donchevskiy's avatar Ivan Donchevskiy

in CycleStorage ViewRows is replaced by ViewRow

parent 13fb4582
......@@ -153,7 +153,11 @@ void testJournal1(void)
j->AddRow(str);
}
printf("\nfirst 30 elements:\n");
j->ViewRows(0,30);
for(i=0;i<30;i++)
{
if(j->ViewRow(i,str))
printf("%s\n",str);
}
printf("test of 2 classes working in 1 file together\n");
TableBlockStorage *t = new TableBlockStorage("big_file.test", 4, 40, 20000, 5,28,0);
......@@ -169,19 +173,31 @@ void testJournal1(void)
{
j->DelRow(i);
}
j->ViewRows(0,30);
for(i=0;i<30;i++)
{
if(j->ViewRow(i,str))
printf("%s\n",str);
}
printf("\nfirst 20 after adding 10 elements\n");
for(i=10001;i<10011;i++)
{
sprintf(str,"%d",i);
j->AddRow(str);
}
j->ViewRows(0,20);
for(i=0;i<20;i++)
{
if(j->ViewRow(i,str))
printf("%s\n",str);
}
printf("\nthe same after reopen:\n");
delete j;
j = new CycleStorage();
j->Open("big_file.test",30,1000000,20000);
j->ViewRows(0,20);
for(i=0;i<20;i++)
{
if(j->ViewRow(i,str))
printf("%s\n",str);
}
printf("\n");
j->ExportToXML("Xml.xml");
delete t;
......@@ -197,7 +213,6 @@ void testJournal2(void)
printf("journal test 2 - checking number of iterations to find head/tail\n");
printf("size = %d\n\n",j->size);
printf("iterations = %d\n",j->iter);
//j->ViewRows(10,20);
for(i=0;i<20;i++)
{
for(k=1000;k<3000;k++)
......
......@@ -118,7 +118,8 @@ class CycleStorage
bool AddRow(void* str);
bool DelRow(int row);
bool DelAllRows(void);
bool ViewRows(int beg, int num);
//bool ViewRows(int beg, int num);
void* ViewRow(int num, void* str);
bool ExportToXML(const char* name);
};
......
......@@ -345,31 +345,21 @@ bool CycleStorage::DelAllRows()
return true;
}
bool CycleStorage::ViewRows(int beg, int num)
void* CycleStorage::ViewRow(int num, void* str)
{
int i,j=(head+beg)%size,n=num,k;
if(num==0) n=size;
if(num>size) n=size;
if(file==NULL) return false;
int i,j=(head+num)%size;
if((file==NULL)||(num>size)) return false;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
fseek(file,seekpos+j*full_size,0);
for(i=0;i<n;i++)
fread(jrn,full_size,1,file);
if((jrn->status==1)||(jrn->status==2)||(jrn->status==4))
{
if(j==size)
{
j=0;
fseek(file,seekpos,0);
}
fread(jrn,full_size,1,file);
if((jrn->status==1)||(jrn->status==2)||(jrn->status==4))
{
printf("%s",((char*)(jrn)+sizeof(CycleStorageElem)));
printf("\n");
}
j++;
memcpy(str,ValPointer(jrn),inf_size);
delete jrn;
return str;
}
delete jrn;
return true;
return 0;
}
bool CycleStorage::ExportToXML(const char* name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment