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
13fb4582
Commit
13fb4582
authored
Jul 27, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some changes in code, create flag also added to CycleStorage
parent
8369969e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
89 deletions
+104
-89
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+1
-1
Storages.h
include/Storages.h
+6
-3
CycleStorage.cc
src/Various/CycleStorage.cc
+45
-35
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+52
-50
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
13fb4582
...
...
@@ -145,7 +145,7 @@ void testJournal1(void)
int
i
;
char
*
str
=
new
char
[
30
];
printf
(
"journal test 1
\n
"
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
);
j
=
new
CycleStorage
(
"big_file.test"
,
30
,
1000000
,
20000
,
true
);
printf
(
"size = %d
\n
"
,
j
->
size
);
for
(
i
=
1
;
i
<
33000
;
i
++
)
{
...
...
include/Storages.h
View file @
13fb4582
...
...
@@ -89,8 +89,10 @@ class 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
();
private
:
void
filewrite
(
TableBlockStorageElem
*
tbl
,
int
seek
,
bool
needflush
=
true
);
void
filewrite
(
int
seek
,
bool
needflush
=
true
);
bool
CopyToNextBlock
();
void
*
KeyPointer
(
void
*
pnt
);
void
*
ValPointer
(
void
*
pnt
);
public
:
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
);
...
...
@@ -103,12 +105,13 @@ class CycleStorage
{
FILE
*
file
;
int
seekpos
,
inf_size
;
int
head
,
tail
;
int
head
,
tail
,
full_size
;
void
filewrite
(
CycleStorageElem
*
jrn
,
int
seek
,
bool
needflush
=
true
);
void
*
ValPointer
(
void
*
pnt
);
public
:
int
size
,
iter
;
CycleStorage
();
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
,
bool
create
=
false
);
~
CycleStorage
();
bool
Open
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
bool
Create
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
...
...
src/Various/CycleStorage.cc
View file @
13fb4582
...
...
@@ -39,11 +39,14 @@ CycleStorage::CycleStorage()
file
=
NULL
;
}
CycleStorage
::
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
CycleStorage
::
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
,
bool
create
)
{
file
=
NULL
;
if
(
!
Open
(
name
,
inf_sz
,
sz
,
seek
))
Create
(
name
,
inf_sz
,
sz
,
seek
);
if
(
create
)
Create
(
name
,
inf_sz
,
sz
,
seek
);
else
file
=
NULL
;
}
CycleStorage
::~
CycleStorage
()
...
...
@@ -51,10 +54,15 @@ CycleStorage::~CycleStorage()
fclose
(
file
);
}
void
*
CycleStorage
::
ValPointer
(
void
*
pnt
)
{
return
(
char
*
)
pnt
+
sizeof
(
CycleStorageElem
);
}
void
CycleStorage
::
filewrite
(
CycleStorageElem
*
jrn
,
int
seek
,
bool
needflush
)
{
fseek
(
file
,
seekpos
+
seek
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fseek
(
file
,
seekpos
+
seek
*
full_size
,
0
);
fwrite
(
jrn
,
full_size
,
1
,
file
);
if
(
needflush
)
fflush
(
file
);
}
...
...
@@ -83,15 +91,16 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
}
delete
csa
;
size
=
(
sz
-
sizeof
(
CycleStorageAttr
))
/
(
sizeof
(
CycleStorageElem
)
+
inf_sz
);
inf_size
=
inf_sz
;
full_size
=
sizeof
(
CycleStorageElem
)
+
inf_size
;
size
=
(
sz
-
sizeof
(
CycleStorageAttr
))
/
full_size
;
seekpos
=
seek
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
(
sizeof
(
CycleStorageElem
)
+
inf_sz
)
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
int
l
=-
1
,
r
=
size
,
mid
;
iter
=
0
;
seekpos
+=
sizeof
(
CycleStorageAttr
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fread
(
jrn
,
full_size
,
1
,
file
);
/*! jrn->status: 0 - , 1 - , 2,4 -
( 2 - 4 , ), 3 - 2, 5 - 4, 6 - 1.
...
...
@@ -109,8 +118,8 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
while
(
r
-
l
>
1
)
{
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fseek
(
file
,
seekpos
+
mid
*
full_size
,
0
);
fread
(
jrn
,
full_size
,
1
,
file
);
iter
++
;
if
(
jrn
->
status
==
0
)
r
=
mid
;
...
...
@@ -130,8 +139,8 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
{
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fseek
(
file
,
seekpos
+
mid
*
full_size
,
0
);
fread
(
jrn
,
full_size
,
1
,
file
);
iter
++
;
if
((
jrn
->
status
==
i
)
||
(
jrn
->
status
==
i
+
1
))
l
=
mid
;
...
...
@@ -164,12 +173,13 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
file
=
fopen
(
name
,
"r+"
);
}
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[(
sizeof
(
CycleStorageElem
)
+
inf_sz
)];
inf_size
=
inf_sz
;
full_size
=
sizeof
(
CycleStorageElem
)
+
inf_size
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
jrn
->
status
=
0
;
size
=
(
sz
-
sizeof
(
CycleStorageAttr
))
/
(
sizeof
(
CycleStorageElem
)
+
inf_sz
)
;
size
=
(
sz
-
sizeof
(
CycleStorageAttr
))
/
full_size
;
iter
=
0
;
inf_size
=
inf_sz
;
seekpos
=
seek
;
CycleStorageAttr
*
csa
=
new
CycleStorageAttr
();
...
...
@@ -191,7 +201,7 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
/*! , ,
*/
int
emp
=
sz
-
size
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
-
sizeof
(
CycleStorageAttr
);
int
emp
=
sz
-
size
*
full_size
-
sizeof
(
CycleStorageAttr
);
if
(
emp
>
0
)
{
char
*
empty
=
new
char
[
emp
];
...
...
@@ -209,13 +219,13 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
bool
CycleStorage
::
AddRow
(
void
*
str
)
{
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
int
i
=
0
,
k
;
/*! 2 - (head=-1), 1 (head=tail=0) )
*/
memcpy
(
(
char
*
)
jrn
+
sizeof
(
CycleStorageElem
),
str
,
inf_size
);
memcpy
(
ValPointer
(
jrn
),
str
,
inf_size
);
if
(
head
==-
1
)
{
jrn
->
status
=
1
;
...
...
@@ -233,8 +243,8 @@ bool CycleStorage::AddRow(void* str)
delete
jrn
;
return
true
;
}
fseek
(
file
,
seekpos
+
tail
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fseek
(
file
,
seekpos
+
tail
*
full_size
,
0
);
fread
(
jrn
,
full_size
,
1
,
file
);
/*! 2, 3 -> 2; 4, 5 -> 4
*/
...
...
@@ -254,8 +264,8 @@ bool CycleStorage::AddRow(void* str)
else
i
=
2
;
}
else
tail
++
;
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
memcpy
(
(
char
*
)
jrn
+
sizeof
(
CycleStorageElem
),
str
,
inf_size
);
fread
(
jrn
,
full_size
,
1
,
file
);
memcpy
(
ValPointer
(
jrn
),
str
,
inf_size
);
if
(
jrn
->
status
==
0
)
{
jrn
->
status
=
2
;
...
...
@@ -271,8 +281,8 @@ bool CycleStorage::AddRow(void* str)
if
(
head
>=
size
)
head
=
0
;
jrn
->
status
=
i
;
filewrite
(
jrn
,
tail
);
fseek
(
file
,
seekpos
+
head
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fseek
(
file
,
seekpos
+
head
*
full_size
,
0
);
fread
(
jrn
,
full_size
,
1
,
file
);
if
((
jrn
->
status
==
3
)
||
(
jrn
->
status
==
5
))
jrn
->
status
=
6
;
else
jrn
->
status
=
1
;
filewrite
(
jrn
,
head
);
...
...
@@ -286,9 +296,9 @@ bool CycleStorage::DelRow(int row)
int
i
=
(
head
+
row
)
%
size
,
j
;
if
(
row
>=
size
)
return
false
;
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
];
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
fseek
(
file
,
seekpos
+
i
*
full_size
,
0
);
fread
(
jrn
,
full_size
,
1
,
file
);
/*! 1->6, 2->3, 4->5 false
*/
...
...
@@ -316,13 +326,13 @@ bool CycleStorage::DelRow(int row)
bool
CycleStorage
::
DelAllRows
()
{
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
int
i
,
j
;
fseek
(
file
,
seekpos
,
0
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fread
(
jrn
,
full_size
,
1
,
file
);
if
(
jrn
->
status
!=
0
)
{
jrn
->
status
=
0
;
...
...
@@ -341,8 +351,8 @@ bool CycleStorage::ViewRows(int beg, int num)
if
(
num
==
0
)
n
=
size
;
if
(
num
>
size
)
n
=
size
;
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
];
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
fseek
(
file
,
seekpos
+
j
*
full_size
,
0
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
if
(
j
==
size
)
...
...
@@ -350,7 +360,7 @@ bool CycleStorage::ViewRows(int beg, int num)
j
=
0
;
fseek
(
file
,
seekpos
,
0
);
}
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fread
(
jrn
,
full_size
,
1
,
file
);
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
2
)
||
(
jrn
->
status
==
4
))
{
printf
(
"%s"
,((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)));
...
...
@@ -366,10 +376,10 @@ bool CycleStorage::ExportToXML(const char* name)
{
int
i
,
j
=
head
;
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
UniXML
*
f
=
new
UniXML
();
f
->
newDoc
(
"!"
);
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
0
);
fseek
(
file
,
seekpos
+
j
*
full_size
,
0
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
j
==
size
)
...
...
@@ -377,10 +387,10 @@ bool CycleStorage::ExportToXML(const char* name)
j
=
0
;
fseek
(
file
,
seekpos
,
0
);
}
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
)
,
1
,
file
);
fread
(
jrn
,
full_size
,
1
,
file
);
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
2
)
||
(
jrn
->
status
==
4
))
{
f
->
createNext
(
f
->
cur
,
"!"
,(
(
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)
));
f
->
createNext
(
f
->
cur
,
"!"
,(
char
*
)
ValPointer
(
jrn
));
}
j
++
;
}
...
...
src/Various/TableBlockStorage.cc
View file @
13fb4582
...
...
@@ -34,18 +34,12 @@
#include "Storages.h"
#define block_begin -5
#define empty_elem -1
bool
KeyCompare
(
void
*
key1
,
void
*
key2
,
int
cnt
)
{
bool
fl
=
true
;
for
(
int
i
=
0
;
i
<
cnt
;
i
++
)
{
if
(
*
((
char
*
)
key1
+
sizeof
(
TableBlockStorageElem
)
+
i
)
!=*
((
char
*
)
key2
+
i
))
{
fl
=
false
;
break
;
}
}
return
fl
;
return
!
memcmp
((
char
*
)
key1
+
sizeof
(
TableBlockStorageElem
),
key2
,
cnt
);
}
TableBlockStorage
::
TableBlockStorage
()
...
...
@@ -74,35 +68,47 @@ TableBlockStorage::~TableBlockStorage()
if
(
file
!=
NULL
)
fclose
(
file
);
}
void
TableBlockStorage
::
filewrite
(
TableBlockStorageElem
*
tbl
,
int
seek
,
bool
needflush
)
void
*
TableBlockStorage
::
KeyPointer
(
void
*
pnt
)
{
fseek
(
file
,
seekpos
+
seek
*
(
sizeof
(
TableBlockStorageElem
)
+
k_size
+
inf_size
),
0
);
fwrite
(
tbl
,(
sizeof
(
TableBlockStorageElem
)
+
k_size
+
inf_size
),
1
,
file
);
return
(
char
*
)
pnt
+
sizeof
(
TableBlockStorageElem
);
}
void
*
TableBlockStorage
::
ValPointer
(
void
*
pnt
)
{
return
(
char
*
)
pnt
+
sizeof
(
TableBlockStorageElem
)
+
k_size
;
}
void
TableBlockStorage
::
filewrite
(
int
seek
,
bool
needflush
)
{
fseek
(
file
,
seekpos
+
(
seek
+
cur_block
*
block_size
)
*
full_size
,
0
);
fwrite
(
mem
[
seek
],
full_size
,
1
,
file
);
if
(
needflush
)
fflush
(
file
);
}
bool
TableBlockStorage
::
CopyToNextBlock
(
void
)
{
int
i
,
j
;
int
i
;
TableBlockStorageElem
*
tbl
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
if
(
max
==
lim
-
1
)
{
if
((
cur_block
+
2
)
*
block_size
<=
size
)
{
max
=-
1
;
j
=
0
;
max
=-
1
;;
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
(
mem
[
i
]
->
count
>=
0
)
{
mem
[
i
]
->
count
=++
max
;
filewrite
(
mem
[
i
],(
cur_block
+
1
)
*
block_size
+
j
,
false
);
j
++
;
cur_block
++
;
filewrite
(
i
,
false
);
cur_block
--
;
}
}
tbl
->
count
=-
5
;
filewrite
(
tbl
,
cur_block
*
block_size
);
tbl
->
count
=
block_begin
;
fseek
(
file
,
seekpos
+
cur_block
*
block_size
*
full_size
,
0
);
fwrite
(
tbl
,
full_size
,
1
,
file
);
fflush
(
file
);
cur_block
++
;
}
}
...
...
@@ -119,7 +125,8 @@ bool TableBlockStorage::Open(const char* name, int key_sz, int inf_sz, int sz, i
seekpos
=
seek
;
StorageAttr
*
sa
=
new
StorageAttr
();
if
(
fseek
(
file
,
seekpos
,
0
)
==
0
)
fread
(
sa
,
sizeof
(
StorageAttr
),
1
,
file
);
if
(
fseek
(
file
,
seekpos
,
0
)
==
0
)
fread
(
sa
,
sizeof
(
StorageAttr
),
1
,
file
);
else
{
delete
sa
;
...
...
@@ -195,7 +202,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
lim
=
block_lim
;
full_size
=
sizeof
(
TableBlockStorageElem
)
+
k_size
+
inf_size
;
int
i
;
TableBlockStorageElem
*
t
=
(
TableBlockStorageElem
*
)
new
char
[
full_size
];
size
=
(
sz
-
sizeof
(
StorageAttr
))
/
(
full_size
);
block_number
=
block_num
;
...
...
@@ -224,17 +231,20 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
seekpos
+=
sizeof
(
StorageAttr
);
/*! :
(-5) - , , ,
(-1) -
block_begin=(-5) - , , , empty_elem=(-1) -
*/
mem
[
0
]
->
count
=
block_begin
;
for
(
i
=
1
;
i
<
block_size
;
i
++
)
mem
[
i
]
->
count
=
empty_elem
;
/*! */
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
i
%
block_size
==
0
)
t
->
count
=-
5
;
else
t
->
count
=-
1
;
filewrite
(
t
,
i
,
false
);
if
((
i
!=
0
)
&&
(
i
%
block_size
==
0
))
cur_block
++
;
filewrite
(
i
%
block_size
,
false
);
}
cur_block
=
0
;
fflush
(
file
);
int
emp
=
sz
-
size
*
full_size
-
sizeof
(
StorageAttr
);
...
...
@@ -244,11 +254,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
fwrite
(
empty
,
emp
,
1
,
file
);
fflush
(
file
);
}
mem
[
0
]
->
count
=-
5
;
for
(
i
=
1
;
i
<
block_size
;
i
++
)
mem
[
i
]
->
count
=-
1
;
delete
sa
;
delete
t
;
return
true
;
}
...
...
@@ -260,22 +266,17 @@ bool TableBlockStorage::AddRow(void* key, void* value)
CopyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
((
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
->
count
>=
0
))
if
(
KeyCompare
(
mem
[
i
],
key
,
k_size
))
pos
=
i
;
if
(
mem
[
i
]
->
count
>=
0
)
if
(
KeyCompare
(
mem
[
i
],
key
,
k_size
))
pos
=
i
;
if
((
mem
[
i
]
->
count
<
0
)
&&
(
empty
<
0
))
empty
=
i
;
}
if
(
pos
>=
0
)
{
mem
[
pos
]
->
count
=++
max
;
memcpy
((
char
*
)
mem
[
pos
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
,
value
,
inf_size
);
filewrite
(
mem
[
pos
],
cur_block
*
block_size
+
pos
);
return
true
;;
}
if
(
pos
>=
0
)
empty
=
pos
;
else
memcpy
(
KeyPointer
(
mem
[
empty
]),
key
,
k_size
);
mem
[
empty
]
->
count
=++
max
;
memcpy
((
char
*
)
mem
[
empty
]
+
sizeof
(
TableBlockStorageElem
),
key
,
k_size
);
memcpy
((
char
*
)
mem
[
empty
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
,
value
,
inf_size
);
filewrite
(
mem
[
empty
],
cur_block
*
block_size
+
empty
);
memcpy
(
ValPointer
(
mem
[
empty
]),
value
,
inf_size
);
filewrite
(
empty
);
return
true
;
}
...
...
@@ -290,12 +291,13 @@ bool TableBlockStorage::DelRow(void* key)
CopyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
(
(
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
->
count
>=
0
)
)
if
(
mem
[
i
]
->
count
>=
0
)
if
(
KeyCompare
(
mem
[
i
],
key
,
k_size
))
{
mem
[
i
]
->
count
=++
max
;
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
=
0
;
filewrite
(
mem
[
i
],
cur_block
*
block_size
+
i
);
for
(
int
k
=
0
;
k
<
k_size
;
k
++
)
*
((
char
*
)
KeyPointer
(
mem
[
i
])
+
k
)
=
0
;
filewrite
(
i
);
return
true
;
}
}
...
...
@@ -308,10 +310,10 @@ void* TableBlockStorage::FindKeyValue(void* key, void* val)
{
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
(
(
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
>=
0
)
)
if
(
mem
[
i
]
->
count
>=
0
)
if
(
KeyCompare
(
mem
[
i
],
key
,
k_size
))
{
memcpy
(
val
,
(
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
,
inf_size
);
memcpy
(
val
,
ValPointer
(
mem
[
i
])
,
inf_size
);
return
val
;
}
}
...
...
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