1

I am programming a database similar to Cassandra. I use C++.

Simplified database store its data in one or two "memory table" and several "disk tables", all stored in single directory.

I have class that dealing with single "disk table" and another class for "memory table".

I need to make a class that deals with array of "memory tables" and "disk tables".

Currently I am thinking of following:

class MultipleTable : public AbstractTable{
    // get, set, bla...
    virtual Pair *get(string key){
         for(unsigned i = 0; i < getTableCount(); ++i){
              // Do not pay attention to pointers,
              // I am working to remove them.
              AbstractTable *table = getTable(i);
              Pair *p = table->get(key);
              if (p)
                    return p;
         }
         return nullptr;
    }

    virtual AbstractTable getTable(unsigned id) = 0;
    virtual unsigned getTableCount() = 0;
}

Then I plan to extend this class and override the exact "storage" of the tables (because there may be two or three different subclases).

However I wonder if this the best way to do so?

As alternative I could use std::vector or my own storage class similar to std::vector and pass it into the c-tor.

From the other hand, this current way will "isolate" some ugly code for scanning directories and probably give me some other benefits later with memtables.

  • 1
    implementation looks no different to a std::map to me. – gbjbaanb Jul 13 '15 at 9:31
  • sure is very similar to std::map or memcached, except it is on the disk and hopefully will be able to handle terabytes of data. – Nick Jul 13 '15 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.