Skip to content

Instantly share code, notes, and snippets.

@Araq
Created May 27, 2015 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Araq/b40932a30b9dbb824364 to your computer and use it in GitHub Desktop.
Save Araq/b40932a30b9dbb824364 to your computer and use it in GitHub Desktop.
import threadpool, tables, strutils
var db {.threadvar.}: CountTable[string]
proc rawPut(key: string) =
inc(db, key)
proc rawInit() =
db = initCountTable[string]()
proc put(key: string) =
pinnedSpawn 0, rawPut(key)
proc init =
pinnedSpawn 0, rawInit()
proc rawGet(): string =
db.sort()
result = db.largest()[0]
proc getMax(): string =
let flow = pinnedSpawn(0, rawGet())
result = ^flow
proc main =
init()
for x in split(readFile("readme.txt")):
put x
echo getMax()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment