예제 #1
0
// enumerate out every pairwise match
boolean PairwiseMatchFinder::EnumerateMatches( IdmerList& match_list ) {

    match_list.sort(&idmer_id_lessthan);
    IdmerList::iterator iter = match_list.begin();
    IdmerList::iterator iter2 = match_list.begin();
    uint cur_id_count = 1;
    IdmerList unique_list;
    // identify all of the unique seeds and add them to unique_list
    while(iter2 != match_list.end()) {
        ++iter2;
        if(iter2 == match_list.end() || iter->id != iter2->id) {
            if( cur_id_count == 1 )
                unique_list.push_back( *iter );
            else
                cur_id_count = 1;
        } else
            cur_id_count++;
        ++iter;
    }
    // hash each pair of unique seeds
    boolean success = true;
    for( iter = unique_list.begin(); iter != unique_list.end(); ++iter )
    {
        for( iter2 = iter; iter2 != unique_list.end(); ++iter2 )
        {
            if( iter == iter2 )
                continue;
            IdmerList hash_list;
            hash_list.push_back( *iter );
            hash_list.push_back( *iter2 );
            success = success && HashMatch(hash_list);
        }
    }
    return success;
}
예제 #2
0
//哈希表删除一个元素
int HashRemove( T_HASH_TBL* pHash, void** pData )
{
    int key = 0;
    T_LIST_ELMT* pPrev = NULL;
    T_LIST_ELMT* pCur = NULL;
    if( ( NULL == pHash ) || ( NULL == pData ) )
    {
        return -1;
    }
    //计算哈希键值
    if( ( key = HashKey( *pData ) ) < 0 )
    {
        return -1;
    }
    //上一个元素指针初始化必须为空,这样才能删除匹配的头结点
    pPrev = NULL;
    pCur = LIST_HEAD( &(pHash->pList[key]) );
    while( pCur != NULL )
    {
        //在链表中遍历是否存在该元素,找到后就删除它
        if( 0 == HashMatch( pCur->pData, *pData ) )
        {
            if( 0 == ListRemoveNext( &(pHash->pList[key]), pPrev, pData ) )
            {
                pHash->size--;
                return 0;
            }
            //删除元素失败
            return -1;
        }
        //遍历下一个元素,但是要记录上一个元素的位置
        pPrev = pCur;
        pCur = pCur->pNext;
    }
    //没有找到要删除的元素
    return -1;
}