mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Rename some "cOffset" variables
This commit is contained in:
1 parent
7be27661b9
commit
7e26fe8086
2 files changed
+37
-36
No files matched your search
+2
-2
@@ -29,8 +29,8 @@ const (
|
|||||||
// MaxCSize is the maximum RAC file size (in both CSpace and DSpace).
|
// MaxCSize is the maximum RAC file size (in both CSpace and DSpace).
|
||||||
MaxSize = (1 << 48) - 1
|
MaxSize = (1 << 48) - 1
|
||||||
|
|
||||||
// invalidCOffset is ((1 << 64) - 1).
|
// invalidCOffsetCLength is ((1 << 64) - 1).
|
||||||
invalidCOffset = 0xFFFFFFFFFFFFFFFF
|
invalidCOffsetCLength = 0xFFFFFFFFFFFFFFFF
|
||||||
)
|
)
|
||||||
|
|
||||||
// Codec is the compression codec for the RAC file.
|
// Codec is the compression codec for the RAC file.
|
||||||
|
|||||||
+35
-34
@@ -137,12 +137,13 @@ type Writer struct {
|
|||||||
// sum of all the dRangeSize arguments passed to AddChunk.
|
// sum of all the dRangeSize arguments passed to AddChunk.
|
||||||
dFileSize uint64
|
dFileSize uint64
|
||||||
|
|
||||||
// resourcesCOffsets is the file offsets of each shared resource. Those
|
// resourcesCOffCLens is the COffset and CLength values for each shared
|
||||||
// offsets are for the compressed file (what the RAC spec calls CSpace).
|
// resource. Those values are for the compressed file (what the RAC spec
|
||||||
|
// calls CSpace).
|
||||||
//
|
//
|
||||||
// The first element (if it exists) is an unused placeholder, as a zero
|
// The first element (if it exists) is an unused placeholder, as a zero
|
||||||
// OptResource means unused.
|
// OptResource means unused.
|
||||||
resourcesCOffsets []uint64
|
resourcesCOffCLens []uint64
|
||||||
|
|
||||||
// leafNodes are the non-resource leaf nodes of the hierarchical index.
|
// leafNodes are the non-resource leaf nodes of the hierarchical index.
|
||||||
leafNodes []node
|
leafNodes []node
|
||||||
@@ -306,7 +307,7 @@ func (w *Writer) roundUpToCPageBoundary(x uint64) uint64 {
|
|||||||
//
|
//
|
||||||
// The caller may modify resource's contents after this method returns.
|
// The caller may modify resource's contents after this method returns.
|
||||||
func (w *Writer) AddResource(resource []byte) (OptResource, error) {
|
func (w *Writer) AddResource(resource []byte) (OptResource, error) {
|
||||||
if len(w.resourcesCOffsets) >= (1 << 30) {
|
if len(w.resourcesCOffCLens) >= (1 << 30) {
|
||||||
w.err = errors.New("rac: too many resources")
|
w.err = errors.New("rac: too many resources")
|
||||||
return 0, w.err
|
return 0, w.err
|
||||||
}
|
}
|
||||||
@@ -318,13 +319,13 @@ func (w *Writer) AddResource(resource []byte) (OptResource, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(w.resourcesCOffsets) == 0 {
|
if len(w.resourcesCOffCLens) == 0 {
|
||||||
w.resourcesCOffsets = make([]uint64, 1, 8)
|
w.resourcesCOffCLens = make([]uint64, 1, 8)
|
||||||
}
|
}
|
||||||
id := OptResource(len(w.resourcesCOffsets))
|
id := OptResource(len(w.resourcesCOffCLens))
|
||||||
cOffset := w.dataSize - uint64(len(resource))
|
cOffset := w.dataSize - uint64(len(resource))
|
||||||
cLength := calcCLength(len(resource))
|
cLength := calcCLength(len(resource))
|
||||||
w.resourcesCOffsets = append(w.resourcesCOffsets, cOffset|(cLength<<48))
|
w.resourcesCOffCLens = append(w.resourcesCOffCLens, cOffset|(cLength<<48))
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,10 +362,10 @@ func (w *Writer) AddChunk(dRangeSize uint64, primary []byte, secondary OptResour
|
|||||||
cLength := calcCLength(len(primary))
|
cLength := calcCLength(len(primary))
|
||||||
w.dFileSize += dRangeSize
|
w.dFileSize += dRangeSize
|
||||||
w.leafNodes = append(w.leafNodes, node{
|
w.leafNodes = append(w.leafNodes, node{
|
||||||
dRangeSize: dRangeSize,
|
dRangeSize: dRangeSize,
|
||||||
cOffset: cOffset | (cLength << 48),
|
cOffsetCLength: cOffset | (cLength << 48),
|
||||||
secondary: secondary,
|
secondary: secondary,
|
||||||
tertiary: tertiary,
|
tertiary: tertiary,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -402,9 +403,9 @@ func (w *Writer) Close() error {
|
|||||||
indexSize := rootNode.calcEncodedSize(0)
|
indexSize := rootNode.calcEncodedSize(0)
|
||||||
|
|
||||||
nw := &nodeWriter{
|
nw := &nodeWriter{
|
||||||
w: w.Writer,
|
w: w.Writer,
|
||||||
resourcesCOffsets: w.resourcesCOffsets,
|
resourcesCOffCLens: w.resourcesCOffCLens,
|
||||||
codec: w.Codec,
|
codec: w.Codec,
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.IndexLocation == IndexLocationAtEnd {
|
if w.IndexLocation == IndexLocationAtEnd {
|
||||||
@@ -475,15 +476,15 @@ type node struct {
|
|||||||
children []node // Excludes resource-node chidren.
|
children []node // Excludes resource-node chidren.
|
||||||
resources []int
|
resources []int
|
||||||
|
|
||||||
cOffset uint64
|
cOffsetCLength uint64
|
||||||
secondary OptResource
|
secondary OptResource
|
||||||
tertiary OptResource
|
tertiary OptResource
|
||||||
}
|
}
|
||||||
|
|
||||||
// calcEncodedSize accumulates the encoded size of n and its children,
|
// calcEncodedSize accumulates the encoded size of n and its children,
|
||||||
// traversing the nodes in depth-first order.
|
// traversing the nodes in depth-first order.
|
||||||
//
|
//
|
||||||
// As a side effect, it also sets n.cOffset for branch nodes.
|
// As a side effect, it also sets n.cOffsetCLength for branch nodes.
|
||||||
func (n *node) calcEncodedSize(accumulator uint64) (newAccumulator uint64) {
|
func (n *node) calcEncodedSize(accumulator uint64) (newAccumulator uint64) {
|
||||||
arity := len(n.children) + len(n.resources)
|
arity := len(n.children) + len(n.resources)
|
||||||
if arity == 0 {
|
if arity == 0 {
|
||||||
@@ -491,7 +492,7 @@ func (n *node) calcEncodedSize(accumulator uint64) (newAccumulator uint64) {
|
|||||||
}
|
}
|
||||||
size := (arity * 16) + 16
|
size := (arity * 16) + 16
|
||||||
cLength := calcCLength(size)
|
cLength := calcCLength(size)
|
||||||
n.cOffset = accumulator | (cLength << 48)
|
n.cOffsetCLength = accumulator | (cLength << 48)
|
||||||
accumulator += uint64(size)
|
accumulator += uint64(size)
|
||||||
for i := range n.children {
|
for i := range n.children {
|
||||||
accumulator = n.children[i].calcEncodedSize(accumulator)
|
accumulator = n.children[i].calcEncodedSize(accumulator)
|
||||||
@@ -502,10 +503,10 @@ func (n *node) calcEncodedSize(accumulator uint64) (newAccumulator uint64) {
|
|||||||
type nodeWriter struct {
|
type nodeWriter struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
|
|
||||||
cFileSize uint64
|
cFileSize uint64
|
||||||
dataCOffset uint64
|
dataCOffset uint64
|
||||||
indexCOffset uint64
|
indexCOffset uint64
|
||||||
resourcesCOffsets []uint64
|
resourcesCOffCLens []uint64
|
||||||
|
|
||||||
codec Codec
|
codec Codec
|
||||||
|
|
||||||
@@ -545,18 +546,18 @@ func (w *nodeWriter) writeIndex(n *node) error {
|
|||||||
// CPtr's. While the RAC format allows otherwise, this Writer always keeps
|
// CPtr's. While the RAC format allows otherwise, this Writer always keeps
|
||||||
// the CBias at zero, so that a CPtr equals a COffset.
|
// the CBias at zero, so that a CPtr equals a COffset.
|
||||||
for i, res := range n.resources {
|
for i, res := range n.resources {
|
||||||
cOffset := w.resourcesCOffsets[res] + w.dataCOffset
|
cOffsetCLength := w.resourcesCOffCLens[res] + w.dataCOffset
|
||||||
putU64LE(buf[8*i:], cOffset|tagFF)
|
putU64LE(buf[8*i:], cOffsetCLength|tagFF)
|
||||||
}
|
}
|
||||||
buf = buf[8*len(n.resources):]
|
buf = buf[8*len(n.resources):]
|
||||||
for i, o := range n.children {
|
for i, o := range n.children {
|
||||||
cOffset := o.cOffset
|
cOffsetCLength := o.cOffsetCLength
|
||||||
if len(o.children) == 0 {
|
if len(o.children) == 0 {
|
||||||
cOffset += w.dataCOffset
|
cOffsetCLength += w.dataCOffset
|
||||||
} else {
|
} else {
|
||||||
cOffset += w.indexCOffset
|
cOffsetCLength += w.indexCOffset
|
||||||
}
|
}
|
||||||
putU64LE(buf[8*i:], cOffset|resourceToTag(n.resources, o.secondary))
|
putU64LE(buf[8*i:], cOffsetCLength|resourceToTag(n.resources, o.secondary))
|
||||||
}
|
}
|
||||||
buf = buf[8*len(n.children):]
|
buf = buf[8*len(n.children):]
|
||||||
|
|
||||||
@@ -675,9 +676,9 @@ func makeBranch(children []node, resMap map[OptResource]bool) node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return node{
|
return node{
|
||||||
dRangeSize: dRangeSize,
|
dRangeSize: dRangeSize,
|
||||||
children: children,
|
children: children,
|
||||||
resources: resList,
|
resources: resList,
|
||||||
cOffset: invalidCOffset,
|
cOffsetCLength: invalidCOffsetCLength,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user