Пример #1
0
//Insere um indice no arquivo de indices
void insertIndexOnFile(indice *index)
{
  if(openIndex())
  {
    //Altera o cabeçalho com o contador da lista
    fseek(ind,0,SEEK_SET);
    
    int head=0;
    fread(&head,sizeof(int),1,ind);
    
    int cont=head;
    cont=cont+1;
    fseek(ind,0,SEEK_SET);
    fwrite(&cont,sizeof(int),1,ind);
    
    fflush(ind);
    
    //insere o indice
    fseek(ind,0,SEEK_END);
    fwrite(&index->id_locacao,sizeof(int),1,ind);
    fwrite(&index->offset,sizeof(int),1,ind);
  }
  
  closeIndex();
}
Пример #2
0
//Cria lista de indices a partir do arquivo de indices
void getAllIndexesOnFile(indice **lista)
{
  if(openIndex())
  { 
    int tam = getIndexCount();
    int count=0;
    
    fseek(ind,4,SEEK_SET);
    
    while(count<tam)
    {
        indice *i=(indice *)malloc(sizeof(indice));

        fread(&i->id_locacao,sizeof(int),1,ind);
        fread(&i->offset,sizeof(int),1,ind);
        i->prox=NULL;
        
        insertIndexOnList(lista,i);
        
        count++; 
    }
  }
  
  closeIndex();
}
Пример #3
0
//Remove indice do arquivo de indices
void removeIndexFromFile(indice *i,indice **lista)
{
  if(openIndex())
  {
  //zera o contador da lista
  fseek(ind,0,SEEK_SET);
  
  int cont=0;
  
  //insere os indices, menos o que foi excluido
  fseek(ind,4,SEEK_SET);
  
  while(*lista!=NULL)
  {
    if((*lista)->id_locacao!=i->id_locacao)
    {
      fwrite(&(*lista)->id_locacao,sizeof(int),1,ind);
      fwrite(&(*lista)->offset,sizeof(int),1,ind);
      cont++;
    }
    
    *lista = (*lista)->prox;
  }
  
  fseek(ind,0,SEEK_SET);
  fwrite(&cont,sizeof(int),1,ind);
  fflush(ind);
  }
  
  closeIndex();
}
Пример #4
0
void SingleChromosomeBCFIndex::close() {
  if (fBcfFile_) {
    bgzf_close(fBcfFile_);
    fBcfFile_ = NULL;
  }
  closeIndex();
}
Пример #5
0
void testExtractFromWildcardQuery( CuTest * tc )
{
    Directory *     pIndex  = setUpIndex();
    IndexReader *   pReader = IndexReader::open( pIndex );
    TermSet         termSet;
    WildcardQuery * wildcard;
    Term *          t1;
    Query *         rewrite;


    t1 = _CLNEW Term( _T("data"), _T("aaaa?") );
    wildcard = _CLNEW WildcardQuery( t1 );
    rewrite = wildcard->rewrite( pReader );
    rewrite->extractTerms( &termSet );
    _CLLDECDELETE( t1 );

    assertEqualsMsg( _T( "wrong number of terms" ), 3, termSet.size() );
    for( TermSet::iterator itTerms = termSet.begin(); itTerms != termSet.end(); itTerms++ )
    {
        Term * pTerm = *itTerms;
        if(    0 != _tcscmp( _T( "aaaaa" ), pTerm->text()) 
            && 0 != _tcscmp( _T( "aaaab" ), pTerm->text())
            && 0 != _tcscmp( _T( "aaaac" ), pTerm->text()))
        {
            assertTrueMsg( _T( "wrong term" ), false );
        }
    }

    clearTermSet( termSet );
    if( rewrite != wildcard )
        _CLDELETE( rewrite );
    _CLDELETE( wildcard );
    

    t1 = _CLNEW Term( _T("data"), _T("aaa*") );
    wildcard = _CLNEW WildcardQuery( t1 );
    rewrite = wildcard->rewrite( pReader );
    rewrite->extractTerms( &termSet );
    _CLLDECDELETE( t1 );

    assertEqualsMsg( _T( "wrong number of terms" ), 5, termSet.size() );
    for( TermSet::iterator itTerms = termSet.begin(); itTerms != termSet.end(); itTerms++ )
    {
        Term * pTerm = *itTerms;
        assertTrueMsg( _T( "wrong term" ), ( 0 == _tcsncmp( _T( "aaa" ), pTerm->text(), 3 )));
    }

    clearTermSet( termSet );
    if( rewrite != wildcard )
        _CLDELETE( rewrite );
    _CLDELETE( wildcard );


    pReader->close();
    _CLDELETE( pReader );

    closeIndex( pIndex );
    pIndex = NULL;
}
Пример #6
0
/**
 * @brief CommandServer::disconnect Disconnects from all clients
 * @return true on success
 */
