MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / intsetUpgradeAndAdd

Function intsetUpgradeAndAdd

src/intset.c:159–182  ·  view source on GitHub ↗

Upgrades the intset to a larger encoding and inserts the given integer. */

Source from the content-addressed store, hash-verified

157
158/* Upgrades the intset to a larger encoding and inserts the given integer. */
159static intset *intsetUpgradeAndAdd(intset *is, int64_t value) {
160 uint8_t curenc = intrev32ifbe(is->encoding);
161 uint8_t newenc = _intsetValueEncoding(value);
162 int length = intrev32ifbe(is->length);
163 int prepend = value < 0 ? 1 : 0;
164
165 /* First set new encoding and resize */
166 is->encoding = intrev32ifbe(newenc);
167 is = intsetResize(is,intrev32ifbe(is->length)+1);
168
169 /* Upgrade back-to-front so we don't overwrite values.
170 * Note that the "prepend" variable is used to make sure we have an empty
171 * space at either the beginning or the end of the intset. */
172 while(length--)
173 _intsetSet(is,length+prepend,_intsetGetEncoded(is,length,curenc));
174
175 /* Set the value at the beginning or the end. */
176 if (prepend)
177 _intsetSet(is,0,value);
178 else
179 _intsetSet(is,intrev32ifbe(is->length),value);
180 is->length = intrev32ifbe(intrev32ifbe(is->length)+1);
181 return is;
182}
183
184static void intsetMoveTail(intset *is, uint32_t from, uint32_t to) {
185 void *src, *dst;

Callers 1

intsetAddFunction · 0.85

Calls 4

_intsetValueEncodingFunction · 0.85
intsetResizeFunction · 0.85
_intsetSetFunction · 0.85
_intsetGetEncodedFunction · 0.85

Tested by

no test coverage detected