Logo Search packages:      
Sourcecode: icu version File versions  Download package

int32_t UnicodeSet::findCodePoint ( UChar32  c  )  const [private]

Returns the smallest value i such that c < list[i]. Caller must ensure that c is a legal value or this method will enter an infinite loop. This method performs a binary search.

Parameters:
c a character in the range MIN_VALUE..MAX_VALUE inclusive
Returns:
the smallest integer i in the range 0..len-1, inclusive, such that c < list[i]

Definition at line 430 of file uniset.cpp.

Referenced by add(), contains(), and containsNone().

                                                 {
    /* Examples:
                                       findCodePoint(c)
       set              list[]         c=0 1 3 4 7 8
       ===              ==============   ===========
       []               [110000]         0 0 0 0 0 0
       [\u0000-\u0003]  [0, 4, 110000]   1 1 1 2 2 2
       [\u0004-\u0007]  [4, 8, 110000]   0 0 0 1 1 2
       [:Any:]          [0, 110000]      1 1 1 1 1 1
     */

    // Return the smallest i such that c < list[i].  Assume
    // list[len - 1] == HIGH and that c is legal (0..HIGH-1).
    if (c < list[0])
        return 0;
    // High runner test.  c is often after the last range, so an
    // initial check for this condition pays off.
    int32_t lo = 0;
    int32_t hi = len - 1;
    if (lo >= hi || c >= list[hi-1])
        return hi;
    // invariant: c >= list[lo]
    // invariant: c < list[hi]
    for (;;) {
        int32_t i = (lo + hi) >> 1;
        if (i == lo) {
            break; // Found!
        } else if (c < list[i]) {
            hi = i;
        } else {
            lo = i;
        }
    }
    return hi;
}


Generated by  Doxygen 1.6.0   Back to index