gfx/skia/trunk/src/gpu/GrTBSearch.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright 2010 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #ifndef GrTBSearch_DEFINED
     9 #define GrTBSearch_DEFINED
    11 #include "SkTypes.h"
    13 template <typename ELEM, typename KEY>
    14 int GrTBSearch(const ELEM array[], int count, KEY target) {
    15     SkASSERT(count >= 0);
    16     if (0 == count) {
    17         // we should insert it at 0
    18         return ~0;
    19     }
    21     int high = count - 1;
    22     int low = 0;
    23     while (high > low) {
    24         int index = (low + high) >> 1;
    25         if (LT(array[index], target)) {
    26             low = index + 1;
    27         } else {
    28             high = index;
    29         }
    30     }
    32     // check if we found it
    33     if (EQ(array[high], target)) {
    34         return high;
    35     }
    37     // now return the ~ of where we should insert it
    38     if (LT(array[high], target)) {
    39         high += 1;
    40     }
    41     return ~high;
    42 }
    44 #endif

mercurial