Example #1
0
int commonPrefixSize(struct slName *list)
/* Return length of common prefix */
{
if (list == NULL)
    return 0;
int commonSize = strlen(list->name);
struct slName *el, *lastEl = list;
for (el = list->next; el != NULL; el = el->next)
    {
    int sameSize = countSame(el->name, lastEl->name);
    commonSize = min(sameSize, commonSize);
    lastEl = el;
    }
return commonSize;
}
Example #2
0
static void addIfFirstMatch(struct dbDb *dbDb, enum dbDbMatchType type, int offset, char *target,
                            char *term, struct hash *matchHash, struct dbDbMatch **pMatchList)
/* If target doesn't already have a match in matchHash, compute matchLength and isWord,
 * and then add the new match to pMatchList and add target to matchHash. */
{
if (dbDb->active && ! hashLookup(matchHash, target))
    {
    char *termInTarget = (offset >= 0) ? target+offset : target;
    int matchLength = countSame(term, termInTarget);
    // is the match complete up to a word boundary in termInTarget?
    boolean isWord = (matchLength == strlen(term) &&
                       (termInTarget[matchLength] == '\0' || isspace(termInTarget[matchLength])));
    boolean isComplete = sameString(term, target);
    struct dbDbMatch *match = dbDbMatchNew(dbDb, type, offset, isWord, isComplete);
    slAddHead(pMatchList, match);
    hashStore(matchHash, target);
    }
}