master
Jordan Orelli 8 years ago
parent 227ebfd445
commit ba6a97fba8

@ -19,9 +19,9 @@ func (r *intRing) add(i int) {
if !r.full && r.next == 0 { if !r.full && r.next == 0 {
r.full = true r.full = true
} }
if r.full { if r.full {
r.base = r.incr(r.base) r.base = r.incr(r.base)
} }
} }
func (r *intRing) incr(i int) int { func (r *intRing) incr(i int) int {
@ -32,15 +32,15 @@ func (r *intRing) incr(i int) int {
} }
func (r *intRing) at(i int) int { func (r *intRing) at(i int) int {
idx := r.base + i idx := r.base + i
for idx >= len(r.items) { for idx >= len(r.items) {
idx -= len(r.items) idx -= len(r.items)
} }
return r.items[idx] return r.items[idx]
} }
func (r *intRing) clear() { func (r *intRing) clear() {
r.next = 0 r.next = 0
r.full = false r.full = false
r.base = 0 r.base = 0
} }

@ -186,7 +186,7 @@ func (t *stringTable) update(br *bit.BufReader, changed int) {
} }
entry = &t.entries[idx] entry = &t.entries[idx]
fmt.Printf("%s -> ", entry) fmt.Printf("%s -> ", entry)
// key flag // key flag
if bit.ReadBool(br) { if bit.ReadBool(br) {
@ -195,31 +195,31 @@ func (t *stringTable) update(br *bit.BufReader, changed int) {
prev, pLen := h.at(int(br.ReadBits(5))), int(br.ReadBits(5)) prev, pLen := h.at(int(br.ReadBits(5))), int(br.ReadBits(5))
if prev < len(t.entries) { if prev < len(t.entries) {
prevEntry := &t.entries[prev] prevEntry := &t.entries[prev]
entry.key = prevEntry.key[:pLen] + bit.ReadString(br) entry.key = prevEntry.key[:pLen] + bit.ReadString(br)
} else { } else {
panic("backread error") panic("backread error")
} }
} else { } else {
entry.key = bit.ReadString(br) entry.key = bit.ReadString(br)
} }
} }
// value flag // value flag
if bit.ReadBool(br) { if bit.ReadBool(br) {
if t.byteSize != 0 { if t.byteSize != 0 {
if entry.value == nil { if entry.value == nil {
entry.value = make([]byte, t.byteSize) entry.value = make([]byte, t.byteSize)
} }
} else { } else {
size, _ := int(br.ReadBits(14)), br.ReadBits(3) size, _ := int(br.ReadBits(14)), br.ReadBits(3)
if len(entry.value) < size { if len(entry.value) < size {
entry.value = make([]byte, size) entry.value = make([]byte, size)
} else { } else {
entry.value = entry.value[:size] entry.value = entry.value[:size]
} }
} }
br.Read(entry.value) br.Read(entry.value)
} }
fmt.Printf("%s\n", entry) fmt.Printf("%s\n", entry)
} }
} }

Loading…
Cancel
Save