lexicographical_order

Last updated:

0 purchases

lexicographical_order Image
lexicographical_order Images
Add to Cart

Description:

lexicographical order

About #
A string generator designed to enhance real-time editing of ordered sequences by making the process of reordering, sorting, and interleaving transactions more efficient.
Usage #


between(String prev, String next).
It generates a lexicographically ordered string between prev and next. The returned string is intended to be used as a sort key for some data.
final mid = between(prev: 'B', next: 'D');
assert(
areEqual(
[mid, 'D', 'B']..sort(),
['B', mid, 'D'],
),
);
copied to clipboard


generateOrderKeys(int keyCount).
It generates a series of strings to serve as sorting keys for data.
final keyCount = 100;
final orderKeys = generateOrderKeys(keyCount);
copied to clipboard
Use cases:


When 'between' is unsuitable due to an empty table or collection:
Future<void> addTodo(CreateTodo command) async {
final String orderKey = todos.isEmpty
? generateOrderKeys(1).first // <==
: between(prev: todos.last.orderKey);

final todo = await todoRepository.create(command, orderKey);
todos.add(todo);
}
copied to clipboard


During migration to an efficient ordered system:
Future<void> migrateToLexicalOrderSystem(Table table) async {
final itemCount = table.count();
final orderKeys = generateOrderKeys(itemCount);
/* omitted */
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.