This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (trie-typed) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
What
Brief
This is a standalone Trie data structure from the data-structure-typed collection. If you wish to access more data
structures or advanced features, you can transition to directly installing the
complete data-structure-typed package
How
install
npm
npm i trie-typed --save
yarn
yarnadd trie-typed
snippet
Autocomplete: Prefix validation and checking
const autocomplete =newTrie<string>(['gmail.com','gmail.co.nz','gmail.co.jp','yahoo.com','outlook.com']);// Get all completions for a prefixconst gmailCompletions = autocomplete.getWords('gmail');console.log(gmailCompletions);// ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
File System Path Operations
const fileSystem =newTrie<string>(['/home/user/documents/file1.txt','/home/user/documents/file2.txt','/home/user/pictures/photo.jpg','/home/user/pictures/vacation/','/home/user/downloads']);// Find common directory prefixconsole.log(fileSystem.getLongestCommonPrefix());// '/home/user/'// List all files in a directoryconst documentsFiles = fileSystem.getWords('/home/user/documents/');console.log(documentsFiles);// ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
Autocomplete: Basic word suggestions
// Create a trie for autocompleteconst autocomplete =newTrie<string>(['function','functional','functions','class','classes','classical','closure','const','constructor']);// Test autocomplete with different prefixesconsole.log(autocomplete.getWords('fun'));// ['functional', 'functions', 'function']console.log(autocomplete.getWords('cla'));// ['classes', 'classical', 'class']console.log(autocomplete.getWords('con'));// ['constructor', 'const']// Test with non-matching prefixconsole.log(autocomplete.getWords('xyz'));// []
Dictionary: Case-insensitive word lookup
// Create a case-insensitive dictionaryconst dictionary =newTrie<string>([],{ caseSensitive:false});// Add words with mixed casing
dictionary.add('Hello');
dictionary.add('WORLD');
dictionary.add('JavaScript');// Test lookups with different casingsconsole.log(dictionary.has('hello'));// trueconsole.log(dictionary.has('HELLO'));// trueconsole.log(dictionary.has('Hello'));// trueconsole.log(dictionary.has('javascript'));// trueconsole.log(dictionary.has('JAVASCRIPT'));// true
IP Address Routing Table
// Add IP address prefixes and their corresponding routesconst routes ={'192.168.1':'LAN_SUBNET_1','192.168.2':'LAN_SUBNET_2','10.0.0':'PRIVATE_NETWORK_1','10.0.1':'PRIVATE_NETWORK_2'};const ipRoutingTable =newTrie<string>(Object.keys(routes));// Check IP address prefix matchingconsole.log(ipRoutingTable.hasPrefix('192.168.1'));// trueconsole.log(ipRoutingTable.hasPrefix('192.168.2'));// true// Validate IP address belongs to subnetconst ip ='192.168.1.100';const subnet = ip.split('.').slice(0,3).join('.');console.log(ipRoutingTable.hasPrefix(subnet));// true
Follows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names.
Extensibility
Adheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures.
Modularization
Includes data structure modularization and independent NPM packages.
Efficiency
All methods provide time and space complexity, comparable to native JS performance.
Maintainability
Follows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns.
Testability
Automated and customized unit testing, performance testing, and integration testing.
Portability
Plans for porting to Java, Python, and C++, currently achieved to 80%.
Reusability
Fully decoupled, minimized side effects, and adheres to OOP.
Security
Carefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects.
Scalability
Data structure software does not involve load issues.