Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
llvm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
llvm-watermarker
Commits
5cd32e7f
Commit
5cd32e7f
authored
Nov 17, 2018
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
順列生成関数を実装
parent
571e3bbe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
5 deletions
+130
-5
.gitignore
.gitignore
+2
-0
Makefile
Makefile
+23
-5
PermutationTable.hpp
src/nykk/PermutationTable.hpp
+67
-0
Test.cpp
test/Test.cpp
+6
-0
TestPermutationTable.hpp
test/TestPermutationTable.hpp
+32
-0
No files found.
.gitignore
View file @
5cd32e7f
...
@@ -6,3 +6,5 @@
...
@@ -6,3 +6,5 @@
*.o
*.o
*.ll
*.ll
*.s
*.s
test_*
Makefile
View file @
5cd32e7f
LLVM_INCLUDE_DIRS
:=
$(
shell
llvm-config-6.0
--includedir
)
CXX
:=
g++
CXX
:=
g++
CXXFLAGS
:=
\
CXXFLAGS
:=
\
...
@@ -6,18 +8,34 @@ CXXFLAGS := \
...
@@ -6,18 +8,34 @@ CXXFLAGS := \
-Wextra
\
-Wextra
\
-pedantic
\
-pedantic
\
-Werror
\
-Werror
\
$
(
shell
llvm-config-6.0
--cxxflags
)
$
{
LLVM_INCLUDE_DIRS
:%
=-I%
}
LDFLAGS
:=
\
LDFLAGS
:=
\
$(
shell
llvm-config-6.0
--ldflags
)
\
$(
shell
llvm-config-6.0
--ldflags
)
\
$(
shell
llvm-config-6.0
--libs
)
$(
shell
llvm-config-6.0
--libs
)
.PHONY
:
all clean
.PHONY
:
all test clean
all
:
testpass.so test_pass
test
:
test_pass
./test_pass
testpass.so
:
\
src/nykk/pass/TestPass.o
\
src/nykk/pass/BlockCounterPass.o
\
src/nykk/pass/BlockWatermarkPass.o
test/Test.o
:
\
test/Test.cpp
\
test/TestPermutationTable.hpp
\
src/nykk/PermutationTable.hpp
all
:
testpass.so
test_pass
:
test/Test.o
${
CXX
}
${
CXXFLAGS
}
-o
$@
$^
${
LDFLAGS
}
testpass.so
:
src/nykk/pass/TestPass.o src/nykk/pass/BlockCounterPass.o
%.so
:
${
CXX
}
${
CXXFLAGS
}
-shared
-o
$@
$^
${
LDFLAGS
}
${
CXX
}
${
CXXFLAGS
}
-shared
-o
$@
$^
${
LDFLAGS
}
clean
:
clean
:
${
RM
}
*
.so
src/
*
/
*
.o
${
RM
}
*
.so
test_pass src/
*
/
*
.o
test
/
*
.o
src/nykk/PermutationTable.hpp
0 → 100644
View file @
5cd32e7f
#ifndef INCLUDE_NYKK_PERMUTATIONTABLE_HPP
#define INCLUDE_NYKK_PERMUTATIONTABLE_HPP
#include <cassert>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <type_traits>
#include <vector>
#include <iostream>
namespace
nykk
{
/**
* @brief Compute factorial `x!`.
*
* @param[in] x
*
* @tparam Integer Integer type.
* @tparam <unnamed>
*
* @return `x!`.
*/
template
<
typename
Integer
,
std
::
enable_if_t
<
std
::
is_integral_v
<
Integer
>
,
std
::
nullptr_t
>
=
nullptr
>
[[
nodiscard
]]
constexpr
Integer
factorial
(
Integer
x
)
{
Integer
n
=
1
;
for
(
Integer
i
=
1
;
i
<=
x
;
++
i
)
{
n
*=
i
;
}
return
n
;
}
/**
* @brief Compute a permutation table of sequence [0, n).
*
* @param[in] n Size of a number sequence.
*
* @return Pre-computed permutation table.
*/
[[
nodiscard
]]
inline
std
::
vector
<
std
::
vector
<
std
::
uint8_t
>>
create_permutation_table
(
std
::
size_t
n
)
{
assert
(
n
<
13
&&
"too large `n` to compute permutation table"
);
auto
table
=
std
::
vector
<
std
::
vector
<
std
::
uint8_t
>>
{};
table
.
reserve
(
factorial
(
n
));
// [0, n)
auto
v
=
std
::
vector
<
std
::
uint8_t
>
(
n
);
std
::
iota
(
std
::
begin
(
v
),
std
::
end
(
v
),
0
);
do
{
table
.
emplace_back
(
v
);
}
while
(
std
::
next_permutation
(
std
::
begin
(
v
),
std
::
end
(
v
)));
return
table
;
}
}
#endif
test/Test.cpp
0 → 100644
View file @
5cd32e7f
#include "TestPermutationTable.hpp"
int
main
()
{
run_test_permutation_table
();
}
test/TestPermutationTable.hpp
0 → 100644
View file @
5cd32e7f
#ifndef INCLUDE_TEST_TESTPERMUTATIONTABLE_HPP
#define INCLUDE_TEST_TESTPERMUTATIONTABLE_HPP
#include "../src/nykk/PermutationTable.hpp"
template
<
typename
T
,
typename
U
>
[[
nodiscard
]]
inline
bool
range_test
(
std
::
initializer_list
<
T
>
expected
,
U
&&
actual
)
{
return
std
::
equal
(
std
::
begin
(
expected
),
std
::
end
(
expected
),
std
::
begin
(
actual
),
std
::
end
(
actual
));
}
inline
void
run_test_permutation_table
()
{
static_assert
(
nykk
::
factorial
(
0
)
==
1
);
static_assert
(
nykk
::
factorial
(
1
)
==
1
);
static_assert
(
nykk
::
factorial
(
2
)
==
2
);
static_assert
(
nykk
::
factorial
(
5
)
==
120
);
const
auto
table
=
nykk
::
create_permutation_table
(
3
);
assert
(
table
.
size
()
==
6
);
assert
(
range_test
({
0
,
1
,
2
},
table
[
0
]));
assert
(
range_test
({
0
,
2
,
1
},
table
[
1
]));
assert
(
range_test
({
1
,
0
,
2
},
table
[
2
]));
assert
(
range_test
({
1
,
2
,
0
},
table
[
3
]));
assert
(
range_test
({
2
,
0
,
1
},
table
[
4
]));
assert
(
range_test
({
2
,
1
,
0
},
table
[
5
]));
}
#endif
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