Ejemplo n.º 1
0
void TestFlacon::testOutFormatEncoderArgs()
{
    QFETCH(QString, formatId);
    QFETCH(SettingsValues, config);
    QFETCH(QString, expected);

    applySettings(config);

    foreach (OutFormat *format, OutFormat::allFormats())
    {
        if (format->id() != formatId)
            continue;

        Disk *disk = standardDisk();
        QStringList args = format->encoderArgs(disk->track(0), "OutFile.wav");

        QString result = args.join(" ");
        if (result != expected)
        {
            QString msg = QString("Compared values are not the same\n   Format   %1\n   Actual:   %2\n   Expected: %3").arg(
                        formatId,
                        result,
                        expected);
            QFAIL(msg.toLocal8Bit());
        }
        return;
    }

    FAIL(QString("Unknown format \"%1\"").arg(formatId).toLocal8Bit());
}
Ejemplo n.º 2
0
void shiftLeft(int start, int end, int diskCount, Queue<int> board[])
{
    int onePeg = start - 1;
    int otherPeg = end - 1;
    int steps = 0;
    double totalSteps = pow(2.0, (double)diskCount) - 1;
    Disk test;
    while(steps < totalSteps)
    {
        bool cases = (board[onePeg].isEmpty() || board[onePeg].peek() > board[otherPeg].peek()) ? true : false;
        makeValidMove(board[onePeg], board[otherPeg]);
        test.displayQueue(19, 20, board[0]);
        test.displayQueue(19, 40, board[1]);
        test.displayQueue(19, 60, board[2]);
        delay_output(DELAY);
        if(cases)
            board[onePeg].prioritize(board[onePeg].seek(board[onePeg].size()-1));   
        else
            board[otherPeg].prioritize(board[otherPeg].seek(board[otherPeg].size()-1));
        onePeg = (onePeg == 2) ? 0 : onePeg + 1;
        otherPeg = (otherPeg == 2) ? 0 : otherPeg + 1;
        steps++;
        test.displayQueue(19, 20, board[0]);
        test.displayQueue(19, 40, board[1]);
        test.displayQueue(19, 60, board[2]);
        delay_output(DELAY);
    }
}
Ejemplo n.º 3
0
/**
 * @brief BTRecordFile::readRecordFromDiskTest
 * @param pDisk
 * @param pRecordID
 * Hace la lectura de un registro en la RAM
 */
void BTRecordFile::readRecordFromDiskTest(Disk pDisk, unsigned short pRecordID)
{
    const char *padre = pDisk.read(this->_metadataPtr->getFirstRecordPos(), 7);
    const char *hizq = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 8, 7);
    const char *hder = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 16, 7);
    std::string father(padre);          // obtiene el padre
    std::string HI(hizq);               // obtiene el hijo izq
    std::string HD(hder);               // obtiene el hijo der
    unsigned short _sizeCounter = this->_metadataPtr->getFirstRecordPos() + 24;       // inicio de la data
    DLL<IRecordDataType*> *tmp1 = _metadataPtr->getRecordStruct();
    DLLNode<IRecordDataType*> *tmp = tmp1->getHeadPtr();
    const char *data;

    cout << "Binario " << father << " " << HI << " " << HD << endl;
    std::string P = _conversion->binaryToDecimal(father);
    std::string PHI = _conversion->binaryToDecimal(HI);
    std::string PHD = _conversion->binaryToDecimal(HD);
    cout << P << " " << PHI << " " << PHD << " ";
    while (tmp != nullptr) {
        data = (dynamic_cast<RecordDataType<char>*>(tmp->getData()))->getDataPtr();
        const char *DATO = pDisk.read(_sizeCounter, 7);
        std::string DATOSTR(DATO);       // obtiene el padre
        _sizeCounter += 8;
        cout << sortUserDataFromDisk(DATOSTR, *data) << endl;
        tmp = tmp->getNextPtr();
    }
}
Ejemplo n.º 4
0
string diskTest()
{
	Disk * disk = new Disk(1000000000, "test", false);
	
	if(disk->isReadOnly()) return "readonly check failed";
	if(disk->getCapacity() != 1000000000) return "capacity check failed";
	if(!disk->getRootFolder()) return "root folder was not generated";
	if(disk->getRootFolder()->getName() != "test") return "root folder name check failed";
	
	File * infected = new File();
	Virus * virus = new Virus();
	
	infected->setVirus(virus);
	disk->getRootFolder()->addFile(infected);
	
	Disk * backup = new Disk(1000000000, "b", true);
	if(!disk->backup(backup)) return "backup failed";
	
	vector<pair<Folder *, int>> folds;
	backup->getRootFolder()->getAllFoldersRecursively(folds);
	if(!folds.size()) return "backup was not created";
	
	delete disk;
	delete backup;
	
	return "";
}
Ejemplo n.º 5
0
int TrackViewModel::rowCount(const QModelIndex &parent) const
{
    if (!parent.isValid())
        return project->count();

    QObject *obj = static_cast<QObject*>(parent.internalPointer());
    Disk *disk = qobject_cast<Disk*>(obj);
    if(disk)
        return disk->count();

    return 0;
}
Ejemplo n.º 6
0
bool IsDeepThoughtDisk (Disk &disk, const Sector *&sector)
{
	// Try the primary catalogue location on cyl 0
	if (!disk.find(Header(0, 0, 0, SizeToCode(4096)), sector))
	{
		// Try the backup location on cyl 1
		if (!disk.find(Header(1, 0, 0, SizeToCode(4096)), sector))
			return false;
	}

	return true;
}
Ejemplo n.º 7
0
Archivo: core.cpp Proyecto: ravitx/608
void selectFromTable(bool dis, string attributes, string tabs, string whereCondition, string orderBy) {
	
	int disk0 = disk.getDiskIOs();
	vector<string> tableNames = split(tabs, ',');
	vector<string> attributeNames = split(attributes, ',');
	string tableName;
	if(validate(tableNames)) return;
	if(tableNames.size()==1) {
		Relation *relation = schemaManager.getRelation(tableNames[0]);
		string pName = projection(attributeNames, tableNames[0], whereCondition);
		string d;
		relation = schemaManager.getRelation(pName);
		if(dis) {
			d = distinct(pName);
			relation = schemaManager.getRelation(d);	
		}
		cout<<*relation<<endl;
		if(!(attributeNames.size()==1 && attributeNames[0]=="*" && whereCondition.empty()))
		schemaManager.deleteRelation(pName);
		if(dis)
		schemaManager.deleteRelation(d);
	}
	else {
		vector<string>::iterator it;
		vector<string> projections;
		if(tableNames.size()==2) {
			string ptemp = crossJoin(attributeNames, tableNames[0], tableNames[1], whereCondition, false);
			string d;
			Relation *relation = schemaManager.getRelation(ptemp);
			if(dis) {
				d = distinct(ptemp);
				relation = schemaManager.getRelation(d);
			} 
			cout<<*relation<<endl;
			schemaManager.deleteRelation(ptemp);
			if(dis)
			schemaManager.deleteRelation(d);
		}
		else {
			bool flag =true;
			vector<string> blah;
			string str = crossJoin(blah, tableNames[0],tableNames[1], whereCondition, false);
			for(int i=2;i<tableNames.size();i++) {
				str = crossJoin(blah, str, tableNames[i], whereCondition, true);
			}
			Relation *relation = schemaManager.getRelation(str);
			cout<<*relation<<endl;
			schemaManager.deleteRelation(str);
		}
	}
	cout<<"No. of disk IO's used for this opertaion are "<<disk.getDiskIOs()-disk0<<endl;
}
Ejemplo n.º 8
0
Assembly *GraspGLObjects::CreateTorso( void ) {

	Assembly *torso = new Assembly();
	Slab *slab = new Slab( torso_shape[X], torso_shape[Y], torso_shape[Z] );
	slab->SetColor( 0.1f, 0.4f, 0.0f );
	torso->AddComponent( slab );
	Disk *disk = new Disk( 50.0 );
	disk->SetPosition( 0.0, 0.0, -40.0 );
	disk->SetColor( 1.0f, 0.7f, 0.0f );
	torso->AddComponent( disk );
	return torso;

}
Ejemplo n.º 9
0
Assembly *GraspGLObjects::CreateIndicator( Texture *texture, double hole_radius ) {

	Assembly	*assembly = new Assembly();
	Disk		*surface;

	surface = new Disk( 120.0, hole_radius, 128 );
	surface->SetTexture( texture );
	assembly->AddComponent( surface );
	assembly->SetColor( 0.9, 0.9, 1.0, hmdTransparency );
	assembly->Disable();

	return assembly;
}
Ejemplo n.º 10
0
Device* DiskDeviceClass::CreateDevice(DeviceClass* deviceClass, SP_DEVINFO_DATA deviceInfoData, CString path)
{
	Disk* disk = new Disk(deviceClass, deviceInfoData.DevInst, path, m_pLibHandle);

	// Only Create USB Disks
	if ( disk->IsUsb() )
	{
		return disk;
	}

	delete disk;

	return NULL;
}
Ejemplo n.º 11
0
// draws solid Disk and wire Disk together. The wire color is always black
void drawDisk(vec4 color)
{
    glUniform4fv( model_color, 1,color );
    myDisk.draw();
    glUniform4fv( model_color, 1,vec4(0,0,0,1) );
    myWireDisk.draw();
}
Ejemplo n.º 12
0
bool WillCollide(float a_dt, 
                 Disk const & a_disk, 
                 vec3 const & a_vel, 
                 Line const & a_line, 
                 float a_lineLength, 
                 float & a_outTime)
{
  Dg::R2::FPCDiskLine<float> fpc;
  Dg::R2::FPCDiskLine<float>::Result result_fpc = fpc(a_disk, a_vel, a_line, vec3::ZeroVector());

  bool willCollide = result_fpc.code == Dg::QC_Intersecting;
  willCollide = willCollide && (result_fpc.t <= a_dt);
  willCollide = willCollide && (result_fpc.t >= 0.0f);
  if (willCollide)
  {
    vec3 p = a_disk.Center() + result_fpc.t * a_vel;

    Dg::R2::CPPointLine<float> cp;
    Dg::R2::CPPointLine<float>::Result result_cp = cp(p, a_line);

    willCollide = willCollide && (result_cp.u <= a_lineLength);
    willCollide = willCollide && (result_cp.u >= 0.0f);
    a_outTime = result_fpc.t;
  }

  return willCollide;
}
Ejemplo n.º 13
0
void Async::disk_transfer(
    Disk          disk,
    const Dirent& ent,
    on_write_func write_func,
    on_after_func callback,
    const size_t  CHUNK_SIZE)
{
  typedef delegate<void(size_t)> next_func_t;
  auto next = std::make_shared<next_func_t> ();
  auto weak_next = std::weak_ptr<next_func_t>(next);

  *next = next_func_t::make_packed(
  [weak_next, disk, ent, write_func, callback, CHUNK_SIZE] (size_t pos) {

    // number of write calls necessary
    const size_t writes = roundup(ent.size(), CHUNK_SIZE);

    // done condition
    if (pos >= writes) {
      callback(fs::no_error, true);
      return;
    }
    auto next = weak_next.lock();
    // read chunk from file
    disk->fs().read(
      ent,
      pos * CHUNK_SIZE,
      CHUNK_SIZE,
      fs::on_read_func::make_packed(
      [next, pos, write_func, callback] (
          fs::error_t  err,
          fs::buffer_t buffer)
      {
        debug("<Async> len=%lu\n", buffer->size());
        if (err) {
          printf("%s\n", err.to_string().c_str());
          callback(err, false);
          return;
        }

        // call write callback with data
        write_func(
          buffer,
          next_func::make_packed(
          [next, pos, callback] (bool good)
          {
            // if the write succeeded, call next
            if (LIKELY(good))
              (*next)(pos+1);
            else
              // otherwise, fail
              callback({fs::error_t::E_IO, "Write failed"}, false);
          })
        );
      })
    );
  });
  // start async loop
  (*next)(0);
}
Ejemplo n.º 14
0
// OpenGL initialization
void
init()
{
    program = InitShader( "/home/GONZAGA/yerion/Documents/ACAR/LgsparksCar/vertex.glsl", "/home/GONZAGA/yerion/Documents/ACAR/LgsparksCar/fragment.glsl" );
    glUseProgram( program );

    // Uniform variables: color and viewing parameters
    model_color = glGetUniformLocation( program, "model_color" );
    model_view = glGetUniformLocation( program, "model_view" );
    projection = glGetUniformLocation( program, "projection" );

    // Create multiple vertex array objects using an array of vertex array objects
    GLuint vao[6];
    glGenVertexArrays( 6, vao );

    //********  Create the VAOs ************//

    myCube.createVAO(vao[0],program);
    myWireCube.createVAO(vao[1],program);
    myDisk.createVAO(vao[2],program);
    myWireDisk.createVAO(vao[3],program);
    myCylinder.createVAO(vao[4],program);
    myWireCylinder.createVAO(vao[5],program);

    glUniform4fv( model_color, 1,vec4(1,1,1,1) ); // set color to white initially

    glLineWidth(4);
    glEnable( GL_DEPTH_TEST );
    glClearColor( 0.5, 0.5, 0.5, 1.0 );
}
Ejemplo n.º 15
0
//----------------------------------------------------------------------------------------------------------------------  
void SMCAgentViz::init() 
{ 
  NodeGroup::init(); 
  
  m_agentDisk = new Disk(m_agent->getRadius(), m_agent->getRadius()/2, 32);
  m_agentDisk->m_color = ci::Vec4f(0,0,0,1);
  m_agentDisk->createGeometry();
  m_children.push_back(m_agentDisk);
  
  Disk* innerDisk = new Disk(m_agent->getRadius()/2.0, 0, 32);
  //innerDisk->translate(cinder::Vec4f(0,0,0,0));
  innerDisk->m_color = ci::Vec4f(0,0,0, 1);
  innerDisk->createGeometry();
  m_children.push_back(innerDisk);
  
  m_paused = false;
}
Ejemplo n.º 16
0
void
dump_double_indirect_stream(Disk& disk, bfs_inode* node, bool showOffsets)
{
	if (node->data.max_double_indirect_range == 0)
		return;

	int32 bytes = node->data.double_indirect.length * disk.BlockSize();
	int32 count = bytes / sizeof(block_run);
	block_run runs[count];

	off_t offset = node->data.max_indirect_range;

	ssize_t bytesRead = disk.ReadAt(disk.ToOffset(node->data.double_indirect),
		(uint8*)runs, bytes);
	if (bytesRead < bytes) {
		fprintf(stderr, "couldn't read double indirect runs: %s\n",
			strerror(bytesRead));
		return;
	}

	puts("double indirect stream:");

	for (int32 i = 0; i < count; i++) {
		if (runs[i].IsZero())
			return;

		printf("  double_indirect[%02" B_PRId32 "]       = ", i);

		dump_block_run("", runs[i], "");

		int32 indirectBytes = runs[i].length * disk.BlockSize();
		int32 indirectCount = indirectBytes / sizeof(block_run);
		block_run indirectRuns[indirectCount];

		bytesRead = disk.ReadAt(disk.ToOffset(runs[i]), (uint8*)indirectRuns,
			indirectBytes);
		if (bytesRead < indirectBytes) {
			fprintf(stderr, "couldn't read double indirect runs: %s\n",
				strerror(bytesRead));
			continue;
		}

		for (int32 j = 0; j < indirectCount; j++) {
			if (indirectRuns[j].IsZero())
				break;

			printf("                     [%04" B_PRId32 "] = ", j);

			char buffer[256];
			if (showOffsets)
				snprintf(buffer, sizeof(buffer), " %16" B_PRIdOFF, offset);
			else
				buffer[0] = '\0';

			dump_block_run("", indirectRuns[j], buffer);

			offset += indirectRuns[j].length * disk.BlockSize();
		}
	}
}
Ejemplo n.º 17
0
Archivo: main.cpp Proyecto: ssidko/DMT
int _tmain(int argc, _TCHAR* argv[])
{
	BOOL ret = FALSE;
	DiskMaster *dm = NULL;
	DiskMasterManager *dm_mgr = DM::GetDiskMasterManager();

	int x = 0;
	ULONGLONG size = 0;
	Disk *disk = NULL;
	if (dm_mgr->Rescan()) {
		dm = dm_mgr->GetDiskMaster(0);
		if (dm->Open()) {
			disk = dm->Rescan(kSata1);
			size = disk->Size();
			size = disk->NativeSize();
			disk->SetSize(size);
			size = disk->Size();
			
			x++;
			dm->Close();
		}		
		x--;
	}

	_tprintf(_T("\nPress any key for exit ..."));
	_getch();

	////////////////////////////////////////////////////////
	// Message loop
	//
	//MSG msg;
	//memset(&msg, 0x00, sizeof(MSG));
	//while (ret = ::GetMessage(&msg, NULL, 0, 0)) {
	//	if (ret == -1) {
	//		return ::GetLastError();
	//	}
	//	else {
	//		TranslateMessage(&msg); 
	//		DispatchMessage(&msg); 
	//	}
	//}

	return 0;
}
Ejemplo n.º 18
0
MeterStick::MeterStick( void ) {

  double stick_radius = 25.0;

  Cylinder *cylinder;
  Disk *disk;

  cylinder = new Cylinder( stick_radius, stick_radius, 200.0 );
  cylinder->SetColor( RED );
  AddComponent( cylinder );
  cylinder = new Cylinder( stick_radius, stick_radius, 200.0 );
  cylinder->SetOffset( 0.0, 0.0, 200.0 );
  cylinder->SetColor( WHITE );
  AddComponent( cylinder );
  cylinder = new Cylinder( stick_radius, stick_radius, 200.0 );
  cylinder->SetOffset( 0.0, 0.0, 400.0 );
  cylinder->SetColor( RED );
  AddComponent( cylinder );
  cylinder = new Cylinder( stick_radius, stick_radius, 200.0 );
  cylinder->SetOffset( 0.0, 0.0, 600.0 );
  cylinder->SetColor( WHITE );
  AddComponent( cylinder );
  cylinder = new Cylinder( stick_radius, stick_radius, 200.0 );
  cylinder->SetOffset( 0.0, 0.0, 800.0 );
  cylinder->SetColor( RED );
  AddComponent( cylinder );

  cylinder = new Cylinder( stick_radius / 2.0, stick_radius / 2.0, 100.0 );
  cylinder->SetAttitude( 90.0, j_vector );
  cylinder->SetColor( BLACK );
  AddComponent( cylinder );

  cylinder = new Cylinder( stick_radius / 2.0, stick_radius / 2.0, 100.0 );
  cylinder->SetAttitude( 90.0, j_vector );
  cylinder->SetPosition( 0.0, 0.0, 1000.0 - stick_radius );
  cylinder->SetColor( BLACK );
  AddComponent( cylinder );

  disk = new Disk( stick_radius );
  disk->SetPosition( 0.0, 0.0, 990.0 );
  disk->SetColor( RED );
  AddComponent( disk );

}
Ejemplo n.º 19
0
QModelIndex TrackViewModel::index(int row, int column, const QModelIndex &parent) const
{
    if (!hasIndex(row, column, parent))
        return QModelIndex();


    if (parent.internalPointer() == project)
        return createIndex(row, column, project->disk(row));

    QObject *obj = static_cast<QObject*>(parent.internalPointer());
    Disk *disk = qobject_cast<Disk*>(obj);
    if(disk)
        return createIndex(row, column, disk->track(row));
    else
        return createIndex(row, column, project->disk(row));


    return QModelIndex();
}
Ejemplo n.º 20
0
FAT::FAT(Disk& disk) : disk(disk)
{
  // Allocate the FAT entries

  entry = new int[disk.num_blocks()];

  // Populate the FAT from Disk

  retrieve();
}
Ejemplo n.º 21
0
block_run
parseBlockRun(Disk &disk, char *first, char *last)
{
	char *comma;

	if (last) {
		return block_run::Run(atol(first), atol(last), 1);
	} else if ((comma = strchr(first, ',')) != NULL) {
		*comma++ = '\0';
		return block_run::Run(atol(first), atol(comma));
	}

	return disk.ToBlockRun(atoll(first));
}
Ejemplo n.º 22
0
void CueCreator::initGlobalTags()
{
    QStringList tagNames;
    tagNames << TAG_GENRE;
    tagNames << TAG_DATE;
    tagNames << TAG_PERFORMER;
    tagNames << TAG_SONGWRITER;
    tagNames << TAG_ALBUM;

    Track *firstTrack = mDisk->track(0);

    foreach(QString tagName, tagNames)
    {
        QString value = firstTrack->tag(tagName);

        for (int i=1; i<mDisk->count(); ++i)
        {
            if (mDisk->track(i)->tag(tagName) != value)
                value = "";
        }

        mGlobalTags.insert(tagName, value);
    }
Ejemplo n.º 23
0
void LongScheduler::moveToRAM()
{
	ofstream longSchedLog_RAM;
	longSchedLog_RAM.open("longSchedLog-RAM.txt", fstream::out);

	int j = current_process;

	// write the processes into RAM
	for(j; j<=30; j++)//should loop 30 times for the number of totalt processes
		{

			
			longSchedLog_RAM << "PID: " << j << endl;
			longSchedLog_RAM << "Free Space in RAM: " << ram.howManyFreeBytes() << endl;

			if(((pcb_table.getCodeSize(j) + 44)*8 ) < ram.howManyFreeBytes())//check to make sure that there is enough room to write the whole process to RAM
			{

				longSchedLog_RAM << "Process size: " << ((pcb_table.getCodeSize(j)+44)*8) << endl;

				for(int k = 0; k <= (pcb_table.getCodeSize(j)+44); k++)//loop to write the entire process to RAM
				{
					ram.writeNBytesToNextFreeAdr(disk1.readLine(k).c_str(),8);//writing process to RAM
				}
				
				
				longSchedLog_RAM << "Successfully transferred process " << j << " into RAM" << endl;
				longSchedLog_RAM << "Amount of space left in RAM: " << ram.howManyFreeBytes() << endl;

				//move pid for process that was just written to RAM from the new queue to the running queue
				running_queue.push(new_queue.front());
				pcb_table.setStatus(j,RUNNING);//to update the status of the process in the PCB
				longSchedLog_RAM << "Successfully added process to running queue" << endl;

				//remove pid for process that was just written to RAM from new queue
				new_queue.pop();
				longSchedLog_RAM << "Successfully removed process from new queue" << endl << endl;
			}
			else
			{
				
				current_process = j;// this will be so that the next time the moveToRAM functon is called, it will know where to start so
				                    // not to duplicate the processes
				return;
			}
		}

	longSchedLog_RAM.close();//close ostream
}
Ejemplo n.º 24
0
void
collectFiles(Disk &disk)
{
	Directory *root = (Directory *)Inode::Factory(&disk,disk.Root());

	puts("Collecting files (this will take some time)...");

	if (root == NULL || root->InitCheck() < B_OK)
	{
		fprintf(stderr,"  Could not open root directory!\n");
		return;
	}
	collectFiles(disk,root);

	printf("  %7Ld files found.\n",gCount);

	delete root;
}
Ejemplo n.º 25
0
Archivo: core.cpp Proyecto: ravitx/608
void insertIntoTable(string tableName, vector<string> fieldNames, vector<string> fieldValues) {

        if(!schemaManager.relationExists(tableName)) { 
		cout<<"Illegal Tablename"<<endl;
		return;
	}	
	Relation *relation = schemaManager.getRelation(tableName);
	Tuple tuple = relation->createTuple();
	Schema schema = relation->getSchema();
 	vector<string>::iterator it,it1;	
	for(it = fieldNames.begin(),it1 = fieldValues.begin();it!=fieldNames.end();it++, it1++) {
		string str=*it,str1=*it1;
		str = removeSpaces(str);
		int type = schema.getFieldType(str);
		if(!type) {
			str1 = removeSpaces(str1);
			if(isNumber(str1)) {
				tuple.setField(str,stoi(str1));
			}
			else {
				cout<<"Data type is not supported\n";
				return;
			}
		} 
		else {
			regex exp("\\ *\"(.*)\"");
			cmatch match;
			if(regex_match(str1.c_str(),match,exp)) {
				str1 = match[1];
				if(str1.length()>20) {
					cout<<"Data type is not supported\n";
					return;
				}
				else tuple.setField(str,str1);
			}
			else {
				cout<<"Data type is not supported\n";
				return;
			}
		}
	}
	insertTuple(tableName, tuple);
	cout<<disk.getDiskIOs()<<endl;
}
Ejemplo n.º 26
0
void
checkIndexForNonExistingFiles(Disk &disk,BPlusTree &tree)
{
	char name[B_FILE_NAME_LENGTH];
	uint16 length;
	off_t offset;

	while (tree.GetNextEntry(name,&length,B_FILE_NAME_LENGTH,&offset) == B_OK)
	{
		name[length] = 0;
		block_run run = disk.ToBlockRun(offset);
		if (!gHashtable.Contains(&run))
		{
			printf("  inode at (%ld, %d), offset %Ld, doesn't exist!",run.allocation_group,run.start,offset);
			switch (tree.Type())
			{
				case BPLUSTREE_STRING_TYPE:
					printf(" (string = \"%s\")",name);
					break;
				case BPLUSTREE_INT32_TYPE:
					printf(" (int32 = %ld)",*(int32 *)&name);
					break;
				case BPLUSTREE_UINT32_TYPE:
					printf(" (uint32 = %lu)",*(uint32 *)&name);
					break;
				case BPLUSTREE_INT64_TYPE:
					printf(" (int64 = %Ld)",*(int64 *)&name);
					break;
				case BPLUSTREE_UINT64_TYPE:
					printf(" (uint64 = %Lu)",*(uint64 *)&name);
					break;
				case BPLUSTREE_FLOAT_TYPE:
					printf(" (float = %g)",*(float *)&name);
					break;
				case BPLUSTREE_DOUBLE_TYPE:
					printf(" (double = %g)",*(double *)&name);
					break;
			}
			putchar('\n');
		}
	}
}
Ejemplo n.º 27
0
void LongScheduler::moveToDisk()
{
	ofstream longSchedLog_Disk;
	longSchedLog_Disk.open("longSchedLog-Disk.txt", fstream::out);
	
		//check PCB for terminated processes
	for(int i = 1; i<=30; i++)
	{

	longSchedLog_Disk << "PID: " << i << endl;
	longSchedLog_Disk << "Amount of free space in RAM: " << ram.howManyFreeBytes() << endl;

		//if process is terminated, continue to remove process information from RAM
		if(pcb_table.getStatus(i) == TERMINATED)
		{
			longSchedLog_Disk << "Terminated PID: " << i << endl;

			//remove process from RAM int Disk
			for(int j = 0; j < (pcb_table.getCodeSize(i) + 44); j++)
			{ 
				int ram_line_number = pcb_table.getCodeStartRamAddress(i) + j;
				int disk_line_number = pcb_table.getCodeDiskAddress(i)+j;
				disk1.writeLine(ram.readCharLine(ram_line_number),	disk_line_number);

				longSchedLog_Disk << "Process Sucessfully written to Disk" << endl;

			}
		}

		terminated_queue.pop();
		longSchedLog_Disk << "Process Successfully removed from terminated queue." << endl;


		//reallocate space in RAM for removed process
		//Troy can you write a function to allow for me to pass the current process number 
		//and the function will allocate the appropriate amount of space into RAM

		longSchedLog_Disk << "Amount of free space in RAM: " << ram.howManyFreeBytes() << endl << endl;
	}

	longSchedLog_Disk.close();
}
Ejemplo n.º 28
0
int main(int argc, char ** argv){
	// Initialize the memory, disk and the schema manager
	MainMemory mem;
	Disk disk;
	//cout << "The memory contains " << mem.getMemorySize() << " blocks" << endl;
	SchemaManager schema_manager(&mem,&disk);
	disk.resetDiskIOs();
	disk.resetDiskTimer();
	resetFreeBlocks();
	clock_t start_time;
	start_time=clock();

	//=======================Read Input=========================
	ifstream input;
	bool interactive_mode = false;
	assert(argv && argc >= 1);

	cout<<endl;
	cout<<"                   ";
	cout<<"============================================="<<endl<<endl;
	cout<<"                   ";
	cout<<"Welcome to TinySQL Database Management System"<<endl<<endl;
	cout<<"                   ";
	cout<<"Develped by Jimmy Jin & Tony Wang, 12/6/2016"<<endl<<endl;
	cout<<"                   ";
	cout<<"============================================="<<endl<<endl;


	if (argc == 1){
		cout<<endl<<"Entering Interactive Mode: Type query and ENTER to execute; Type EXIT to exit the program."<<endl<<endl;
		interactive_mode = true;
	}
	else if (argc == 2){
		string filename = argv[1];
		input.open(filename.c_str());
		if (!input.is_open()){
			cout<<"Cannot Open file: "<<filename<<endl;
			return 0;
		}
	}
	else{
		cout<<"To use TinySQL to read input file, type:   ";
		cout<<"./Tiny <filename>"<<endl; 
		cout<<"To use TinySQL in Interactive Mode, type:  ";
		cout<<"./Tiny"<<endl;
		return 0;
	}
	unsigned long int ios = 0;
	double time = 0;
	string line;
	vector<string> words;

	// for each command line
	while(1){
		if (interactive_mode){
			cout<<">>";
			char console_input[1000];
			cin.getline(console_input, sizeof(console_input));
			line = string(console_input);
			if (line == "EXIT") break;
			cout<<endl;
		}
		else{
			if (!getline(input, line)) break;
			cout<<line<<endl;	
		}
		if(line[0] == '#')	continue;
		if(line.size() == 0)	continue;
		// extract each word into vector words
		words = splitBy(line," ");

		// prepare memory
		resetFreeBlocks();

		if (words[0] == "CREATE"){
			Create(words, schema_manager, mem);
		}
		else if (words[0] == "DROP"){
			string relation_name = words[2];
			schema_manager.deleteRelation(relation_name);
		}
		else if (words[0] == "INSERT"){
			Insert(words, line, schema_manager, mem);
			//	cout<< *(schema_manager.getRelation(relation_name))<<endl;
		}
		else if (words[0] == "DELETE"){
			Delete(words, schema_manager, mem);
		}
		else if (words[0] == "SELECT"){
			Select(words, schema_manager, mem);
		}
		else{
			cout<<"Not a valid Tiny-SQL command!"<<endl<<endl;
			continue;
			//abort();
		}
		words.clear();
		cout << "Elapse time = " << disk.getDiskTimer() - time<< " ms" << endl;
		cout << "Disk I/Os = " << disk.getDiskIOs() - ios<< endl<<endl;
		time = disk.getDiskTimer();
		ios = disk.getDiskIOs();
	}
	if (!interactive_mode)	input.close();
	cout << "==== End of inputs ==== "<<endl;
	cout << "Total elapse time = " << ((double)(clock()-start_time)/CLOCKS_PER_SEC*1000) << " ms" << endl;
	cout << "Total Disk elapse time = " << disk.getDiskTimer() << " ms" << endl;
	cout << "Total Disk I/Os = " << disk.getDiskIOs() << endl;
	return 0;
}
Ejemplo n.º 29
0
int main() {
  //=======================Initialization=========================
  cout << "=======================Initialization=========================" << endl;

  // Initialize the memory, disk and the schema manager
  MainMemory mem;
  Disk disk;
  cout << "The memory contains " << mem.getMemorySize() << " blocks" << endl;
  cout << mem << endl << endl;
  SchemaManager schema_manager(&mem,&disk);
  Schema *schema;

  disk.resetDiskIOs();
  disk.resetDiskTimer();
  // Another way to time
  clock_t start_time;
  start_time=clock();
  
  // TODO Set up a block here??
  
  //=========================Initialization ends ==========================
  string line;
  vector<string> strings;
  ifstream myfile ("TinySQL_linux.txt");
  if(myfile.is_open()) {
    while(getline (myfile,line)) {
      //cout << line << '\n';
      istringstream f(line);
      string s;    
      while(getline(f, s, ' ')) {
        //cout << s << endl;
        strings.push_back(s);
      }
      if(strings[0].compare("CREATE") == 0) {
        // Creating a schema for the create statement.
		schema = processCreate(strings);
		//printSchema(*schema);
		// Creating the relation with the schema above using schema manager.
		string relation_name=strings[2];
		cout << "Creating table " << relation_name << endl;
		Relation* relation_ptr=schema_manager.createRelation(relation_name, *schema);
		//printRelation(relation_ptr);
	  }
	  // TODO Change the command to lower-case and compare
	  else if(strings[0].compare("INSERT") == 0) {
	    cout << "It is an INSERT statement " << endl;
		processInsert(line, strings, schema_manager);
	  }
	  else if(strings[0].compare("SELECT") == 0) {
	    cout << "It is a SELECT statement " << endl;
		processSelect(line, strings, schema_manager, &mem);
	  }
    strings.clear();  
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}
Ejemplo n.º 30
0
int main(int argc, char *argv[])
{
    int diskCount = getDiskCount();
    int startPos = getStartPos();
    int endPos = getEndPos(startPos);

    Queue<int> peg1(diskCount);
    Queue<int> peg2(diskCount);
    Queue<int> peg3(diskCount);

    switch(startPos)
    {
    case 1:
        for(int i = 1; i <= diskCount; i++)
            peg1.enqueue(i);
        break;
    case 2:
        for(int i = 1; i <= diskCount; i++)
            peg2.enqueue(i);
        break;
    case 3:
        for(int i = 1; i <= diskCount; i++)
            peg3.enqueue(i);
        break;
    default:
        cout << "error in initializing startPeg. " << endl;
        break;
    }

    Queue<int> board[3];
    board[0] = peg1;
    board[1] = peg2;
    board[2] = peg3;

    initialize();
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    
    Disk test;
    test.displayQueue(19, 20, board[0]);
    test.displayQueue(19, 40, board[1]);
    test.displayQueue(19, 60, board[2]);
    delay_output(DELAY);
    
    int findGoal = (startPos == 3) ? 1 : startPos + 1;
    cout << "                    1                   2                   3" << endl;
    
    if(diskCount%2) //case for odd number of disks
    {
        //shift in the same direction of peg
        if(findGoal == endPos) //if end peg is on right
            shiftRight(startPos, endPos, diskCount, board);
        else
            shiftLeft(startPos, endPos, diskCount, board);
    }
    else    //case for even number of disks
    {
        //shift in opposite direction of peg
        int otherPeg = findOtherPeg(startPos, endPos);
        if(findGoal == endPos) //if end peg is on right
            shiftLeft(startPos, otherPeg, diskCount, board);
        else
            shiftRight(startPos, otherPeg, diskCount, board);
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}