1056N/A/*
1056N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1056N/A *
1056N/A * This code is free software; you can redistribute it and/or modify it
1056N/A * under the terms of the GNU General Public License version 2 only, as
1056N/A * published by the Free Software Foundation. Oracle designates this
1056N/A * particular file as subject to the "Classpath" exception as provided
1056N/A * by Oracle in the LICENSE file that accompanied this code.
1056N/A *
1056N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1056N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1056N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1056N/A * version 2 for more details (a copy is included in the LICENSE file that
1056N/A * accompanied this code).
1056N/A *
1056N/A * You should have received a copy of the GNU General Public License version
1056N/A * 2 along with this work; if not, write to the Free Software Foundation,
1056N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1056N/A *
1056N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1056N/A * or visit www.oracle.com if you need additional information or have any
1056N/A * questions.
1056N/A *
1056N/A */
1056N/A
1056N/A/*
1056N/A *
1056N/A * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
1056N/A *
1056N/A */
1056N/A
1056N/A#include "LETypes.h"
1056N/A#include "LayoutTables.h"
1056N/A#include "LookupTables.h"
1056N/A#include "LESwaps.h"
1056N/A
1056N/AU_NAMESPACE_BEGIN
1056N/A
1056N/A/*
1056N/A These are the rolled-up versions of the uniform binary search.
1056N/A Someday, if we need more performance, we can un-roll them.
1056N/A
1056N/A Note: I put these in the base class, so they only have to
1056N/A be written once. Since the base class doesn't define the
1056N/A segment table, these routines assume that it's right after
1056N/A the binary search header.
1056N/A
1056N/A Another way to do this is to put each of these routines in one
1056N/A of the derived classes, and implement it in the others by casting
1056N/A the "this" pointer to the type that has the implementation.
1056N/A*/
1056N/Aconst LookupSegment *BinarySearchLookupTable::lookupSegment(const LETableReference &base, const LookupSegment *segments, LEGlyphID glyph, LEErrorCode &success) const
1056N/A{
1056N/A
1056N/A le_int16 unity = SWAPW(unitSize);
1056N/A le_int16 probe = SWAPW(searchRange);
1056N/A le_int16 extra = SWAPW(rangeShift);
1056N/A TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph);
1056N/A LEReferenceTo<LookupSegment> entry(base, success, segments);
1056N/A LEReferenceTo<LookupSegment> trial(entry, success, extra);
1056N/A
1056N/A if(LE_FAILURE(success)) return NULL;
1056N/A
1056N/A if (SWAPW(trial->lastGlyph) <= ttGlyph) {
1056N/A entry = trial;
1056N/A }
1056N/A
1056N/A while (probe > unity && LE_SUCCESS(success)) {
1056N/A probe >>= 1;
1056N/A trial = entry; // copy
1056N/A trial.addOffset(probe, success);
1056N/A
1056N/A if (SWAPW(trial->lastGlyph) <= ttGlyph) {
1056N/A entry = trial;
1056N/A }
1056N/A }
1056N/A
1056N/A if (SWAPW(entry->firstGlyph) <= ttGlyph) {
1056N/A return entry.getAlias();
1056N/A }
1056N/A
1056N/A return NULL;
1056N/A}
1056N/A
1056N/Aconst LookupSingle *BinarySearchLookupTable::lookupSingle(const LETableReference &base, const LookupSingle *entries, LEGlyphID glyph, LEErrorCode &success) const
1056N/A{
1056N/A le_int16 unity = SWAPW(unitSize);
1056N/A le_int16 probe = SWAPW(searchRange);
1056N/A le_int16 extra = SWAPW(rangeShift);
1056N/A TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph);
1056N/A LEReferenceTo<LookupSingle> entry(base, success, entries);
1056N/A LEReferenceTo<LookupSingle> trial(entry, success, extra);
1056N/A
1056N/A if (SWAPW(trial->glyph) <= ttGlyph) {
1056N/A entry = trial;
1056N/A }
1056N/A
1056N/A while (probe > unity && LE_SUCCESS(success)) {
1056N/A probe >>= 1;
1056N/A trial = entry;
1056N/A trial.addOffset(probe, success);
1056N/A
1056N/A if (SWAPW(trial->glyph) <= ttGlyph) {
1056N/A entry = trial;
1056N/A }
1056N/A }
1056N/A
1056N/A if (SWAPW(entry->glyph) == ttGlyph) {
1056N/A return entry.getAlias();
1056N/A }
1056N/A
1056N/A return NULL;
1056N/A}
1056N/A
1056N/AU_NAMESPACE_END
1056N/A