Home | History | Annotate | Download | only in ngram
      1 
      2 // Licensed under the Apache License, Version 2.0 (the "License");
      3 // you may not use this file except in compliance with the License.
      4 // You may obtain a copy of the License at
      5 //
      6 //     http://www.apache.org/licenses/LICENSE-2.0
      7 //
      8 // Unless required by applicable law or agreed to in writing, software
      9 // distributed under the License is distributed on an "AS IS" BASIS,
     10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11 // See the License for the specific language governing permissions and
     12 // limitations under the License.
     13 //
     14 // Copyright 2005-2010 Google, Inc.
     15 // Author: sorenj (at) google.com (Jeffrey Sorensen
     16 
     17 #include <fst/extensions/ngram/nthbit.h>
     18 
     19 //
     20 // This table is generate using:
     21 //
     22 //  unsigned int nth_bit_scan(uint64 v, unsigned int r) {
     23 //    int i=0;
     24 //    for (; i<64; i++) {
     25 //      if ((r -= v & 1) == 0) return i;
     26 //      v >>= 1;
     27 //    }
     28 //    return i;
     29 //  }
     30 //
     31 //  for (size_t i = 0; i < 256; ++i) {
     32 //    uint32 offsets = 0;
     33 //    for (size_t b = 1; b <= 8; ++b) {
     34 //      uint32 offset = min<uint32>(nth_bit_scan(i, b), 8);
     35 //      offsets |= (offset << ((b - 1) << 2));
     36 //    }
     37 //    bit_offset = offsets;
     38 //    printf("0x%x, ", bit_offset);
     39 //    if (i % 4 == 3) printf("\n");
     40 //  }
     41 //
     42 uint32 nth_bit_bit_offset[] = {
     43 0x88888888, 0x88888880, 0x88888881, 0x88888810,
     44 0x88888882, 0x88888820, 0x88888821, 0x88888210,
     45 0x88888883, 0x88888830, 0x88888831, 0x88888310,
     46 0x88888832, 0x88888320, 0x88888321, 0x88883210,
     47 0x88888884, 0x88888840, 0x88888841, 0x88888410,
     48 0x88888842, 0x88888420, 0x88888421, 0x88884210,
     49 0x88888843, 0x88888430, 0x88888431, 0x88884310,
     50 0x88888432, 0x88884320, 0x88884321, 0x88843210,
     51 0x88888885, 0x88888850, 0x88888851, 0x88888510,
     52 0x88888852, 0x88888520, 0x88888521, 0x88885210,
     53 0x88888853, 0x88888530, 0x88888531, 0x88885310,
     54 0x88888532, 0x88885320, 0x88885321, 0x88853210,
     55 0x88888854, 0x88888540, 0x88888541, 0x88885410,
     56 0x88888542, 0x88885420, 0x88885421, 0x88854210,
     57 0x88888543, 0x88885430, 0x88885431, 0x88854310,
     58 0x88885432, 0x88854320, 0x88854321, 0x88543210,
     59 0x88888886, 0x88888860, 0x88888861, 0x88888610,
     60 0x88888862, 0x88888620, 0x88888621, 0x88886210,
     61 0x88888863, 0x88888630, 0x88888631, 0x88886310,
     62 0x88888632, 0x88886320, 0x88886321, 0x88863210,
     63 0x88888864, 0x88888640, 0x88888641, 0x88886410,
     64 0x88888642, 0x88886420, 0x88886421, 0x88864210,
     65 0x88888643, 0x88886430, 0x88886431, 0x88864310,
     66 0x88886432, 0x88864320, 0x88864321, 0x88643210,
     67 0x88888865, 0x88888650, 0x88888651, 0x88886510,
     68 0x88888652, 0x88886520, 0x88886521, 0x88865210,
     69 0x88888653, 0x88886530, 0x88886531, 0x88865310,
     70 0x88886532, 0x88865320, 0x88865321, 0x88653210,
     71 0x88888654, 0x88886540, 0x88886541, 0x88865410,
     72 0x88886542, 0x88865420, 0x88865421, 0x88654210,
     73 0x88886543, 0x88865430, 0x88865431, 0x88654310,
     74 0x88865432, 0x88654320, 0x88654321, 0x86543210,
     75 0x88888887, 0x88888870, 0x88888871, 0x88888710,
     76 0x88888872, 0x88888720, 0x88888721, 0x88887210,
     77 0x88888873, 0x88888730, 0x88888731, 0x88887310,
     78 0x88888732, 0x88887320, 0x88887321, 0x88873210,
     79 0x88888874, 0x88888740, 0x88888741, 0x88887410,
     80 0x88888742, 0x88887420, 0x88887421, 0x88874210,
     81 0x88888743, 0x88887430, 0x88887431, 0x88874310,
     82 0x88887432, 0x88874320, 0x88874321, 0x88743210,
     83 0x88888875, 0x88888750, 0x88888751, 0x88887510,
     84 0x88888752, 0x88887520, 0x88887521, 0x88875210,
     85 0x88888753, 0x88887530, 0x88887531, 0x88875310,
     86 0x88887532, 0x88875320, 0x88875321, 0x88753210,
     87 0x88888754, 0x88887540, 0x88887541, 0x88875410,
     88 0x88887542, 0x88875420, 0x88875421, 0x88754210,
     89 0x88887543, 0x88875430, 0x88875431, 0x88754310,
     90 0x88875432, 0x88754320, 0x88754321, 0x87543210,
     91 0x88888876, 0x88888760, 0x88888761, 0x88887610,
     92 0x88888762, 0x88887620, 0x88887621, 0x88876210,
     93 0x88888763, 0x88887630, 0x88887631, 0x88876310,
     94 0x88887632, 0x88876320, 0x88876321, 0x88763210,
     95 0x88888764, 0x88887640, 0x88887641, 0x88876410,
     96 0x88887642, 0x88876420, 0x88876421, 0x88764210,
     97 0x88887643, 0x88876430, 0x88876431, 0x88764310,
     98 0x88876432, 0x88764320, 0x88764321, 0x87643210,
     99 0x88888765, 0x88887650, 0x88887651, 0x88876510,
    100 0x88887652, 0x88876520, 0x88876521, 0x88765210,
    101 0x88887653, 0x88876530, 0x88876531, 0x88765310,
    102 0x88876532, 0x88765320, 0x88765321, 0x87653210,
    103 0x88887654, 0x88876540, 0x88876541, 0x88765410,
    104 0x88876542, 0x88765420, 0x88765421, 0x87654210,
    105 0x88876543, 0x88765430, 0x88765431, 0x87654310,
    106 0x88765432, 0x87654320, 0x87654321, 0x76543210,
    107 };
    108