| 2066 | typedef union zsetopsrc::_uT::_iterzset iterzset; |
| 2067 | |
| 2068 | void zuiInitIterator(zsetopsrc *op) { |
| 2069 | if (op->subject == NULL) |
| 2070 | return; |
| 2071 | |
| 2072 | if (op->type == OBJ_SET) { |
| 2073 | iterset *it = (iterset*)&op->iter.set; |
| 2074 | if (op->encoding == OBJ_ENCODING_INTSET) { |
| 2075 | it->is.is = (intset*)op->subject->m_ptr; |
| 2076 | it->is.ii = 0; |
| 2077 | } else if (op->encoding == OBJ_ENCODING_HT) { |
| 2078 | it->ht.dict = (dict*)op->subject->m_ptr; |
| 2079 | it->ht.di = dictGetIterator((dict*)op->subject->m_ptr); |
| 2080 | it->ht.de = dictNext(it->ht.di); |
| 2081 | } else { |
| 2082 | serverPanic("Unknown set encoding"); |
| 2083 | } |
| 2084 | } else if (op->type == OBJ_ZSET) { |
| 2085 | /* Sorted sets are traversed in reverse order to optimize for |
| 2086 | * the insertion of the elements in a new list as in |
| 2087 | * ZDIFF/ZINTER/ZUNION */ |
| 2088 | iterzset *it = (iterzset*)&op->iter.iterzset; |
| 2089 | if (op->encoding == OBJ_ENCODING_ZIPLIST) { |
| 2090 | it->zl.zl = (unsigned char*)op->subject->m_ptr; |
| 2091 | it->zl.eptr = ziplistIndex(it->zl.zl,-2); |
| 2092 | if (it->zl.eptr != NULL) { |
| 2093 | it->zl.sptr = ziplistNext(it->zl.zl,it->zl.eptr); |
| 2094 | serverAssert(it->zl.sptr != NULL); |
| 2095 | } |
| 2096 | } else if (op->encoding == OBJ_ENCODING_SKIPLIST) { |
| 2097 | it->sl.zs = (zset*)op->subject->m_ptr; |
| 2098 | it->sl.node = it->sl.zs->zsl->tail; |
| 2099 | } else { |
| 2100 | serverPanic("Unknown sorted set encoding"); |
| 2101 | } |
| 2102 | } else { |
| 2103 | serverPanic("Unsupported type"); |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | void zuiClearIterator(zsetopsrc *op) { |
| 2108 | if (op->subject == NULL) |
no test coverage detected