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 betweenprev
andnext
. 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'], ), );
-
generateOrderKeys(int keyCount).
It generates a series of strings to serve as sorting keys for data.final keyCount = 100; final orderKeys = generateOrderKeys(keyCount);
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); }
-
During migration to an efficient ordered system:
Future<void> migrateToLexicalOrderSystem(Table table) async { final itemCount = table.count(); final orderKeys = generateOrderKeys(itemCount); /* omitted */ }
-
Note of Caution
For optimal results, it is recommended to exclusively utilize the 'between' and 'generateOrderKey' functions provided by this package for key generation. These functions are specifically tailored to maintain the lexicographical order of your data. The use of arguments derived from external sources in conjunction with the 'between' function may inadvertently disrupt the intended ordering of your data.