- double *score = zmalloc(sizeof(double));
- *score = 0.0;
- for (j = 0; j < zsetnum; j++) {
- if (!srcdict[j]) continue;
+ dstobj = createZsetObject();
+ dstzset = dstobj->ptr;
+
+ if (op == REDIS_OP_INTER) {
+ /* store index of smallest zset in variable j */
+ for (i = 0, j = 0; i < zsetnum; i++) {
+ if (!srcdicts[i] || dictSize(srcdicts[i]) == 0) {
+ break;
+ }
+ if (dictSize(srcdicts[i]) < dictSize(srcdicts[j])) {
+ j = i;
+ }
+ }
+ /* skip going over all entries if at least one dict was NULL or empty */
+ if (i == zsetnum) {
+ /* precondition: all srcdicts are non-NULL and non-empty */
+ di = dictGetIterator(srcdicts[j]);
+ while((de = dictNext(di)) != NULL) {
+ double *score = zmalloc(sizeof(double));
+ *score = 0.0;
+
+ for (k = 0; k < zsetnum; k++) {
+ dictEntry *other = (k == j) ? de : dictFind(srcdicts[k],dictGetEntryKey(de));
+ if (other) {
+ *score = *score + weights[k] * (*(double*)dictGetEntryVal(other));
+ } else {
+ break;
+ }
+ }