bool CommandServer::disconnect()
{
    Stop();
    Join();

    auto it = m_connections.begin();
    while(it != m_connections.end()) {
        closeIndex((it++)->second);
    }
    m_connections.clear();

    return true;
}
Пример #7
0
//zera o contador de indice
void emptyIndex()
{
  if(openIndex())
  {
    //Coloca o ponteiro no cabeçalho do arquivo
    fseek(ind,0,SEEK_SET);
  
    //nula a lista de espaços disponiveis
    int nullValue=0;
    fwrite(&nullValue,sizeof(int),1,ind);
  }
  
  closeIndex();
}
Пример #8
0
int SingleChromosomeBCFIndex::openIndex() {
  closeIndex();
  // read everything
  size_t fsize = getFileSize(indexFile_.c_str());
  REprintf("fsize = %ld\n", (long int)fsize);
  data_ = new uint8_t[fsize];
  FILE* fp = fopen(indexFile_.c_str(), "rb");
  if (fread(data_, sizeof(uint8_t), fsize, fp) != fsize) {
    REprintf("Read incomplete index\n");
    return -1;
  }
  
  // verify file integrity
  int64_t* d = (int64_t*) data_;
  if (fsize != sizeof(Record)  * (2L + d[1])) { // d[0, 1]: number of sample; number of marker
    REprintf("Check file integrity!\n");
    REprintf("d = %ld %ld fsize = %ld\n", d[0], d[1], (int)fsize);
    return -1;
  }
  return 0;
}
Пример #9
0
void testExtractFromTermQuery( CuTest * tc )
{
    Directory *     pIndex  = setUpIndex();
    IndexReader *   pReader = IndexReader::open( pIndex );
    TermSet         termSet;
 
    Term * t1 = _CLNEW Term( _T("data"), _T("aaaaa") );
    Term * t2 = _CLNEW Term( _T("data"), _T("bbbbb") );
    Query * q1 = _CLNEW TermQuery( t1 );
    Query * q2 = _CLNEW TermQuery( t2 );
    Query * rewrite1 = q1->rewrite( pReader );
    Query * rewrite2 = q2->rewrite( pReader );

    rewrite1->extractTerms( &termSet );
    assertEqualsMsg( _T( "wrong number of terms" ), 1, termSet.size() );
    assertEqualsMsg( _T( "wrong term" ), 0, t1->compareTo( *(termSet.begin())) );
    clearTermSet( termSet );

    rewrite2->extractTerms( &termSet );
    assertEqualsMsg( _T( "wrong number of terms" ), 1, termSet.size() );
    assertEqualsMsg( _T( "wrong term" ), 0, t2->compareTo( *(termSet.begin())) );
    clearTermSet( termSet );

    _CLLDECDELETE( t1 );
    _CLLDECDELETE( t2 );

    if( q1 != rewrite1 )
        _CLDELETE( rewrite1 );
    _CLDELETE( q1 );
    
    if( q2 != rewrite2 )
        _CLDELETE( rewrite2 );
    _CLDELETE( q2 );
    
    pReader->close();
    _CLDELETE( pReader );

    closeIndex( pIndex );
    pIndex = NULL;
}
Пример #10
0
void testExtractFromFuzzyQuery( CuTest * tc )
{
    Directory *     pIndex  = setUpIndex();
    IndexReader *   pReader = IndexReader::open( pIndex );
    TermSet         termSet;
    FuzzyQuery *    fuzzy;
    Term *          t1;
    Query *         rewrite;


    t1 = _CLNEW Term( _T("data"), _T("aaaab") );
    fuzzy = _CLNEW FuzzyQuery( t1, 0.7f );
    rewrite = fuzzy->rewrite( pReader );
    rewrite->extractTerms( &termSet );
    _CLLDECDELETE( t1 );

    assertEqualsMsg( _T( "wrong number of terms" ), 4, termSet.size() );
    for( TermSet::iterator itTerms = termSet.begin(); itTerms != termSet.end(); itTerms++ )
    {
        Term * pTerm = *itTerms;
        if(    0 != _tcscmp( _T( "aaaaa" ), pTerm->text()) 
            && 0 != _tcscmp( _T( "aaaab" ), pTerm->text())
            && 0 != _tcscmp( _T( "aaabb" ), pTerm->text())
            && 0 != _tcscmp( _T( "aaaac" ), pTerm->text()))
        {
            assertTrueMsg( _T( "wrong term" ), false );
        }
    }

    clearTermSet( termSet );
    if( rewrite != fuzzy )
        _CLDELETE( rewrite );
    _CLDELETE( fuzzy );
    
    pReader->close();
    _CLDELETE( pReader );

    closeIndex( pIndex );
    pIndex = NULL;
}
Пример #11
0
void testExtractFromBooleanQuery( CuTest * tc )
{
    Directory *     pIndex  = setUpIndex();
    IndexReader *   pReader = IndexReader::open( pIndex );
    TermSet         termSet;
 
    Term * t1 = _CLNEW Term( _T("data"), _T("aaaab") );
    Term * t2 = _CLNEW Term( _T("data"), _T("aaabb") );
    Term * t3 = _CLNEW Term( _T("data"), _T("aaabb") );
    BooleanQuery * bq = _CLNEW BooleanQuery();
    bq->add( _CLNEW TermQuery( t1 ), true, BooleanClause::SHOULD );
    bq->add( _CLNEW TermQuery( t2 ), true, BooleanClause::SHOULD );
    bq->add( _CLNEW TermQuery( t3 ), true, BooleanClause::SHOULD );

    Query * rewrite = bq->rewrite( pReader );

    rewrite->extractTerms( &termSet );
    assertEqualsMsg( _T( "wrong number of terms" ), 2, termSet.size() );
    for( TermSet::iterator itTerms = termSet.begin(); itTerms != termSet.end(); itTerms++ )
    {
        Term * pTerm = *itTerms;
        assertTrueMsg( _T( "wrong term" ), ( 0 == t1->compareTo( pTerm ) || 0 == t2->compareTo( pTerm )));
    }
    clearTermSet( termSet );

    _CLLDECDELETE( t1 );
    _CLLDECDELETE( t2 );
    _CLLDECDELETE( t3 );

    if( rewrite != bq )
        _CLDELETE( rewrite );
    _CLDELETE( bq );
    
    pReader->close();
    _CLDELETE( pReader );

    closeIndex( pIndex );
    pIndex = NULL;
}