Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
c018f2b4
Commit
c018f2b4
authored
11 years ago
by
Nicolas Marsic
Browse files
Options
Downloads
Patches
Plain Diff
Serialize PermutationTree: can access byte stream from interface
parent
5acdec04
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
FunctionSpace/PermutationTree.cpp
+54
-36
54 additions, 36 deletions
FunctionSpace/PermutationTree.cpp
FunctionSpace/PermutationTree.h
+26
-7
26 additions, 7 deletions
FunctionSpace/PermutationTree.h
with
80 additions
and
43 deletions
FunctionSpace/PermutationTree.cpp
+
54
−
36
View file @
c018f2b4
...
...
@@ -37,45 +37,34 @@ PermutationTree::PermutationTree(const vector<size_t>& refSequence){
leaf
[
i
]
->
leafId
=
i
;
}
PermutationTree
::
PermutationTree
(
string
path
){
PermutationTree
::
PermutationTree
(
const
char
*
stream
){
// Populate from stream
populateFromStream
(
stream
);
}
PermutationTree
::
PermutationTree
(
const
string
&
path
){
// Read file //
// Open Stream
ifstream
input
;
input
.
exceptions
(
std
::
ifstream
::
failbit
|
std
::
ifstream
::
badbit
);
input
.
open
(
path
.
c_str
(),
std
::
ifstream
::
binary
);
// Alloc stream for header
char
*
stream
=
new
char
[
3
*
sizeof
(
size_t
)];
// Read header
size_t
uSize
;
// Unlink struct size
size_t
nSize
;
// Total size for unlink struct
input
.
read
(
stream
,
3
*
sizeof
(
size_t
));
// Get size of stream (go to stream end)
input
.
seekg
(
0
,
std
::
ifstream
::
end
);
const
size_t
size
=
input
.
tellg
();
memcpy
(
&
uSize
,
stream
+
0
*
sizeof
(
size_t
),
sizeof
(
size_t
));
memcpy
(
&
nextNodeId
,
stream
+
1
*
sizeof
(
size_t
),
sizeof
(
size_t
));
memcpy
(
&
sequenceSize
,
stream
+
2
*
sizeof
(
size_t
),
sizeof
(
size_t
));
// Reset stream possition
input
.
seekg
(
0
,
std
::
ifstream
::
beg
);
// Alloc stream for unlink struct
delete
[]
stream
;
nSize
=
uSize
*
nextNodeId
;
stream
=
new
char
[
nSize
];
// Alloc byte stream & Read file
char
*
stream
=
new
char
[
size
];
input
.
read
(
stream
,
size
);
// Read unlink struct & close
input
.
read
(
stream
,
nSize
);
input
.
close
();
// Unserialize unlink struct
vector
<
unlink_t
>
unlink
(
nextNodeId
);
for
(
size_t
i
=
0
;
i
<
nextNodeId
;
i
++
)
unserialize
(
stream
+
(
i
*
uSize
),
&
unlink
[
i
]);
// Populate from stream
populateFromStream
(
stream
);
// Free stream
delete
[]
stream
;
// Regenerate Tree //
rebuild
(
unlink
);
}
void
PermutationTree
::
populate
(
node_t
*
node
,
...
...
@@ -126,7 +115,27 @@ void PermutationTree::populate(node_t* node,
listOfLeaf
.
push_back
(
node
);
}
void
PermutationTree
::
unserialize
(
char
*
stream
,
unlink_t
*
unlink
){
void
PermutationTree
::
populateFromStream
(
const
char
*
stream
){
// Header Size
const
size_t
hSize
=
headerSize
();
// Read header
size_t
uSize
;
// Unlink struct size
memcpy
(
&
uSize
,
stream
+
0
*
sizeof
(
size_t
),
sizeof
(
size_t
));
memcpy
(
&
nextNodeId
,
stream
+
1
*
sizeof
(
size_t
),
sizeof
(
size_t
));
memcpy
(
&
sequenceSize
,
stream
+
2
*
sizeof
(
size_t
),
sizeof
(
size_t
));
// Unserialize unlink struct
vector
<
unlink_t
>
unlink
(
nextNodeId
);
for
(
size_t
i
=
0
;
i
<
nextNodeId
;
i
++
)
unserialize
(
stream
+
hSize
+
(
i
*
uSize
),
&
unlink
[
i
]);
// Regenerate Tree //
rebuild
(
unlink
);
}
void
PermutationTree
::
unserialize
(
const
char
*
stream
,
unlink_t
*
unlink
){
// Some padding data //
const
size_t
nxtChoiceStart
=
2
*
sizeof
(
size_t
);
const
size_t
fatherIdStart
=
nxtChoiceStart
+
sequenceSize
*
sizeof
(
size_t
);
...
...
@@ -352,7 +361,7 @@ string PermutationTree::toString(void) const{
return
stream
.
str
();
}
void
PermutationTree
::
serialize
(
string
path
)
const
{
std
::
pair
<
size_t
,
char
*>
PermutationTree
::
serialize
(
void
)
const
{
// Enumerate Nodes //
list
<
node_t
*>
node
;
enumerate
(
root
,
node
);
...
...
@@ -367,18 +376,19 @@ void PermutationTree::serialize(string path) const{
const
size_t
uSize
=
unlinkSize
(
&
tmp
);
// Unlink struct size
const
size_t
nNode
=
node
.
size
();
// Number of node/unlink struct
const
size_t
nSize
=
uSize
*
nNode
;
// Total size for unlink struct
const
size_t
sSize
=
hSize
+
nSize
;
// Stream size
// Alloc byte
s
tream
char
*
stream
=
new
char
[
nSize
+
h
Size
];
for
(
size_t
i
=
0
;
i
<
nSize
+
h
Size
;
i
++
)
// Alloc byte
S
tream
char
*
stream
=
new
char
[
s
Size
];
for
(
size_t
i
=
0
;
i
<
s
Size
;
i
++
)
stream
[
i
]
=
0
;
// Write header
// Write header
in Stream
memcpy
(
stream
+
0
*
sizeof
(
size_t
),
&
uSize
,
sizeof
(
size_t
));
memcpy
(
stream
+
1
*
sizeof
(
size_t
),
&
nNode
,
sizeof
(
size_t
));
memcpy
(
stream
+
2
*
sizeof
(
size_t
),
&
sequenceSize
,
sizeof
(
size_t
));
// Write unlinked node
// Write unlinked node
in Stream
list
<
node_t
*>::
iterator
it
=
node
.
begin
();
for
(
size_t
i
=
0
;
i
<
nNode
;
i
++
,
it
++
){
...
...
@@ -386,15 +396,23 @@ void PermutationTree::serialize(string path) const{
serialize
(
stream
+
hSize
+
(
i
*
uSize
),
&
tmp
);
}
// Return Stream & its size
return
pair
<
size_t
,
char
*>
(
sSize
,
stream
);
}
void
PermutationTree
::
serialize
(
const
string
&
path
)
const
{
// Serialize into byte Stream
std
::
pair
<
size_t
,
char
*>
stream
=
serialize
();
// Write byte stream
ofstream
output
;
output
.
exceptions
(
std
::
ofstream
::
failbit
|
std
::
ofstream
::
badbit
);
output
.
open
(
path
.
c_str
(),
std
::
ofstream
::
binary
);
output
.
write
(
stream
,
nSize
+
hSize
);
output
.
write
(
stream
.
second
,
stream
.
first
);
output
.
close
();
// Free
delete
[]
stream
;
delete
[]
stream
.
second
;
}
void
PermutationTree
::
enumerate
(
node_t
*
node
,
std
::
list
<
node_t
*>&
listOfNode
){
...
...
This diff is collapsed.
Click to expand it.
FunctionSpace/PermutationTree.h
+
26
−
7
View file @
c018f2b4
...
...
@@ -65,7 +65,8 @@ class PermutationTree{
public
:
PermutationTree
(
const
std
::
vector
<
size_t
>&
refSequence
);
PermutationTree
(
std
::
string
path
);
PermutationTree
(
const
char
*
stream
);
PermutationTree
(
const
std
::
string
&
path
);
~
PermutationTree
(
void
);
size_t
getSequenceSize
(
void
)
const
;
...
...
@@ -83,11 +84,13 @@ class PermutationTree{
std
::
vector
<
std
::
pair
<
size_t
,
size_t
>
>
getAllTagsCount
(
void
)
const
;
std
::
string
toString
(
void
)
const
;
void
serialize
(
std
::
string
path
)
const
;
std
::
pair
<
size_t
,
char
*>
serialize
(
void
)
const
;
void
serialize
(
const
std
::
string
&
path
)
const
;
private
:
void
populate
(
node_t
*
node
,
std
::
list
<
node_t
*>&
listOfLeaf
);
void
unserialize
(
char
*
stream
,
unlink_t
*
unlink
);
void
populateFromStream
(
const
char
*
stream
);
void
unserialize
(
const
char
*
stream
,
unlink_t
*
unlink
);
void
rebuild
(
std
::
vector
<
unlink_t
>&
unlink
);
static
node_t
*
copy
(
unlink_t
*
unlink
);
...
...
@@ -112,13 +115,20 @@ class PermutationTree{
Instanciates a new PermutationTree build on the given vector
**
@fn PermutationTree::PermutationTree(const char* stream)
@param stream A byte stream
Instanciates a new PermutationTree by loading the given byte stream
@see PermutationTree:serialize(char*)
**
@fn PermutationTree::PermutationTree(std::string path)
@param path A file path
Instanciates a new PermutationTree by loading the
serialized PermutationTree given in path
Instanciates a new PermutationTree by loading the file given in path
@see PermutationTree:serialize()
@see PermutationTree:serialize(
const std::string&
)
**
@fn PermutationTree::~PermutationTree
...
...
@@ -185,7 +195,16 @@ class PermutationTree{
@return Returns a string describing this PermutationTree
**
@fn PermutationTree::serialize
@fn PermutationTree::serialize(void)
Serialize this PermutationTree into a byte stream
@return Returns a pair such that:
@li The first entry is stream size
@li the second entry is a pointer to the allocated stream
**
@fn PermutationTree::serialize(const std::string&)
@param path A file path
Serialize this PermutationTree into the given file path
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment