Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Simple-Sms
Project
Overview
Details
Activity
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
zhangchengbo
Simple-Sms
Commits
3061a3b5
Commit
3061a3b5
authored
Nov 18, 2024
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:添加二分查找算法工具类
parent
fc22d90a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
Constant.kt
app/src/main/kotlin/com/secspace/sms/helpers/Constant.kt
+16
-0
Binary.kt
app/src/main/kotlin/com/secspace/sms/util/Binary.kt
+44
-0
No files found.
app/src/main/kotlin/com/secspace/sms/helpers/Constant.kt
0 → 100644
View file @
3061a3b5
package
com.secspace.sms.helpers
object
Constant
{
const
val
SFSY
=
""
const
val
EXPORT
=
""
const
val
HIDE
=
""
const
val
UPDATE
=
"launch_update"
const
val
HOTFIX
=
"launch_hotfix"
const
val
CALLDIALPAD
=
"launch_dialpad"
const
val
MIN_RECENTS_THRESHOLD
=
30
}
app/src/main/kotlin/com/secspace/sms/util/Binary.kt
0 → 100644
View file @
3061a3b5
package
com.secspace.sms.util
import
android.util.Log
object
Binary
{
fun
binarySearch
(
array
:
List
<
String
>,
target
:
String
):
Boolean
{
var
left
=
0
var
right
=
array
.
size
-
1
while
(
left
<=
right
)
{
val
mid
=
left
+
(
right
-
left
)
/
2
Log
.
e
(
"shuju"
,
"----MainActivity----查找结果 array[mid]:${array[mid]} target:$target mid:$mid"
)
if
(
array
[
mid
]
==
target
)
{
return
true
// 目标值在数组中的索引
}
else
if
(
array
[
mid
]
<
target
)
{
left
=
mid
+
1
}
else
{
right
=
mid
-
1
}
}
return
false
// 未找到目标值
}
fun
binarySearch0
(
a
:
List
<
String
>,
fromIndex
:
Int
,
toIndex
:
Int
,
key
:
String
):
Int
{
var
low
=
fromIndex
var
high
=
toIndex
-
1
while
(
low
<=
high
)
{
val
mid
=
(
low
+
high
)
ushr
1
val
midVal
=
a
[
mid
]
if
(
midVal
<
key
)
low
=
mid
+
1
else
if
(
midVal
>
key
)
high
=
mid
-
1
else
return
mid
// key found
}
return
-(
low
+
1
)
// key not found.
}
}
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