1 /* 2 3 -Procedure removi_c ( Remove an item from an integer set ) 4 5 -Abstract 6 7 Remove an item from an integer set. 8 9 -Disclaimer 10 11 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 12 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 13 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 14 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 15 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 16 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 17 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 18 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 19 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 20 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 21 22 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 23 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 24 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 25 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 26 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 27 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 28 29 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 30 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 31 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 32 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 33 34 -Required_Reading 35 36 SETS 37 38 -Keywords 39 40 CELLS, SETS 41 42 */ 43 44 #include "SpiceUsr.h" 45 #include "SpiceZfc.h" 46 #include "SpiceZmc.h" 47 48 removi_c(SpiceInt item,SpiceCell * set)49 void removi_c ( SpiceInt item, 50 SpiceCell * set ) 51 52 53 /* 54 55 -Brief_I/O 56 57 VARIABLE I/O DESCRIPTION 58 -------- --- -------------------------------------------------- 59 item I Item to be removed. 60 set I/O Removal set. 61 62 -Detailed_Input 63 64 item is an item which is to be removed from the specified 65 set. item may or may not already be an element of the 66 set. 67 68 69 set is a CSPICE set. set must be declared as an integer 70 SpiceCell. 71 72 On input, set may or may not contain the input item 73 as an element. 74 75 -Detailed_Output 76 77 set on output contains the difference of the input set and 78 the input item. If the item is not an element of the 79 set, the set is not changed. 80 81 -Parameters 82 83 None. 84 85 -Exceptions 86 87 1) If the input set argument is a SpiceCell of type other than 88 integer, the error SPICE(TYPEMISMATCH) is signaled. 89 90 2) If the input set argument does not qualify as a CSPICE set, 91 the error SPICE(NOTASET) will be signaled. CSPICE sets have 92 their data elements sorted in increasing order and contain 93 no duplicate data elements. 94 95 -Files 96 97 None. 98 99 -Particulars 100 101 None. 102 103 -Examples 104 105 1) In the following example, the NAIF ID code of Pluto is removed from 106 the integer set planets and inserted into the integer set 107 asteroids. 108 109 #include "SpiceUsr.h" 110 . 111 . 112 . 113 /. 114 Declare the sets with maximum number of elements MAXSIZ. 115 ./ 116 SPICEINT_CELL ( planets, MAXSIZ ); 117 SPICEINT_CELL ( asteroids, MAXSIZ ); 118 . 119 . 120 . 121 removi_c ( 999, &planets ); 122 insrti_c ( 999, &asteroids ); 123 124 125 If 999 is not an element of planets, then the contents of planets 126 are not changed. Similarly, if 999 is already an element of 127 asteroids, the contents of asteroids remain unchanged. 128 129 -Restrictions 130 131 None. 132 133 -Literature_References 134 135 None. 136 137 -Author_and_Institution 138 139 N.J. Bachman (JPL) 140 C.A. Curzon (JPL) 141 W.L. Taber (JPL) 142 I.M. Underwood (JPL) 143 144 -Version 145 146 -CSPICE Version 1.0.0, 07-AUG-2002 (NJB) (CAC) (WLT) (IMU) 147 148 -Index_Entries 149 150 remove an item from an integer set 151 152 -& 153 */ 154 { 155 /* 156 local variables 157 */ 158 SpiceBoolean inSet; 159 160 SpiceInt i; 161 SpiceInt * idata; 162 SpiceInt loc; 163 164 165 /* 166 Use discovery check-in. 167 */ 168 169 /* 170 Make sure we're working with an integer cell. 171 */ 172 CELLTYPECHK ( CHK_DISCOVER, "removi_c", SPICE_INT, set ); 173 174 idata = (SpiceInt *) (set->data); 175 176 177 /* 178 Make sure the cell is really a set. 179 */ 180 CELLISSETCHK ( CHK_DISCOVER, "removi_c", set ); 181 182 183 /* 184 Initialize the set if necessary. 185 */ 186 CELLINIT ( set ); 187 188 189 /* 190 Is the item in the set? If not, we're done now. 191 */ 192 loc = lstlei_c ( item, set->card, idata ); 193 194 inSet = ( loc > -1 ) && ( item == idata[loc] ); 195 196 if ( !inSet ) 197 { 198 return; 199 } 200 201 202 /* 203 Shift the set's contents to overwrite the slot at index loc. 204 */ 205 for ( i = loc; i < (set->card) - 1; i++ ) 206 { 207 idata[i] = idata[i+1]; 208 } 209 210 211 /* 212 Decrement the set's cardinality. 213 */ 214 (set->card) --; 215 216 217 /* 218 Sync the set. 219 */ 220 zzsynccl_c ( C2F, set ); 221 } 222 223