[REBOL] Re: byte frequencies
From: jeff:rebol at: 6-Jul-2001 8:39
If you assume that NULL chars in your files are infrequent you
can just use a 1-based index.
If bytefreq3 generates an error, then fall back to one of the
others. This version is faster than bf2.
bytefreq3: func [fi [file!] /local ft cnt] [
ft: array/initial 255 0
foreach ch read/binary fi [
change at ft ch 1 + ft/:ch ;- <- err?
]
repeat ch 255 [
if 0 < cnt: ft/:ch [
print [mold to-char ch tab cnt]
]
]
]
If you're handling very large files you'd want to use:
fi: open/binary/direct fi
while [ch: pick fi 1][
....
fi: next fi
]
That will be much faster over some minimum size.
-jeff