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
94204758
Commit
94204758
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
129 additions
and
102 deletions
+129
-102
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+4
-5
Storages.h
include/Storages.h
+7
-3
CycleStorage.cc
src/Various/CycleStorage.cc
+55
-39
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+63
-55
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
94204758
...
@@ -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 @
94204758
...
@@ -32,7 +32,10 @@
...
@@ -32,7 +32,10 @@
#include <string.h>
#include <string.h>
#include <string>
#include <string>
#include "UniXML.h"
/*! 2 TableBlockStorage count,
TableBlockStorageElem */
#define EMPTY_BLOCK -5
#define EMPTY_ELEM -1
#define key_size 20
#define key_size 20
...
@@ -153,10 +156,10 @@ class CycleStorage
...
@@ -153,10 +156,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 +172,7 @@ class CycleStorage
...
@@ -169,6 +172,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 @
94204758
...
@@ -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
;
...
@@ -109,7 +82,9 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
...
@@ -109,7 +82,9 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
}
}
else
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
6
))
else
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
6
))
{
{
/*! - */
head
=
0
;
head
=
0
;
/*! , */
while
(
r
-
l
>
1
)
while
(
r
-
l
>
1
)
{
{
mid
=
(
l
+
r
)
/
2
;
mid
=
(
l
+
r
)
/
2
;
...
@@ -129,6 +104,8 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
...
@@ -129,6 +104,8 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
else
else
{
{
int
i
,
j
;
int
i
,
j
;
/*! i 2-, 4-, 2-, 4-
*/
i
=
jrn
->
status
-
jrn
->
status
%
2
;
i
=
jrn
->
status
-
jrn
->
status
%
2
;
if
(
i
==
2
)
j
=
4
;
else
j
=
2
;
if
(
i
==
2
)
j
=
4
;
else
j
=
2
;
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
...
@@ -141,7 +118,7 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
...
@@ -141,7 +118,7 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
l
=
mid
;
l
=
mid
;
else
if
((
jrn
->
status
==
j
)
||
(
jrn
->
status
==
j
+
1
))
else
if
((
jrn
->
status
==
j
)
||
(
jrn
->
status
==
j
+
1
))
r
=
mid
;
r
=
mid
;
else
else
{
{
r
=
mid
;
r
=
mid
;
break
;
break
;
...
@@ -150,10 +127,46 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
...
@@ -150,10 +127,46 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
if
(
r
<
size
)
if
(
r
<
size
)
head
=
r
;
head
=
r
;
else
head
=
size
-
1
;
else
head
=
size
-
1
;
/*! 1 , .. , */
tail
=
head
-
1
;
tail
=
head
-
1
;
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
!=
(
int
)((
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
;
}
}
...
@@ -161,6 +174,7 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
...
@@ -161,6 +174,7 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
{
{
if
(
file
!=
NULL
)
fclose
(
file
);
if
(
file
!=
NULL
)
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
file
=
fopen
(
name
,
"r+"
);
/*! , */
if
(
file
==
NULL
)
if
(
file
==
NULL
)
{
{
FILE
*
f
=
fopen
(
name
,
"w"
);
FILE
*
f
=
fopen
(
name
,
"w"
);
...
@@ -180,6 +194,7 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
...
@@ -180,6 +194,7 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
jrn
->
status
=
0
;
jrn
->
status
=
0
;
/*! */
CycleStorageAttr
*
csa
=
new
CycleStorageAttr
();
CycleStorageAttr
*
csa
=
new
CycleStorageAttr
();
csa
->
inf_size
=
inf_size
;
csa
->
inf_size
=
inf_size
;
csa
->
size
=
size
;
csa
->
size
=
size
;
...
@@ -189,15 +204,14 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
...
@@ -189,15 +204,14 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
fflush
(
file
);
fflush
(
file
);
seekpos
+=
sizeof
(
CycleStorageAttr
);
seekpos
+=
sizeof
(
CycleStorageAttr
);
/*! */
for
(
int
i
=
0
;
i
<
size
;
i
++
)
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
{
filewrite
(
jrn
,
i
,
false
);
filewrite
(
jrn
,
i
,
false
);
}
}
fflush
(
file
);
fflush
(
file
);
/*! , ,
/*! , , */
*/
int
emp
=
sz
-
size
*
full_size
-
sizeof
(
CycleStorageAttr
);
int
emp
=
sz
-
size
*
full_size
-
sizeof
(
CycleStorageAttr
);
if
(
emp
>
0
)
if
(
emp
>
0
)
{
{
...
@@ -322,6 +336,7 @@ bool CycleStorage::DelRow(int row)
...
@@ -322,6 +336,7 @@ bool CycleStorage::DelRow(int row)
bool
CycleStorage
::
DelAllRows
()
bool
CycleStorage
::
DelAllRows
()
{
{
/*! */
if
(
file
==
NULL
)
return
false
;
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
int
i
;
int
i
;
...
@@ -342,8 +357,9 @@ bool CycleStorage::DelAllRows()
...
@@ -342,8 +357,9 @@ 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 +377,7 @@ void* CycleStorage::ViewRow(int num, void* str)
...
@@ -361,7 +377,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 +407,7 @@ bool CycleStorage::ExportToXML(const char* name)
...
@@ -391,7 +407,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 @
94204758
...
@@ -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
;
...
@@ -78,6 +75,7 @@ void* TableBlockStorage::ValPointer(int num)
...
@@ -78,6 +75,7 @@ void* TableBlockStorage::ValPointer(int num)
void
TableBlockStorage
::
filewrite
(
int
seek
,
bool
needflush
)
void
TableBlockStorage
::
filewrite
(
int
seek
,
bool
needflush
)
{
{
/*! i */
fseek
(
file
,
seekpos
+
(
seek
+
cur_block
*
block_size
)
*
full_size
,
0
);
fseek
(
file
,
seekpos
+
(
seek
+
cur_block
*
block_size
)
*
full_size
,
0
);
fwrite
(
mem
[
seek
],
full_size
,
1
,
file
);
fwrite
(
mem
[
seek
],
full_size
,
1
,
file
);
if
(
needflush
)
fflush
(
file
);
if
(
needflush
)
fflush
(
file
);
...
@@ -85,37 +83,40 @@ void TableBlockStorage::filewrite(int seek, bool needflush)
...
@@ -85,37 +83,40 @@ void TableBlockStorage::filewrite(int seek, bool needflush)
bool
TableBlockStorage
::
CopyToNextBlock
(
void
)
bool
TableBlockStorage
::
CopyToNextBlock
(
void
)
{
{
int
i
;
/*! */
TableBlockStorageElem
*
tbl
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
max
=-
1
;
int
tmp
=
mem
[
0
]
->
count
;
mem
[
0
]
->
count
=
EMPTY_BLOCK
;
filewrite
(
0
,
false
);
mem
[
0
]
->
count
=
tmp
;
if
(
max
==
lim
-
1
)
if
(
cur_block
>=
block_number
-
1
)
cur_block
=
0
;
else
cur_block
++
;
/*! */
for
(
int
i
=
0
;
i
<
block_size
;
i
++
)
{
{
if
(
(
cur_block
+
2
)
*
block_size
<=
size
)
if
(
mem
[
i
]
->
count
>=
0
)
{
{
max
=-
1
;;
mem
[
i
]
->
count
=++
max
;
for
(
i
=
0
;
i
<
block_size
;
i
++
)
filewrite
(
i
,
false
);
{
if
(
mem
[
i
]
->
count
>=
0
)
{
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
++
;
}
}
}
}
delete
tbl
;
fflush
(
file
);
/*! , false */
if
(
cur_block
>=
block_number
-
1
)
return
false
;
return
true
;
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
)
{
{
/*! , */
if
(
file
!=
NULL
)
fclose
(
file
);
if
(
file
!=
NULL
)
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
file
=
fopen
(
name
,
"r+"
);
...
@@ -124,6 +125,7 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
...
@@ -124,6 +125,7 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
seekpos
=
seek
;
seekpos
=
seek
;
if
(
fseek
(
file
,
seekpos
,
0
)
==-
1
)
return
false
;
if
(
fseek
(
file
,
seekpos
,
0
)
==-
1
)
return
false
;
/*! */
StorageAttr
*
sa
=
new
StorageAttr
();
StorageAttr
*
sa
=
new
StorageAttr
();
fread
(
sa
,
sizeof
(
StorageAttr
),
1
,
file
);
fread
(
sa
,
sizeof
(
StorageAttr
),
1
,
file
);
...
@@ -133,6 +135,7 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
...
@@ -133,6 +135,7 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
int
tmpblock
=
tmpsize
/
block_num
;
int
tmpblock
=
tmpsize
/
block_num
;
tmpsize
=
tmpblock
*
block_num
;
tmpsize
=
tmpblock
*
block_num
;
/*! */
if
((
sa
->
k_size
!=
key_sz
)
||
(
sa
->
inf_size
!=
inf_sz
)
||
(
sa
->
size
!=
tmpsize
)
||
(
sa
->
block_number
!=
block_num
)
||
(
sa
->
lim
!=
block_lim
)
||
(
sa
->
seekpos
!=
seek
))
if
((
sa
->
k_size
!=
key_sz
)
||
(
sa
->
inf_size
!=
inf_sz
)
||
(
sa
->
size
!=
tmpsize
)
||
(
sa
->
block_number
!=
block_num
)
||
(
sa
->
lim
!=
block_lim
)
||
(
sa
->
seekpos
!=
seek
))
{
{
delete
sa
;
delete
sa
;
...
@@ -149,10 +152,10 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
...
@@ -149,10 +152,10 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
size
=
block_size
*
block_num
;
size
=
block_size
*
block_num
;
max
=-
1
;
max
=-
1
;
int
i
;
/*! */
mem
=
new
TableBlockStorageElem
*
[
block_size
];
mem
=
new
TableBlockStorageElem
*
[
block_size
];
for
(
i
=
0
;
i
<
block_size
;
i
++
)
for
(
i
nt
i
=
0
;
i
<
block_size
;
i
++
)
{
{
mem
[
i
]
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
mem
[
i
]
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
}
}
...
@@ -160,18 +163,18 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
...
@@ -160,18 +163,18 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
TableBlockStorageElem
*
t
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
TableBlockStorageElem
*
t
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
seekpos
+=
sizeof
(
StorageAttr
);
seekpos
+=
sizeof
(
StorageAttr
);
for
(
i
=
0
;
i
<
block_num
;
i
++
)
/*! , , 0 */
for
(
cur_block
=
0
;
cur_block
<
block_num
;
cur_block
++
)
{
{
fseek
(
file
,
seekpos
+
i
*
block_size
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
cur_block
*
block_size
*
(
full_size
),
0
);
fread
(
t
,(
full_size
),
1
,
file
);
fread
(
t
,(
full_size
),
1
,
file
);
if
(
t
->
count
>=
0
)
if
(
t
->
count
>=
0
)
{
cur_block
=
i
;
break
;
break
;
}
}
}
/*! */
fseek
(
file
,
seekpos
+
(
cur_block
*
block_size
)
*
(
full_size
),
0
);
fseek
(
file
,
seekpos
+
(
cur_block
*
block_size
)
*
(
full_size
),
0
);
for
(
i
=
0
;
i
<
block_size
;
i
++
)
for
(
i
nt
i
=
0
;
i
<
block_size
;
i
++
)
{
{
fread
(
mem
[
i
],(
full_size
),
1
,
file
);
fread
(
mem
[
i
],(
full_size
),
1
,
file
);
if
(
mem
[
i
]
->
count
>
max
)
max
=
mem
[
i
]
->
count
;
if
(
mem
[
i
]
->
count
>
max
)
max
=
mem
[
i
]
->
count
;
...
@@ -206,6 +209,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
...
@@ -206,6 +209,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
if
(
fseek
(
file
,
seekpos
,
0
)
==-
1
)
return
false
;
if
(
fseek
(
file
,
seekpos
,
0
)
==-
1
)
return
false
;
/*! */
mem
=
new
TableBlockStorageElem
*
[
block_size
];
mem
=
new
TableBlockStorageElem
*
[
block_size
];
for
(
i
=
0
;
i
<
block_size
;
i
++
)
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
{
...
@@ -220,18 +224,19 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
...
@@ -220,18 +224,19 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
sa
->
lim
=
lim
;
sa
->
lim
=
lim
;
sa
->
seekpos
=
seekpos
;
sa
->
seekpos
=
seekpos
;
/*! */
cur_block
=
0
;
cur_block
=
0
;
fwrite
(
sa
,
sizeof
(
StorageAttr
),
1
,
file
);
fwrite
(
sa
,
sizeof
(
StorageAttr
),
1
,
file
);
fflush
(
file
);
fflush
(
file
);
seekpos
+=
sizeof
(
StorageAttr
);
seekpos
+=
sizeof
(
StorageAttr
);
/*! :
/*! :
block_begin=(-5) - , , , empty_elem
=(-1) -
EMPTY_BLOCK=(-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
++
)
...
@@ -242,6 +247,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
...
@@ -242,6 +247,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
cur_block
=
0
;
cur_block
=
0
;
fflush
(
file
);
fflush
(
file
);
/*! , , */
int
emp
=
sz
-
size
*
full_size
-
sizeof
(
StorageAttr
);
int
emp
=
sz
-
size
*
full_size
-
sizeof
(
StorageAttr
);
if
(
emp
>
0
)
if
(
emp
>
0
)
{
{
...
@@ -258,7 +264,7 @@ bool TableBlockStorage::AddRow(void* key, void* value)
...
@@ -258,7 +264,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
)
...
@@ -266,6 +272,7 @@ bool TableBlockStorage::AddRow(void* key, void* value)
...
@@ -266,6 +272,7 @@ bool TableBlockStorage::AddRow(void* key, void* value)
if
((
mem
[
i
]
->
count
<
0
)
&&
(
empty
<
0
))
empty
=
i
;
if
((
mem
[
i
]
->
count
<
0
)
&&
(
empty
<
0
))
empty
=
i
;
}
}
/*! , pos>=0, , empty */
if
(
pos
>=
0
)
empty
=
pos
;
if
(
pos
>=
0
)
empty
=
pos
;
else
memcpy
(
KeyPointer
(
empty
),
key
,
k_size
);
else
memcpy
(
KeyPointer
(
empty
),
key
,
k_size
);
...
@@ -280,20 +287,19 @@ bool TableBlockStorage::DelRow(void* key)
...
@@ -280,20 +287,19 @@ bool TableBlockStorage::DelRow(void* key)
int
i
;
int
i
;
if
(
file
==
NULL
)
return
false
;
if
(
file
==
NULL
)
return
false
;
/*!
/*! */
*/
if
(
max
==
lim
-
1
)
CopyToNextBlock
();
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
)
if
(
KeyCompare
(
i
,
key
))
continue
;
{
if
(
KeyCompare
(
i
,
key
))
mem
[
i
]
->
count
=++
max
;
{
memset
(
KeyPointer
(
i
),
0
,
k_size
);
mem
[
i
]
->
count
=++
max
;
filewrite
(
i
);
memset
(
KeyPointer
(
i
),
0
,
k_size
);
return
true
;
filewrite
(
i
);
}
return
true
;
}
}
}
return
false
;
return
false
;
}
}
...
@@ -304,12 +310,14 @@ void* TableBlockStorage::FindKeyValue(void* key, void* val)
...
@@ -304,12 +310,14 @@ void* TableBlockStorage::FindKeyValue(void* key, void* val)
if
(
file
==
NULL
)
return
0
;
if
(
file
==
NULL
)
return
0
;
for
(
i
=
0
;
i
<
block_size
;
i
++
)
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
{
if
(
mem
[
i
]
->
count
>=
0
)
/*! >= 0, .. */
if
(
KeyCompare
(
i
,
key
))
if
(
mem
[
i
]
->
count
<
0
)
{
continue
;
memcpy
(
val
,
ValPointer
(
i
),
inf_size
);
if
(
KeyCompare
(
i
,
key
))
return
val
;
{
}
memcpy
(
val
,
ValPointer
(
i
),
inf_size
);
return
val
;
}
}
}
return
0
;
return
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