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
b21a332f
Commit
b21a332f
authored
Jul 27, 2009
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
the candidate for final version of TableBlockStorage and CycleStorage
parent
13c5133e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
34 deletions
+38
-34
Storages.h
include/Storages.h
+3
-3
CycleStorage.cc
src/Various/CycleStorage.cc
+5
-3
TableBlockStorage.cc
src/Various/TableBlockStorage.cc
+30
-28
No files found.
include/Storages.h
View file @
b21a332f
...
@@ -91,8 +91,9 @@ class TableBlockStorage
...
@@ -91,8 +91,9 @@ class TableBlockStorage
private
:
private
:
void
filewrite
(
int
seek
,
bool
needflush
=
true
);
void
filewrite
(
int
seek
,
bool
needflush
=
true
);
bool
CopyToNextBlock
();
bool
CopyToNextBlock
();
void
*
KeyPointer
(
void
*
pnt
);
bool
KeyCompare
(
int
i
,
void
*
key
);
void
*
ValPointer
(
void
*
pnt
);
void
*
KeyPointer
(
int
num
);
void
*
ValPointer
(
int
num
);
public
:
public
:
bool
Open
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
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
Create
(
const
char
*
name
,
int
inf_sz
,
int
key_sz
,
int
sz
,
int
block_num
,
int
block_lim
,
int
seek
);
...
@@ -118,7 +119,6 @@ class CycleStorage
...
@@ -118,7 +119,6 @@ class CycleStorage
bool
AddRow
(
void
*
str
);
bool
AddRow
(
void
*
str
);
bool
DelRow
(
int
row
);
bool
DelRow
(
int
row
);
bool
DelAllRows
(
void
);
bool
DelAllRows
(
void
);
//bool ViewRows(int beg, int num);
void
*
ViewRow
(
int
num
,
void
*
str
);
void
*
ViewRow
(
int
num
,
void
*
str
);
bool
ExportToXML
(
const
char
*
name
);
bool
ExportToXML
(
const
char
*
name
);
};
};
...
...
src/Various/CycleStorage.cc
View file @
b21a332f
...
@@ -43,10 +43,12 @@ CycleStorage::CycleStorage(const char* name, int inf_sz, int sz, int seek, bool
...
@@ -43,10 +43,12 @@ CycleStorage::CycleStorage(const char* name, int inf_sz, int sz, int seek, bool
{
{
file
=
NULL
;
file
=
NULL
;
if
(
!
Open
(
name
,
inf_sz
,
sz
,
seek
))
if
(
!
Open
(
name
,
inf_sz
,
sz
,
seek
))
{
if
(
create
)
if
(
create
)
Create
(
name
,
inf_sz
,
sz
,
seek
);
Create
(
name
,
inf_sz
,
sz
,
seek
);
else
else
file
=
NULL
;
file
=
NULL
;
}
}
}
CycleStorage
::~
CycleStorage
()
CycleStorage
::~
CycleStorage
()
...
@@ -220,7 +222,7 @@ bool CycleStorage::AddRow(void* str)
...
@@ -220,7 +222,7 @@ bool CycleStorage::AddRow(void* str)
{
{
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
=
0
,
k
;
int
i
=
0
;
/*! 2 - (head=-1), 1 (head=tail=0) )
/*! 2 - (head=-1), 1 (head=tail=0) )
*/
*/
...
@@ -327,7 +329,7 @@ bool CycleStorage::DelAllRows()
...
@@ -327,7 +329,7 @@ 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
,
j
;
int
i
;
fseek
(
file
,
seekpos
,
0
);
fseek
(
file
,
seekpos
,
0
);
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
...
@@ -347,7 +349,7 @@ bool CycleStorage::DelAllRows()
...
@@ -347,7 +349,7 @@ bool CycleStorage::DelAllRows()
void
*
CycleStorage
::
ViewRow
(
int
num
,
void
*
str
)
void
*
CycleStorage
::
ViewRow
(
int
num
,
void
*
str
)
{
{
int
i
,
j
=
(
head
+
num
)
%
size
;
int
j
=
(
head
+
num
)
%
size
;
if
((
file
==
NULL
)
||
(
num
>
size
))
return
false
;
if
((
file
==
NULL
)
||
(
num
>
size
))
return
false
;
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
new
char
[
full_size
];
fseek
(
file
,
seekpos
+
j
*
full_size
,
0
);
fseek
(
file
,
seekpos
+
j
*
full_size
,
0
);
...
...
src/Various/TableBlockStorage.cc
View file @
b21a332f
...
@@ -37,11 +37,6 @@
...
@@ -37,11 +37,6 @@
#define block_begin -5
#define block_begin -5
#define empty_elem -1
#define empty_elem -1
bool
KeyCompare
(
void
*
key1
,
void
*
key2
,
int
cnt
)
{
return
!
memcmp
((
char
*
)
key1
+
sizeof
(
TableBlockStorageElem
),
key2
,
cnt
);
}
TableBlockStorage
::
TableBlockStorage
()
TableBlockStorage
::
TableBlockStorage
()
{
{
file
=
NULL
;
file
=
NULL
;
...
@@ -51,10 +46,12 @@ TableBlockStorage::TableBlockStorage(const char* name, int key_sz, int inf_sz, i
...
@@ -51,10 +46,12 @@ TableBlockStorage::TableBlockStorage(const char* name, int key_sz, int inf_sz, i
{
{
file
=
NULL
;
file
=
NULL
;
if
(
!
Open
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
))
if
(
!
Open
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
))
{
if
(
create
)
if
(
create
)
Create
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
);
Create
(
name
,
key_sz
,
inf_sz
,
sz
,
block_num
,
block_lim
,
seek
);
else
else
file
=
NULL
;
file
=
NULL
;
}
}
}
TableBlockStorage
::~
TableBlockStorage
()
TableBlockStorage
::~
TableBlockStorage
()
...
@@ -68,14 +65,19 @@ TableBlockStorage::~TableBlockStorage()
...
@@ -68,14 +65,19 @@ TableBlockStorage::~TableBlockStorage()
if
(
file
!=
NULL
)
fclose
(
file
);
if
(
file
!=
NULL
)
fclose
(
file
);
}
}
void
*
TableBlockStorage
::
KeyPointer
(
void
*
pnt
)
bool
TableBlockStorage
::
KeyCompare
(
int
i
,
void
*
key
)
{
{
return
(
char
*
)
pnt
+
sizeof
(
TableBlockStorageElem
);
return
!
memcmp
((
char
*
)
mem
[
i
]
+
sizeof
(
TableBlockStorageElem
),
key
,
k_size
);
}
}
void
*
TableBlockStorage
::
ValPointer
(
void
*
pnt
)
void
*
TableBlockStorage
::
KeyPointer
(
int
num
)
{
{
return
(
char
*
)
pnt
+
sizeof
(
TableBlockStorageElem
)
+
k_size
;
return
(
char
*
)
mem
[
num
]
+
sizeof
(
TableBlockStorageElem
);
}
void
*
TableBlockStorage
::
ValPointer
(
int
num
)
{
return
(
char
*
)
mem
[
num
]
+
sizeof
(
TableBlockStorageElem
)
+
k_size
;
}
}
void
TableBlockStorage
::
filewrite
(
int
seek
,
bool
needflush
)
void
TableBlockStorage
::
filewrite
(
int
seek
,
bool
needflush
)
...
@@ -260,22 +262,22 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
...
@@ -260,22 +262,22 @@ bool TableBlockStorage::Create(const char* name, int key_sz, int inf_sz, int sz,
bool
TableBlockStorage
::
AddRow
(
void
*
key
,
void
*
value
)
bool
TableBlockStorage
::
AddRow
(
void
*
key
,
void
*
value
)
{
{
int
i
=
0
,
pos
=-
1
,
empty
=-
1
,
k
;
int
i
=
0
,
pos
=-
1
,
empty
=-
1
;
if
(
file
==
NULL
)
return
false
;
if
(
file
==
NULL
)
return
false
;
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
(
mem
[
i
],
key
,
k_size
))
pos
=
i
;
if
(
KeyCompare
(
i
,
key
))
pos
=
i
;
if
((
mem
[
i
]
->
count
<
0
)
&&
(
empty
<
0
))
empty
=
i
;
if
((
mem
[
i
]
->
count
<
0
)
&&
(
empty
<
0
))
empty
=
i
;
}
}
if
(
pos
>=
0
)
empty
=
pos
;
if
(
pos
>=
0
)
empty
=
pos
;
else
memcpy
(
KeyPointer
(
mem
[
empty
]
),
key
,
k_size
);
else
memcpy
(
KeyPointer
(
empty
),
key
,
k_size
);
mem
[
empty
]
->
count
=++
max
;
mem
[
empty
]
->
count
=++
max
;
memcpy
(
ValPointer
(
mem
[
empty
]
),
value
,
inf_size
);
memcpy
(
ValPointer
(
empty
),
value
,
inf_size
);
filewrite
(
empty
);
filewrite
(
empty
);
return
true
;
return
true
;
}
}
...
@@ -292,32 +294,32 @@ bool TableBlockStorage::DelRow(void* key)
...
@@ -292,32 +294,32 @@ bool TableBlockStorage::DelRow(void* key)
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
(
mem
[
i
],
key
,
k_size
))
if
(
KeyCompare
(
i
,
key
))
{
{
mem
[
i
]
->
count
=++
max
;
mem
[
i
]
->
count
=++
max
;
for
(
int
k
=
0
;
k
<
k_size
;
k
++
)
memset
(
KeyPointer
(
i
),
0
,
k_size
);
*
((
char
*
)
KeyPointer
(
mem
[
i
])
+
k
)
=
0
;
//for(int k=0;k<k_size;k++)
// *((char*)KeyPointer(i)+k)=0;
filewrite
(
i
);
filewrite
(
i
);
return
true
;
return
true
;
}
}
}
}
return
false
;
}
}
void
*
TableBlockStorage
::
FindKeyValue
(
void
*
key
,
void
*
val
)
void
*
TableBlockStorage
::
FindKeyValue
(
void
*
key
,
void
*
val
)
{
{
int
i
,
k
;
int
i
;
if
(
file
!=
NULL
)
if
(
file
==
NULL
)
return
0
;
for
(
i
=
0
;
i
<
block_size
;
i
++
)
{
{
for
(
i
=
0
;
i
<
block_size
;
i
++
)
if
(
mem
[
i
]
->
count
>=
0
)
{
if
(
KeyCompare
(
i
,
key
))
if
(
mem
[
i
]
->
count
>=
0
)
{
if
(
KeyCompare
(
mem
[
i
],
key
,
k_size
))
memcpy
(
val
,
ValPointer
(
i
),
inf_size
);
{
return
val
;
memcpy
(
val
,
ValPointer
(
mem
[
i
]),
inf_size
);
}
return
val
;
}
}
}
}
return
0
;
return
false
;
}
}
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