@@ -37,10 +37,14 @@ import (
37
37
)
38
38
39
39
const (
40
- // These sum of these four values must be no greater than 32.
40
+ // This must be a multiple of 8 and no greater than 64.
41
+ // Update nodeValue in list.go if this changes.
42
+ nodesBits = 40
43
+
44
+ // These sum of these four values must be no greater than nodesBits.
41
45
nodesBitsChildren = 10
42
46
nodesBitsICANN = 1
43
- nodesBitsTextOffset = 15
47
+ nodesBitsTextOffset = 16
44
48
nodesBitsTextLength = 6
45
49
46
50
// These sum of these four values must be no greater than 32.
@@ -97,7 +101,7 @@ const (
97
101
)
98
102
99
103
var (
100
- labelEncoding = map [string ]uint32 {}
104
+ labelEncoding = map [string ]uint64 {}
101
105
labelsList = []string {}
102
106
labelsMap = map [string ]bool {}
103
107
rules = []string {}
@@ -127,7 +131,13 @@ func main() {
127
131
128
132
func main1 () error {
129
133
flag .Parse ()
130
- if nodesBitsTextLength + nodesBitsTextOffset + nodesBitsICANN + nodesBitsChildren > 32 {
134
+ if nodesBits > 64 {
135
+ return fmt .Errorf ("nodesBits is too large" )
136
+ }
137
+ if nodesBits % 8 != 0 {
138
+ return fmt .Errorf ("nodesBits must be a multiple of 8" )
139
+ }
140
+ if nodesBitsTextLength + nodesBitsTextOffset + nodesBitsICANN + nodesBitsChildren > nodesBits {
131
141
return fmt .Errorf ("not enough bits to encode the nodes table" )
132
142
}
133
143
if childrenBitsLo + childrenBitsHi + childrenBitsNodeType + childrenBitsWildcard > 32 {
@@ -312,6 +322,7 @@ package publicsuffix
312
322
const version = %q
313
323
314
324
const (
325
+ nodesBits = %d
315
326
nodesBitsChildren = %d
316
327
nodesBitsICANN = %d
317
328
nodesBitsTextOffset = %d
@@ -334,6 +345,7 @@ const numTLD = %d
334
345
335
346
`
336
347
fmt .Fprintf (w , header , * version ,
348
+ nodesBits ,
337
349
nodesBitsChildren , nodesBitsICANN , nodesBitsTextOffset , nodesBitsTextLength ,
338
350
childrenBitsWildcard , childrenBitsNodeType , childrenBitsHi , childrenBitsLo ,
339
351
nodeTypeNormal , nodeTypeException , nodeTypeParentOnly , len (n .children ))
@@ -354,7 +366,7 @@ const numTLD = %d
354
366
if length >= 1 << nodesBitsTextLength {
355
367
return fmt .Errorf ("text length %d is too large, or nodeBitsTextLength is too small" , length )
356
368
}
357
- labelEncoding [label ] = uint32 (offset )<< nodesBitsTextLength | uint32 (length )
369
+ labelEncoding [label ] = uint64 (offset )<< nodesBitsTextLength | uint64 (length )
358
370
}
359
371
fmt .Fprintf (w , "// Text is the combined text of all labels.\n const text = " )
360
372
for len (text ) > 0 {
@@ -372,9 +384,9 @@ const numTLD = %d
372
384
373
385
fmt .Fprintf (w , `
374
386
375
- // nodes is the list of nodes. Each node is represented as a uint32, which
376
- // encodes the node's children, wildcard bit and node type (as an index into
377
- // the children array), ICANN bit and text.
387
+ // nodes is the list of nodes. Each node is represented as a %v-bit integer,
388
+ // which encodes the node's children, wildcard bit and node type (as an index
389
+ // into the children array), ICANN bit and text.
378
390
//
379
391
// If the table was generated with the -comments flag, there is a //-comment
380
392
// after each node's data. In it is the nodes-array indexes of the children,
@@ -383,15 +395,16 @@ const numTLD = %d
383
395
// nodes that have children but don't match a domain label in their own right.
384
396
// An I denotes an ICANN domain.
385
397
//
386
- // The layout within the uint32 , from MSB to LSB, is:
398
+ // The layout within the node , from MSB to LSB, is:
387
399
// [%2d bits] unused
388
400
// [%2d bits] children index
389
401
// [%2d bits] ICANN bit
390
402
// [%2d bits] text index
391
403
// [%2d bits] text length
392
- var nodes = [...]uint32 {
404
+ var nodes = [...]uint8 {
393
405
` ,
394
- 32 - nodesBitsChildren - nodesBitsICANN - nodesBitsTextOffset - nodesBitsTextLength ,
406
+ nodesBits ,
407
+ nodesBits - nodesBitsChildren - nodesBitsICANN - nodesBitsTextOffset - nodesBitsTextLength ,
395
408
nodesBitsChildren , nodesBitsICANN , nodesBitsTextOffset , nodesBitsTextLength )
396
409
if err := n .walk (w , printNode ); err != nil {
397
410
return err
@@ -558,14 +571,17 @@ func printNode(w io.Writer, n *node) error {
558
571
if c .icann {
559
572
encoding |= 1 << (nodesBitsTextLength + nodesBitsTextOffset )
560
573
}
561
- encoding |= uint32 (c .childrenIndex ) << (nodesBitsTextLength + nodesBitsTextOffset + nodesBitsICANN )
574
+ encoding |= uint64 (c .childrenIndex ) << (nodesBitsTextLength + nodesBitsTextOffset + nodesBitsICANN )
575
+ for i := nodesBits - 8 ; i >= 0 ; i -= 8 {
576
+ fmt .Fprintf (w , "0x%02x, " , (encoding >> i )& 0xff )
577
+ }
562
578
if * comments {
563
- fmt .Fprintf (w , "0x%08x, // n0x%04x c0x%04x (%s)%s %s %s %s\n " ,
564
- encoding , c .nodesIndex , c .childrenIndex , s , wildcardStr (c .wildcard ),
579
+ fmt .Fprintf (w , "// n0x%04x c0x%04x (%s)%s %s %s %s\n " ,
580
+ c .nodesIndex , c .childrenIndex , s , wildcardStr (c .wildcard ),
565
581
nodeTypeStr (c .nodeType ), icannStr (c .icann ), c .label ,
566
582
)
567
583
} else {
568
- fmt .Fprintf (w , "0x%x, \n " , encoding )
584
+ fmt .Fprintf (w , "\n " )
569
585
}
570
586
}
571
587
return nil
0 commit comments