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

Function stralgoLCS

src/t_string.cpp:732–963  ·  view source on GitHub ↗

STRALGO [IDX] [LEN] [MINMATCHLEN ] [WITHMATCHLEN] * STRINGS | KEYS */

Source from the content-addressed store, hash-verified

730 * STRINGS <string> <string> | KEYS <keya> <keyb>
731 */
732void stralgoLCS(client *c) {
733 uint32_t i, j;
734 long long minmatchlen = 0;
735 const char *a = NULL, *b = NULL;
736 int getlen = 0, getidx = 0, withmatchlen = 0;
737 robj_roptr obja = nullptr, objb = nullptr;
738 uint32_t arraylen = 0; /* Number of ranges emitted in the array. */
739 int computelcs;
740
741 for (j = 2; j < (uint32_t)c->argc; j++) {
742 char *opt = szFromObj(c->argv[j]);
743 int moreargs = (c->argc-1) - j;
744
745 if (!strcasecmp(opt,"IDX")) {
746 getidx = 1;
747 } else if (!strcasecmp(opt,"LEN")) {
748 getlen = 1;
749 } else if (!strcasecmp(opt,"WITHMATCHLEN")) {
750 withmatchlen = 1;
751 } else if (!strcasecmp(opt,"MINMATCHLEN") && moreargs) {
752 if (getLongLongFromObjectOrReply(c,c->argv[j+1],&minmatchlen,NULL)
753 != C_OK) goto cleanup;
754 if (minmatchlen < 0) minmatchlen = 0;
755 j++;
756 } else if (!strcasecmp(opt,"STRINGS") && moreargs > 1) {
757 if (a != NULL) {
758 addReplyError(c,"Either use STRINGS or KEYS");
759 goto cleanup;
760 }
761 a = szFromObj(c->argv[j+1]);
762 b = szFromObj(c->argv[j+2]);
763 j += 2;
764 } else if (!strcasecmp(opt,"KEYS") && moreargs > 1) {
765 if (a != NULL) {
766 addReplyError(c,"Either use STRINGS or KEYS");
767 goto cleanup;
768 }
769 obja = lookupKeyRead(c->db,c->argv[j+1]);
770 objb = lookupKeyRead(c->db,c->argv[j+2]);
771 if ((obja && obja->type != OBJ_STRING) ||
772 (objb && objb->type != OBJ_STRING))
773 {
774 addReplyError(c,
775 "The specified keys must contain string values");
776 /* Don't cleanup the objects, we need to do that
777 * only after calling getDecodedObject(). */
778 obja = NULL;
779 objb = NULL;
780 goto cleanup;
781 }
782 obja = obja ? getDecodedObject(obja) : createStringObject("",0);
783 objb = objb ? getDecodedObject(objb) : createStringObject("",0);
784 a = szFromObj(obja);
785 b = szFromObj(objb);
786 j += 2;
787 } else {
788 addReplyErrorObject(c,shared.syntaxerr);
789 goto cleanup;

Callers 1

stralgoCommandFunction · 0.85

Calls 15

szFromObjFunction · 0.85
addReplyErrorFunction · 0.85
lookupKeyReadFunction · 0.85
getDecodedObjectFunction · 0.85
addReplyErrorObjectFunction · 0.85
sdslenFunction · 0.85
ztrymallocFunction · 0.85
sdsnewlenFunction · 0.85
addReplyMapLenFunction · 0.85
addReplyBulkCStringFunction · 0.85
addReplyDeferredLenFunction · 0.85

Tested by

no test coverage detected