1 // Copyright 2016 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.
9 // This file contains code common to gen.go and the package code.
11 // The mapping from rune to string (i.e. offset and length in the data string)
12 // is encoded as a two level table. The first level maps from contiguous rune
13 // ranges [runeOffset, runeOffset+runeLength) to entries. Entries are either
14 // direct (for repeated names such as "<CJK Ideograph>") or indirect (for runs
15 // of unique names such as "SPACE", "EXCLAMATION MARK", "QUOTATION MARK", ...).
17 // Each first level table element is 64 bits. The runeOffset (21 bits) and
18 // runeLength (16 bits) take the 37 high bits. The entry takes the 27 low bits,
19 // with directness encoded in the least significant bit.
21 // A direct entry encodes a dataOffset (18 bits) and dataLength (8 bits) in the
22 // data string. 18 bits is too short to encode the entire data string's length,
23 // but the data string's contents are arranged so that all of the few direct
24 // entries' offsets come before all of the many indirect entries' offsets.
26 // An indirect entry encodes a dataBase (10 bits) and a table1Offset (16 bits).
27 // The table1Offset is the start of a range in the second level table. The
28 // length of that range is the same as the runeLength.
30 // Each second level table element is 16 bits, an index into data, relative to
31 // a bias equal to (dataBase << dataBaseUnit). That (bias + index) is the
32 // (dataOffset + dataLength) in the data string. The dataOffset is implied by
33 // the previous table element (with the same implicit bias).
45 shiftRuneOffset = 0 + bitsDirect + bitsDataLength + bitsDataOffset + bitsRuneLength
46 shiftRuneLength = 0 + bitsDirect + bitsDataLength + bitsDataOffset
47 shiftDataOffset = 0 + bitsDirect + bitsDataLength
48 shiftDataLength = 0 + bitsDirect
51 shiftDataBase = 0 + bitsDirect + bitsTable1Offset
52 shiftTable1Offset = 0 + bitsDirect
54 maskRuneLength = 1<<bitsRuneLength - 1
55 maskDataOffset = 1<<bitsDataOffset - 1
56 maskDataLength = 1<<bitsDataLength - 1
57 maskDirect = 1<<bitsDirect - 1
59 maskDataBase = 1<<bitsDataBase - 1
60 maskTable1Offset = 1<<bitsTable1Offset - 1