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) ...@@ -153,7 +153,11 @@ void testJournal1(void)
j->AddRow(str); j->AddRow(str);
} }
printf("\nfirst 30 elements:\n"); 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"); printf("test of 2 classes working in 1 file together\n");
TableBlockStorage *t = new TableBlockStorage("big_file.test", 4, 40, 20000, 5,28,0); TableBlockStorage *t = new TableBlockStorage("big_file.test", 4, 40, 20000, 5,28,0);
...@@ -169,19 +173,31 @@ void testJournal1(void) ...@@ -169,19 +173,31 @@ void testJournal1(void)
{ {
j->DelRow(i); 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"); printf("\nfirst 20 after adding 10 elements\n");
for(i=10001;i<10011;i++) for(i=10001;i<10011;i++)
{ {
sprintf(str,"%d",i); sprintf(str,"%d",i);
j->AddRow(str); 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"); printf("\nthe same after reopen:\n");
delete j; delete j;
j = new CycleStorage(); j = new CycleStorage();
j->Open("big_file.test",30,1000000,20000); 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"); printf("\n");
j->ExportToXML("Xml.xml"); j->ExportToXML("Xml.xml");
delete t; delete t;
...@@ -197,7 +213,6 @@ void testJournal2(void) ...@@ -197,7 +213,6 @@ void testJournal2(void)
printf("journal test 2 - checking number of iterations to find head/tail\n"); printf("journal test 2 - checking number of iterations to find head/tail\n");
printf("size = %d\n\n",j->size); printf("size = %d\n\n",j->size);
printf("iterations = %d\n",j->iter); printf("iterations = %d\n",j->iter);
//j->ViewRows(10,20);
for(i=0;i<20;i++) for(i=0;i<20;i++)
{ {
for(k=1000;k<3000;k++) for(k=1000;k<3000;k++)
......
...@@ -118,7 +118,8 @@ class CycleStorage ...@@ -118,7 +118,8 @@ class CycleStorage
bool AddRow(void* str); bool AddRow(void* str);
bool DelRow(int row); bool DelRow(int row);
bool DelAllRows(void); 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); bool ExportToXML(const char* name);
}; };
......
...@@ -345,31 +345,21 @@ bool CycleStorage::DelAllRows() ...@@ -345,31 +345,21 @@ bool CycleStorage::DelAllRows()
return true; 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; int i,j=(head+num)%size;
if(num==0) n=size; if((file==NULL)||(num>size)) return false;
if(num>size) n=size;
if(file==NULL) return false;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size]; CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
fseek(file,seekpos+j*full_size,0); 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) memcpy(str,ValPointer(jrn),inf_size);
{ delete jrn;
j=0; return str;
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++;
} }
delete jrn; delete jrn;
return true; return 0;
} }
bool CycleStorage::ExportToXML(const char* name) 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