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

Function raxCompare

app/redis-6.2.6/src/rax.c:1778–1804  ·  view source on GitHub ↗

Compare the key currently pointed by the iterator to the specified * key according to the specified operator. Returns 1 if the comparison is * true, otherwise 0 is returned. */

Source from the content-addressed store, hash-verified

1776 * key according to the specified operator. Returns 1 if the comparison is
1777 * true, otherwise 0 is returned. */
1778int raxCompare(raxIterator *iter, const char *op, unsigned char *key, size_t key_len) {
1779 int eq = 0, lt = 0, gt = 0;
1780
1781 if (op[0] == '=' || op[1] == '=') eq = 1;
1782 if (op[0] == '>') gt = 1;
1783 else if (op[0] == '<') lt = 1;
1784 else if (op[1] != '=') return 0; /* Syntax error. */
1785
1786 size_t minlen = key_len < iter->key_len ? key_len : iter->key_len;
1787 int cmp = memcmp(iter->key,key,minlen);
1788
1789 /* Handle == */
1790 if (lt == 0 && gt == 0) return cmp == 0 && key_len == iter->key_len;
1791
1792 /* Handle >, >=, <, <= */
1793 if (cmp == 0) {
1794 /* Same prefix: longer wins. */
1795 if (eq && key_len == iter->key_len) return 1;
1796 else if (lt) return iter->key_len < key_len;
1797 else if (gt) return iter->key_len > key_len;
1798 else return 0; /* Avoid warning, just 'eq' is handled before. */
1799 } else if (cmp > 0) {
1800 return gt ? 1 : 0;
1801 } else /* (cmp < 0) */ {
1802 return lt ? 1 : 0;
1803 }
1804}
1805
1806/* Free the iterator. */
1807void raxStop(raxIterator *it) {

Callers 2

RM_DictCompareCFunction · 0.85
RM_DictCompareFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected