private function find_string($string, $start = -1, $end = -1) {
        if (($start == -1) or ($end == -1)) {
            // find_string is called with only one parameter, set start end end
            $start = 0;
            $end = $this->total;
        }
        if (abs($start - $end) <= 1) {
            // We're done, now we either found the string, or it doesn't exist
            $txt = $this->get_original_string($start);
            if ($string == $txt)
                return $start;
            else
                return -1;
        }
        else if ($start > $end) {
            // start > end -> turn around and start over
            return $this->find_string($string, $end, $start);
        }
        else {
            // Divide table in two parts
            $half = (int)(($start + $end) / 2);
            $cmp = strcmp($string, $this->get_original_string($half));
            if ($cmp == 0)
                // string is exactly in the middle => return it
                return $half;
            else if ($cmp < 0)
                // The string is in the upper half
                return $this->find_string($string, $start, $half);
            else
                // The string is in the lower half
                return $this->find_string($string, $half, $end);
        }
    }
private function find_string($string, $start = -1, $end = -1) {
        if (($start == -1) or ($end == -1)) {
            // find_string is called with only one parameter, set start end end
            $start = 0;
            $end = $this->total;
        }
        if (abs($start - $end) <= 1) {
            // We're done, now we either found the string, or it doesn't exist
            $txt = $this->get_original_string($start);
            if ($string == $txt)
                return $start;
            else
                return -1;
        }
        else if ($start > $end) {
            // start > end -> turn around and start over
            return $this->find_string($string, $end, $start);
        }
        else {
            // Divide table in two parts
            $half = (int)(($start + $end) / 2);
            $cmp = strcmp($string, $this->get_original_string($half));
            if ($cmp == 0)
                // string is exactly in the middle => return it
                return $half;
            else if ($cmp < 0)
                // The string is in the upper half
                return $this->find_string($string, $start, $half);
            else
                // The string is in the lower half
                return $this->find_string($string, $half, $end);
        }
    }
private function find_string ( $ string , $ start = - 1 , $ end = - 1 ) { if ( ( $ start == - 1 ) or ( $ end == - 1 ) ) { // find_string is called with only one parameter, set start end end $ start = 0 ; $ end = $ this -> total ; } if ( abs ( $ start - $ end ) <= 1 ) { // We're done, now we either found the string, or it doesn't exist $ txt = $ this -> get_original_string ( $ start ) ; if ( $ string == $ txt ) return $ start ; else return - 1 ; } else if ( $ start > $ end ) { // start > end -> turn around and start over return $ this -> find_string ( $ string , $ end , $ start ) ; } else { // Divide table in two parts $ half = ( int ) ( ( $ start + $ end ) / 2 ) ; $ cmp = strcmp ( $ string , $ this -> get_original_string ( $ half ) ) ; if ( $ cmp == 0 ) // string is exactly in the middle => return it return $ half ; else if ( $ cmp < 0 ) // The string is in the upper half return $ this -> find_string ( $ string , $ start , $ half ) ; else // The string is in the lower half return $ this -> find_string ( $ string , $ half , $ end ) ; } }
Binary search for string

@access private
@param string string
@param int start (internally used in recursive function)
@param int end (internally used in recursive function)
@return int string number (offset in originals table)
Binary search for string