YetAgain
BAN USERShe wanted to know about versioned writes, where each process makes its own copy of the shared data known as shadow copy, adds a version [timestamp etc] to it and makes changes to the copy only. In case of multiple process writes, it's not the database's / admin's responsibility to maintain consistency but the updating library's. Read Amazon's Dynamo File system. And this for basic concept : edndoc.esri.com/arcsde/9.1/general_topics/what_versioned_dbase.htm
- YetAgain February 24, 2013@Juggernaut .. Quick Union method is correct but it's sort of complicated when all we have to do is just count the number of connected components. Quick union will give who's the root node for each component etc. Such a matrix is a directed graph with nodes only in 2 directions (right and down). We simply need to run a BFS starting from top most position until all no more 1's can be reached. This will be 1 component. Now repeat the process, until ALL cells are discovered.
- YetAgain February 21, 2013I think the focus is on OOP here. User provides a file from the list of folders/files and your system should be able to identify which type of file it is and select correct player to play it.
enum type {NONE, MP3, AV4, WAV, AIFF, TGP};
class file
{
public:
string fileName;
string filePath;
type fileType;
type fetchType(string name);
file(string fileName, string filePath) : fileType(NONE), fileName(fileName), filePath(filePath) {fileType = fetchType(fileName);}
};
type file::fetchType(string name)
{
int posDot = name.find('.');
string extension(name, posDot+1); //convert tolower
if(!extension.compare("aiff"))
fileType = AIFF;
else if(!extension.compare("mp3"))
fileType = MP3;
else if(!extension.compare("av4"))
fileType = AV4;
else if(!extension.compare("wav"))
fileType = WAV;
else if(!extension.compare("3gp"))
fileType = TGP;
return fileType;
}
class Player
{
string playerName;
public:
Player(string name) : playerName(name) {}
virtual void play(file* fileObj) =0;
};
void Player::play(file* fileObj) {
if(!fileObj)
cout<<"I'm "<<playerName<<" and I'm given an Invalid file to play\n";
else
{ // Check for folder and file permissions here
cout<<"I'm "<<playerName<<" and I'm playing : "<<fileObj->fileName<<" of type: "<<fileObj->fileType<<"\n";
}
}
class MP3Player: public Player
{
// MP3Player specific details here
public:
MP3Player() : Player("MP3Player") {cout<<"MP3Player instance created\n";}
virtual void play(file* fileObj) { cout<<"... MP3Player playing...\n";}
};
//... MORE CLASSES HERE ...//
class TGPlayer : public Player
{
// TGP specific details here
public:
TGPlayer() : Player("3GPPlayer") {cout<<"TGPlayer instance created\n";}
virtual void play(file* fileObj) {cout<<"..TGPlayer playing..\n";}
};
void play(file name)
{
Player* newPlayer = NULL;
switch(name.fileType)
{
case MP3: newPlayer = new MP3Player();
break;
case AV4: newPlayer = new AV4Player();
break;
case WAV: newPlayer = new WavPlayer();
break;
case AIFF: newPlayer = new AIFFPlayer();
break;
case TGP: newPlayer = new TGPlayer();
break;
case NONE:
default: cout<<"Invalid player type ..Aborting\n";
return;
}
newPlayer->play(&name);
}
int main()
{
string folder[3] = {"/path/folder1", "/path/folder2", "/path/folder3"};
file input("music.aiff", folder[0]);
play(input);
}
~
The logic of merging is same, whether you compare from the two ends or you compare from starting in parallel.
- YetAgain March 03, 2013