Created
July 1, 2011 00:44
-
-
Save serialhex/1057637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
//"./file" | |
"fmt" | |
"bufio" | |
"os" | |
) | |
// will initialize dict here... | |
func loadDict(fname string) []string { | |
fmt.Print("Loading Dictionary\n") | |
opn, _ := file.Open(fname) | |
defer opn.Close() | |
reader := bufio.NewReader(opn) | |
theGuess := 10 // the file is ~ this big... | |
dict := make([]string, 0, theGuess) | |
// ahh... so much nicer!! | |
for { | |
line, _, err := reader.ReadLine() | |
dict = append(dict, string(line)) | |
if err == os.EOF { break } | |
} | |
return dict | |
} | |
func main() { | |
dict := loadDict("tmp") | |
fmt.Print("printing dict", dict) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./social_distance | |
Loading Dictionary | |
3 | |
foo<nil> 3 | |
bar<nil> 3 | |
baz<nil> 0 | |
EOF printing dict[foo bar baz ]% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo | |
bar | |
baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment