Typeahead algorithm first version