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
66eb4a98
Commit
66eb4a98
authored
Jul 31, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
function names changed in CycleStorage, TableBlockStorage
parent
34fb5e84
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
172 deletions
+119
-172
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+41
-43
Storages.h
include/Storages.h
+22
-25
CycleStorage.cc
src/Various/CycleStorage.cc
+21
-51
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+26
-25
TableStorage.cc
src/Various/TableStorage.cc
+9
-28
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
66eb4a98
...
...
@@ -42,32 +42,32 @@ void testTable1(void)
{
chr
[
0
]
=
i
;
sprintf
(
val
,
"%d"
,
i
);
t
->
A
ddRow
(
chr
,
val
);
t
->
a
ddRow
(
chr
,
val
);
}
printf
(
"elements with values=keys added:
\n
"
);
for
(
i
=
0
;
i
<
40
;
i
++
)
{
chr
[
0
]
=
i
;
if
(
t
->
F
indKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
"
);
for
(
i
=
9
;
i
<
15
;
i
++
)
{
chr
[
0
]
=
i
;
t
->
D
elRow
(
chr
);
t
->
d
elRow
(
chr
);
}
printf
(
"elements with keys from 9 to 14 deleted
\n
"
);
for
(
i
=
9
;
i
<
15
;
i
++
)
{
chr
[
0
]
=
i
;
sprintf
(
val
,
"%d"
,
i
+
40
);
t
->
A
ddRow
(
chr
,
val
);
t
->
a
ddRow
(
chr
,
val
);
}
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
->
F
indKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
"
);
}
...
...
@@ -77,14 +77,14 @@ bool testTable2(void)
char
*
val
=
new
char
[
40
];
TableBlockStorage
*
t
;
t
=
new
TableBlockStorage
();
t
->
C
reate
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
t
->
c
reate
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
int
i
;
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
F
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
"
);
if
(
t
->
G
etCurBlock
()
!=
0
)
if
(
t
->
g
etCurBlock
()
!=
0
)
{
delete
t
;
return
false
;
...
...
@@ -92,16 +92,16 @@ bool testTable2(void)
for
(
i
=
1
;
i
<
11
;
i
++
)
{
sprintf
(
val
,
"%d"
,
i
);
t
->
A
ddRow
((
char
*
)
&
i
,
val
);
t
->
a
ddRow
((
char
*
)
&
i
,
val
);
}
if
(
t
->
G
etCurBlock
()
!=
0
)
if
(
t
->
g
etCurBlock
()
!=
0
)
{
delete
t
;
return
false
;
}
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
F
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
val
[
0
]
==
0
)
{
delete
t
;
...
...
@@ -109,7 +109,7 @@ bool testTable2(void)
}
}
printf
(
"
\n
"
);
if
(
t
->
G
etCurBlock
()
!=
0
)
if
(
t
->
g
etCurBlock
()
!=
0
)
{
delete
t
;
return
false
;
...
...
@@ -117,16 +117,16 @@ bool testTable2(void)
for
(
i
=
1
;
i
<
8
;
i
++
)
{
sprintf
(
val
,
"%d"
,
i
+
10
);
t
->
A
ddRow
(
&
i
,
val
);
t
->
a
ddRow
(
&
i
,
val
);
}
printf
(
"deleteing 8-10 elements
\n
"
);
for
(
i
=
8
;
i
<
11
;
i
++
)
{
t
->
D
elRow
(
&
i
);
t
->
d
elRow
(
&
i
);
}
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
F
indKeyValue
(
&
i
,
val
)
!=
0
)
if
(
t
->
f
indKeyValue
(
&
i
,
val
)
!=
0
)
{
printf
(
"%s, "
,
val
);
if
((
i
>
7
)
&&
(
i
<
11
))
...
...
@@ -142,7 +142,7 @@ bool testTable2(void)
}
}
printf
(
"
\n
rewriting 3-10 elements with values=keys+40
\n
"
);
if
(
t
->
G
etCurBlock
()
!=
0
)
if
(
t
->
g
etCurBlock
()
!=
0
)
{
delete
t
;
return
false
;
...
...
@@ -150,11 +150,11 @@ bool testTable2(void)
for
(
i
=
3
;
i
<
11
;
i
++
)
{
sprintf
(
val
,
"%d"
,
i
+
40
);
t
->
A
ddRow
(
&
i
,
val
);
t
->
a
ddRow
(
&
i
,
val
);
}
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
F
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
((
atoi
(
val
)
!=
i
+
40
)
&&
(
i
>
2
)
&&
(
i
<
11
))
{
delete
t
;
...
...
@@ -166,7 +166,7 @@ bool testTable2(void)
return
false
;
}
}
if
(
t
->
G
etCurBlock
()
!=
0
)
if
(
t
->
g
etCurBlock
()
!=
0
)
{
delete
t
;
return
false
;
...
...
@@ -174,23 +174,23 @@ bool testTable2(void)
strcpy
(
val
,
"new block"
);
i
=
9
;
t
->
A
ddRow
(
&
i
,
val
);
t
->
a
ddRow
(
&
i
,
val
);
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
F
indKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
if
(
t
->
G
etCurBlock
()
!=
1
)
if
(
t
->
g
etCurBlock
()
!=
1
)
{
delete
t
;
return
false
;
}
printf
(
"after reopen:
\n
"
);
t
->
O
pen
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
t
->
o
pen
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
F
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
if
(
t
->
G
etCurBlock
()
!=
1
)
if
(
t
->
g
etCurBlock
()
!=
1
)
{
delete
t
;
return
false
;
...
...
@@ -209,12 +209,12 @@ bool testJournal1(void)
for
(
i
=
1
;
i
<
33000
;
i
++
)
{
sprintf
(
str
,
"%d"
,
i
);
j
->
A
ddRow
(
str
);
j
->
a
ddRow
(
str
);
}
printf
(
"first 30 elements:
\n
"
);
for
(
i
=
0
;
i
<
30
;
i
++
)
{
if
(
j
->
R
eadRow
(
i
,
str
))
if
(
j
->
r
eadRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
...
...
@@ -232,7 +232,7 @@ bool testJournal1(void)
char
*
val
=
new
char
[
40
];
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
F
indKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
f
indKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
((
atoi
(
val
)
!=
i
+
10
)
&&
(
i
<
3
))
{
delete
t
;
...
...
@@ -244,11 +244,11 @@ bool testJournal1(void)
printf
(
"
\n
first 30 elements after deleting first 20:
\n
"
);
for
(
i
=
0
;
i
<
20
;
i
++
)
{
j
->
D
elRow
(
i
);
j
->
d
elRow
(
i
);
}
for
(
i
=
0
;
i
<
30
;
i
++
)
{
if
(
j
->
R
eadRow
(
i
,
str
))
if
(
j
->
r
eadRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
...
...
@@ -266,11 +266,11 @@ bool testJournal1(void)
for
(
i
=
10001
;
i
<
10011
;
i
++
)
{
sprintf
(
str
,
"%d"
,
i
);
j
->
A
ddRow
(
str
);
j
->
a
ddRow
(
str
);
}
for
(
i
=
0
;
i
<
20
;
i
++
)
{
if
(
j
->
R
eadRow
(
i
,
str
))
if
(
j
->
r
eadRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
...
...
@@ -285,12 +285,11 @@ bool testJournal1(void)
k
=
0
;
printf
(
"the same after reopen:
\n
"
);
delete
j
;
j
=
new
CycleStorage
();
j
->
O
pen
(
"big_file.test"
,
30
,
1000000
,
20000
);
j
->
o
pen
(
"big_file.test"
,
30
,
1000000
,
20000
);
for
(
i
=
0
;
i
<
20
;
i
++
)
{
if
(
j
->
R
eadRow
(
i
,
str
))
if
(
j
->
r
eadRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
...
...
@@ -305,12 +304,11 @@ bool testJournal1(void)
k
=
0
;
printf
(
"the same after reopen:
\n
"
);
delete
j
;
j
=
new
CycleStorage
();
j
->
O
pen
(
"big_file.test"
,
30
,
1000000
,
20000
);
j
->
o
pen
(
"big_file.test"
,
30
,
1000000
,
20000
);
for
(
i
=
0
;
i
<
20
;
i
++
)
{
if
(
j
->
R
eadRow
(
i
,
str
))
if
(
j
->
r
eadRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
...
...
@@ -320,7 +318,7 @@ bool testJournal1(void)
{
delete
t
;
delete
j
;
//
return false;
return
false
;
}
delete
t
;
...
...
@@ -335,16 +333,16 @@ void testJournal2(void)
char
*
str
=
(
char
*
)
malloc
(
30
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
);
printf
(
"journal test 2 - checking number of iterations to find head/tail
\n
"
);
printf
(
"iterations = %d
\n
"
,
j
->
G
etIter
());
printf
(
"iterations = %d
\n
"
,
j
->
g
etIter
());
for
(
i
=
0
;
i
<
20
;
i
++
)
{
for
(
k
=
1000
;
k
<
3000
;
k
++
)
{
sprintf
(
str
,
"%d"
,
k
);
j
->
A
ddRow
(
str
);
j
->
a
ddRow
(
str
);
}
j
->
O
pen
(
"big_file.test"
,
30
,
1000000
,
20000
);
printf
(
"iterations = %d
\n
"
,
j
->
G
etIter
());
j
->
o
pen
(
"big_file.test"
,
30
,
1000000
,
20000
);
printf
(
"iterations = %d
\n
"
,
j
->
g
etIter
());
}
printf
(
"
\n
"
);
delete
j
;
...
...
include/Storages.h
View file @
66eb4a98
...
...
@@ -79,9 +79,9 @@ class TableStorage
public
:
TableStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
~
TableStorage
();
int
A
ddRow
(
char
*
key
,
char
*
val
);
int
D
elRow
(
char
*
key
);
char
*
F
indKeyValue
(
char
*
key
,
char
*
val
);
int
a
ddRow
(
char
*
key
,
char
*
val
);
int
d
elRow
(
char
*
key
);
char
*
f
indKeyValue
(
char
*
key
,
char
*
val
);
};
class
TableBlockStorage
...
...
@@ -100,20 +100,20 @@ class TableBlockStorage
block_num - - ( = sz/block_num
, ), block_lim - ,
seek - ( , ) */
bool
O
pen
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
bool
C
reate
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
bool
o
pen
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
bool
c
reate
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
/*! , */
bool
A
ddRow
(
void
*
key
,
void
*
val
);
bool
a
ddRow
(
void
*
key
,
void
*
val
);
/*! , , */
bool
D
elRow
(
void
*
key
);
bool
d
elRow
(
void
*
key
);
/*! , 0 */
void
*
F
indKeyValue
(
void
*
key
,
void
*
val
);
void
*
f
indKeyValue
(
void
*
key
,
void
*
val
);
/*! ( ) */
int
G
etCurBlock
(
void
);
int
g
etCurBlock
(
void
);
protected
:
FILE
*
file
;
int
inf_size
;
...
...
@@ -123,10 +123,10 @@ class TableBlockStorage
int
k_size
,
lim
,
seekpos
;
int
size
,
block_size
,
block_number
,
full_size
;
void
filewrite
(
int
seek
,
bool
needflush
=
true
);
bool
C
opyToNextBlock
();
bool
K
eyCompare
(
int
i
,
void
*
key
);
void
*
K
eyPointer
(
int
num
);
void
*
V
alPointer
(
int
num
);
bool
c
opyToNextBlock
();
bool
k
eyCompare
(
int
i
,
void
*
key
);
void
*
k
eyPointer
(
int
num
);
void
*
v
alPointer
(
int
num
);
};
class
CycleStorage
...
...
@@ -143,26 +143,23 @@ class CycleStorage
/*! inf_sz - , sz - ,
seek - ( , ) */
bool
O
pen
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
bool
C
reate
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
bool
o
pen
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
bool
c
reate
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
/*! */
bool
A
ddRow
(
void
*
str
);
bool
a
ddRow
(
void
*
str
);
/*! row */
bool
D
elRow
(
int
row
);
bool
d
elRow
(
int
row
);
/*! */
bool
D
elAllRows
(
void
);
bool
d
elAllRows
(
void
);
/*! num */
void
*
ReadRow
(
int
num
,
void
*
str
);
/*! Xml- name */
//bool ExportToXML(const char* name);
void
*
readRow
(
int
num
,
void
*
str
);
/*! - / ( ) */
int
G
etIter
(
void
);
int
g
etIter
(
void
);
protected
:
FILE
*
file
;
int
inf_size
;
...
...
@@ -171,8 +168,8 @@ class CycleStorage
int
size
,
seekpos
,
iter
;
int
full_size
;
void
filewrite
(
CycleStorageElem
*
jrn
,
int
seek
,
bool
needflush
=
true
);
void
*
V
alPointer
(
void
*
pnt
);
void
F
indHead
();
void
*
v
alPointer
(
void
*
pnt
);
void
f
indHead
();
};
#endif
src/Various/CycleStorage.cc
View file @
66eb4a98
...
...
@@ -35,13 +35,13 @@ CycleStorage::CycleStorage()
file
=
NULL
;
}
CycleStorage
::
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
,
bool
cr
eate
)
CycleStorage
::
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
,
bool
cr
)
{
file
=
NULL
;
if
(
!
O
pen
(
name
,
inf_sz
,
sz
,
seek
))
if
(
!
o
pen
(
name
,
inf_sz
,
sz
,
seek
))
{
if
(
cr
eate
)
C
reate
(
name
,
inf_sz
,
sz
,
seek
);
if
(
cr
)
c
reate
(
name
,
inf_sz
,
sz
,
seek
);
else
file
=
NULL
;
}
...
...
@@ -52,7 +52,7 @@ CycleStorage::~CycleStorage()
fclose
(
file
);
}
void
*
CycleStorage
::
V
alPointer
(
void
*
pnt
)
void
*
CycleStorage
::
v
alPointer
(
void
*
pnt
)
{
return
(
char
*
)
pnt
+
sizeof
(
CycleStorageElem
);
}
...
...
@@ -68,7 +68,7 @@ void CycleStorage::filewrite(CycleStorageElem* jrn,int seek,bool needflush)
( 2 - 4 , ), 3 - 2, 5 - 4, 6 - 1.
|
*/
void
CycleStorage
::
F
indHead
()
void
CycleStorage
::
f
indHead
()
{
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
int
l
=-
1
,
r
=
size
,
mid
;
...
...
@@ -134,7 +134,7 @@ void CycleStorage::FindHead()
delete
jrn
;
}
bool
CycleStorage
::
O
pen
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
bool
CycleStorage
::
o
pen
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
{
/*! ,
*/
...
...
@@ -165,12 +165,12 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
seekpos
+=
sizeof
(
CycleStorageAttr
);
F
indHead
();
f
indHead
();
return
true
;
}
bool
CycleStorage
::
C
reate
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
bool
CycleStorage
::
c
reate
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
{
if
(
file
!=
NULL
)
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
...
...
@@ -203,6 +203,7 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
fwrite
(
csa
,
sizeof
(
CycleStorageAttr
),
1
,
file
);
fflush
(
file
);
seekpos
+=
sizeof
(
CycleStorageAttr
);
delete
csa
;
/*! */
for
(
int
i
=
0
;
i
<
size
;
i
++
)
...
...
@@ -222,12 +223,11 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
}
head
=
tail
=-
1
;
delete
csa
;
delete
jrn
;
return
true
;
}
bool
CycleStorage
::
A
ddRow
(
void
*
str
)
bool
CycleStorage
::
a
ddRow
(
void
*
str
)
{
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
...
...
@@ -236,7 +236,7 @@ bool CycleStorage::AddRow(void* str)
/*! 2 - (head=-1), 1 (head=tail=0) )
*/
memcpy
(
V
alPointer
(
jrn
),
str
,
inf_size
);
memcpy
(
v
alPointer
(
jrn
),
str
,
inf_size
);
if
(
head
==-
1
)
{
jrn
->
status
=
1
;
...
...
@@ -276,7 +276,7 @@ bool CycleStorage::AddRow(void* str)
}
else
tail
++
;
fread
(
jrn
,
full_size
,
1
,
file
);
memcpy
(
V
alPointer
(
jrn
),
str
,
inf_size
);
memcpy
(
v
alPointer
(
jrn
),
str
,
inf_size
);
if
(
jrn
->
status
==
0
)
{
jrn
->
status
=
2
;
...
...
@@ -302,7 +302,7 @@ bool CycleStorage::AddRow(void* str)
return
true
;
}
bool
CycleStorage
::
D
elRow
(
int
row
)
bool
CycleStorage
::
d
elRow
(
int
row
)
{
int
i
=
(
head
+
row
)
%
size
,
j
;
if
(
row
>=
size
)
return
false
;
...
...
@@ -334,7 +334,7 @@ bool CycleStorage::DelRow(int row)
return
true
;
}
bool
CycleStorage
::
D
elAllRows
()
bool
CycleStorage
::
d
elAllRows
()
{
/*! */
if
(
file
==
NULL
)
return
false
;
...
...
@@ -357,7 +357,8 @@ bool CycleStorage::DelAllRows()
return
true
;
}
void
*
CycleStorage
::
ReadRow
(
int
num
,
void
*
str
)
/*! TODO: str, */
void
*
CycleStorage
::
readRow
(
int
num
,
void
*
str
)
{
/*! */
int
j
=
(
head
+
num
)
%
size
;
...
...
@@ -369,47 +370,15 @@ void* CycleStorage::ReadRow(int num, void* str)
fread
(
jrn
,
full_size
,
1
,
file
);
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
2
)
||
(
jrn
->
status
==
4
))
{
memcpy
(
str
,
V
alPointer
(
jrn
),
inf_size
);
memcpy
(
str
,
v
alPointer
(
jrn
),
inf_size
);
delete
jrn
;
return
str
;
}
delete
jrn
;
return
0
;
return
NULL
;
}
/*bool CycleStorage::ExportToXML(const char* name)
{
int i,j=head;
if(file==NULL) return false;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
UniXML* f = new UniXML();
xmlNode* xn;
f->newDoc("journal");
fseek(file,seekpos+j*full_size,0);
char* num = new char[10];
for(i=0;i<size;i++)
{
if(j==size)
{
j=0;
fseek(file,seekpos,0);
}
fread(jrn,full_size,1,file);
if((jrn->status==1)||(jrn->status==2)||(jrn->status==4))
{
sprintf(num,"%d",i);
xn=f->createChild(f->cur,"item","");
f->setProp(xn,"key",num);
f->setProp(xn,"text",(char*)ValPointer(jrn));
}
j++;
}
f->save(name);
delete jrn;
return true;
}*/
int
CycleStorage
::
GetIter
()
int
CycleStorage
::
getIter
()
{
return
iter
;
}
\ No newline at end of file
src/Various/TableBlockStorage.cc
View file @
66eb4a98
...
...
@@ -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
eate
)
TableBlockStorage
::
TableBlockStorage
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
,
bool
cr
)
{
file
=
NULL
;
if
(
!
O
pen
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
))
if
(
!
o
pen
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
))
{
if
(
cr
eate
)
C
reate
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
);
if
(
cr
)
c
reate
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
);
else
file
=
NULL
;
}
...
...
@@ -58,17 +58,17 @@ TableBlockStorage::~TableBlockStorage()
if
(
file
!=
NULL
)
fclose
(
file
);
}
bool
TableBlockStorage
::
K
eyCompare
(
int
i
,
void
*
key
)
bool
TableBlockStorage
::
k
eyCompare
(
int
i
,
void
*
key
)
{
return
!
memcmp
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
),
key
,
k_size
);
}
void
*
TableBlockStorage
::
K
eyPointer
(
int
num
)
void
*
TableBlockStorage
::
k
eyPointer
(
int
num
)
{
return
(
char
*
)
mem
[
num
]
+
sizeof
(
TableBlockStorageElem
);
}
void
*
TableBlockStorage
::
V
alPointer
(
int
num
)
void
*
TableBlockStorage
::
v
alPointer
(
int
num
)
{
return
(
char
*
)
mem
[
num
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
;
}
...
...
@@ -81,7 +81,7 @@ void TableBlockStorage::filewrite(int seek, bool needflush)
if
(
needflush
)
fflush
(
file
);
}
bool
TableBlockStorage
::
C
opyToNextBlock
(
void
)
bool
TableBlockStorage
::
c
opyToNextBlock
(
void
)
{
/*! */
max
=-
1
;
...
...
@@ -114,7 +114,7 @@ bool TableBlockStorage::CopyToNextBlock(void)
return
true
;
}
bool
TableBlockStorage
::
O
pen
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
bool
TableBlockStorage
::
o
pen
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
{
/*! , */
if
(
file
!=
NULL
)
fclose
(
file
);
...
...
@@ -183,7 +183,7 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
return
true
;
}
bool
TableBlockStorage
::
C
reate
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
bool
TableBlockStorage
::
c
reate
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
{
if
(
file
!=
NULL
)
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
...
...
@@ -229,6 +229,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
fwrite
(
sa
,
sizeof
(
StorageAttr
),
1
,
file
);
fflush
(
file
);
seekpos
+=
sizeof
(
StorageAttr
);
delete
sa
;
/*! :
EMPTY_BLOCK=(-5) - , , , EMPTY_ELEM=(-1) -
...
...
@@ -255,48 +256,47 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
fwrite
(
empty
,
emp
,
1
,
file
);
fflush
(
file
);
}
delete
sa
;
return
true
;
}
bool
TableBlockStorage
::
A
ddRow
(
void
*
key
,
void
*
value
)
bool
TableBlockStorage
::
a
ddRow
(
void
*
key
,
void
*
value
)
{
int
i
=
0
,
pos
=-
1
,
empty
=-
1
;
if
(
file
==
NULL
)
return
false
;
if
(
max
==
lim
-
1
)
C
opyToNextBlock
();
if
(
max
==
lim
-
1
)
c
opyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
(
mem
[
i
]
->
count
>=
0
)
if
(
K
eyCompare
(
i
,
key
))
pos
=
i
;
if
(
k
eyCompare
(
i
,
key
))
pos
=
i
;
if
((
mem
[
i
]
->
count
<
0
)
&&
(
empty
<
0
))
empty
=
i
;
}
/*! , pos>=0, , empty */
if
(
pos
>=
0
)
empty
=
pos
;
else
memcpy
(
K
eyPointer
(
empty
),
key
,
k_size
);
else
memcpy
(
k
eyPointer
(
empty
),
key
,
k_size
);
mem
[
empty
]
->
count
=++
max
;
memcpy
(
V
alPointer
(
empty
),
value
,
inf_size
);
memcpy
(
v
alPointer
(
empty
),
value
,
inf_size
);
filewrite
(
empty
);
return
true
;
}
bool
TableBlockStorage
::
D
elRow
(
void
*
key
)
bool
TableBlockStorage
::
d
elRow
(
void
*
key
)
{
int
i
;
if
(
file
==
NULL
)
return
false
;
/*! */
if
(
max
==
lim
-
1
)
C
opyToNextBlock
();
if
(
max
==
lim
-
1
)
c
opyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
(
mem
[
i
]
->
count
<
0
)
continue
;
if
(
K
eyCompare
(
i
,
key
))
if
(
k
eyCompare
(
i
,
key
))
{
mem
[
i
]
->
count
=++
max
;
memset
(
K
eyPointer
(
i
),
0
,
k_size
);
memset
(
k
eyPointer
(
i
),
0
,
k_size
);
filewrite
(
i
);
return
true
;
}
...
...
@@ -304,7 +304,8 @@ bool TableBlockStorage::DelRow(void* key)
return
false
;
}
void
*
TableBlockStorage
::
FindKeyValue
(
void
*
key
,
void
*
val
)
/*! TODO: val, */
void
*
TableBlockStorage
::
findKeyValue
(
void
*
key
,
void
*
val
)
{
int
i
;
if
(
file
==
NULL
)
return
0
;
...
...
@@ -313,16 +314,16 @@ void* TableBlockStorage::FindKeyValue(void* key, void* val)
/*! >= 0, .. */
if
(
mem
[
i
]
->
count
<
0
)
continue
;
if
(
K
eyCompare
(
i
,
key
))
if
(
k
eyCompare
(
i
,
key
))
{
memcpy
(
val
,
V
alPointer
(
i
),
inf_size
);
memcpy
(
val
,
v
alPointer
(
i
),
inf_size
);
return
val
;
}
}
return
0
;
return
NULL
;
}
int
TableBlockStorage
::
G
etCurBlock
()
int
TableBlockStorage
::
g
etCurBlock
()
{
return
cur_block
;
}
...
...
src/Various/TableStorage.cc
View file @
66eb4a98
...
...
@@ -110,10 +110,10 @@ TableStorage::~TableStorage()
fclose
(
file
);
}
int
TableStorage
::
A
ddRow
(
char
*
key
,
char
*
value
)
int
TableStorage
::
a
ddRow
(
char
*
key
,
char
*
value
)
{
TableStorageElem
*
tbl
=
(
TableStorageElem
*
)
malloc
(
sizeof
(
TableStorageElem
)
+
inf_size
);
int
i
,
k
,
j
;
int
i
,
k
,
j
,
st
;
if
(
file
!=
NULL
)
{
if
(
head
==-
1
)
...
...
@@ -151,19 +151,14 @@ int TableStorage::AddRow(char* key, char* value)
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
if
(
j
==
head
)
{
if
((
tbl
->
status
==
2
)
||
(
tbl
->
status
==
3
))
tbl
->
status
=
2
;
else
tbl
->
status
=
4
;
if
((
tbl
->
status
==
2
)
||
(
tbl
->
status
==
3
))
st
=
2
;
else
st
=
4
;
if
(
j
==
0
)
{
if
(
tbl
->
status
==
2
)
tbl
->
status
=
4
;
else
tbl
->
status
=
2
;
}
if
(
st
==
2
)
st
=
4
;
else
st
=
2
;
tbl
->
status
=
st
;
strcpy
(
tbl
->
key
,
key
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)(
tbl
)
+
sizeof
(
TableStorageElem
)
+
k
)
=*
(
value
+
k
);
...
...
@@ -184,25 +179,11 @@ int TableStorage::AddRow(char* key, char* value)
if
(
head
>=
size
)
head
=
0
;
return
0
;
}
/*for(i=0;i<size;i++)
{
fread(tbl,(sizeof(TableStorageElem)+inf_size),1,file);
if(tbl->key[0]==0)
{
strcpy(tbl->key,key);
for(k=0;k<inf_size;k++)
*((char*)(tbl)+sizeof(TableStorageElem)+k)=*(value+k);
fseek(file,seekpos+i*(sizeof(TableStorageElem)+inf_size),0);
fwrite(tbl,(sizeof(TableStorageElem)+inf_size),1,file);
return 0;
}
}*/
}
return
1
;
}
int
TableStorage
::
D
elRow
(
char
*
key
)
int
TableStorage
::
d
elRow
(
char
*
key
)
{
TableStorageElem
*
tbl
=
(
TableStorageElem
*
)
malloc
(
sizeof
(
TableStorageElem
)
+
inf_size
);
int
i
,
j
;
...
...
@@ -234,7 +215,7 @@ int TableStorage::DelRow(char* key)
return
1
;
}
char
*
TableStorage
::
F
indKeyValue
(
char
*
key
,
char
*
val
)
char
*
TableStorage
::
f
indKeyValue
(
char
*
key
,
char
*
val
)
{
TableStorageElem
*
tbl
=
(
TableStorageElem
*
)
malloc
(
sizeof
(
TableStorageElem
)
+
inf_size
);
int
i
,
k
;
...
...
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