Back to index

glibc  2.9
coll-lookup.c
Go to the documentation of this file.
00001 /* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stdint.h>
00021 
00022 /* Lookup in a table of int32_t, with default value 0.  */
00023 int32_t
00024 internal_function
00025 __collidx_table_lookup (const char *table, uint32_t wc)
00026 {
00027   uint32_t shift1 = ((const uint32_t *) table)[0];
00028   uint32_t index1 = wc >> shift1;
00029   uint32_t bound = ((const uint32_t *) table)[1];
00030   if (index1 < bound)
00031     {
00032       uint32_t lookup1 = ((const uint32_t *) table)[5 + index1];
00033       if (lookup1 != 0)
00034        {
00035          uint32_t shift2 = ((const uint32_t *) table)[2];
00036          uint32_t mask2 = ((const uint32_t *) table)[3];
00037          uint32_t index2 = (wc >> shift2) & mask2;
00038          uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2];
00039          if (lookup2 != 0)
00040            {
00041              uint32_t mask3 = ((const uint32_t *) table)[4];
00042              uint32_t index3 = wc & mask3;
00043              int32_t lookup3 = ((const int32_t *)(table + lookup2))[index3];
00044 
00045              return lookup3;
00046            }
00047        }
00048     }
00049   return 0;
00050 }
00051 
00052 
00053 /* Lookup in a table of uint32_t, with default value 0xffffffff.  */
00054 uint32_t
00055 internal_function
00056 __collseq_table_lookup (const char *table, uint32_t wc)
00057 {
00058   uint32_t shift1 = ((const uint32_t *) table)[0];
00059   uint32_t index1 = wc >> shift1;
00060   uint32_t bound = ((const uint32_t *) table)[1];
00061   if (index1 < bound)
00062     {
00063       uint32_t lookup1 = ((const uint32_t *) table)[5 + index1];
00064       if (lookup1 != 0)
00065        {
00066          uint32_t shift2 = ((const uint32_t *) table)[2];
00067          uint32_t mask2 = ((const uint32_t *) table)[3];
00068          uint32_t index2 = (wc >> shift2) & mask2;
00069          uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2];
00070          if (lookup2 != 0)
00071            {
00072              uint32_t mask3 = ((const uint32_t *) table)[4];
00073              uint32_t index3 = wc & mask3;
00074              uint32_t lookup3 = ((const uint32_t *)(table + lookup2))[index3];
00075 
00076              return lookup3;
00077            }
00078        }
00079     }
00080   return ~((uint32_t) 0);
00081 }