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
8369969e
Commit
8369969e
authored
Jul 27, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed type of fields in classes Cyclestorage and TableblockStorage from char*…
changed type of fields in classes Cyclestorage and TableblockStorage from char* to void* (bugs 4090, 4115)
parent
745e9631
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
61 deletions
+36
-61
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+9
-9
Storages.h
include/Storages.h
+4
-4
CycleStorage.cc
src/Various/CycleStorage.cc
+9
-34
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+14
-14
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
8369969e
...
...
@@ -81,7 +81,7 @@ void testTable2(void)
int
i
;
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
for
(
i
=
1
;
i
<
11
;
i
++
)
...
...
@@ -92,38 +92,38 @@ void testTable2(void)
printf
(
"current block = %d, elements with values=keys added:
\n
"
,
t
->
cur_block
);
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d, rewriting first 7 with values=keys+10
\n
"
,
t
->
cur_block
);
for
(
i
=
1
;
i
<
8
;
i
++
)
{
sprintf
(
val
,
"%d"
,
i
+
10
);
t
->
AddRow
(
(
char
*
)
&
i
,
val
);
t
->
AddRow
(
&
i
,
val
);
}
printf
(
"deleteing 8-10 elements
\n
"
);
for
(
i
=
8
;
i
<
11
;
i
++
)
{
t
->
DelRow
(
(
char
*
)
&
i
);
t
->
DelRow
(
&
i
);
}
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d, rewriting 3-10 elements with values=keys+40
\n
"
,
t
->
cur_block
);
for
(
i
=
3
;
i
<
11
;
i
++
)
{
sprintf
(
val
,
"%d"
,
i
+
40
);
t
->
AddRow
(
(
char
*
)
&
i
,
val
);
t
->
AddRow
(
&
i
,
val
);
}
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
strcpy
(
val
,
"new block"
);
i
=
9
;
t
->
AddRow
(
(
char
*
)
&
i
,
val
);
t
->
AddRow
(
&
i
,
val
);
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
((
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
...
...
@@ -133,7 +133,7 @@ void testTable2(void)
t
->
Open
(
"big_file.test"
,
4
,
40
,
20000
,
5
,
28
,
0
);
for
(
i
=
1
;
i
<
20
;
i
++
)
{
if
(
t
->
FindKeyValue
(
(
char
*
)
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
if
(
t
->
FindKeyValue
(
&
i
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
current block = %d
\n
"
,
t
->
cur_block
);
delete
t
;
...
...
include/Storages.h
View file @
8369969e
...
...
@@ -94,9 +94,9 @@ class TableBlockStorage
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
);
bool
AddRow
(
char
*
key
,
char
*
val
);
bool
DelRow
(
char
*
key
);
char
*
FindKeyValue
(
char
*
key
,
char
*
val
);
bool
AddRow
(
void
*
key
,
void
*
val
);
bool
DelRow
(
void
*
key
);
void
*
FindKeyValue
(
void
*
key
,
void
*
val
);
};
class
CycleStorage
...
...
@@ -112,7 +112,7 @@ class CycleStorage
~
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
);
bool
AddRow
(
char
*
str
);
bool
AddRow
(
void
*
str
);
bool
DelRow
(
int
row
);
bool
DelAllRows
(
void
);
bool
ViewRows
(
int
beg
,
int
num
);
...
...
src/Various/CycleStorage.cc
View file @
8369969e
...
...
@@ -118,48 +118,25 @@ bool CycleStorage::Open(const char* name, int inf_sz, int sz, int seek)
}
if
(
r
<
size
)
{
fseek
(
file
,
seekpos
+
r
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
tail
=
r
-
1
;
}
else
tail
=
size
-
1
;
}
else
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
{
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
);
iter
++
;
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
l
=
mid
;
else
if
((
jrn
->
status
==
4
)
||
(
jrn
->
status
==
5
))
r
=
mid
;
else
{
r
=
mid
;
break
;
}
}
if
(
r
<
size
)
head
=
r
;
else
head
=
size
-
1
;
tail
=
head
-
1
;
if
(
tail
<
0
)
tail
=
size
-
1
;
}
else
{
int
i
,
j
;
i
=
jrn
->
status
-
jrn
->
status
%
2
;
if
(
i
==
2
)
j
=
4
;
else
j
=
2
;
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
);
iter
++
;
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
r
=
mid
;
else
if
((
jrn
->
status
==
4
)
||
(
jrn
->
status
==
5
))
if
((
jrn
->
status
==
i
)
||
(
jrn
->
status
==
i
+
1
))
l
=
mid
;
else
if
((
jrn
->
status
==
j
)
||
(
jrn
->
status
==
j
+
1
))
r
=
mid
;
else
{
r
=
mid
;
...
...
@@ -229,7 +206,7 @@ bool CycleStorage::Create(const char* name, int inf_sz, int sz, int seek)
return
true
;
}
bool
CycleStorage
::
AddRow
(
char
*
str
)
bool
CycleStorage
::
AddRow
(
void
*
str
)
{
if
(
file
==
NULL
)
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[(
sizeof
(
CycleStorageElem
)
+
inf_size
)];
...
...
@@ -238,10 +215,10 @@ bool CycleStorage::AddRow(char* str)
/*! 2 - (head=-1), 1 (head=tail=0) )
*/
memcpy
((
char
*
)
jrn
+
sizeof
(
CycleStorageElem
),
str
,
inf_size
);
if
(
head
==-
1
)
{
jrn
->
status
=
1
;
memcpy
((
void
*
)((
char
*
)
jrn
+
sizeof
(
CycleStorageElem
)),(
void
*
)
str
,
inf_size
);
filewrite
(
jrn
,
0
);
head
=
0
;
tail
=
0
;
...
...
@@ -251,7 +228,6 @@ bool CycleStorage::AddRow(char* str)
if
(
head
==
tail
)
{
jrn
->
status
=
2
;
memcpy
((
void
*
)((
char
*
)
jrn
+
sizeof
(
CycleStorageElem
)),(
void
*
)
str
,
inf_size
);
filewrite
(
jrn
,
1
);
tail
=
1
;
delete
jrn
;
...
...
@@ -279,10 +255,10 @@ bool CycleStorage::AddRow(char* str)
}
else
tail
++
;
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
memcpy
((
char
*
)
jrn
+
sizeof
(
CycleStorageElem
),
str
,
inf_size
);
if
(
jrn
->
status
==
0
)
{
jrn
->
status
=
2
;
memcpy
((
void
*
)((
char
*
)
jrn
+
sizeof
(
CycleStorageElem
)),(
void
*
)
str
,
inf_size
);
filewrite
(
jrn
,
tail
);
}
else
...
...
@@ -294,7 +270,6 @@ bool CycleStorage::AddRow(char* str)
head
++
;
if
(
head
>=
size
)
head
=
0
;
jrn
->
status
=
i
;
memcpy
((
void
*
)((
char
*
)
jrn
+
sizeof
(
CycleStorageElem
)),(
void
*
)
str
,
inf_size
);
filewrite
(
jrn
,
tail
);
fseek
(
file
,
seekpos
+
head
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
...
...
src/Various/TableBlockStorage.cc
View file @
8369969e
...
...
@@ -34,12 +34,12 @@
#include "Storages.h"
bool
KeyCompare
(
char
*
key1
,
char
*
key2
,
int
cnt
)
bool
KeyCompare
(
void
*
key1
,
void
*
key2
,
int
cnt
)
{
bool
fl
=
true
;
for
(
int
i
=
0
;
i
<
cnt
;
i
++
)
{
if
(
*
(
key1
+
sizeof
(
TableBlockStorageElem
)
+
i
)
!=*
(
key2
+
i
))
if
(
*
(
(
char
*
)
key1
+
sizeof
(
TableBlockStorageElem
)
+
i
)
!=*
((
char
*
)
key2
+
i
))
{
fl
=
false
;
break
;
...
...
@@ -252,7 +252,7 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
return
true
;
}
bool
TableBlockStorage
::
AddRow
(
char
*
key
,
char
*
value
)
bool
TableBlockStorage
::
AddRow
(
void
*
key
,
void
*
value
)
{
int
i
=
0
,
pos
=-
1
,
empty
=-
1
,
k
;
if
(
file
==
NULL
)
return
false
;
...
...
@@ -260,26 +260,26 @@ bool TableBlockStorage::AddRow(char* key, char* value)
CopyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
((
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
>=
0
))
if
(
KeyCompare
(
(
char
*
)
mem
[
i
],
key
,
k_size
))
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
)
&&
(
empty
<
0
))
empty
=
i
;
}
if
(
pos
>=
0
)
{
mem
[
pos
]
->
count
=++
max
;
memcpy
((
void
*
)((
char
*
)
mem
[
pos
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
),(
void
*
)
value
,
inf_size
);
memcpy
((
char
*
)
mem
[
pos
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
,
value
,
inf_size
);
filewrite
(
mem
[
pos
],
cur_block
*
block_size
+
pos
);
return
true
;;
}
mem
[
empty
]
->
count
=++
max
;
memcpy
((
void
*
)((
char
*
)
mem
[
empty
]
+
sizeof
(
TableBlockStorageElem
)),(
void
*
)
key
,
k_size
);
memcpy
((
void
*
)((
char
*
)
mem
[
empty
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
),(
void
*
)
value
,
inf_size
);
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
);
return
true
;
}
bool
TableBlockStorage
::
DelRow
(
char
*
key
)
bool
TableBlockStorage
::
DelRow
(
void
*
key
)
{
int
i
;
if
(
file
==
NULL
)
return
false
;
...
...
@@ -290,8 +290,8 @@ bool TableBlockStorage::DelRow(char* key)
CopyToNextBlock
();
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
((
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
>=
0
))
if
(
KeyCompare
(
(
char
*
)
mem
[
i
],
key
,
k_size
))
if
((
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
->
count
>=
0
))
if
(
KeyCompare
(
mem
[
i
],
key
,
k_size
))
{
mem
[
i
]
->
count
=++
max
;
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
=
0
;
...
...
@@ -301,7 +301,7 @@ bool TableBlockStorage::DelRow(char* key)
}
}
char
*
TableBlockStorage
::
FindKeyValue
(
char
*
key
,
char
*
val
)
void
*
TableBlockStorage
::
FindKeyValue
(
void
*
key
,
void
*
val
)
{
int
i
,
k
;
if
(
file
!=
NULL
)
...
...
@@ -309,9 +309,9 @@ char* TableBlockStorage::FindKeyValue(char* key, char* val)
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
if
((
*
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
))
!=
0
)
&&
(
mem
[
i
]
>=
0
))
if
(
KeyCompare
(
(
char
*
)
mem
[
i
],
key
,
k_size
))
if
(
KeyCompare
(
mem
[
i
],
key
,
k_size
))
{
memcpy
(
(
void
*
)
val
,(
void
*
)((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
)
,
inf_size
);
memcpy
(
val
,(
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
,
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