Giter VIP home page Giter VIP logo

inmemorydb's Introduction

InMemoryDb

An in memory database with transaction support implemented with C++ 20 (extra credit). The optional<int> to return nullopt is not used because it is part of C++ 17 standard.

Table of Contents

Specification

Class information:

  • The class uses two separate data structures to isolate the effects of transactions from the committed data.
  • The get() method returns a special value (numeric_limits::max()) during a transaction to indicate that the data is not yet visible.

Data Structure:

  • globalStore (unordered_map<string, int>): This stores the committed key-value pairs, representing the persistent state of the database.
  • transactionStore (unordered_map<string, int>): This stores the changes made within the current transaction, isolated from the globalStore.
  • transactionInProgress (bool): A flag indicating whether a transaction is currently active.

Functions:

  1. begin_transaction():

    a. Purpose: Starts a new transaction.

    b. Checks: If a transaction is already in progress, it throws a runtime_error.

    c. Action: Sets the transactionInProgress flag to true.

  2. put(string key, int value):

    a. Purpose: Adds or updates a key-value pair within the current transaction.

    b. Checks: If no transaction is in progress, it throws a runtime_error.

    c. Action: Stores the key-value pair in the transactionStore.

  3. get(string key):

    a. Purpose: Retrieves the value associated with a key.

    b. Logic:

    1. If a transaction is in progress, it returns numeric_limits::max() (effectively representing "null" or "not found" as the actual value is not yet committed).
    2. Otherwise, it checks the globalStore and returns the value if the key exists, or numeric_limits::max() if not found.
  4. commit():

    a. Purpose: Applies the changes made within the current transaction to the persistent globalStore.

    b. Checks: If no transaction is in progress, it throws a runtime_error.

    c. Actions:

    1. Copies all key-value pairs from the transactionStore to the globalStore.
    2. Clears the transactionStore.
    3. Sets transactionInProgress to false, ending the transaction.
  5. rollback():

    a. Purpose: Discards all changes made within the current transaction.

    b. Checks: If no transaction is in progress, it throws a runtime_error.

    c. Action: Clears the transactionStore and sets transactionInProgress to false.

How to run the code

Option 1:

Option 2:

Dependencies
  • A C++ compiler (e.g., g++, clang)
Build and Run Instructions
  1. Compile: Open a terminal in the project directory and run the following command:

    • g++ -o InMemoryDB main.cpp

    • This will create an executable file named InMemoryDB.

  2. Run: Execute the compiled program by typing:

    • ./InMemoryDB
  3. The program will output the results of the example usage demonstrated in the main() function.

Personal Comments

The instructions for the in-memory database with transaction support assignment are clear; however, some areas can be improved. The instructions have syntax errors and need to be corrected as needed. Another point is that the grading scheme favors the working code hugely. The README file just gets 2 points. It would be best if the grading scheme was a bit more balanced and provided partial credits based on the quality of the code, the documentation, and the extent to which the assignment was done to the instructions. To make this an official assignment, I think adding more clarity or examples to edge cases or error handling scenarios in the instructions would be good. Furthermore, grading could be expanded to include functional correctness to code organization, and readability.

inmemorydb's People

Contributors

mihirp161 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.