Insert an integer in the intset */
| 204 | |
| 205 | /* Insert an integer in the intset */ |
| 206 | intset *intsetAdd(intset *is, int64_t value, uint8_t *success) { |
| 207 | uint8_t valenc = _intsetValueEncoding(value); |
| 208 | uint32_t pos; |
| 209 | if (success) *success = 1; |
| 210 | |
| 211 | /* Upgrade encoding if necessary. If we need to upgrade, we know that |
| 212 | * this value should be either appended (if > 0) or prepended (if < 0), |
| 213 | * because it lies outside the range of existing values. */ |
| 214 | if (valenc > intrev32ifbe(is->encoding)) { |
| 215 | /* This always succeeds, so we don't need to curry *success. */ |
| 216 | return intsetUpgradeAndAdd(is,value); |
| 217 | } else { |
| 218 | /* Abort if the value is already present in the set. |
| 219 | * This call will populate "pos" with the right position to insert |
| 220 | * the value when it cannot be found. */ |
| 221 | if (intsetSearch(is,value,&pos)) { |
| 222 | if (success) *success = 0; |
| 223 | return is; |
| 224 | } |
| 225 | |
| 226 | is = intsetResize(is,intrev32ifbe(is->length)+1); |
| 227 | if (pos < intrev32ifbe(is->length)) intsetMoveTail(is,pos,pos+1); |
| 228 | } |
| 229 | |
| 230 | _intsetSet(is,pos,value); |
| 231 | is->length = intrev32ifbe(intrev32ifbe(is->length)+1); |
| 232 | return is; |
| 233 | } |
| 234 | |
| 235 | /* Delete integer from intset */ |
| 236 | intset *intsetRemove(intset *is, int64_t value, int *success) { |
no test coverage detected