lexicographical_order 1.5.0 copy "lexicographical_order: ^1.5.0" to clipboard
lexicographical_order: ^1.5.0 copied to clipboard

A string generator that helps to implement real-time editing of an ordered sequence. this makes reordering transactions faster and simpler.

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'],
      ),
    );
    
  • 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:

    1. 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);
      }
      
    2. During migration to an efficient ordered system:

      Future<void> migrateToLexicalOrderSystem(Table table) async {
        final itemCount = table.count();
        final orderKeys = generateOrderKeys(itemCount);
        /* omitted */
      }
      
7
likes
140
pub points
36%
popularity

Publisher

verified publishersylfree.com

A string generator that helps to implement real-time editing of an ordered sequence. this makes reordering transactions faster and simpler.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on lexicographical_order