autotrie 0.3.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new61

AutoTrie #

A versatile library which solves autocompletion in Dart/Flutter. It is based around a space-efficient implementation of Trie which uses variable-length lists. With this, serving auto-suggestions is both fast and no-hassle. Suggestions are also sorted by how often they've been entered and subsorted by recency of entry, for search-engine-like results.

Read more about Trie here.

Usage #

A usage example is provided below. Check the API Reference for detailed docs:

import 'package:autotrie/autotrie.dart';

void main() {
  var engine = AutoComplete(); //You can also initialize with a starting databank.

  engine.enter('more'); // Enter more thrice.
  engine.enter('more');
  engine.enter('more');

  engine.enter('moody'); // Enter moody twice.
  engine.enter('moody');

  engine.enter('morose'); // Enter scattered words (with mo).
  engine.enter('morty');
  engine.enter('moment');
  engine.enter('momentum');

  engine.enter('sorose'); // Enter scattered words (without mo).
  engine.enter('sorty');

  engine.delete('morose'); // Delete morose.

  // Check if morose is deleted.
  print('Morose deletion check: ${engine.contains('morose')}');

  // Check if engine is empty.
  print('Engine emptiness check: ${engine.isEmpty}');

  // Suggestions starting with 'mo'.
  // They've been sorted by frequency and subsorted by recency.
  print("'mo' suggestions: ${engine.suggest('mo')}");
  // Result: [more, moody, momentum, moment, morty]

  // Get all entries.
  // They've been sorted by frequency and subsorted by recency.
  print('All entries: ${engine.allEntries}');
  // Result: [more, moody, sorty, sorose, momentum, moment, morty]
}

Hive Integration #

  • Hive is a speedy, local, and key-value database for Dart/Flutter. Go check it out if you haven't already!
  • Hive integration is now available with autotrie:
    • Uses the AutoCompleteBox class, which extends Hive's Box class.
    • Call refreshAuto after making changes to build the autocomplete engine
    • You can then use searchKeys(String prefix) and searchValues(String prefix) to get auto-suggestions.

Features and bugs #

Please file feature requests and bugs at the issue tracker.


This library and its contents are subject to the terms of the Mozilla Public License, v. 2.0.
© 2020 Aditya Kishore

0.3.1 #

  • Added subsorting by recency
  • Removed isEnd to save space and replaced it with > 0 checks
  • Somewhat better/more detailed docs

0.2.1 #

  • Added integration with Hive
  • Better documentation

0.1.2 #

  • Added methods for adding List
  • Better documentation

0.1.1 - 0.1.1+1 #

  • Initial commit and publish
  • Provides Trie engine for autocompletion
  • Has all the basic methods

example/autotrie_example.dart

import 'package:autotrie/autotrie.dart';

void main() {
  var engine = AutoComplete(); //You can also initialize with a starting databank.

  engine.enter('more'); // Enter more thrice.
  engine.enter('more');
  engine.enter('more');

  engine.enter('moody'); // Enter moody twice.
  engine.enter('moody');

  engine.enter('morose'); // Enter scattered words (with mo).
  engine.enter('morty');
  engine.enter('moment');
  engine.enter('momentum');

  engine.enter('sorose'); // Enter scattered words (without mo).
  engine.enter('sorty');

  engine.delete('morose'); // Delete morose.

  // Check if morose is deleted.
  print('Morose deletion check: ${engine.contains('morose')}');

  // Check if engine is empty.
  print('Engine emptiness check: ${engine.isEmpty}');

  // Suggestions starting with 'mo'.
  // They've been sorted by frequency and subsorted by recency.
  print("'mo' suggestions: ${engine.suggest('mo')}");
  // Result: [more, moody, momentum, moment, morty]

  // Get all entries.
  // They've been sorted by frequency and subsorted by recency.
  print('All entries: ${engine.allEntries}');
  // Result: [more, moody, sorty, sorose, momentum, moment, morty]
}

// Check the API Reference for the latest information and adv.
// methods from this class.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  autotrie: ^0.3.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:autotrie/autotrie.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Feb 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Format lib/autotrie.dart.

Run dartfmt to format lib/autotrie.dart.

Format lib/src/autotrie_base.dart.

Run dartfmt to format lib/src/autotrie_base.dart.

Format lib/src/datatree/datatree_test.dart.

Run dartfmt to format lib/src/datatree/datatree_test.dart.

Format lib/src/datatree/tree.dart.

Run dartfmt to format lib/src/datatree/tree.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
collection ^1.14.12 1.14.12
hive ^1.4.0+1 1.4.1+1
Transitive dependencies
charcode 1.1.3
convert 2.1.1
crypto 2.1.4
meta 1.1.8
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0
test ^1.6.0