14607 - GitImplementation   

Description

Restriction
1.Only <iostream>, <vector>, <stack>, <list>, and <string> can be used for this homework. For fairness and simplicity, other STL libraries or external librariesare not allowed.
2.Plagiarism is strictly prohibited. If we find any similarities between your code and another student's ,a penalty will be applied.
3.The due date is April 27th at 23:59. Late submissions will be penalized according to the previously announced policy

Introduction
Git is a distributed version control system used to track changes in computer files. If you are pursuing a career in Computer Science, it's essential to understand Git, as it is very useful for keeping track of your progress and changes.
 
Let’s consider a scenario: you are developing an app and making steady progress every day. You can save your daily progress by committing your updates. Suppose you store your commits as "nodes". This allows you to review your progress from the previous week by examining the corresponding node.

Problem
In this assignment, we will design a simple version of Git. We only need to implement three functions: CommitSwitch,  and Open. We start at the root node, where the files are initially empty.
 

1. Commit
In the input command, we will give below command, as <total_files> will be an integer

git commit <total_files>

After this commit command, the next input will consist of<total_files>entries representing filechanges. For each file, the format is:

<file_name> <insertion_lines> <deletion_lines>
<line_number> <line_changes>
...
<line_number> <line_changes>
<line_number>
...
<line_number>

First, there will be <insertion_lines> lines for insertion string to files, and then <deletion_lines> lines for deletion to the files.

Insertion will do the processing for the file first, based on the ascending line number. After insertion,we will delete the given line number for the new changes. <file_name> will only consist lowercase letter, while <line_changes> consist any letter or numbers, including space.

From this command, it will create a new node. The new node will be assigned as the children of the current node, and then the current node will be change to the recent created node

The line number for insertion and deletion are already sorted, so you don't need to sort it again

2. Switch

git switch <ID>

Switch the current node to <ID>, and <ID> will be integer.

After that you need to print "Swithed to Branch <ID>"

3. Open

git open <filename>

We have implemented the print function for this, but you still need to complete the function to be able to implement this that return std::vector<std::string>

Details

1. The input will consist of N queries, each representing one of the commands described above.

2. The parameter of the input is describe below:

  • 1 <= N <=5 * 106
  • 0 <= insertion_lines, deletion_lines <= 100
  • ID is guaranteed valid based on the commit given
  • filename is guaranteed non empty at 1 <= len(filename) <= 10 and only consist of lowercase alphabet
  • line_changesis guaranteed non empty and consist of words >= 1, with each word length 1 <= len(word) <= 10 and could consist number and any character

3. Try to submit using C++11 or above

4. This is a Partial Judge question, so you don’t need to worry about the input/output format.

5. You are required to implement the following functions:

6. Please refer to video or PPT if you struggle to understand the sample input/output

Git Structure

We have provided you with a GitNode and Commit class. Each GitNode is designed to store its own commit information.

The Commit class uses a Trie data structure: Trie-Wikipedia

Implementing a Trie is required to improve the performance of data searches, especially for the git open command.

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

14607.cpp

Partial Judge Header

14607.h


Discuss