github.com/go-xe2/third@v1.0.3/golang.org/x/text/unicode/runenames/bits.go (about)

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