Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
bf56ea5e
Commit
bf56ea5e
authored
Jul 21, 2009
by
Ivan Donchevskiy
Committed by
Ivan Donchevskiy
Jul 23, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added seekpos (start position in file) to TableBlockStorage
parent
2c1a7417
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
66 deletions
+46
-66
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+22
-38
Storages.h
include/Storages.h
+6
-6
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+18
-22
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
bf56ea5e
...
...
@@ -97,77 +97,61 @@ void testTable2(void)
char
*
chr
=
(
char
*
)
malloc
(
20
);
char
*
val
=
(
char
*
)
malloc
(
40
);
TableBlockStorage
*
t
;
t
=
new
TableBlockStorage
(
"blocktable
.test"
,
40
,
20000
,
5
,
4
0
);
t
=
new
TableBlockStorage
(
"blocktable
int.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
int
i
;
printf
(
"testTable
\n
size = %d
\n
"
,
t
->
block_size
);
for
(
i
=
1
;
i
<
1
6
;
i
++
)
for
(
i
=
1
;
i
<
1
1
;
i
++
)
{
chr
[
0
]
=
i
;
val
=
itoa
(
i
,
10
);
t
->
AddRow
(
chr
,
val
);
t
->
AddRow
(
(
char
*
)
&
i
,
val
);
}
printf
(
"current block = %d, elements with values=keys added:
\n
"
,
t
->
cur_block
);
for
(
i
=
1
;
i
<
1
6
;
i
++
)
for
(
i
=
1
;
i
<
1
1
;
i
++
)
{
chr
[
0
]
=
i
;
if
(
t
->
FindKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
for
(
i
=
1
;
i
<
16
;
i
++
)
for
(
i
=
1
;
i
<
8
;
i
++
)
{
chr
[
0
]
=
i
;
val
=
itoa
(
i
+
10
,
10
);
t
->
AddRow
(
chr
,
val
);
t
->
AddRow
(
(
char
*
)
&
i
,
val
);
}
for
(
i
=
1
;
i
<
16
;
i
++
)
for
(
i
=
8
;
i
<
11
;
i
++
)
{
chr
[
0
]
=
i
;
if
(
t
->
FindKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
t
->
DelRow
((
char
*
)
&
i
);
}
for
(
i
=
1
;
i
<
11
;
i
++
)
{
chr
[
0
]
=
i
;
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
for
(
i
=
20
;
i
<
30
;
i
++
)
for
(
i
=
3
;
i
<
11
;
i
++
)
{
chr
[
0
]
=
i
;
val
=
itoa
(
i
,
10
);
t
->
AddRow
(
chr
,
val
);
val
=
itoa
(
i
+
40
,
10
);
t
->
AddRow
(
(
char
*
)
&
i
,
val
);
}
for
(
i
=
1
;
i
<
40
;
i
++
)
for
(
i
=
1
;
i
<
11
;
i
++
)
{
chr
[
0
]
=
i
;
if
(
t
->
FindKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
chr
[
0
]
=
3
0
;
chr
[
0
]
=
1
0
;
strcpy
(
val
,
"new block"
);
t
->
AddRow
(
chr
,
val
);
t
->
AddRow
(
(
char
*
)
&
i
,
val
);
for
(
i
=
1
;
i
<
40
;
i
++
)
{
chr
[
0
]
=
i
;
if
(
t
->
FindKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
/*for(i=9;i<15;i++)
{
chr[0]=i;
t->DelRow(chr);
}
//printf("elements with keys from 40 to 60 deleted\n");
printf("elements with keys from 9 to 14 deleted\n");
for(i=9;i<15;i++)
{
chr[0]=i;
val=itoa(i+40,10);
t->AddRow(chr,val);
}
//printf("elements with keys from 30 to 50 with values=key+40 added\nvalues from keys 25-59\n");
printf("elements with keys from 9 to 14 with values=key+40 added, all elements:\n");
for(i=0;i<40;i++)
{
chr[0]=i;
if(t->FindKeyValue(chr,val)!=0) printf("%s, ",val);
}
printf("\n");*/
}
void
testJournal1
(
void
)
...
...
include/Storages.h
View file @
bf56ea5e
...
...
@@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include
<UniXML.h>
#include
"UniXML.h"
#define key_size 20
...
...
@@ -67,16 +67,16 @@ class TableStorage
class
TableBlockStorage
{
FILE
*
file
;
int
inf_size
,
k_size
;
int
max
,
lim
;
int
max
,
lim
,
seekpos
;
TableBlockStorageElem
**
mem
;
public
:
FILE
*
file
;
int
inf_size
,
k_size
;
int
size
,
cur_block
,
block_size
;
TableBlockStorage
();
TableBlockStorage
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
);
TableBlockStorage
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
~
TableBlockStorage
();
int
Open
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
);
int
Open
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
int
AddRow
(
char
*
key
,
char
*
val
);
int
DelRow
(
char
*
key
);
char
*
FindKeyValue
(
char
*
key
,
char
*
val
);
...
...
src/Various/TableBlockStorage.cc
View file @
bf56ea5e
...
...
@@ -53,13 +53,16 @@ TableBlockStorage::TableBlockStorage()
lim
=
0
;
cur_block
=
0
;
block_size
=
0
;
seekpos
=
0
;
file
=
NULL
;
}
TableBlockStorage
::
TableBlockStorage
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
)
TableBlockStorage
::
TableBlockStorage
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
{
file
=
fopen
(
name
,
"r+"
);
k_size
=
key_sz
;
inf_size
=
inf_sz
;
seekpos
=
seek
;
int
i
,
full_size
=
sizeof
(
TableBlockStorageElem
)
+
k_size
+
inf_size
;
max
=-
1
;
lim
=
block_lim
;
...
...
@@ -78,6 +81,7 @@ TableBlockStorage::TableBlockStorage(const char* name, int key_sz, int inf_sz, i
{
file
=
fopen
(
name
,
"w"
);
cur_block
=
0
;
fseek
(
file
,
seekpos
,
0
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
i
%
block_size
==
0
)
...
...
@@ -95,7 +99,7 @@ TableBlockStorage::TableBlockStorage(const char* name, int key_sz, int inf_sz, i
{
for
(
i
=
0
;
i
<
block_num
;
i
++
)
{
fseek
(
file
,
i
*
block_size
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
i
*
block_size
*
(
full_size
),
0
);
fread
(
t
,(
full_size
),
1
,
file
);
if
(
t
->
count
>=
0
)
{
...
...
@@ -103,7 +107,7 @@ TableBlockStorage::TableBlockStorage(const char* name, int key_sz, int inf_sz, i
break
;
}
}
fseek
(
file
,(
cur_block
*
block_size
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
(
cur_block
*
block_size
)
*
(
full_size
),
0
);
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
fread
(
mem
[
i
],(
full_size
),
1
,
file
);
...
...
@@ -117,11 +121,12 @@ TableBlockStorage::~TableBlockStorage()
fclose
(
file
);
}
int
TableBlockStorage
::
Open
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
)
int
TableBlockStorage
::
Open
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
{
file
=
fopen
(
name
,
"r+"
);
k_size
=
key_sz
;
inf_size
=
inf_sz
;
seekpos
=
seek
;
int
i
,
full_size
=
sizeof
(
TableBlockStorageElem
)
+
k_size
+
inf_size
;
max
=-
1
;
lim
=
block_lim
;
...
...
@@ -144,7 +149,7 @@ int TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, in
{
for
(
i
=
0
;
i
<
block_num
;
i
++
)
{
fseek
(
file
,
i
*
block_size
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
i
*
block_size
*
(
full_size
),
0
);
fread
(
t
,(
full_size
),
1
,
file
);
if
(
t
->
count
>=
0
)
{
...
...
@@ -152,7 +157,7 @@ int TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, in
break
;
}
}
fseek
(
file
,(
cur_block
*
block_size
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
(
cur_block
*
block_size
)
*
(
full_size
),
0
);
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
fread
(
mem
[
i
],(
full_size
),
1
,
file
);
...
...
@@ -180,23 +185,15 @@ int TableBlockStorage::AddRow(char* key, char* value)
if
(
mem
[
i
]
->
count
>=
0
)
{
mem
[
i
]
->
count
=++
max
;
fseek
(
file
,((
cur_block
+
1
)
*
block_size
+
j
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
((
cur_block
+
1
)
*
block_size
+
j
)
*
(
full_size
),
0
);
fwrite
(
mem
[
i
],(
full_size
),
1
,
file
);
j
++
;
}
}
/*fseek(file,((cur_block+1)*block_size+j)*(full_size),0);
mem[j]->count=++max;
for(k=0;k<k_size;k++)
*((char*)mem[j]+sizeof(TableBlockStorageElem)+k)=*(key+k);
for(k=0;k<inf_size;k++)
*((char*)mem[j]+sizeof(TableBlockStorageElem)+k_size+k)=*(value+k);
fwrite(mem[j],(sizeof(TableBlockStorageElem)+inf_size),1,file);*/
tbl
->
count
=-
5
;
fseek
(
file
,
cur_block
*
block_size
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
cur_block
*
block_size
*
(
full_size
),
0
);
fwrite
(
tbl
,(
full_size
),
1
,
file
);
cur_block
++
;
//return 0;
}
}
for
(
i
=
0
;
i
<
block_size
;
i
++
)
...
...
@@ -211,7 +208,7 @@ int TableBlockStorage::AddRow(char* key, char* value)
mem
[
pos
]
->
count
=++
max
;
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)
mem
[
pos
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
+
k
)
=*
(
value
+
k
);
fseek
(
file
,(
cur_block
*
block_size
+
pos
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
(
cur_block
*
block_size
+
pos
)
*
(
full_size
),
0
);
fwrite
(
mem
[
pos
],(
full_size
),
1
,
file
);
return
0
;
}
...
...
@@ -220,7 +217,7 @@ int TableBlockStorage::AddRow(char* key, char* value)
*
((
char
*
)
mem
[
empty
]
+
sizeof
(
TableBlockStorageElem
)
+
k
)
=*
(
key
+
k
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)
mem
[
empty
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
+
k
)
=*
(
value
+
k
);
fseek
(
file
,(
cur_block
*
block_size
+
empty
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
(
cur_block
*
block_size
+
empty
)
*
(
full_size
),
0
);
fwrite
(
mem
[
empty
],(
full_size
),
1
,
file
);
return
0
;
}
...
...
@@ -245,13 +242,13 @@ int TableBlockStorage::DelRow(char* key)
if
(
mem
[
i
]
->
count
>=
0
)
{
mem
[
i
]
->
count
=++
max
;
fseek
(
file
,((
cur_block
+
1
)
*
block_size
+
j
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
((
cur_block
+
1
)
*
block_size
+
j
)
*
(
full_size
),
0
);
fwrite
(
mem
[
i
],(
full_size
),
1
,
file
);
j
++
;
}
}
tbl
->
count
=-
5
;
fseek
(
file
,
cur_block
*
block_size
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
cur_block
*
block_size
*
(
full_size
),
0
);
fwrite
(
tbl
,(
full_size
),
1
,
file
);
cur_block
++
;
}
...
...
@@ -261,7 +258,7 @@ int TableBlockStorage::DelRow(char* key)
if
((
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
>=
0
))
if
(
KeyCompare
((
char
*
)
mem
[
i
],
key
,
k_size
))
{
fseek
(
file
,(
cur_block
*
block_size
+
i
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
(
cur_block
*
block_size
+
i
)
*
(
full_size
),
0
);
mem
[
i
]
->
count
=++
max
;
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
=
0
;
fwrite
(
mem
[
i
],(
full_size
),
1
,
file
);
...
...
@@ -277,7 +274,6 @@ char* TableBlockStorage::FindKeyValue(char* key, char* val)
int
i
,
k
;
if
(
file
!=
NULL
)
{
//fseek(file,cur_block*block_size*(full_size),0);
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
//fread(tbl,(full_size),1,file);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment