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
9bcba674
Commit
9bcba674
authored
Jul 28, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed export to XML in CycleStorage
parent
b21a332f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
38 deletions
+50
-38
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+13
-16
Storages.h
include/Storages.h
+24
-20
CycleStorage.cc
src/Various/CycleStorage.cc
+13
-2
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
9bcba674
...
@@ -33,13 +33,12 @@
...
@@ -33,13 +33,12 @@
void
testTable1
(
void
)
void
testTable1
(
void
)
{
{
char
*
chr
=
(
char
*
)
malloc
(
20
)
;
char
*
chr
=
new
char
[
20
]
;
char
*
val
=
(
char
*
)
malloc
(
40
)
;
char
*
val
=
new
char
[
40
]
;
TableStorage
*
t
;
TableStorage
*
t
;
t
=
new
TableStorage
(
"table.test"
,
40
,
1220
,
0
);
t
=
new
TableStorage
(
"table.test"
,
40
,
1220
,
0
);
int
i
;
int
i
;
printf
(
"testTable
\n
size = %d
\n
"
,
t
->
size
);
for
(
i
=
0
;
i
<
20
;
i
++
)
for
(
i
=
0
;
i
<
t
->
size
;
i
++
)
{
{
chr
[
0
]
=
i
;
chr
[
0
]
=
i
;
sprintf
(
val
,
"%d"
,
i
);
sprintf
(
val
,
"%d"
,
i
);
...
@@ -83,18 +82,18 @@ void testTable2(void)
...
@@ -83,18 +82,18 @@ void testTable2(void)
{
{
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
printf
(
"
\n
current block = %d
\n
"
,
t
->
GetCurBlock
()
);
for
(
i
=
1
;
i
<
11
;
i
++
)
for
(
i
=
1
;
i
<
11
;
i
++
)
{
{
sprintf
(
val
,
"%d"
,
i
);
sprintf
(
val
,
"%d"
,
i
);
t
->
AddRow
((
char
*
)
&
i
,
val
);
t
->
AddRow
((
char
*
)
&
i
,
val
);
}
}
printf
(
"current block = %d, elements with values=keys added:
\n
"
,
t
->
cur_block
);
printf
(
"current block = %d, elements with values=keys added:
\n
"
,
t
->
GetCurBlock
()
);
for
(
i
=
1
;
i
<
20
;
i
++
)
for
(
i
=
1
;
i
<
20
;
i
++
)
{
{
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
}
printf
(
"
\n
current block = %d, rewriting first 7 with values=keys+10
\n
"
,
t
->
cur_block
);
printf
(
"
\n
current block = %d, rewriting first 7 with values=keys+10
\n
"
,
t
->
GetCurBlock
()
);
for
(
i
=
1
;
i
<
8
;
i
++
)
for
(
i
=
1
;
i
<
8
;
i
++
)
{
{
sprintf
(
val
,
"%d"
,
i
+
10
);
sprintf
(
val
,
"%d"
,
i
+
10
);
...
@@ -109,7 +108,7 @@ void testTable2(void)
...
@@ -109,7 +108,7 @@ void testTable2(void)
{
{
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
}
printf
(
"
\n
current block = %d, rewriting 3-10 elements with values=keys+40
\n
"
,
t
->
cur_block
);
printf
(
"
\n
current block = %d, rewriting 3-10 elements with values=keys+40
\n
"
,
t
->
GetCurBlock
()
);
for
(
i
=
3
;
i
<
11
;
i
++
)
for
(
i
=
3
;
i
<
11
;
i
++
)
{
{
sprintf
(
val
,
"%d"
,
i
+
40
);
sprintf
(
val
,
"%d"
,
i
+
40
);
...
@@ -119,7 +118,7 @@ void testTable2(void)
...
@@ -119,7 +118,7 @@ void testTable2(void)
{
{
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
printf
(
"
\n
current block = %d
\n
"
,
t
->
GetCurBlock
()
);
strcpy
(
val
,
"new block"
);
strcpy
(
val
,
"new block"
);
i
=
9
;
i
=
9
;
...
@@ -128,14 +127,14 @@ void testTable2(void)
...
@@ -128,14 +127,14 @@ void testTable2(void)
{
{
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
printf
(
"
\n
current block = %d
\n
"
,
t
->
GetCurBlock
()
);
printf
(
"after reopen:
\n
"
);
printf
(
"after reopen:
\n
"
);
t
->
Open
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
t
->
Open
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
for
(
i
=
1
;
i
<
20
;
i
++
)
for
(
i
=
1
;
i
<
20
;
i
++
)
{
{
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
printf
(
"
\n
current block = %d
\n
"
,
t
->
GetCurBlock
()
);
delete
t
;
delete
t
;
}
}
...
@@ -146,7 +145,6 @@ void testJournal1(void)
...
@@ -146,7 +145,6 @@ void testJournal1(void)
char
*
str
=
new
char
[
30
];
char
*
str
=
new
char
[
30
];
printf
(
"journal test 1
\n
"
);
printf
(
"journal test 1
\n
"
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
,
true
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
,
true
);
printf
(
"size = %d
\n
"
,
j
->
size
);
for
(
i
=
1
;
i
<
33000
;
i
++
)
for
(
i
=
1
;
i
<
33000
;
i
++
)
{
{
sprintf
(
str
,
"%d"
,
i
);
sprintf
(
str
,
"%d"
,
i
);
...
@@ -166,7 +164,7 @@ void testJournal1(void)
...
@@ -166,7 +164,7 @@ void testJournal1(void)
{
{
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
}
printf
(
"
\n
current block = %d
\n\n
"
,
t
->
cur_block
);
printf
(
"
\n
current block = %d
\n\n
"
,
t
->
GetCurBlock
()
);
printf
(
"
\n
first 30 elements after deleting first 20:
\n
"
);
printf
(
"
\n
first 30 elements after deleting first 20:
\n
"
);
for
(
i
=
0
;
i
<
20
;
i
++
)
for
(
i
=
0
;
i
<
20
;
i
++
)
...
@@ -211,8 +209,7 @@ void testJournal2(void)
...
@@ -211,8 +209,7 @@ void testJournal2(void)
char
*
str
=
(
char
*
)
malloc
(
30
);
char
*
str
=
(
char
*
)
malloc
(
30
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
);
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
(
"iterations = %d
\n
"
,
j
->
GetIter
());
printf
(
"iterations = %d
\n
"
,
j
->
iter
);
for
(
i
=
0
;
i
<
20
;
i
++
)
for
(
i
=
0
;
i
<
20
;
i
++
)
{
{
for
(
k
=
1000
;
k
<
3000
;
k
++
)
for
(
k
=
1000
;
k
<
3000
;
k
++
)
...
@@ -221,7 +218,7 @@ void testJournal2(void)
...
@@ -221,7 +218,7 @@ void testJournal2(void)
j
->
AddRow
(
str
);
j
->
AddRow
(
str
);
}
}
j
->
Open
(
"big_file.test"
,
30
,
1000000
,
20000
);
j
->
Open
(
"big_file.test"
,
30
,
1000000
,
20000
);
printf
(
"iterations = %d
\n
"
,
j
->
iter
);
printf
(
"iterations = %d
\n
"
,
j
->
GetIter
()
);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
delete
j
;
delete
j
;
...
...
include/Storages.h
View file @
9bcba674
...
@@ -65,10 +65,9 @@ struct CycleStorageElem
...
@@ -65,10 +65,9 @@ struct CycleStorageElem
class
TableStorage
class
TableStorage
{
{
FILE
*
file
;
FILE
*
file
;
int
seekpos
,
inf_size
;
int
s
ize
,
s
eekpos
,
inf_size
;
int
head
;
int
head
;
public
:
public
:
int
size
;
TableStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
TableStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
~
TableStorage
();
~
TableStorage
();
int
AddRow
(
char
*
key
,
char
*
val
);
int
AddRow
(
char
*
key
,
char
*
val
);
...
@@ -78,39 +77,37 @@ class TableStorage
...
@@ -78,39 +77,37 @@ class TableStorage
class
TableBlockStorage
class
TableBlockStorage
{
{
int
max
;
TableBlockStorageElem
**
mem
;
int
k_size
,
lim
,
seekpos
;
int
size
,
block_size
,
block_number
,
full_size
;
public
:
public
:
FILE
*
file
;
int
cur_block
,
inf_size
;
TableBlockStorage
();
TableBlockStorage
();
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
sz
,
int
block_num
,
int
block_lim
,
int
seek
,
bool
create
=
false
);
~
TableBlockStorage
();
~
TableBlockStorage
();
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
);
bool
AddRow
(
void
*
key
,
void
*
val
);
bool
DelRow
(
void
*
key
);
void
*
FindKeyValue
(
void
*
key
,
void
*
val
);
int
GetCurBlock
(
void
);
protected
:
FILE
*
file
;
int
inf_size
;
private
:
private
:
int
max
,
cur_block
;
TableBlockStorageElem
**
mem
;
int
k_size
,
lim
,
seekpos
;
int
size
,
block_size
,
block_number
,
full_size
;
void
filewrite
(
int
seek
,
bool
needflush
=
true
);
void
filewrite
(
int
seek
,
bool
needflush
=
true
);
bool
CopyToNextBlock
();
bool
CopyToNextBlock
();
bool
KeyCompare
(
int
i
,
void
*
key
);
bool
KeyCompare
(
int
i
,
void
*
key
);
void
*
KeyPointer
(
int
num
);
void
*
KeyPointer
(
int
num
);
void
*
ValPointer
(
int
num
);
void
*
ValPointer
(
int
num
);
public
:
/*public:
bool
Open
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
FILE *file;
bool
Create
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
int cur_block,inf_size;*/
bool
AddRow
(
void
*
key
,
void
*
val
);
bool
DelRow
(
void
*
key
);
void
*
FindKeyValue
(
void
*
key
,
void
*
val
);
};
};
class
CycleStorage
class
CycleStorage
{
{
FILE
*
file
;
int
seekpos
,
inf_size
;
int
head
,
tail
,
full_size
;
void
filewrite
(
CycleStorageElem
*
jrn
,
int
seek
,
bool
needflush
=
true
);
void
*
ValPointer
(
void
*
pnt
);
public
:
public
:
int
size
,
iter
;
CycleStorage
();
CycleStorage
();
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
,
bool
create
=
false
);
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
,
bool
create
=
false
);
~
CycleStorage
();
~
CycleStorage
();
...
@@ -121,6 +118,13 @@ class CycleStorage
...
@@ -121,6 +118,13 @@ class CycleStorage
bool
DelAllRows
(
void
);
bool
DelAllRows
(
void
);
void
*
ViewRow
(
int
num
,
void
*
str
);
void
*
ViewRow
(
int
num
,
void
*
str
);
bool
ExportToXML
(
const
char
*
name
);
bool
ExportToXML
(
const
char
*
name
);
int
GetIter
(
void
);
private
:
FILE
*
file
;
int
size
,
seekpos
,
inf_size
,
iter
;
int
head
,
tail
,
full_size
;
void
filewrite
(
CycleStorageElem
*
jrn
,
int
seek
,
bool
needflush
=
true
);
void
*
ValPointer
(
void
*
pnt
);
};
};
#endif
#endif
src/Various/CycleStorage.cc
View file @
9bcba674
...
@@ -370,8 +370,10 @@ bool CycleStorage::ExportToXML(const char* name)
...
@@ -370,8 +370,10 @@ bool CycleStorage::ExportToXML(const char* name)
if
(
file
==
NULL
)
return
false
;
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
UniXML
*
f
=
new
UniXML
();
UniXML
*
f
=
new
UniXML
();
f
->
newDoc
(
"!"
);
xmlNode
*
xn
;
f
->
newDoc
(
"journal"
);
fseek
(
file
,
seekpos
+
j
*
full_size
,
0
);
fseek
(
file
,
seekpos
+
j
*
full_size
,
0
);
char
*
num
=
new
char
[
10
];
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
{
{
if
(
j
==
size
)
if
(
j
==
size
)
...
@@ -382,11 +384,19 @@ bool CycleStorage::ExportToXML(const char* name)
...
@@ -382,11 +384,19 @@ bool CycleStorage::ExportToXML(const char* name)
fread
(
jrn
,
full_size
,
1
,
file
);
fread
(
jrn
,
full_size
,
1
,
file
);
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
2
)
||
(
jrn
->
status
==
4
))
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
2
)
||
(
jrn
->
status
==
4
))
{
{
f
->
createNext
(
f
->
cur
,
"!"
,(
char
*
)
ValPointer
(
jrn
));
sprintf
(
num
,
"%d"
,
i
);
xn
=
f
->
createChild
(
f
->
cur
,
"item"
,
""
);
f
->
setProp
(
xn
,
"key"
,
num
);
f
->
setProp
(
xn
,
"text"
,(
char
*
)
ValPointer
(
jrn
));
}
}
j
++
;
j
++
;
}
}
f
->
save
(
name
);
f
->
save
(
name
);
delete
jrn
;
delete
jrn
;
return
true
;
return
true
;
}
int
CycleStorage
::
GetIter
()
{
return
iter
;
}
}
\ No newline at end of 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