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
9217174b
Commit
9217174b
authored
Jul 30, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code changes in CycleStorage and TableBlockStorage
parent
c0997d17
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
71 deletions
+70
-71
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+4
-5
Storages.h
include/Storages.h
+5
-3
CycleStorage.cc
src/Various/CycleStorage.cc
+41
-35
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+20
-28
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
9217174b
...
@@ -153,7 +153,7 @@ void testJournal1(void)
...
@@ -153,7 +153,7 @@ void testJournal1(void)
printf
(
"
\n
first 30 elements:
\n
"
);
printf
(
"
\n
first 30 elements:
\n
"
);
for
(
i
=
0
;
i
<
30
;
i
++
)
for
(
i
=
0
;
i
<
30
;
i
++
)
{
{
if
(
j
->
View
Row
(
i
,
str
))
if
(
j
->
Read
Row
(
i
,
str
))
printf
(
"%s
\n
"
,
str
);
printf
(
"%s
\n
"
,
str
);
}
}
...
@@ -173,7 +173,7 @@ void testJournal1(void)
...
@@ -173,7 +173,7 @@ void testJournal1(void)
}
}
for
(
i
=
0
;
i
<
30
;
i
++
)
for
(
i
=
0
;
i
<
30
;
i
++
)
{
{
if
(
j
->
View
Row
(
i
,
str
))
if
(
j
->
Read
Row
(
i
,
str
))
printf
(
"%s
\n
"
,
str
);
printf
(
"%s
\n
"
,
str
);
}
}
printf
(
"
\n
first 20 after adding 10 elements
\n
"
);
printf
(
"
\n
first 20 after adding 10 elements
\n
"
);
...
@@ -184,7 +184,7 @@ void testJournal1(void)
...
@@ -184,7 +184,7 @@ void testJournal1(void)
}
}
for
(
i
=
0
;
i
<
20
;
i
++
)
for
(
i
=
0
;
i
<
20
;
i
++
)
{
{
if
(
j
->
View
Row
(
i
,
str
))
if
(
j
->
Read
Row
(
i
,
str
))
printf
(
"%s
\n
"
,
str
);
printf
(
"%s
\n
"
,
str
);
}
}
printf
(
"
\n
the same after reopen:
\n
"
);
printf
(
"
\n
the same after reopen:
\n
"
);
...
@@ -193,11 +193,10 @@ void testJournal1(void)
...
@@ -193,11 +193,10 @@ void testJournal1(void)
j
->
Open
(
"big_file.test"
,
30
,
1000000
,
20000
);
j
->
Open
(
"big_file.test"
,
30
,
1000000
,
20000
);
for
(
i
=
0
;
i
<
20
;
i
++
)
for
(
i
=
0
;
i
<
20
;
i
++
)
{
{
if
(
j
->
View
Row
(
i
,
str
))
if
(
j
->
Read
Row
(
i
,
str
))
printf
(
"%s
\n
"
,
str
);
printf
(
"%s
\n
"
,
str
);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
j
->
ExportToXML
(
"Xml.xml"
);
delete
t
;
delete
t
;
delete
j
;
delete
j
;
}
}
...
...
include/Storages.h
View file @
9217174b
...
@@ -32,7 +32,8 @@
...
@@ -32,7 +32,8 @@
#include <string.h>
#include <string.h>
#include <string>
#include <string>
#include "UniXML.h"
#define EMPTY_BLOCK -5
#define EMPTY_ELEM -1
#define key_size 20
#define key_size 20
...
@@ -153,10 +154,10 @@ class CycleStorage
...
@@ -153,10 +154,10 @@ class CycleStorage
bool
DelAllRows
(
void
);
bool
DelAllRows
(
void
);
/*! num */
/*! num */
void
*
View
Row
(
int
num
,
void
*
str
);
void
*
Read
Row
(
int
num
,
void
*
str
);
/*! Xml- name */
/*! Xml- name */
bool
ExportToXML
(
const
char
*
name
);
//
bool ExportToXML(const char* name);
/*! - / ( ) */
/*! - / ( ) */
int
GetIter
(
void
);
int
GetIter
(
void
);
...
@@ -169,6 +170,7 @@ class CycleStorage
...
@@ -169,6 +170,7 @@ class CycleStorage
int
full_size
;
int
full_size
;
void
filewrite
(
CycleStorageElem
*
jrn
,
int
seek
,
bool
needflush
=
true
);
void
filewrite
(
CycleStorageElem
*
jrn
,
int
seek
,
bool
needflush
=
true
);
void
*
ValPointer
(
void
*
pnt
);
void
*
ValPointer
(
void
*
pnt
);
void
FindHead
();
};
};
#endif
#endif
src/Various/CycleStorage.cc
View file @
9217174b
...
@@ -64,44 +64,17 @@ void CycleStorage::filewrite(CycleStorageElem* jrn,int seek,bool needflush)
...
@@ -64,44 +64,17 @@ void CycleStorage::filewrite(CycleStorageElem* jrn,int seek,bool needflush)
if
(
needflush
)
fflush
(
file
);
if
(
needflush
)
fflush
(
file
);
}
}
bool
CycleStorage
::
Open
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
/*! jrn->status: 0 - , 1 - , 2,4 -
( 2 - 4 , ), 3 - 2, 5 - 4, 6 - 1.
|
*/
void
CycleStorage
::
FindHead
()
{
{
/*! ,
*/
if
(
file
!=
NULL
)
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
if
(
file
==
NULL
)
return
false
;
seekpos
=
seek
;
if
(
fseek
(
file
,
seekpos
,
0
)
==-
1
)
return
false
;
CycleStorageAttr
*
csa
=
new
CycleStorageAttr
();
fread
(
csa
,
sizeof
(
CycleStorageAttr
),
1
,
file
);
if
((
csa
->
size
!=
((
sz
-
sizeof
(
CycleStorageAttr
))
/
(
sizeof
(
CycleStorageElem
)
+
inf_sz
)))
||
(
csa
->
inf_size
!=
inf_sz
)
||
(
csa
->
seekpos
!=
seek
))
{
delete
csa
;
return
false
;
}
delete
csa
;
inf_size
=
inf_sz
;
full_size
=
sizeof
(
CycleStorageElem
)
+
inf_size
;
size
=
(
sz
-
sizeof
(
CycleStorageAttr
))
/
full_size
;
seekpos
=
seek
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
int
l
=-
1
,
r
=
size
,
mid
;
int
l
=-
1
,
r
=
size
,
mid
;
iter
=
0
;
iter
=
0
;
seekpos
+=
sizeof
(
CycleStorageAttr
);
seekpos
+=
sizeof
(
CycleStorageAttr
);
fread
(
jrn
,
full_size
,
1
,
file
);
fread
(
jrn
,
full_size
,
1
,
file
);
/*! jrn->status: 0 - , 1 - , 2,4 -
( 2 - 4 , ), 3 - 2, 5 - 4, 6 - 1.
|
*/
if
(
jrn
->
status
==
0
)
if
(
jrn
->
status
==
0
)
{
{
head
=-
1
;
head
=-
1
;
...
@@ -154,6 +127,39 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
...
@@ -154,6 +127,39 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
if
(
tail
<
0
)
tail
=
size
-
1
;
if
(
tail
<
0
)
tail
=
size
-
1
;
}
}
delete
jrn
;
delete
jrn
;
}
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
;
seekpos
=
seek
;
if
(
fseek
(
file
,
seekpos
,
0
)
==-
1
)
return
false
;
CycleStorageAttr
*
csa
=
new
CycleStorageAttr
();
fread
(
csa
,
sizeof
(
CycleStorageAttr
),
1
,
file
);
if
((
csa
->
size
!=
((
sz
-
sizeof
(
CycleStorageAttr
))
/
(
sizeof
(
CycleStorageElem
)
+
inf_sz
)))
||
(
csa
->
inf_size
!=
inf_sz
)
||
(
csa
->
seekpos
!=
seek
))
{
delete
csa
;
return
false
;
}
delete
csa
;
inf_size
=
inf_sz
;
full_size
=
sizeof
(
CycleStorageElem
)
+
inf_size
;
size
=
(
sz
-
sizeof
(
CycleStorageAttr
))
/
full_size
;
seekpos
=
seek
;
seekpos
+=
sizeof
(
CycleStorageAttr
);
FindHead
();
return
true
;
return
true
;
}
}
...
@@ -342,7 +348,7 @@ bool CycleStorage::DelAllRows()
...
@@ -342,7 +348,7 @@ bool CycleStorage::DelAllRows()
return
true
;
return
true
;
}
}
void
*
CycleStorage
::
View
Row
(
int
num
,
void
*
str
)
void
*
CycleStorage
::
Read
Row
(
int
num
,
void
*
str
)
{
{
int
j
=
(
head
+
num
)
%
size
;
int
j
=
(
head
+
num
)
%
size
;
if
((
file
==
NULL
)
||
(
num
>=
size
))
return
0
;
if
((
file
==
NULL
)
||
(
num
>=
size
))
return
0
;
...
@@ -361,7 +367,7 @@ void* CycleStorage::ViewRow(int num, void* str)
...
@@ -361,7 +367,7 @@ void* CycleStorage::ViewRow(int num, void* str)
return
0
;
return
0
;
}
}
bool
CycleStorage
::
ExportToXML
(
const
char
*
name
)
/*
bool CycleStorage::ExportToXML(const char* name)
{
{
int i,j=head;
int i,j=head;
if(file==NULL) return false;
if(file==NULL) return false;
...
@@ -391,7 +397,7 @@ bool CycleStorage::ExportToXML(const char* name)
...
@@ -391,7 +397,7 @@ bool CycleStorage::ExportToXML(const char* name)
f->save(name);
f->save(name);
delete jrn;
delete jrn;
return true;
return true;
}
}
*/
int
CycleStorage
::
GetIter
()
int
CycleStorage
::
GetIter
()
{
{
...
...
src/Various/TableBlockStorage.cc
View file @
9217174b
...
@@ -30,9 +30,6 @@
...
@@ -30,9 +30,6 @@
#include "Storages.h"
#include "Storages.h"
#define block_begin -5
#define empty_elem -1
TableBlockStorage
::
TableBlockStorage
()
TableBlockStorage
::
TableBlockStorage
()
{
{
file
=
NULL
;
file
=
NULL
;
...
@@ -85,33 +82,28 @@ void TableBlockStorage::filewrite(int seek, bool needflush)
...
@@ -85,33 +82,28 @@ void TableBlockStorage::filewrite(int seek, bool needflush)
bool
TableBlockStorage
::
CopyToNextBlock
(
void
)
bool
TableBlockStorage
::
CopyToNextBlock
(
void
)
{
{
int
i
;
if
(
cur_block
<
block_number
-
1
)
TableBlockStorageElem
*
tbl
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
if
(
max
==
lim
-
1
)
{
{
if
((
cur_block
+
2
)
*
block_size
<=
size
)
int
i
;
max
=-
1
;
mem
[
0
]
->
count
=
EMPTY_BLOCK
;
filewrite
(
0
,
false
);
cur_block
++
;
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
{
max
=-
1
;;
if
(
mem
[
i
]
->
count
>=
0
)
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
{
if
(
mem
[
i
]
->
count
>=
0
)
mem
[
i
]
->
count
=++
max
;
{
filewrite
(
i
,
false
);
mem
[
i
]
->
count
=++
max
;
cur_block
++
;
filewrite
(
i
,
false
);
cur_block
--
;
}
}
}
tbl
->
count
=
block_begin
;
fseek
(
file
,
seekpos
+
cur_block
*
block_size
*
full_size
,
0
);
fwrite
(
tbl
,
full_size
,
1
,
file
);
fflush
(
file
);
cur_block
++
;
}
}
fflush
(
file
);
return
true
;
}
}
delete
tbl
;
return
false
;
return
true
;
}
}
bool
TableBlockStorage
::
Open
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
bool
TableBlockStorage
::
Open
(
const
char
*
name
,
int
key_sz
,
int
inf_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
)
...
@@ -229,9 +221,9 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
...
@@ -229,9 +221,9 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
block_begin=(-5) - , , , empty_elem=(-1) -
block_begin=(-5) - , , , empty_elem=(-1) -
*/
*/
mem
[
0
]
->
count
=
block_begin
;
mem
[
0
]
->
count
=
EMPTY_BLOCK
;
for
(
i
=
1
;
i
<
block_size
;
i
++
)
for
(
i
=
1
;
i
<
block_size
;
i
++
)
mem
[
i
]
->
count
=
empty_elem
;
mem
[
i
]
->
count
=
EMPTY_ELEM
;
/*! */
/*! */
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
...
@@ -258,7 +250,7 @@ bool TableBlockStorage::AddRow(void* key, void* value)
...
@@ -258,7 +250,7 @@ bool TableBlockStorage::AddRow(void* key, void* value)
int
i
=
0
,
pos
=-
1
,
empty
=-
1
;
int
i
=
0
,
pos
=-
1
,
empty
=-
1
;
if
(
file
==
NULL
)
return
false
;
if
(
file
==
NULL
)
return
false
;
CopyToNextBlock
();
if
(
max
==
lim
-
1
)
CopyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
{
if
(
mem
[
i
]
->
count
>=
0
)
if
(
mem
[
i
]
->
count
>=
0
)
...
@@ -283,7 +275,7 @@ bool TableBlockStorage::DelRow(void* key)
...
@@ -283,7 +275,7 @@ bool TableBlockStorage::DelRow(void* key)
/*!
/*!
*/
*/
CopyToNextBlock
();
if
(
max
==
lim
-
1
)
CopyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
{
if
(
mem
[
i
]
->
count
>=
0
)
if
(
mem
[
i
]
->
count
>=
0
)
...
...
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