Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-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
wasm-watermarker
Commits
16ed4772
Verified
Commit
16ed4772
authored
Dec 12, 2020
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add safe_unique()
parent
99cbfb41
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
0 deletions
+60
-0
Reordering-inl.hpp
lib/kyut/Reordering-inl.hpp
+1
-0
SafeUnique.hpp
lib/kyut/SafeUnique.hpp
+45
-0
CMakeLists.txt
test/CMakeLists.txt
+1
-0
test_SafeUnique.cpp
test/test_SafeUnique.cpp
+13
-0
No files found.
lib/kyut/Reordering-inl.hpp
View file @
16ed4772
...
...
@@ -6,6 +6,7 @@
#include <algorithm>
#include "BitStreamWriter.hpp"
#include "CircularBitStreamReader.hpp"
#include "SafeUnique.hpp"
namespace
kyut
{
namespace
detail
{
...
...
lib/kyut/SafeUnique.hpp
0 → 100644
View file @
16ed4772
#ifndef INCLUDE_kyut_SafeUnique_cpp
#define INCLUDE_kyut_SafeUnique_cpp
#include <cassert>
#include <vector>
namespace
kyut
{
template
<
typename
Iterator
,
typename
Pred
>
Iterator
safe_unique
(
Iterator
begin
,
Iterator
end
,
Pred
pred
)
{
if
(
begin
==
end
)
{
return
begin
;
}
// This implementation is inefficient
std
::
vector
<
typename
std
::
iterator_traits
<
Iterator
>::
value_type
>
a
,
b
;
auto
it
=
begin
;
a
.
emplace_back
(
std
::
move
(
*
it
++
));
while
(
it
!=
end
)
{
if
(
pred
(
a
.
back
(),
*
it
))
{
b
.
emplace_back
(
std
::
move
(
*
it
));
}
else
{
a
.
emplace_back
(
std
::
move
(
*
it
));
}
++
it
;
}
it
=
begin
;
for
(
std
::
size_t
i
=
0
;
i
<
a
.
size
();
i
++
)
{
*
it
++
=
std
::
move
(
a
[
i
]);
}
const
auto
result
=
it
;
for
(
std
::
size_t
i
=
0
;
i
<
b
.
size
();
i
++
)
{
*
it
++
=
std
::
move
(
b
[
i
]);
}
assert
(
it
==
end
);
return
result
;
}
}
// namespace kyut
#endif // INCLUDE_kyut_SafeUnique_cpp
test/CMakeLists.txt
View file @
16ed4772
...
...
@@ -4,6 +4,7 @@ add_executable(test_kyut
test_BitStreamWriter.cpp
test_CircularBitStreamReader.cpp
test_Reordering.cpp
test_SafeUnique.cpp
)
target_link_libraries
(
test_kyut
...
...
test/test_SafeUnique.cpp
0 → 100644
View file @
16ed4772
#include "kyut/SafeUnique.hpp"
#include <string>
#include <gtest/gtest.h>
TEST
(
kyut
,
safe_unique
)
{
std
::
string
x
=
"01122233458889"
;
const
auto
result
=
kyut
::
safe_unique
(
std
::
begin
(
x
),
std
::
end
(
x
),
[](
char
a
,
char
b
)
{
return
a
==
b
;
});
EXPECT_EQ
(
result
,
std
::
begin
(
x
)
+
8
);
EXPECT_EQ
(
x
,
"01234589122388"
);
}
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