libgo: update to go1.9
[official-gcc.git] / libgo / go / golang_org / x / text / unicode / norm / trie.go
blob4cbea644a1d99c6106c1d50487e01025339e9418
1 // Code generated by running "go run gen.go -core" in golang.org/x/text. DO NOT EDIT.
3 // Copyright 2011 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 package norm
9 type valueRange struct {
10 value uint16 // header: value:stride
11 lo, hi byte // header: lo:n
14 type sparseBlocks struct {
15 values []valueRange
16 offset []uint16
19 var nfcSparse = sparseBlocks{
20 values: nfcSparseValues[:],
21 offset: nfcSparseOffset[:],
24 var nfkcSparse = sparseBlocks{
25 values: nfkcSparseValues[:],
26 offset: nfkcSparseOffset[:],
29 var (
30 nfcData = newNfcTrie(0)
31 nfkcData = newNfkcTrie(0)
34 // lookupValue determines the type of block n and looks up the value for b.
35 // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block
36 // is a list of ranges with an accompanying value. Given a matching range r,
37 // the value for b is by r.value + (b - r.lo) * stride.
38 func (t *sparseBlocks) lookup(n uint32, b byte) uint16 {
39 offset := t.offset[n]
40 header := t.values[offset]
41 lo := offset + 1
42 hi := lo + uint16(header.lo)
43 for lo < hi {
44 m := lo + (hi-lo)/2
45 r := t.values[m]
46 if r.lo <= b && b <= r.hi {
47 return r.value + uint16(b-r.lo)*header.value
49 if b < r.lo {
50 hi = m
51 } else {
52 lo = m + 1
55 return 0