lexicographical_order 1.0.3
lexicographical_order: ^1.0.3 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']);
-
Generates strings that satisfy the minimum average string length and lexicographic order.
const stringCount = 100; List<String> orderKeys = generateOrderKeys(stringCount).toList();
How to use? #
-
The
between
function accepts only alphabetic characters or an empty string as arguments.more precisely, the following code must return true.
final alphabet = 'ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuwxyz'.split(''); final String argument = /* omitted */ return argument.isEmpty || argument.split('').every((e) => alphabet.contains(e));
and the following constraint must also be satisfied:
1. `prev` and `next` must not be equal to each other. 1. `prev` must not precede `next` in a lexicographical order.
Caution: the
between
function does not check the constraints in the release build for performance reasons. -
Don't use 'A' as first order key
It is recommended to use
generateOrderKeys(1).first
for the first order key.