bool DDLIndexPopulator::populateIndex(DDLPackageProcessor::DDLResult& result)
 {
   if (makeIndexStructs() )
     insertIndex();
   result = fResult;
   return NO_ERROR != fResult.result;
 }
/*
    Funcao: insertIndex (local)
    Insere matricula e indice na arvore binaria de busca.
    Parametros:
        tree: ponteiro pra ponteiro pra raiz da arvore
        index: indice a ser adicionado
        mat: matricula a ser adicionada
*/
void insertIndex(tArvoreBB **tree, int index, int mat)
{
    if((*tree) == NULL)
    {
        (*tree) = calloc(sizeof(tArvoreBB), 1);
        (*tree)->mat = mat;
        (*tree)->index = index;
    }
    else if((*tree)->mat < mat)
    {
        insertIndex(&(*tree)->dir, index, mat);
    }
    else if((*tree)->mat > mat)
    {
        insertIndex(&(*tree)->esq, index, mat);
    }
}
/*
    Funcao: loadTree
    Carrega indices do arquivo e matriculas na arvore binaria de busca.
    Parametros:
        arq: ponteiro pro arquivo 'func.bin', de onde ele vai pegar os registros
        tree: ponteiro pra ponteiro pra raiz da arvore onde os indices e matriculas serao salvos
*/
void loadTree(FILE* arq, tArvoreBB **tree)
{
    tfunc func;
    
    fseek(arq, 0, SEEK_SET);
    while(fread(&func, sizeof(tfunc), 1, arq) != 0)
    {
        insertIndex(tree, ftell(arq) - sizeof(tfunc), func.mat);
    }
}
/*
    Funcao: insertFunc()
    Insere funcionario no arquivo e na arvore de indexacao
    Parametros:
        arq: ponteiro para o arquivo func.bin
        tree: ponteiro para ponteiro para raiz da arvore
        func: funcionario a ser inserido no registro
*/
void insertFunc(FILE *arq, tArvoreBB **tree, tfunc func)
{ 
    if(searchIndex(*tree, func.mat) != NULL)
    {
        printf("Matricula ja existe!");
    }
    else
    {
        if(fwrite(&func, sizeof(tfunc), 1, arq) > 0)
        {
            fseek(arq, 0, SEEK_END);
            insertIndex(tree, ftell(arq) - sizeof(func), func.mat);
            printf("Funcionario inserido com sucesso!");
        }
        else{
            printf("Erro ao inserir funcionario!");
        }
    } 
}
Exemple #5
0
int History::save(QString user, QDateTime date, QString* lpszData) {
	lmcSettings settings;
	QString path = historyFile();
	
	QDir dir = QFileInfo(path).dir();
	if(!dir.exists())
		dir.mkpath(dir.absolutePath());

	if(!QFile::exists(path))
		create(path);

	QFile file(path);
	if(!file.open(QIODevice::ReadWrite))
		return -1;

	QDataStream stream(&file);

	DBHeader header = readHeader(&stream);
	if(header.marker.compare(HC_DBMARKER) != 0) {
		file.close();
		return -1;
	}

	qint64 dataPos = insertData(&stream, lpszData);
	qint64 newIndex = insertIndex(&stream, dataPos, user, date);
	updateIndex(&stream, header.last, newIndex);

	header.count++;
	header.first = (header.first == 0) ? newIndex : header.first;
	header.last = newIndex;

	writeHeader(&stream, &header);

	file.close();
	return 0;
}
Exemple #6
0
/** map the keys in the key set to lexicographical order */
void RamAutoIndex::solve() { 
    if(searches.size() == 0) return;

//    // -- hack to disable indexing --
//
//    // every search pattern gets its naive index
//    for(SearchColumns cur : searches) {
//
//        // obtain order
//        LexicographicalOrder order;
//        SearchColumns mask = cur;
//        for(int i=0; mask != 0; i++) {
//            if (!(1<<i & mask)) continue;
//            order.push_back(i);
//            // clear bit
//            mask &= ~(1<<i);
//        }
//
//        // add new order
//        orders.push_back(order);
//
//        // register pseudo chain
//        chainToOrder.push_back(Chain());
//        chainToOrder.back().insert(cur);
//    }
//
//    std::cout << "Orders: " << orders << "\n";
//    std::cout << "Chains: " << chainToOrder << "\n";
//
//    return;
//
//    // ------------------------------



    // Construct the matching poblem
    for (SearchSet::const_iterator it = searches.begin(); it != searches.end(); ++it) {
        // For this node check if other nodes are strict subsets
        for (SearchSet::const_iterator itt = searches.begin(); itt != searches.end(); ++itt) {
            if (isStrictSubset(*it, *itt)) {
                matching.addEdge(*it, toB(*itt));
            }
        }
    } 

    // Perform the hopcroft-karp on the graph and receive matchings (mapped A-> B and B->A)
    // Assume: alg.calculate is not called on an empty graph
    ASSERT(searches.size() > 0);
    const RamMaxMatching::Matchings& matchings = matching.calculate();

    // Extract the chains given the nodes and matchings
    const ChainOrderMap chains = getChainsFromMatching(matchings, searches);

    // Should never get no chains back as we never call calculate on an empty graph
    ASSERT(chains.size() > 0);

    for (ChainOrderMap::const_iterator it = chains.begin(); it != chains.end(); ++it) {
        std::vector<int> ids;
        SearchColumns initDelta = *(it->begin());
        insertIndex(ids, initDelta);

        for (Chain::iterator iit = it->begin(); next(iit) != it->end(); ++iit) {
            SearchColumns delta = *(next(iit)) - *iit; 
            insertIndex(ids, delta);
        }

        ASSERT(ids.size() > 0);

        orders.push_back(ids);
    }

    // Construct the matching poblem
    for (SearchSet::const_iterator it = searches.begin(); it != searches.end(); ++it) {
        int idx = map(*it); 
        size_t l = card(*it); 
        SearchColumns k = 0; 
        for (size_t i=0;i<l;i++) { 
            k = k + (1 << (orders[idx][i])); 
        }
        ASSERT(k == *it && "incorrect lexicographical order");  
    } 
}