sl@0: /* sl@0: * sl@0: * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved sl@0: * sl@0: */ sl@0: sl@0: #include "LETypes.h" sl@0: #include "LayoutTables.h" sl@0: #include "LookupTables.h" sl@0: #include "LESwaps.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: /* sl@0: These are the rolled-up versions of the uniform binary search. sl@0: Someday, if we need more performance, we can un-roll them. sl@0: sl@0: Note: I put these in the base class, so they only have to sl@0: be written once. Since the base class doesn't define the sl@0: segment table, these routines assume that it's right after sl@0: the binary search header. sl@0: sl@0: Another way to do this is to put each of these routines in one sl@0: of the derived classes, and implement it in the others by casting sl@0: the "this" pointer to the type that has the implementation. sl@0: */ sl@0: const LookupSegment *BinarySearchLookupTable::lookupSegment(const LookupSegment *segments, LEGlyphID glyph) const sl@0: { sl@0: le_int16 unity = SWAPW(unitSize); sl@0: le_int16 probe = SWAPW(searchRange); sl@0: le_int16 extra = SWAPW(rangeShift); sl@0: TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph); sl@0: const LookupSegment *entry = segments; sl@0: const LookupSegment *trial = (const LookupSegment *) ((char *) entry + extra); sl@0: sl@0: if (SWAPW(trial->lastGlyph) <= ttGlyph) { sl@0: entry = trial; sl@0: } sl@0: sl@0: while (probe > unity) { sl@0: probe >>= 1; sl@0: trial = (const LookupSegment *) ((char *) entry + probe); sl@0: sl@0: if (SWAPW(trial->lastGlyph) <= ttGlyph) { sl@0: entry = trial; sl@0: } sl@0: } sl@0: sl@0: if (SWAPW(entry->firstGlyph) <= ttGlyph) { sl@0: return entry; sl@0: } sl@0: sl@0: return NULL; sl@0: } sl@0: sl@0: const LookupSingle *BinarySearchLookupTable::lookupSingle(const LookupSingle *entries, LEGlyphID glyph) const sl@0: { sl@0: le_int16 unity = SWAPW(unitSize); sl@0: le_int16 probe = SWAPW(searchRange); sl@0: le_int16 extra = SWAPW(rangeShift); sl@0: TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph); sl@0: const LookupSingle *entry = entries; sl@0: const LookupSingle *trial = (const LookupSingle *) ((char *) entry + extra); sl@0: sl@0: if (SWAPW(trial->glyph) <= ttGlyph) { sl@0: entry = trial; sl@0: } sl@0: sl@0: while (probe > unity) { sl@0: probe >>= 1; sl@0: trial = (const LookupSingle *) ((char *) entry + probe); sl@0: sl@0: if (SWAPW(trial->glyph) <= ttGlyph) { sl@0: entry = trial; sl@0: } sl@0: } sl@0: sl@0: if (SWAPW(entry->glyph) == ttGlyph) { sl@0: return entry; sl@0: } sl@0: sl@0: return NULL; sl@0: } sl@0: sl@0: U_NAMESPACE_END