Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
func vlq_encode(num) {
|
||||
var t = (0x7F & num)
|
||||
var str = t.chr
|
||||
while (num >>= 7) {
|
||||
t = (0x7F & num)
|
||||
str += chr(0x80 | t)
|
||||
}
|
||||
str.reverse
|
||||
}
|
||||
|
||||
func vlq_decode(str) {
|
||||
var num = ''
|
||||
str.each_byte { |b|
|
||||
num += ('%07b' % (b & 0x7F))
|
||||
}
|
||||
Num(num, 2)
|
||||
}
|
||||
|
||||
var tests = [0, 0xa, 123, 254, 255, 256,
|
||||
257, 65534, 65535, 65536, 65537, 0x1fffff,
|
||||
0x200000]
|
||||
|
||||
tests.each { |t|
|
||||
var vlq = vlq_encode(t)
|
||||
printf("%8s %12s %8s\n", t,
|
||||
vlq.bytes.join(':', { "%02X" % _ }), vlq_decode(vlq))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue