Skip to content

Instantly share code, notes, and snippets.

@chrisvest
Last active April 15, 2016 20:00
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 chrisvest/9dee53c62a6d61581b32cbdfddfd27f7 to your computer and use it in GitHub Desktop.
Save chrisvest/9dee53c62a6d61581b32cbdfddfd27f7 to your computer and use it in GitHub Desktop.
use "files"
use "collections"
actor Main
new create(env: Env) =>
let collector = Collector(env)
let parser = Parser(collector)
let caps = recover val FileCaps.set(FileRead).set(FileStat) end
try
let path = FilePath(env.root as AmbientAuth, env.args(1), caps)
with file = File.open(path) do
for line in file.lines() do
parser.parse(line)
end
end
parser.done()
end
actor Parser
let _collector: Collector
new create(collector: Collector) =>
_collector = collector
be parse(line: String) =>
try
let snum = line.substring(0, line.find("\t") - 1)
let value = snum.u64()
_collector.collect(value)
end
be done() => _collector.done()
actor Collector
let _env: Env
var _prev: U64
var _count: U32
let _histo: Map[U32,U32]
new create(env: Env) =>
_env = env
_prev = -1
_count = 0
_histo = Map[U32,U32](1000)
be collect(value: U64) => _collect(value)
fun ref _collect(value: U64) =>
if value != _prev then
let c = 1 + try _histo(_count) else 0 end
_histo.update(_count, c)
_count = 0
_prev = value
else
_count = _count + 1
end
be done() =>
_collect(-1)
try _histo.remove(-1) end
for (k,v) in _histo.pairs() do
_env.out.print(k.string() + " => " + v.string())
end
12 13
12 14
12 15
12 16
12 17
12 18
12 20
12 21
12 22
12 23
Real dataset:
The `twitter_rv.tar.gz` social graph from http://an.kaist.ac.kr/traces/WWW2010.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment