bool DataDocumentManager::addDocument(ByteString byteString)
{
	bool saved = false;
	int realID = this->autoIncInteger + 1;
	int documentID;
	string sid = Utility::intToString(realID);
	string did;

	Document document;
	document.Hidratate(byteString);
	document.setFakeId(realID);
	if(document.getTitle()[0] == 'T')
		documentID = this->twtautoIncInteger + 1;
	else if(document.getTitle()[0] == 'N')
		documentID = this->rssautoIncInteger + 1;
	did = Utility::intToString(documentID);
	document.setIdentificador(Utility::concat(document.getTitle(), did));

	int position = this->fileVariableRecord->addDocument(document.Serialize());
	if(position > -1)
	{
		this->autoIncInteger++;
		if(document.getTitle()[0] == 'N')
			rssautoIncInteger++;
		else if(document.getTitle()[0] == 'T')
			twtautoIncInteger++;
		ByteString idDocument;
		idDocument.insertLast(&realID, sizeof(int));
		Key* key = new Key(idDocument.toString());
		ByteString offset;
		offset.insertLast(&position, sizeof(int));
		Record* recPrincipalInd = new Record(key,&offset);
		this->principalIndex->add(recPrincipalInd);
		addIDtoFileFlags(IndexWrapper::AUTOR,idDocument.readAsInt(0));
		addIDtoFileFlags(IndexWrapper::TITULO,idDocument.readAsInt(0));
		addIDtoFileFlags(IndexWrapper::PALABRAS,idDocument.readAsInt(0));
		addIDtoFileFlags(IndexWrapper::IDENTIFICADOR,idDocument.readAsInt(0));
		addIDtoFileFlags(IndexWrapper::FECHA,idDocument.readAsInt(0));

		saved = true;
	}
	return saved;
}
Exemplo n.º 2
0
bool Bucket::Hidratate(ByteString &bytesString){
	bool success = true;
	if(int(bytesString.getSize()) != capacity)
	{
		success = false;
	}
	else
	{
		//si tenia registros los borro
		this->toEmpty();

		//Obtiene la Metadata
		dispersionNumber = bytesString.readAsInt(0);

		//Obtiene los registros
		Record* record = NULL;
		ByteString recordBytesString;
		int position = 1*sizeof(int);
		int recordSize = bytesString.readAsInt(1*sizeof(int));
		while(recordSize > 0)
		{
			record = new Record();
			recordBytesString = bytesString.read(position,recordSize);
			record->Hidratate(recordBytesString);
			success = this->insertRecord(record);

			position = position + recordSize;

			//Valida que quede el minimo recordSize que puede tener un registro
			if(position <= capacity - Record::getMinSize())
				recordSize = bytesString.readAsInt(position);
			else
				recordSize = -1;
		}
	}
	return success;
}
Exemplo n.º 3
0
Node* BPlusTree::hidratateNode(int numeroDeNodo) {

	ByteString byteStr = this->fileBlockManager->readBlock(numeroDeNodo);
	if (byteStr.isEmpty()) {
		return NULL;
	} else {
		int nivel = byteStr.readAsInt(0);
		if (nivel == 0) {
			LeafNode *nuevoNodoHoja = createLeafNode();
			nuevoNodoHoja->Hidratate(byteStr);
			nuevoNodoHoja->number = numeroDeNodo;
			return nuevoNodoHoja;
		} else {
			InnerNode *nuevoNodoInterior = createInnerNode(nivel);
			nuevoNodoInterior->Hidratate(byteStr);
			nuevoNodoInterior->number = numeroDeNodo;
			return nuevoNodoInterior;
		}
	}
}
Node* ClassifBPlusTree::hidratateNode(int nodeNumber)
{
	int block = fileBlockNodeMapper->getBlock(nodeNumber);
	ByteString byteStr = this->fileBlockManager->readBlock(block);
	if (byteStr.isEmpty()) {
		return NULL;
	} else {
		int nivel = byteStr.readAsInt(0);
		if (nivel == 0) {
			LeafNode *nuevoNodoHoja = createLeafNode();
			nuevoNodoHoja->Hidratate(byteStr);
			nuevoNodoHoja->number = nodeNumber;
			return nuevoNodoHoja;
		} else {
			InnerNode *nuevoNodoInterior = createInnerNode(nivel);
			nuevoNodoInterior->Hidratate(byteStr);
			nuevoNodoInterior->number = nodeNumber;
			return nuevoNodoInterior;
		}
	}
}
Exemplo n.º 5
0
bool Book::Hidratate(ByteString & bookByte){
	int position = 0;

	// id
	this->id = bookByte.readAsInt(position);
	position += sizeof(int);

	//  author
	size_t authorSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->author = (bookByte.read(position, authorSize)).toString();
	position += authorSize;

	// editorial
	size_t editorialSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->editorial = (bookByte.read(position, editorialSize)).toString();
	position += editorialSize;

	// title
	size_t titleSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->title = (bookByte.read(position, titleSize)).toString();
	position += titleSize;

	// text
	size_t textSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->text = (bookByte.read(position, textSize)).toString();
	position += textSize;

	// wordcount
	this->wordCount = bookByte.readAsInt(position);

	return true;
}
Exemplo n.º 6
0
void BPlusTree::exportNode(ofstream& salida, Node* unNodo, int tabulacion,bool keyText,bool textContent) {

	if (unNodo->isLeaf()) {

		LeafNode *unNodoHoja = static_cast<LeafNode*> (unNodo);
		salida << endl;
		for(int i = 0 ; i < tabulacion ; i++)
			salida << "  ";

		salida << "Numero: " << unNodoHoja->number << "  Nivel: " << unNodoHoja->level << "  Cant.Elem: " << unNodoHoja->keyMount
			   << "  Esp.Libre: " << TreeConstraits::getEfectiveSizeNode() - unNodoHoja->occupiedSpace << "  Hoja.Sig: " << unNodoHoja->nextLeaf << endl;

		for (int posicion = 0; posicion < unNodoHoja->keyMount; ++posicion) {

			for(int i = 0 ; i < tabulacion + 4 ; i++)
						salida << "  ";

			salida << "(";

			Key unaClave = unNodoHoja->keys[posicion];
			if(keyText)
			{
				salida << unaClave.toString();
			}
			else
			{
				ByteString clave(unaClave.toString());
				salida << Utility::toString(clave.readAsInt(0));
			}

			salida << ";";
			ByteString unDato = unNodoHoja->byteData[posicion];
			if(textContent)
			{
				salida << unDato.toString();
			}
			else
			{
				salida << Utility::intToString(unDato.readAsInt(0));
			}

			salida << ")";

			salida << (unaClave.getSize() + unDato.getSize() + TreeConstraits::getControlSizeRecord()) << endl;
		}

		salida << endl;

	} else {

		InnerNode *unNodoInterior = static_cast<InnerNode*> (unNodo);
		salida << endl << endl;
		for(int i=0; i<tabulacion ; i++)
			salida << "  ";

		salida << "Numero: " << unNodoInterior->number << "  Nivel: " << unNodoInterior->level << "  Cant.Elem: " << unNodoInterior->keyMount
			   << "  Esp.Libre: " << TreeConstraits::getEfectiveSizeNode() - unNodoInterior->occupiedSpace << endl;

		for (int posicion = 0; posicion <= unNodoInterior->keyMount; ++posicion) {

			if (posicion < unNodoInterior->keyMount) {
				Key unaClave = unNodoInterior->keys[posicion];

				for(int i=0; i<(tabulacion+1) ; i++)
					salida << "  ";
				salida << "(";
				if(keyText)
				{
					salida << unaClave.toString();
				}
				else
				{
					ByteString clave(unaClave.toString());
					salida << Utility::toString(clave.readAsInt(0));
				}
				salida << ")";
				salida << unaClave.getSize();
				salida << "  ";
				salida << unNodoInterior->getSons()[posicion] << "   ";
			}
		}
		for (int posicion = 0; posicion <= unNodoInterior->keyMount; ++posicion) {
			Node *hijo = hidratateNode(unNodoInterior->sons[posicion]);
			exportNode(salida, hijo, tabulacion + 2,keyText,textContent);
			if (hijo)
				freeNodeMemory(hijo);
		}
		for(int i=0; i<tabulacion ; i++)
			salida << "  ";
		salida << endl;
	}
}
void ClassifBPlusTree::exportNode(ofstream& salida, Node* unNodo, int tabulacion,bool keytext, bool textContent) {

	if (unNodo->isLeaf()) {

		LeafNode *unNodoHoja = static_cast<LeafNode*> (unNodo);
		salida << endl;
		for(int i = 0 ; i < tabulacion ; i++)
			salida << "  ";

		salida << "Numero: " << unNodoHoja->number << "  Nivel: " << unNodoHoja->level << "  Cant.Elem: " << unNodoHoja->keyMount << "  Esp.Libre: " << TreeConstraits::getEfectiveSizeNode() - unNodoHoja->occupiedSpace << "  Hoja.Sig: " << unNodoHoja->nextLeaf << endl;

		for (int posicion = 0; posicion < unNodoHoja->keyMount; ++posicion) {

			for(int i = 0 ; i < tabulacion + 4 ; i++)
						salida << "  ";

			salida << "(";

			Key unaClave = unNodoHoja->keys[posicion];
			if(keytext)
			{
				salida << unaClave.toString();
			}
			else
			{
				ByteString clave(unaClave.toString());
				if(clave.getSize()==(2*sizeof(int)))
				{
					salida << Utility::toString(clave.readAsInt(0));
					salida << "-";
					salida << Utility::toString(clave.readAsInt(sizeof(int)));
				}
				else
					salida << Utility::toString(clave.readAsInt(0));
			}

			salida << ";";

			ByteString unDato = unNodoHoja->byteData[posicion];

			int idBlock = unDato.readAsInt(0);
			string datoString = Utility::intToString(idBlock);
			salida << datoString;

			salida << ")";

			salida << (unaClave.getSize() + unDato.getSize() + TreeConstraits::getControlSizeRecord()) << endl;

			for(int i = 0 ; i < tabulacion + 4 ; i++)
								salida << "  ";

			ListofID listOfID(this->fileBlockManager,idBlock);
			list<int> listOfInt = listOfID.getListID();
			list<int>::iterator it;

			int id;
			//int count = 0;
			ByteString bs;
			unsigned int i = 0;
			for(it=listOfInt.begin();it!=listOfInt.end();++it)
			{
				i++;
				id = *it;
				bs.insertLast(Utility::intToString(id));
				bs.insertLast(" ");
				if((i == listOfInt.size()) || (bs.toString().size() >80))
				{
					salida << bs.toString();
					salida << endl;
					if(i != listOfInt.size())
					{
						for(int i = 0 ; i < tabulacion + 4 ; i++)
											salida << "  ";
					}
					bs.clean();
				}
			}

		}

	} else {

		InnerNode *unNodoInterior = static_cast<InnerNode*> (unNodo);
		salida << endl << endl;
		for(int i=0; i<tabulacion ; i++)
			salida << "  ";

		salida << "Numero: " << unNodoInterior->number << "  Nivel: " << unNodoInterior->level << "  Cant.Elem: " << unNodoInterior->keyMount
			   << "  Esp.Libre: " << TreeConstraits::getEfectiveSizeNode() - unNodoInterior->occupiedSpace << endl;

		for (int posicion = 0; posicion <= unNodoInterior->keyMount; ++posicion) {

			if (posicion < unNodoInterior->keyMount) {
				Key unaClave = unNodoInterior->keys[posicion];

				for(int i=0; i<(tabulacion+1) ; i++)
					salida << "  ";
				salida << "(";
				if(keytext)
				{
					salida << unaClave.toString();
				}
				else
				{
					ByteString clave(unaClave.toString());
					salida << Utility::toString(clave.readAsInt(0));
				}
				salida << ")";
				salida << unaClave.getSize();
				salida << "  ";
				salida << unNodoInterior->getSons()[posicion] << "   ";
			}
		}
		for (int posicion = 0; posicion <= unNodoInterior->keyMount; ++posicion) {
			Node *hijo = hidratateNode(unNodoInterior->sons[posicion]);
			exportNode(salida, hijo, tabulacion + 2,keytext,textContent);
			if (hijo)
				freeNodeMemory(hijo);
		}
		for(int i=0; i<tabulacion ; i++)
			salida << "  ";
		salida << endl;
	}
}