Commit 2ee860c5 authored by Ivan Donchevskiy's avatar Ivan Donchevskiy

parameter sz removed with inf_count in TableBlockStorage. Added functions…

parameter sz removed with inf_count in TableBlockStorage. Added functions getByteSize to CycleStorage and TableBlockStorage.
parent 299ba4e4
......@@ -31,6 +31,8 @@
#include "Storages.h"
#include "UniXML.h"
int seek=0;
void testTable1(void)
{
char *chr=new char[20];
......@@ -77,7 +79,9 @@ bool testTable2(void)
char *val=new char[40];
TableBlockStorage t;
//t = new TableBlockStorage();
t.create("big_file.test", 4, 40, 20000, 5,28,0);
t.create("big_file.test", 4, 40, 100, 5,28,0);
seek=t.getByteSize();
printf("Table size in bytes = %d\n",seek);
int i;
for(i=1;i<20;i++)
{
......@@ -187,7 +191,7 @@ bool testTable2(void)
return false;
}
printf("after reopen:\n");
t.open("big_file.test", 4, 40, 20000, 5,28,0);
t.open("big_file.test", 4, 40, 100, 5,28,0);
for(i=1;i<20;i++)
{
if(t.findKeyValue(&i,val)!=0) printf("%s, ",val);
......@@ -207,7 +211,7 @@ bool reOpen()
int i,k=0;
char *str = new char[30];
printf("the same after reopen:\n");
if(!j.open("big_file.test",30,32000,20000))
if(!j.open("big_file.test",30,32000,seek))
{
printf("Reopen file error\n");
delete str;
......@@ -229,7 +233,7 @@ bool reOpen()
bool testJournal1(void)
{
CycleStorage j("big_file.test",30,32000,20000,true);
CycleStorage j("big_file.test",30,32000,seek,true);
int i,k=0;
char *str = new char[30];
printf("journal test 1\n");
......@@ -254,8 +258,8 @@ bool testJournal1(void)
}
k = 0;
TableBlockStorage t("big_file.test", 4, 40, 100, 5,28,0);
printf("test of 2 classes working in 1 file together\n");
TableBlockStorage t("big_file.test", 4, 40, 20000, 5,28,0);
char *val = new char[40];
for(i=1;i<20;i++)
{
......@@ -321,20 +325,20 @@ bool testJournal1(void)
void testJournal2(void)
{
CycleStorage j("big_file.test",30,32000,20000);
CycleStorage j("big_file.test",30,32000,seek);
int i,k;
char *str = new char[30];
printf("journal test 2 - checking number of iterations to find head/tail\n");
printf("iterations = %d\n",j.getIter());
for(i=0;i<20;i++)
{
for(k=1000;k<3000;k++)
for(k=1000;k<2999;k++)
{
sprintf(str,"%d",k);
j.addRow(str);
}
j.open("big_file.test",30,32000,20000);
printf("iterations = %d\n",j.getIter());
j.open("big_file.test",30,32000,seek);
printf("i=%d, iterations = %d\n", i, j.getIter());
}
printf("\n");
delete str;
......@@ -356,10 +360,11 @@ bool testJournal3()
return false;
}
printf("Joural size=%d inf_size=%d full_size=%d\n",
printf("Joural size=%d inf_size=%d full_size=%d byte_size=%d\n",
j.getSize(),
j.getInfSize(),
j.getFullSize()
j.getFullSize(),
j.getByteSize()
);
JItem ji;
......
......@@ -92,16 +92,25 @@ class TableBlockStorage
/*! Open, create=true
*/
TableBlockStorage(const char* name, int key_sz, int inf_sz, int sz, int block_num, int block_lim, int seek, bool create=false);
TableBlockStorage(const char* name, int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek, bool create=false);
~TableBlockStorage();
/*! inf_sz - , key_sz - , sz -
block_num - - ( = sz/block_num
, ), block_lim - ,
seek - ( , ) */
bool open(const char* name, int inf_sz, int key_sz, int sz, int block_num, int block_lim, int seek);
bool create(const char* name, int inf_sz, int key_sz, int sz, int block_num, int block_lim, int seek);
/*!
\param inf_sz - ,
\param key_sz - ,
\param inf_count - - ( inf_sz+key_sz
+sizeof(int) )
\param block_num - - ( - = inf_count*block_num,
\param block_lim - ,
\param seek - ( , )
inf_count*block_num*(inf_sz+key_sz+sizeof(int)) +
sizeof(StorageAttr), - ,
, getByteSize()
*/
bool open(const char* name, int inf_sz, int key_sz, int inf_count, int block_num, int block_lim, int seek);
bool create(const char* name, int inf_sz, int key_sz, int inf_count, int block_num, int block_lim, int seek);
/*! , */
bool addRow(void* key, void* val);
......@@ -114,6 +123,9 @@ class TableBlockStorage
/*! ( ) */
int getCurBlock(void);
inline int getByteSize() { return (size*full_size + sizeof(StorageAttr)); }
protected:
FILE *file;
int inf_size;
......@@ -148,6 +160,7 @@ class CycleStorage
inf_count*(inf_sz+1) + sizeof(CycleStorageAttr),
-
, getByteSize()
*/
bool open(const char* name, int inf_sz, int inf_count, int seek);
bool create(const char* name, int inf_sz, int inf_count, int seek);
......@@ -169,6 +182,7 @@ class CycleStorage
/*! - / ( ) */
int getIter(void);
inline int getByteSize() { return (size*full_size + sizeof(CycleStorageAttr)); }
inline int getSize(){ return size; }
inline int getInfSize(){ return inf_size; }
inline int getFullSize(){ return full_size; }
......
......@@ -35,13 +35,13 @@ TableBlockStorage::TableBlockStorage()
file=NULL;
}
TableBlockStorage::TableBlockStorage(const char* name, int key_sz, int inf_sz, int sz, int block_num, int block_lim, int seek, bool cr)
TableBlockStorage::TableBlockStorage(const char* name, int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek, bool cr)
{
file=NULL;
if(!open(name, key_sz, inf_sz, sz, block_num, block_lim, seek))
if(!open(name, key_sz, inf_sz, inf_count, block_num, block_lim, seek))
{
if(cr)
create(name, key_sz, inf_sz, sz, block_num, block_lim, seek);
create(name, key_sz, inf_sz, inf_count, block_num, block_lim, seek);
else
file=NULL;
}
......@@ -114,7 +114,7 @@ bool TableBlockStorage::copyToNextBlock(void)
return true;
}
bool TableBlockStorage::open(const char* name, int key_sz, int inf_sz, int sz, int block_num, int block_lim, int seek)
bool TableBlockStorage::open(const char* name, int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek)
{
/*! , */
if(file!=NULL) fclose(file);
......@@ -136,9 +136,7 @@ bool TableBlockStorage::open(const char* name, int key_sz, int inf_sz, int sz, i
full_size = sizeof(TableBlockStorageElem)+key_sz+inf_sz;
int tmpsize=(sz-sizeof(StorageAttr))/(full_size);
int tmpblock=tmpsize/block_num;
tmpsize=tmpblock*block_num;
int tmpsize=inf_count*block_num;
/*! */
if((sa.k_size!=key_sz)||(sa.inf_size!=inf_sz)||(sa.size!=tmpsize)||(sa.block_number!=block_num)||(sa.lim!=block_lim)||(sa.seekpos!=seek))
......@@ -151,9 +149,8 @@ bool TableBlockStorage::open(const char* name, int key_sz, int inf_sz, int sz, i
k_size=key_sz;
inf_size=inf_sz;
lim=block_lim;
size=(sz-sizeof(StorageAttr))/(full_size);
block_number=block_num;
block_size=size/block_num;
block_size=inf_count;
size=block_size*block_num;
max=-1;
......@@ -188,7 +185,7 @@ bool TableBlockStorage::open(const char* name, int key_sz, int inf_sz, int sz, i
return true;
}
bool TableBlockStorage::create(const char* name, int key_sz, int inf_sz, int sz, int block_num, int block_lim, int seek)
bool TableBlockStorage::create(const char* name, int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek)
{
if(file!=NULL) fclose(file);
file = fopen(name, "r+");
......@@ -205,10 +202,9 @@ bool TableBlockStorage::create(const char* name, int key_sz, int inf_sz, int sz,
full_size = sizeof(TableBlockStorageElem)+k_size+inf_size;
int i;
size=(sz-sizeof(StorageAttr))/(full_size);
block_number=block_num;
block_size=size/block_num;
block_size=inf_count;
size=block_size*block_num;
max=-1;
......@@ -252,15 +248,6 @@ bool TableBlockStorage::create(const char* name, int key_sz, int inf_sz, int sz,
cur_block=0;
fflush(file);
/*! , , */
int emp = sz-size*full_size-sizeof(StorageAttr);
if(emp>0)
{
char* empty=new char[emp];
fwrite(empty,emp,1,file);
fflush(file);
delete empty;
}
return true;
}
......
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