1 /* Three-level bitmap lookup.
2    Copyright (C) 2000-2002, 2005-2007, 2009-2018 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2000-2002.
4 
5    This program is free software: you can redistribute it and/or
6    modify it under the terms of either:
7 
8      * the GNU Lesser General Public License as published by the Free
9        Software Foundation; either version 3 of the License, or (at your
10        option) any later version.
11 
12    or
13 
14      * the GNU General Public License as published by the Free
15        Software Foundation; either version 2 of the License, or (at your
16        option) any later version.
17 
18    or both in parallel, as here.
19    This program is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Lesser General Public License for more details.
23 
24    You should have received a copy of the GNU Lesser General Public License
25    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
26 
27 static inline int bitmap_lookup (const void *table, ucs4_t uc);
28 
29 /* These values are currently hardcoded into gen-ctype.c.  */
30 #define header_0 16
31 #define header_2 9
32 #define header_3 127
33 #define header_4 15
34 
35 static inline int
bitmap_lookup(const void * table,ucs4_t uc)36 bitmap_lookup (const void *table, ucs4_t uc)
37 {
38   unsigned int index1 = uc >> header_0;
39   if (index1 < ((const int *) table)[0])
40     {
41       int lookup1 = ((const int *) table)[1 + index1];
42       if (lookup1 >= 0)
43         {
44           unsigned int index2 = (uc >> header_2) & header_3;
45           int lookup2 = ((const short *) table)[lookup1 + index2];
46           if (lookup2 >= 0)
47             {
48               unsigned int index3 = (uc >> 5) & header_4;
49               unsigned int lookup3 = ((const int *) table)[lookup2 + index3];
50 
51               return (lookup3 >> (uc & 0x1f)) & 1;
52             }
53         }
54     }
55   return 0;
56 }
57