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

Table of contents
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

   insrti_c ( Insert an item into an integer set ) 

   void insrti_c ( SpiceInt        item,
                   SpiceCell     * a    )

Abstract

   Insert an item into an integer set.

Required_Reading

   SETS

Keywords

   CELLS
   SETS


Brief_I/O

   VARIABLE  I/O  DESCRIPTION
   --------  ---  --------------------------------------------------
   item       I   Item to be inserted.
   a         I-O  Insertion set.

Detailed_Input

   item        is an item which is to be inserted into the specified
               set. `item' may or may not already be an element of the
               set.

   a           is a SPICE set.

               On input, `a' may or may not contain the input item as an
               element.

               `a' must be declared as an integer SpiceCell.

               CSPICE provides the following macro, which declares and
               initializes the cell

                  SPICEINT_CELL           ( a, ASZ );

               where ASZ is the maximum capacity of `a'.

Detailed_Output

   a           on output, contains the union of the input set and the
               singleton set containing the input item, unless there was
               not sufficient room in the set for the item to be
               included, in which case the set is not changed and an
               error is returned.

Parameters

   None.

Exceptions

   1)  If the insertion of the element into the set causes an excess
       of elements, the error SPICE(SETEXCESS) is signaled.

   2)  If the `a' cell argument has a type other than SpiceInt, the
       error SPICE(TYPEMISMATCH) is signaled.

   3)  If the `a' cell argument does not qualify as a SPICE set, the
       error SPICE(NOTASET) is signaled. SPICE sets have their data
       elements stored in increasing order and contain no duplicate
       elements.

Files

   None.

Particulars

   None.

Examples

   The numerical results shown for this example may differ across
   platforms. The results depend on the SPICE kernels used as
   input, the compiler and supporting libraries, and the machine
   specific arithmetic implementation.

   1) Create an integer set for ten elements, insert items
      to it and then remove the even values.


      Example code begins here.


      /.
         Program insrti_ex1
      ./
      #include <stdio.h>
      #include "SpiceUsr.h"

      int main( )
      {

         /.
         Local constants.
         ./
         #define SETDIM       10

         /.
         Local variables.
         ./
         SPICEINT_CELL      ( a     , SETDIM );
         SpiceInt             i;

         /.
         Create a list of items and even numbers.
         ./
         SpiceInt             even   [SETDIM] = {  0,  2,  4,  6,  8,
                                                  10, 12, 14, 16, 18  };

         SpiceInt             items  [SETDIM] = {  0,  1,  1,  2,  3,
                                                   5,  8, 10, 13, 21  };

         /.
         Initialize the empty set.
         ./
         valid_c ( SETDIM, 0, &a );

         /.
         Insert the list of integers into the set. If the item is
         an element of the set, the set is not changed.
         ./
         for ( i = 0; i < SETDIM; i++ )
         {
            insrti_c ( items[i], &a );
         }

         /.
         Output the original contents of set `a'.
         ./
         printf( "Items in original set A:\n" );

         for ( i = 0; i < card_c( &a ); i++ )
         {
            printf( "%6d", SPICE_CELL_ELEM_I( &a, i ) );
         }

         printf( " \n" );

         /.
         Remove the even values. If the item is not an element of
         the set, the set is not changed.
         ./
         for ( i = 0; i < SETDIM; i++ )
         {
            removi_c ( even[i], &a );
         }

         /.
         Output the contents of `a'.
         ./
         printf( "Odd numbers in set A:\n" );

         for ( i = 0; i < card_c( &a ); i++ )
         {
            printf( "%6d", SPICE_CELL_ELEM_I( &a, i ) );
         }

         printf( " \n" );

         return ( 0 );
      }


      When this program was executed on a Mac/Intel/cc/64-bit
      platform, the output was:


      Items in original set A:
           0     1     2     3     5     8    10    13    21
      Odd numbers in set A:
           1     3     5    13    21

Restrictions

   None.

Literature_References

   None.

Author_and_Institution

   N.J. Bachman        (JPL)
   C.A. Curzon         (JPL)
   J. Diaz del Rio     (ODC Space)
   W.L. Taber          (JPL)
   I.M. Underwood      (JPL)

Version

   -CSPICE Version 2.1.0, 24-AUG-2021 (JDR)

       Changed the argument name "set" to "a" for consistency with other
       routines.

       Edited the header to comply with NAIF standard. Added complete code
       example.

       Extended description of argument "a" in -Detailed_Input to include
       type and preferred declaration method.

   -CSPICE Version 2.0.0, 01-NOV-2005 (NJB)

       Long error message was updated to include size of
       set into which insertion was attempted.

   -CSPICE Version 1.0.0, 07-AUG-2002 (NJB) (CAC) (WLT) (IMU)

Index_Entries

   insert an item into an integer set
Fri Dec 31 18:41:08 2021