Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
keyboard
LatinIME
Commits
580420d2
Commit
580420d2
authored
10 years ago
by
Keisuke Kuroyanagi
Browse files
Options
Downloads
Patches
Plain Diff
Implement IntArrayView::split for dicttoolkit.
Bug: 10059681 Change-Id: Ic29e79d049bb532727cf5cb1e529fec5d35156ed
parent
0c1822df
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
native/jni/src/utils/int_array_view.h
+23
-0
23 additions, 0 deletions
native/jni/src/utils/int_array_view.h
native/jni/tests/utils/int_array_view_test.cpp
+47
-0
47 additions, 0 deletions
native/jni/tests/utils/int_array_view_test.cpp
with
70 additions
and
0 deletions
native/jni/src/utils/int_array_view.h
+
23
−
0
View file @
580420d2
...
...
@@ -133,6 +133,29 @@ class IntArrayView {
return
std
::
vector
<
int
>
(
begin
(),
end
());
}
std
::
vector
<
IntArrayView
>
split
(
const
int
separator
,
const
int
limit
=
S_INT_MAX
)
const
{
if
(
limit
<=
0
)
{
return
std
::
vector
<
IntArrayView
>
();
}
std
::
vector
<
IntArrayView
>
result
;
if
(
limit
==
1
)
{
result
.
emplace_back
(
mPtr
,
mSize
);
return
result
;
}
size_t
startIndex
=
0
;
for
(
size_t
i
=
0
;
i
<
mSize
;
++
i
)
{
if
(
mPtr
[
i
]
==
separator
)
{
result
.
emplace_back
(
mPtr
+
startIndex
,
i
-
startIndex
);
startIndex
=
i
+
1
;
if
(
result
.
size
()
>=
static_cast
<
size_t
>
(
limit
-
1
))
{
break
;
}
}
}
result
.
emplace_back
(
mPtr
+
startIndex
,
mSize
-
startIndex
);
return
result
;
}
private
:
DISALLOW_ASSIGNMENT_OPERATOR
(
IntArrayView
);
...
...
This diff is collapsed.
Click to expand it.
native/jni/tests/utils/int_array_view_test.cpp
+
47
−
0
View file @
580420d2
...
...
@@ -151,5 +151,52 @@ TEST(IntArrayViewTest, TestToVector) {
EXPECT_EQ
(
std
::
vector
<
int
>
(),
CodePointArrayView
().
toVector
());
}
TEST
(
IntArrayViewTest
,
TestSplit
)
{
EXPECT_TRUE
(
IntArrayView
().
split
(
0
,
0
).
empty
());
{
const
auto
intArrayViews
=
IntArrayView
().
split
(
0
,
1
);
EXPECT_EQ
(
1u
,
intArrayViews
.
size
());
EXPECT_TRUE
(
intArrayViews
[
0
].
empty
());
}
{
const
auto
intArrayViews
=
IntArrayView
().
split
(
0
,
100
);
EXPECT_EQ
(
1u
,
intArrayViews
.
size
());
EXPECT_TRUE
(
intArrayViews
[
0
].
empty
());
}
const
std
::
vector
<
int
>
intVector
=
{
1
,
2
,
3
,
3
,
2
,
3
};
const
IntArrayView
intArrayView
(
intVector
);
{
const
auto
intArrayViews
=
intArrayView
.
split
(
2
);
EXPECT_EQ
(
3u
,
intArrayViews
.
size
());
EXPECT_EQ
(
std
::
vector
<
int
>
({
1
}),
intArrayViews
[
0
].
toVector
());
EXPECT_EQ
(
std
::
vector
<
int
>
({
3
,
3
}),
intArrayViews
[
1
].
toVector
());
EXPECT_EQ
(
std
::
vector
<
int
>
({
3
}),
intArrayViews
[
2
].
toVector
());
}
{
const
auto
intArrayViews
=
intArrayView
.
split
(
2
,
2
);
EXPECT_EQ
(
2u
,
intArrayViews
.
size
());
EXPECT_EQ
(
std
::
vector
<
int
>
({
1
}),
intArrayViews
[
0
].
toVector
());
EXPECT_EQ
(
std
::
vector
<
int
>
({
3
,
3
,
2
,
3
}),
intArrayViews
[
1
].
toVector
());
}
{
const
auto
intArrayViews
=
intArrayView
.
split
(
2
,
1
);
EXPECT_EQ
(
1u
,
intArrayViews
.
size
());
EXPECT_EQ
(
intVector
,
intArrayViews
[
0
].
toVector
());
}
{
const
auto
intArrayViews
=
intArrayView
.
split
(
2
,
0
);
EXPECT_EQ
(
0u
,
intArrayViews
.
size
());
}
{
const
auto
intArrayViews
=
intArrayView
.
split
(
3
);
EXPECT_EQ
(
4u
,
intArrayViews
.
size
());
EXPECT_EQ
(
std
::
vector
<
int
>
({
1
,
2
}),
intArrayViews
[
0
].
toVector
());
EXPECT_EQ
(
std
::
vector
<
int
>
(),
intArrayViews
[
1
].
toVector
());
EXPECT_EQ
(
std
::
vector
<
int
>
({
2
}),
intArrayViews
[
2
].
toVector
());
EXPECT_EQ
(
std
::
vector
<
int
>
(),
intArrayViews
[
3
].
toVector
());
}
}
}
// namespace
}
// namespace latinime
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