Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
35d9bdea
authored
Nov 18, 2019
by
aquilescanta
Committed by
Oliver Woodman
Nov 19, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add Util.linearSearch
PiperOrigin-RevId: 281037183
parent
07bfab8e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
library/core/src/main/java/com/google/android/exoplayer2/util/Util.java
library/core/src/main/java/com/google/android/exoplayer2/util/Util.java
View file @
35d9bdea
...
...
@@ -714,10 +714,28 @@ public final class Util {
}
/**
* Returns the index of the first occurrence of {@code value} in {@code array}, or {@link
* C#INDEX_UNSET} if {@code value} is not contained in {@code array}.
*
* @param array The array to search.
* @param value The value to search for.
* @return The index of the first occurrence of value in {@code array}, or {@link C#INDEX_UNSET}
* if {@code value} is not contained in {@code array}.
*/
public
static
int
linearSearch
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
==
value
)
{
return
i
;
}
}
return
C
.
INDEX_UNSET
;
}
/**
* Returns the index of the largest element in {@code array} that is less than (or optionally
* equal to) a specified {@code value}.
*
<p>
* The search is performed using a binary search algorithm, so the array must be sorted. If the
*
*
<p>
The search is performed using a binary search algorithm, so the array must be sorted. If the
* array contains multiple elements equal to {@code value} and {@code inclusive} is true, the
* index of the first one will be returned.
*
...
...
@@ -731,8 +749,8 @@ public final class Util {
* @return The index of the largest element in {@code array} that is less than (or optionally
* equal to) {@code value}.
*/
public
static
int
binarySearchFloor
(
int
[]
array
,
int
value
,
boolean
inclusive
,
boolean
stayInBounds
)
{
public
static
int
binarySearchFloor
(
int
[]
array
,
int
value
,
boolean
inclusive
,
boolean
stayInBounds
)
{
int
index
=
Arrays
.
binarySearch
(
array
,
value
);
if
(
index
<
0
)
{
index
=
-(
index
+
2
);
...
...
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