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
070c4032
Commit
070c4032
authored
Aug 12, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug with CycleStorage (bug 4174)
parent
e82c4dc3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
53 deletions
+49
-53
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+34
-40
CycleStorage.cc
src/Various/CycleStorage.cc
+15
-13
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
070c4032
...
...
@@ -199,6 +199,32 @@ bool testTable2(void)
return
true
;
}
bool
reOpen
()
{
CycleStorage
j
;
int
i
,
k
=
0
;
char
*
str
=
new
char
[
30
];
printf
(
"the same after reopen:
\n
"
);
if
(
!
j
.
open
(
"big_file.test"
,
30
,
32000
,
20000
))
{
printf
(
"Reopen file error
\n
"
);
delete
str
;
return
false
;
}
for
(
i
=
0
;
i
<
20
;
i
++
)
{
if
(
j
.
readRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
}
}
delete
str
;
if
(
k
!=
10
)
return
false
;
return
true
;
}
bool
testJournal1
(
void
)
{
CycleStorage
j
(
"big_file.test"
,
30
,
32000
,
20000
,
true
);
...
...
@@ -282,43 +308,11 @@ bool testJournal1(void)
}
k
=
0
;
printf
(
"the same after reopen:
\n
"
);
if
(
!
j
.
open
(
"big_file.test"
,
30
,
32000
,
20000
))
{
printf
(
"Reopen file error
\n
"
);
delete
str
;
return
false
;
}
for
(
i
=
0
;
i
<
20
;
i
++
)
{
if
(
j
.
readRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
}
}
if
(
k
!=
10
)
{
delete
str
;
return
false
;
}
k
=
0
;
printf
(
"the same after reopen:
\n
"
);
printf
(
"opening... %d
\n
"
,
j
.
open
(
"big_file.test"
,
30
,
32000
,
20000
));
for
(
i
=
0
;
i
<
20
;
i
++
)
{
if
(
j
.
readRow
(
i
,
str
))
{
printf
(
"%s
\n
"
,
str
);
k
++
;
}
}
if
(
k
!=
10
)
{
delete
str
;
return
false
;
}
if
(
!
reOpen
())
return
false
;
if
(
!
reOpen
())
return
false
;
delete
str
;
return
true
;
}
...
...
@@ -366,9 +360,10 @@ bool testJournal3()
j
.
getFullSize
()
);
JItem
ji
;
printf
(
"write 3
0
elements:
\n
"
);
for
(
int
i
=
0
;
i
<
3
0
;
i
++
)
printf
(
"write 3
5
elements:
\n
"
);
for
(
int
i
=
0
;
i
<
3
5
;
i
++
)
{
JItem
ji
;
ji
.
id
=
i
;
...
...
@@ -378,9 +373,8 @@ bool testJournal3()
j
.
addRow
(
&
ji
);
}
printf
(
"read first
5
elements:
\n
"
);
printf
(
"read first
10
elements:
\n
"
);
JItem
ji
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
if
(
j
.
readRow
(
i
,
&
ji
)
)
...
...
src/Various/CycleStorage.cc
View file @
070c4032
...
...
@@ -59,7 +59,8 @@ void CycleStorage::filewrite(CycleStorageElem* jrn,int seek,bool needflush)
{
fseek
(
file
,
seekpos
+
seek
*
full_size
,
0
);
fwrite
(
jrn
,
full_size
,
1
,
file
);
if
(
needflush
)
fflush
(
file
);
if
(
needflush
)
fflush
(
file
);
}
/*! jrn->status: 0 - , 1 - , 2,4 -
...
...
@@ -71,7 +72,6 @@ bool CycleStorage::findHead()
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
int
l
=-
1
,
r
=
size
,
mid
;
iter
=
0
;
seekpos
+=
sizeof
(
CycleStorageAttr
);
fread
(
jrn
,
full_size
,
1
,
file
);
if
(
jrn
->
status
==
0
)
{
...
...
@@ -122,8 +122,10 @@ bool CycleStorage::findHead()
break
;
}
else
{
return
false
;
}
}
if
(
r
<
size
)
head
=
r
;
else
head
=
size
-
1
;
...
...
@@ -140,12 +142,12 @@ bool CycleStorage::open(const char* name, int inf_sz, int inf_count, int seek)
/*! ,
*/
if
(
file
!=
NULL
)
fclose
(
file
);
if
(
file
!=
NULL
)
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
if
(
file
==
NULL
)
return
false
;
seekpos
=
seek
;
if
(
fseek
(
file
,
seekpos
,
0
)
==-
1
)
return
false
;
if
(
fseek
(
file
,
seek
,
0
)
==-
1
)
return
false
;
/*! */
CycleStorageAttr
csa
;
...
...
@@ -157,11 +159,12 @@ bool CycleStorage::open(const char* name, int inf_sz, int inf_count, int seek)
inf_size
=
inf_sz
;
full_size
=
sizeof
(
CycleStorageElem
)
+
inf_size
;
size
=
inf_count
;
seekpos
=
seek
;
seekpos
=
seek
+
sizeof
(
CycleStorageAttr
)
;
seekpos
+=
sizeof
(
CycleStorageAttr
);
if
(
!
findHead
())
{
return
false
;
}
return
true
;
}
...
...
@@ -191,15 +194,14 @@ bool CycleStorage::create(const char* name, int inf_sz, int inf_count, int seek)
jrn
->
status
=
0
;
/*! */
CycleStorageAttr
*
csa
=
new
CycleStorageAttr
()
;
csa
->
inf_size
=
inf_size
;
csa
->
size
=
size
;
csa
->
seekpos
=
seekpos
;
CycleStorageAttr
csa
;
csa
.
inf_size
=
inf_size
;
csa
.
size
=
size
;
csa
.
seekpos
=
seekpos
;
fwrite
(
csa
,
sizeof
(
CycleStorageAttr
),
1
,
file
);
fwrite
(
&
csa
,
sizeof
(
CycleStorageAttr
),
1
,
file
);
fflush
(
file
);
seekpos
+=
sizeof
(
CycleStorageAttr
);
delete
csa
;
/*! */
for
(
int
i
=
0
;
i
<
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