Index Page lstlti_c

A B C D E F G H I J K L M N O P Q R S T U V W X

Procedure Abstract Required_Reading Keywords Brief_I/O Detailed_Input | Detailed_Output Parameters Exceptions Files Particulars Examples | Restrictions Literature_References Author_and_Institution Version Index_Entries

#### Procedure

       SpiceInt lstlti_c ( SpiceInt          x,
                           SpiceInt          n,
                           ConstSpiceInt   * array )

#### Abstract

       Given a number x and an array of non-decreasing numbers,
       find the index of the largest array element less than x.

#### Required_Reading

       None.

#### Keywords

       SEARCH,  ARRAY

#### Brief_I/O

       VARIABLE  I/O  DESCRIPTION
       --------  ---  --------------------------------------------------
       x          I   Value to search against.
       n          I   Number of elements in array.
       array      I   Array of possible lower bounds.

       The function returns the index of the last element of array that is
       less than x.

#### Detailed_Input

       x              is an integer serving as a key value.

       n              is the total number of elements in array.

       array          is an array of integers that forms a  non-decreasing
                      sequence.

#### Detailed_Output

       The function returns the index of the last element of the non-decreasing
       sequence

          {array[i] : 0 <=  i < n }

       that is less than x.  Indices range from zero to n-1.

       If all elements of array are greater than or equal to x, this routine
       returns the value -1.

#### Parameters

       None.

#### Exceptions

       Error free.

       If n is less than or equal to zero, the function returns -1.  This case
       is not treated as an error.

#### Files

       None.

#### Particulars

       This routine uses a binary search algorithm and so requires
       at most on the order of

          log (n)
             2

       steps to compute the value of lstlti_c.

       Note:  If you need to find the first element of the array that is greater
              than or equal to x, simply add 1 to the result returned by this
              function and check to see if the result is within the array bounds
              given by n.

#### Examples

       1)  Let array be assigned the following values:

              array[0] = -2;
              array[1] = -2;
              array[2] =  0;
              array[3] =  1;
              array[4] =  1;
              array[5] = 11;

           The table below demonstrates the behavior of lstlti_c:

                        Call                       Returned Value
              =========================            ==============
              lstlti_c ( -3, 6, array )                -1

              lstlti_c ( -2, 6, array )                -1

              lstlti_c (  0, 6, array )                 1

              lstlti_c (  1, 6, array )                 2

              lstlti_c ( 12, 6, array )                 5

#### Restrictions

       If the sequence in the input argument array is not non-decreasing,
       the results of this routine are undefined.

#### Literature_References

       None.

#### Author_and_Institution

       N.J. Bachman    (JPL)
       H.A. Neilan     (JPL)
       W.L. Taber      (JPL)

#### Version

       -CSPICE Version 1.0.0, 09-JUL-2002 (NJB) (HAN) (WLT)

#### Index_Entries

       last integer element less_than_or_equal_to

#### Link to routine lstlti_c source file lstlti_c.c

    Wed Apr  5 17:54:38 2017