trie_search 1.0.0
trie_search: ^1.0.0 copied to clipboard
A special data structure used to store strings that can be visualized like a graph.
import 'package:trie_search/trie.dart';
import 'employee_entity.dart';
void main() {
List<Employee> employeeList = [
Employee(
id: 1,
name: 'Apple Inc.',
jobTitle: 'Tech',
workEmail: '[email protected]'),
Employee(
id: 2,
name: 'Batman',
jobTitle: 'Superhero',
workEmail: '[email protected]'),
Employee(
id: 3,
name: 'Ball Corp.',
jobTitle: 'Sports',
workEmail: '[email protected]'),
];
Trie<Employee> trie = Trie<Employee>(
initialData: [
MapEntry('apple', employeeList[0]),
MapEntry('bat', employeeList[1]),
MapEntry('ball', employeeList[2]),
]);
trie.insert(
'batman',
Employee(
id: 4,
name: 'Bruce Wayne',
jobTitle: 'CEO',
workEmail: '[email protected]'));
trie.insert(
'balloon',
Employee(
id: 5,
name: 'John Balloon',
jobTitle: 'Artist',
workEmail: '[email protected]'));
print('Employees with prefix "ball" in Trie:');
Set<Employee> trieResult = trie.getDetailsWithPrefix('ball');
trieResult.forEach((employee) {
print('Name: ${employee.name}, Job: ${employee.jobTitle}, Email: ${employee.workEmail}');
});
print('Employees with prefix "ball" in List:');
List<Employee> listResult = employeeList
.where((employee) => employee.name.startsWith('ball'))
.toList();
listResult.forEach((employee) {
print('Name: ${employee.name}, Job: ${employee.jobTitle}, Email: ${employee.workEmail}');
});
trie.clear();
print('Trie cleared.');
Set<Employee> emptyDetails = trie.getDetailsWithPrefix('ball');
print('Details after clearing the Trie: $emptyDetails');
}