lexicographical_order 1.0.2
lexicographical_order: ^1.0.2 copied to clipboard
A string generator that helps to implement a lexicographical order.
Lexicographical Order #
A string generator that helps to implement a lexicographical order.
Installing #
dependencies:
lexicographical_order:
import 'package:lexicographical_order/lexicographical_order.dart';
Usage #
-
Get a string between two strings in a lexicographical order.
final mid = between(prev: 'B', next: 'D'); final list = [mid, 'D', 'B']; assert(listEqauls(list..sort(), ['B', mid, 'D']);
-
practice
class Todo { final int id; String title; bool completed String _orderKey; void reorderBetween(Todo? prev, Todo? next) { _orderKey = between( prev: prev?._orderKey, next: next?._orderKey, ); } Todo(/* omitted */); }
-
-
Generates strings that satisfy the minimum average string length and lexicographic order.
const stringCount = 100; List<String> orderKeys = generateOrderKeys(stringCount).toList();
Constraints #
-
The
between([String prev='', String next=''])
function accepts only alphabetic characters as arguments, more precisely, the following code must return true.final alphabet = 'ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuwxyz'.split(''); final String argument = /* omitted */ return key.split('').every((e) => alphabet.contains(e));
and the following constraint must also be satisfied:
1. prev and next should consist only of allowed keys
the constraints
-
Don't use 'A' as first order key
no character can precede 'A'.