We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a6e53f9 commit ec13079Copy full SHA for ec13079
pkgs/collection/lib/src/algorithms.dart
@@ -5,7 +5,7 @@
5
/// A selection of data manipulation algorithms.
6
library;
7
8
-import 'dart:math' show Random, ln2, log;
+import 'dart:math' show Random;
9
10
import 'utils.dart';
11
@@ -535,7 +535,11 @@ void quickSortBy<E, K>(
535
const int _pdqInsertionSortThreshold = 24;
536
537
/// Computes the base-2 logarithm of [n].
538
-int _log2(int n) => n == 0 ? 0 : (log(n) / ln2).floor();
+/// Computes the base-2 logarithm of [n].
539
+///
540
+/// Uses bitLength to compute the floor(log2(n)) efficiently. For n == 0
541
+/// we return 0.
542
+int _log2(int n) => n > 0 ? n.bitLength - 1 : 0;
543
544
/// Swaps the elements at positions [i] and [j] in [elements].
545
void _pdqSwap<E>(List<E> elements, int i, int j) {
0 commit comments