示例#1
0
文件: attrib.c 项目: philbooth/server
attrib *a_add(attrib ** pa, attrib * a)
{
    attrib *first = *pa;
    assert(a->next == NULL && a->nexttype == NULL);

    if (first == NULL)
        return *pa = a;
    if (first->type == a->type) {
        return a_insert(first, a);
    }
    for (;;) {
        attrib *next = first->nexttype;
        if (next == NULL) {
            /* the type is not in the list, append it behind the last type */
            attrib **insert = &first->next;
            first->nexttype = a;
            while (*insert)
                insert = &(*insert)->next;
            *insert = a;
            break;
        }
        if (next->type == a->type) {
            return a_insert(next, a);
        }
        first = next;
    }
    return a;
}
 void a_build(vector<string> r)
 {
     //建立AC自动机 插入待查寻字符串 建立失败路径
     for(int i = 0; i < (int)r.size(); ++ i)
         a_insert(r[i]);
     a_failpath();
 }