Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProgrammationParallelle
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JACQUIER Timeo
ProgrammationParallelle
Commits
c1cb9b07
Commit
c1cb9b07
authored
2 years ago
by
Martin
Browse files
Options
Downloads
Patches
Plain Diff
Ajout deuxième bibliotheque Suffix Tree
parent
89e10706
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ProgrammesEnVrac/SuffixTree.cpp
+106
-0
106 additions, 0 deletions
src/ProgrammesEnVrac/SuffixTree.cpp
src/ProgrammesEnVrac/main.cpp
+3
-2
3 additions, 2 deletions
src/ProgrammesEnVrac/main.cpp
src/ProgrammesEnVrac/makefile
+8
-3
8 additions, 3 deletions
src/ProgrammesEnVrac/makefile
with
117 additions
and
5 deletions
src/ProgrammesEnVrac/SuffixTree.cpp
0 → 100644
+
106
−
0
View file @
c1cb9b07
#include
<functional>
#include
<iostream>
#include
<vector>
struct
Node
{
std
::
string
sub
=
""
;
// a substring of the input string
std
::
vector
<
int
>
ch
;
// vector of child nodes
Node
()
{
// empty
}
Node
(
const
std
::
string
&
sub
,
std
::
initializer_list
<
int
>
children
)
:
sub
(
sub
)
{
ch
.
insert
(
ch
.
end
(),
children
);
}
};
struct
SuffixTree
{
std
::
vector
<
Node
>
nodes
;
SuffixTree
(
const
std
::
string
&
str
)
{
nodes
.
push_back
(
Node
{});
for
(
size_t
i
=
0
;
i
<
str
.
length
();
i
++
)
{
addSuffix
(
str
.
substr
(
i
));
}
}
void
visualize
()
{
if
(
nodes
.
size
()
==
0
)
{
std
::
cout
<<
"<empty>
\n
"
;
return
;
}
std
::
function
<
void
(
int
,
const
std
::
string
&
)
>
f
;
f
=
[
&
](
int
n
,
const
std
::
string
&
pre
)
{
auto
children
=
nodes
[
n
].
ch
;
if
(
children
.
size
()
==
0
)
{
std
::
cout
<<
"- "
<<
nodes
[
n
].
sub
<<
'\n'
;
return
;
}
std
::
cout
<<
"+ "
<<
nodes
[
n
].
sub
<<
'\n'
;
auto
it
=
std
::
begin
(
children
);
if
(
it
!=
std
::
end
(
children
))
do
{
if
(
std
::
next
(
it
)
==
std
::
end
(
children
))
break
;
std
::
cout
<<
pre
<<
"+-"
;
f
(
*
it
,
pre
+
"| "
);
it
=
std
::
next
(
it
);
}
while
(
true
);
std
::
cout
<<
pre
<<
"+-"
;
f
(
children
[
children
.
size
()
-
1
],
pre
+
" "
);
};
f
(
0
,
""
);
}
private
:
void
addSuffix
(
const
std
::
string
&
suf
)
{
int
n
=
0
;
size_t
i
=
0
;
while
(
i
<
suf
.
length
())
{
char
b
=
suf
[
i
];
int
x2
=
0
;
int
n2
;
while
(
true
)
{
auto
children
=
nodes
[
n
].
ch
;
if
(
x2
==
children
.
size
())
{
// no matching child, remainder of suf becomes new node
n2
=
nodes
.
size
();
nodes
.
push_back
(
Node
(
suf
.
substr
(
i
),
{}));
nodes
[
n
].
ch
.
push_back
(
n2
);
return
;
}
n2
=
children
[
x2
];
if
(
nodes
[
n2
].
sub
[
0
]
==
b
)
{
break
;
}
x2
++
;
}
// find prefix of remaining suffix in common with child
auto
sub2
=
nodes
[
n2
].
sub
;
size_t
j
=
0
;
while
(
j
<
sub2
.
size
())
{
if
(
suf
[
i
+
j
]
!=
sub2
[
j
])
{
// split n2
auto
n3
=
n2
;
// new node for the part in common
n2
=
nodes
.
size
();
nodes
.
push_back
(
Node
(
sub2
.
substr
(
0
,
j
),
{
n3
}));
nodes
[
n3
].
sub
=
sub2
.
substr
(
j
);
// old node loses the part in common
nodes
[
n
].
ch
[
x2
]
=
n2
;
break
;
// continue down the tree
}
j
++
;
}
i
+=
j
;
// advance past part in common
n
=
n2
;
// continue down the tree
}
}
};
/*
int main() {
SuffixTree("banana$").visualize();
}
*/
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/ProgrammesEnVrac/main.cpp
+
3
−
2
View file @
c1cb9b07
...
@@ -6,7 +6,8 @@
...
@@ -6,7 +6,8 @@
#include
<omp.h>
#include
<omp.h>
#include
"suffixe_tree.cpp"
//#include "suffixe_tree.cpp"
#include
"SuffixTree.cpp"
#define CHRONO
#define CHRONO
...
@@ -250,7 +251,7 @@ void nbAdditifsAvecSansOpenMP(){
...
@@ -250,7 +251,7 @@ void nbAdditifsAvecSansOpenMP(){
}
}
void
arbreDesSuffixes
(){
void
arbreDesSuffixes
(){
int
size
=
4
12
00
;
int
size
=
4
00
00
;
arbre
=
new
SuffixTree
(
fichier
.
substr
(
0
,
size
));
arbre
=
new
SuffixTree
(
fichier
.
substr
(
0
,
size
));
//SuffixTree = arbre->nodes[0]->child
//SuffixTree = arbre->nodes[0]->child
//arbre->visualize();
//arbre->visualize();
...
...
This diff is collapsed.
Click to expand it.
src/ProgrammesEnVrac/makefile
+
8
−
3
View file @
c1cb9b07
...
@@ -8,12 +8,14 @@ RM = rm -r -f
...
@@ -8,12 +8,14 @@ RM = rm -r -f
G
=
g++
G
=
g++
MAKEOPTS
=
-Wall
-Wextra
-pedantic
-std
=
gnu++11
-Wno-unused-parameter
MAKEOPTS
=
-Wall
-Wextra
-pedantic
-std
=
gnu++11
-Wno-unused-parameter
BIB
=
$(
G
)
$(
MAKEOPTS
)
-c
$<
-o
$@
.o
BIB
=
$(
G
)
-c
$<
-o
$@
.o
OPEN
=
-fopenmp
OPEN
=
-fopenmp
MAIN
=
main.cpp
MAIN
=
main.cpp
EXEC
=
main
EXEC
=
main
OBJETS
=
SuffixTree.o suffixe_tree.o
CLEAN
=
$(
EXEC
)
*
.o
*
.exe
CLEAN
=
$(
EXEC
)
*
.o
*
.exe
acc
:
openacc.cpp
acc
:
openacc.cpp
...
@@ -52,8 +54,11 @@ rexe:
...
@@ -52,8 +54,11 @@ rexe:
tree
:
suffixe_tree.cpp
tree
:
suffixe_tree.cpp
$(
BIB
)
$(
BIB
)
main
:
main.cpp suffixe_tree.o
tree2
:
SuffixTree.cpp
$(
G
)
$(
OPEN
)
$(
MAKEOPTS
)
$<
-o
$@
suffixe_tree.o
-lcrypt
$(
BIB
)
main
:
main.cpp $(OBJETS)
$(
G
)
$(
OPEN
)
$<
-o
$@
$(
OBJETS
)
exec
:
exec
:
./
$(
EXEC
)
./
$(
EXEC
)
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