Skip to content

Commit

Permalink
Replace magic numbers with constants
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Oct 2, 2023
1 parent 63ea7a7 commit 53a716f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 22 additions & 2 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,34 @@ const (
// 32 is faster than 24 and 40.
linearScanThreshold = 32

// inlined tag number size: CBOR tag number CBORTagInlinedArray or CBORTagInlinedMap
inlinedTagNumSize = 2

// inlined CBOR array head size: CBOR array head of 3 elements (extra data index, value id, elements)
inlinedCBORArrayHeadSize = 1

// inlined extra data index size: CBOR positive number encoded in 2 bytes [0, 255] (fixed-size for easy computation)
inlinedExtraDataIndexSize = 2

// inlined CBOR byte string head size for value ID: CBOR byte string head for byte string of 8 bytes
inlinedCBORValueIDHeadSize = 1

// inlined value id size: encoded in 8 bytes
inlinedValueIDSize = 8

// inlined array data slab prefix size:
// tag number (2 bytes) +
// 3-element array head (1 byte) +
// extra data ref index (2 bytes) [0, 255] +
// extra data index (2 bytes) [0, 255] +
// value ID index head (1 byte) +
// value ID index (8 bytes) +
// element array head (3 bytes)
inlinedArrayDataSlabPrefixSize = 2 + 1 + 2 + 1 + 8 + arrayDataSlabElementHeadSize
inlinedArrayDataSlabPrefixSize = inlinedTagNumSize +
inlinedCBORArrayHeadSize +
inlinedExtraDataIndexSize +
inlinedCBORValueIDHeadSize +
inlinedValueIDSize +
arrayDataSlabElementHeadSize
)

type ArraySlabHeader struct {
Expand Down
6 changes: 5 additions & 1 deletion map.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ const (
// extra data ref index (2 bytes) [0, 255] +
// value index head (1 byte) +
// value index (8 bytes)
inlinedMapDataSlabPrefixSize = 2 + 1 + 2 + 1 + 8
inlinedMapDataSlabPrefixSize = inlinedTagNumSize +
inlinedCBORArrayHeadSize +
inlinedExtraDataIndexSize +
inlinedCBORValueIDHeadSize +
inlinedValueIDSize
)

// MaxCollisionLimitPerDigest is the noncryptographic hash collision limit
Expand Down

0 comments on commit 53a716f

Please sign in to comment.