alias test {
[color:green]; Create the hash table, the ratio here is 1:10, so 5000 can hold 50,000 items[/color]
[color:green]; This leaves quite a bit of room for expansion, however you can lower it if you like[/color]
hmake CitiesTable 5000
[color:green]; Create a custom window, which is hidden (-h) called @Cities[/color]
window -h @Cities
[color:green]; Load all lines of the textfile into the custom window[/color]
loadbuf @Cities textfile.txt
[color:green]; %i is our counter variable for the while loop[/color]
[color:green]; %ln is set equal to the number of lines in the custom window[/color]
var %i = 1, %ln = $line(@Cities,0)
while (%i <= %ln) {
[color:green]; Loop through all lines of the custom window and add each to the hash table[/color]
[color:green]; You will probably want to change the naming scheme here[/color]
[color:green]; I'm using this format for example purposes only[/color]
hadd CitiesTable $+(City,%i) $line(@Cities,%i)
inc %i
}
[color:green]; Save the hash table[/color]
hsave CitiesTable CitiesTable.hsh
[color:green]; Close the custom window since it's no longer needed[/color]
window -c @Cities
}