Debian Codegraph @

internal/triegen/example_compact_test.go

raw symbols SCIP
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package triegen_testscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/
6
7 import (
8 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
9 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
10
11 "golang.org/x/text/internal/triegenscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/"
12 )
13
14 func ExampleCompacterscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/ExampleCompacter().() {
15 t := triegenscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/.NewTriescip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/NewTrie().("root")
16 for r := rune(0); r < 10000; r += 64 {
17 t.Insertscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/Trie#Insert().(r, 0x9015BADA55^uint64(r))
18 }
19 sz, _ := t.Genscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/Trie#Gen().(ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Discardscip-go gomod github.com/golang/go/src go1.25.0 io/Discard.)
20
21 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Printfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Printf().("Size normal: %5d\n", sz)
22
23 var c myCompacterscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#
24 sz, _ = t.Genscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/Trie#Gen().(ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Discardscip-go gomod github.com/golang/go/src go1.25.0 io/Discard., triegenscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/.Compactscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen`/Compact().(&c))
25
26 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Printfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Printf().("Size compacted: %5d\n", sz)
27
28 // Output:
29 // Size normal: 81344
30 // Size compacted: 3224
31 }
32
33 // A myCompacter accepts a block if only the first value is given.
34 type myCompacterscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter# []uint64
35
36 func (c *myCompacterscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#) Sizescip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#Size().(values []uint64) (sz int, ok bool) {
37 for _, v := range values[1:] {
38 if v != 0 {
39 return 0, false
40 }
41 }
42 return 8, true // the size of a uint64
43 }
44
45 func (c *myCompacterscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#) Storescip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#Store().(v []uint64) uint32 {
46 x := uint32(len(*c))
47 *c = append(*c, v[0])
48 return x
49 }
50
51 func (c *myCompacterscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#) Printscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#Print().(w ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Writerscip-go gomod github.com/golang/go/src go1.25.0 io/Writer#) error {
52 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintln().(w, "var firstValue = []uint64{")
53 for _, v := range *c {
54 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintf().(w, "\t%#x,\n", v)
55 }
56 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintln().(w, "}")
57 return nil
58 }
59
60 func (c *myCompacterscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#) Handlerscip-go gomod golang.org/x/text . `golang.org/x/text/internal/triegen_test`/myCompacter#Handler().() string {
61 return "getFirstValue"
62
63 // Where getFirstValue is included along with the generated code:
64 // func getFirstValue(n uint32, b byte) uint64 {
65 // if b == 0x80 { // the first continuation byte
66 // return firstValue[n]
67 // }
68 // return 0
69 // }
70 }