Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
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
abdullh.alsoleman
Front-End
Commits
557c94ff
Unverified
Commit
557c94ff
authored
Mar 28, 2019
by
Jonah Williams
Committed by
GitHub
Mar 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move binarySearch implementation in animated_list to foundation/collection.dart. (#29860)
parent
16b7fd6a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
9 deletions
+52
-9
collections.dart
packages/flutter/lib/src/foundation/collections.dart
+23
-0
binding.dart
packages/flutter/lib/src/scheduler/binding.dart
+11
-7
animated_list.dart
packages/flutter/lib/src/widgets/animated_list.dart
+1
-2
binary_search_test.dart
packages/flutter/test/foundation/binary_search_test.dart
+17
-0
No files found.
packages/flutter/lib/src/foundation/collections.dart
View file @
557c94ff
...
...
@@ -45,3 +45,26 @@ bool listEquals<T>(List<T> a, List<T> b) {
}
return
true
;
}
/// Returns the position of `value` in the `sortedList`, if it exists.
///
/// Returns `-1` if the `value` is not in the list. Requires the list items
/// to implement [Comparable] and the `sortedList` to already be ordered.
int
binarySearch
<
T
extends
Comparable
<
Object
>>(
List
<
T
>
sortedList
,
T
value
)
{
int
min
=
0
;
int
max
=
sortedList
.
length
;
while
(
min
<
max
)
{
final
int
mid
=
min
+
((
max
-
min
)
>>
1
);
final
T
element
=
sortedList
[
mid
];
final
int
comp
=
element
.
compareTo
(
value
);
if
(
comp
==
0
)
{
return
mid
;
}
if
(
comp
<
0
)
{
min
=
mid
+
1
;
}
else
{
max
=
mid
;
}
}
return
-
1
;
}
packages/flutter/lib/src/scheduler/binding.dart
View file @
557c94ff
...
...
@@ -74,13 +74,17 @@ class _TaskEntry<T> {
Completer
<
T
>
completer
;
void
run
()
{
Timeline
.
timeSync
(
debugLabel
??
'Scheduled Task'
,
()
{
completer
.
complete
(
task
());
},
flow:
flow
!=
null
?
Flow
.
step
(
flow
.
id
)
:
null
,
);
if
(!
kReleaseMode
)
{
Timeline
.
timeSync
(
debugLabel
??
'Scheduled Task'
,
()
{
completer
.
complete
(
task
());
},
flow:
flow
!=
null
?
Flow
.
step
(
flow
.
id
)
:
null
,
);
}
else
{
completer
.
complete
(
task
());
}
}
}
...
...
packages/flutter/lib/src/widgets/animated_list.dart
View file @
557c94ff
...
...
@@ -2,9 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:collection/collection.dart'
show
binarySearch
;
import
'package:flutter/animation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'basic.dart'
;
import
'framework.dart'
;
...
...
packages/flutter/test/foundation/binary_search_test.dart
0 → 100644
View file @
557c94ff
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/src/foundation/collections.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
test
(
'binarySearch'
,
()
{
final
List
<
int
>
items
=
<
int
>[
1
,
2
,
3
];
expect
(
binarySearch
(
items
,
1
),
0
);
expect
(
binarySearch
(
items
,
2
),
1
);
expect
(
binarySearch
(
items
,
3
),
2
);
expect
(
binarySearch
(
items
,
12
),
-
1
);
});
}
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