live local search
todos improve local search
This commit is contained in:
parent
4ade7f1682
commit
a0ed894016
9 changed files with 151 additions and 42 deletions
8
lib/features/core/data/constants/const_sorters.dart
Normal file
8
lib/features/core/data/constants/const_sorters.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
import 'package:string_similarity/string_similarity.dart';
|
||||
|
||||
abstract class ConstSorters {
|
||||
/// Uses Dice's Coefficient as a similarity metric, for a 2-way comparison, between a [targetWord]
|
||||
/// and given words.
|
||||
static int stringsSimilarityTarget(String a, String b, {required String targetWord}) =>
|
||||
a.similarityTo(targetWord).compareTo(b.similarityTo(targetWord));
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
extension MapExtensions<A, B> on Map<A, B> {
|
||||
Map<A, B> get deepCopy => {...this};
|
||||
|
||||
/// Returns the values of a [Map] at given [keys] indices.
|
||||
Iterable<B> valuesByKeys({required Iterable<A> keys}) => keys.map((final key) => this[key]!);
|
||||
}
|
||||
|
|
8
lib/features/core/data/extensions/object_extensions.dart
Normal file
8
lib/features/core/data/extensions/object_extensions.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
extension ObjectExtensions on Object? {
|
||||
E asType<E>() => this as E;
|
||||
E? asNullableType<E>() => this as E?;
|
||||
}
|
||||
|
||||
extension AsCallback<T extends Object> on T {
|
||||
T Function() get asCallback => () => this;
|
||||
}
|
14
lib/features/core/data/extensions/string_extensions.dart
Normal file
14
lib/features/core/data/extensions/string_extensions.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
extension StringExtensions on String {
|
||||
/// Returns true if given word contains atleast all the characters in [targetChars], and `false` otherwise
|
||||
///
|
||||
/// Very efficient `O(n)` instead of naive `O(n*m)`
|
||||
bool containsAllCharacters({required String targetChars}) {
|
||||
final Set<String> characterSet = Set.from(targetChars.split(''));
|
||||
for (final testChar in split('')) {
|
||||
characterSet.remove(testChar);
|
||||
if (characterSet.isEmpty) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue