diff options
author | Corey Hulen <corey@hulen.com> | 2017-03-24 23:31:34 -0700 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-03-25 03:31:34 -0300 |
commit | 54d3d47daf9190275bbdaf8703b84969a4593451 (patch) | |
tree | 05899b296d0186c1a0da8a540bc486e34ad8eec9 /vendor/golang.org/x/text/internal/triegen/example_compact_test.go | |
parent | 7460302dec7796e01c98264e84bece8169cb6ed9 (diff) | |
download | chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.gz chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.bz2 chat-54d3d47daf9190275bbdaf8703b84969a4593451.zip |
PLT-6076 Adding viper libs for config file changes (#5871)
* Adding viper libs for config file changes
* Removing the old fsnotify lib
* updating some missing libs
Diffstat (limited to 'vendor/golang.org/x/text/internal/triegen/example_compact_test.go')
-rw-r--r-- | vendor/golang.org/x/text/internal/triegen/example_compact_test.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/golang.org/x/text/internal/triegen/example_compact_test.go b/vendor/golang.org/x/text/internal/triegen/example_compact_test.go new file mode 100644 index 000000000..7cf604ca4 --- /dev/null +++ b/vendor/golang.org/x/text/internal/triegen/example_compact_test.go @@ -0,0 +1,71 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package triegen_test + +import ( + "fmt" + "io" + "io/ioutil" + + "golang.org/x/text/internal/triegen" +) + +func ExampleCompacter() { + t := triegen.NewTrie("root") + for r := rune(0); r < 10000; r += 64 { + t.Insert(r, 0x9015BADA55^uint64(r)) + } + sz, _ := t.Gen(ioutil.Discard) + + fmt.Printf("Size normal: %5d\n", sz) + + var c myCompacter + sz, _ = t.Gen(ioutil.Discard, triegen.Compact(&c)) + + fmt.Printf("Size compacted: %5d\n", sz) + + // Output: + // Size normal: 81344 + // Size compacted: 3224 +} + +// A myCompacter accepts a block if only the first value is given. +type myCompacter []uint64 + +func (c *myCompacter) Size(values []uint64) (sz int, ok bool) { + for _, v := range values[1:] { + if v != 0 { + return 0, false + } + } + return 8, true // the size of a uint64 +} + +func (c *myCompacter) Store(v []uint64) uint32 { + x := uint32(len(*c)) + *c = append(*c, v[0]) + return x +} + +func (c *myCompacter) Print(w io.Writer) error { + fmt.Fprintln(w, "var firstValue = []uint64{") + for _, v := range *c { + fmt.Fprintf(w, "\t%#x,\n", v) + } + fmt.Fprintln(w, "}") + return nil +} + +func (c *myCompacter) Handler() string { + return "getFirstValue" + + // Where getFirstValue is included along with the generated code: + // func getFirstValue(n uint32, b byte) uint64 { + // if b == 0x80 { // the first continuation byte + // return firstValue[n] + // } + // return 0 + // } +} |