lexicographical_order 1.1.3
lexicographical_order: ^1.1.3 copied to clipboard
A string generator that helps to implement a lexicographical order. this makes reordering transactions faster and simpler.
Lexicographical Order #
A string generator that helps to implement a lexicographical order(lexical order).
This makes reordering transactions faster and simpler.
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 order keys.
final keyCount = 100; final orderKeys = generateOrderKeys(keyCount);
this is useful for generating first order keys.
Caution #
The between
function accepts only allowed characters as arguments
more precisely, the following code must return true.
final prev = prevEntity.orderKey;
final next = nextEntity.orderKey;
return LexOrderValidator().checkBetweenArgs(prev: prev, next: next);
The LexOrderValidator
checks the follwing constraints:
-
both
prev
andnext
must be empty or composed of alphabets. -
next
must not be 'A' -
prev
andnext
must not be equal to each other. -
if both
prev
andnext
are not empty,prev
must not precedenext
in the lexicographical order. for example:between(prev: 'C', next: 'B');
that argument combination is invalid because
between
cannot calculate the string between 'C' and 'B'.
In debug mode, you get an exception if you violate the above constraints. but not in release mode. you can check the constraints manually by using LexOrderValidator
.