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
5ab9f645
Commit
5ab9f645
authored
Jul 24, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some comments for CycleStorage and TableBlockStorage
parent
b4113aa4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
19 deletions
+71
-19
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+16
-13
Storages.h
include/Storages.h
+4
-3
CycleStorage.cc
src/Various/CycleStorage.cc
+39
-3
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+12
-0
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
5ab9f645
...
...
@@ -75,11 +75,10 @@ void testTable1(void)
void
testTable2
(
void
)
{
char
*
val
=
(
char
*
)
malloc
(
40
)
;
char
*
val
=
new
char
[
40
]
;
TableBlockStorage
*
t
;
t
=
new
TableBlockStorage
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
int
i
;
printf
(
"testTable
\n
size = %d
\n
"
,
t
->
block_size
);
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
...
...
@@ -133,59 +132,62 @@ void testTable2(void)
t
->
Open
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
i
=
11
;
sprintf
(
val
,
"%d"
,
i
);
//
t->AddRow((char*)&i,val);
t
->
AddRow
((
char
*
)
&
i
,
val
);
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
delete
t
;
}
void
testJournal1
(
void
)
{
CycleStorage
*
j
;
int
i
;
char
*
str
=
(
char
*
)
malloc
(
30
)
;
char
*
str
=
new
char
[
30
]
;
printf
(
"journal test 1
\n
"
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
);
printf
(
"size = %d
\n
"
,
j
->
size
);
for
(
i
=
1
;
i
<
40
000
;
i
++
)
for
(
i
=
1
;
i
<
33
000
;
i
++
)
{
sprintf
(
str
,
"%d"
,
i
);
j
->
AddRow
(
str
);
}
printf
(
"
\n
20 elements from 10-th
:
\n
"
);
j
->
ViewRows
(
10
,
2
0
);
printf
(
"
\n
first 30 elements
:
\n
"
);
j
->
ViewRows
(
0
,
3
0
);
printf
(
"test of 2 classes working in 1 file together
\n
"
);
TableBlockStorage
*
t
=
new
TableBlockStorage
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
char
*
val
=
(
char
*
)
malloc
(
40
)
;
char
*
val
=
new
char
[
40
]
;
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n\n
"
,
t
->
cur_block
);
printf
(
"
\n
20 elements from 10-th
after deleting first 20:
\n
"
);
printf
(
"
\n
first 30 elements
after deleting first 20:
\n
"
);
for
(
i
=
0
;
i
<
20
;
i
++
)
{
j
->
DelRow
(
i
);
}
j
->
ViewRows
(
10
,
2
0
);
j
->
ViewRows
(
0
,
3
0
);
printf
(
"
\n
first 20 after adding 10 elements
\n
"
);
for
(
i
=
1
;
i
<
11
;
i
++
)
for
(
i
=
1
0001
;
i
<
100
11
;
i
++
)
{
sprintf
(
str
,
"%d"
,
i
);
j
->
AddRow
(
str
);
}
j
->
ViewRows
(
0
,
20
);
printf
(
"
\n
the same after reopen:
\n
"
);
delete
j
;
j
=
new
CycleStorage
();
j
->
Open
(
"big_file.test"
,
30
,
1000000
,
20000
);
j
->
ViewRows
(
0
,
20
);
printf
(
"
\n
"
);
j
->
ExportToXML
(
"Xml.xml"
);
delete
t
;
delete
j
;
}
void
testJournal2
(
void
)
...
...
@@ -209,12 +211,13 @@ void testJournal2(void)
printf
(
"iterations = %d
\n
"
,
j
->
iter
);
}
printf
(
"
\n
"
);
delete
j
;
}
int
main
(
int
args
,
char
**
argv
)
{
testTable1
();
//
testTable1();
testTable2
();
testJournal1
();
...
...
include/Storages.h
View file @
5ab9f645
...
...
@@ -80,10 +80,11 @@ class TableBlockStorage
{
int
max
;
TableBlockStorageElem
**
mem
;
FILE
*
file
;
int
inf_size
,
k_size
,
lim
,
seekpos
;
int
size
,
block_size
,
block_number
,
full_size
;
public
:
FILE
*
file
;
int
inf_size
,
k_size
,
lim
,
seekpos
;
int
size
,
cur_block
,
block_size
,
block_number
;
int
cur_block
;
TableBlockStorage
();
TableBlockStorage
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
~
TableBlockStorage
();
...
...
src/Various/CycleStorage.cc
View file @
5ab9f645
...
...
@@ -24,6 +24,10 @@
*/
// --------------------------------------------------------------------------
/*! CycleStorage, ,
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -56,6 +60,9 @@ void CycleStorage::filewrite(CycleStorageElem* jrn,int seek,bool needflush)
bool
CycleStorage
::
Open
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
{
/*! ,
*/
if
(
file
!=
NULL
)
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
if
(
file
==
NULL
)
return
false
;
...
...
@@ -85,6 +92,12 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
iter
=
0
;
seekpos
+=
sizeof
(
CycleStorageAttr
);
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
/*! jrn->status: 0 - , 1 - , 2,4 -
( 2 - 4 , ), 3 - 2, 5 - 4, 6 - 1.
|
*/
if
(
jrn
->
status
==
0
)
{
head
=-
1
;
...
...
@@ -198,6 +211,9 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
}
fflush
(
file
);
/*! , ,
*/
int
emp
=
sz
-
size
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
-
sizeof
(
CycleStorageAttr
);
if
(
emp
>
0
)
{
...
...
@@ -218,6 +234,10 @@ bool CycleStorage::AddRow(char* str)
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[(
sizeof
(
CycleStorageElem
)
+
inf_size
)];
int
i
=
0
,
k
;
/*! 2 - (head=-1), 1 (head=tail=0) )
*/
if
(
head
==-
1
)
{
jrn
->
status
=
1
;
...
...
@@ -239,9 +259,17 @@ bool CycleStorage::AddRow(char* str)
}
fseek
(
file
,
seekpos
+
tail
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
i
=
2
;
/*! 2, 3 -> 2; 4, 5 -> 4
*/
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
i
=
2
;
else
i
=
4
;
/*! ,
2->4, 4->2
*/
if
(
tail
==
size
-
1
)
{
fseek
(
file
,
seekpos
,
0
);
...
...
@@ -259,6 +287,10 @@ bool CycleStorage::AddRow(char* str)
}
else
{
/*! , ,
. . 1
*/
head
++
;
if
(
head
>=
size
)
head
=
0
;
jrn
->
status
=
i
;
...
...
@@ -282,6 +314,10 @@ bool CycleStorage::DelRow(int row)
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[(
sizeof
(
CycleStorageElem
)
+
inf_size
)];
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
/*! 1->6, 2->3, 4->5 false
*/
if
(
jrn
->
status
==
1
)
{
jrn
->
status
=
6
;
...
...
@@ -367,7 +403,7 @@ bool CycleStorage::ExportToXML(const char* name)
fseek
(
file
,
seekpos
,
0
);
}
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
((
jrn
->
status
!=
0
)
&&
(
jrn
->
status
!=
3
)
&&
(
jrn
->
status
!=
5
)
&&
(
jrn
->
status
!=
6
))
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
2
)
||
(
jrn
->
status
==
4
))
{
f
->
createNext
(
f
->
cur
,
"!"
,((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)));
}
...
...
src/Various/TableBlockStorage.cc
View file @
5ab9f645
...
...
@@ -24,6 +24,10 @@
*/
// --------------------------------------------------------------------------
/*! TableBlockStorage, - -
, ,
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -216,6 +220,11 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
fflush
(
file
);
seekpos
+=
sizeof
(
StorageAttr
);
/*! :
(-5) - , , ,
(-1) -
*/
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
i
%
block_size
==
0
)
...
...
@@ -272,6 +281,9 @@ bool TableBlockStorage::DelRow(char* key)
int
i
;
if
(
file
==
NULL
)
return
false
;
/*!
*/
CopyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
...
...
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