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

Function zipTryEncoding

app/redis-6.2.6/src/ziplist.c:522–546  ·  view source on GitHub ↗

Check if string pointed to by 'entry' can be encoded as an integer. * Stores the integer value in 'v' and its encoding in 'encoding'. */

Source from the content-addressed store, hash-verified

520/* Check if string pointed to by 'entry' can be encoded as an integer.
521 * Stores the integer value in 'v' and its encoding in 'encoding'. */
522int zipTryEncoding(unsigned char *entry, unsigned int entrylen, long long *v, unsigned char *encoding) {
523 long long value;
524
525 if (entrylen >= 32 || entrylen == 0) return 0;
526 if (string2ll((char*)entry,entrylen,&value)) {
527 /* Great, the string can be encoded. Check what's the smallest
528 * of our encoding types that can hold this value. */
529 if (value >= 0 && value <= 12) {
530 *encoding = ZIP_INT_IMM_MIN+value;
531 } else if (value >= INT8_MIN && value <= INT8_MAX) {
532 *encoding = ZIP_INT_8B;
533 } else if (value >= INT16_MIN && value <= INT16_MAX) {
534 *encoding = ZIP_INT_16B;
535 } else if (value >= INT24_MIN && value <= INT24_MAX) {
536 *encoding = ZIP_INT_24B;
537 } else if (value >= INT32_MIN && value <= INT32_MAX) {
538 *encoding = ZIP_INT_32B;
539 } else {
540 *encoding = ZIP_INT_64B;
541 }
542 *v = value;
543 return 1;
544 }
545 return 0;
546}
547
548/* Store integer 'value' at 'p', encoded as 'encoding' */
549void zipSaveInteger(unsigned char *p, int64_t value, unsigned char encoding) {

Callers 4

__ziplistInsertFunction · 0.85
ziplistReplaceFunction · 0.85
ziplistCompareFunction · 0.85
ziplistFindFunction · 0.85

Calls 1

string2llFunction · 0.70

Tested by

no test coverage detected