MCPcopy Create free account
hub / github.com/F-Stack/f-stack / intsetAdd

Function intsetAdd

app/redis-6.2.6/src/intset.c:206–233  ·  view source on GitHub ↗

Insert an integer in the intset */

Source from the content-addressed store, hash-verified

204
205/* Insert an integer in the intset */
206intset *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 */
236intset *intsetRemove(intset *is, int64_t value, int *success) {

Callers 4

rdbLoadObjectFunction · 0.85
createSetFunction · 0.85
intsetTestFunction · 0.85
setTypeAddFunction · 0.85

Calls 6

_intsetValueEncodingFunction · 0.85
intsetUpgradeAndAddFunction · 0.85
intsetSearchFunction · 0.85
intsetResizeFunction · 0.85
intsetMoveTailFunction · 0.85
_intsetSetFunction · 0.85

Tested by

no test coverage detected