Concept
-------

LogDB is a persisted fixed size array with full log.

It is possible to read the value of an element as it were at a specific time.


C++ API
-------

Include logdb.h in your cpp file.

Declare instance:

    LogDB db(total_number_of_records, size_of_one_record, number_records_per_data_block);

    high number_records_per_data_block => faster data access, more disk space used wuth update

    low number_records_per_data_block => slower data access, less disk space used wuth update

Associate with new files:

    db.Init(file_name, function_to_get_initial_values);
    
    creates .logdb and .ix files and populate with initial values
    
    function_to_get_initial_values must have a signature like:
        void get(INT ix, void* buf)

Associate with existing files:

    db.Open(file_name);

Read latest version of element:

    db.Read(index_of_element, &buffer_for_element);

Read version of element from specific time:

    db.Read(index_of_element, &buffer_for_element, time);

Update element:

    db.Update(index_of_element, &buffer_for_element);

Batch update:

    db.BatchUpdateBegin();
    db.BatchUpdate(index_of_element_1, &buffer_for_element_1);
    ....
    db.BatchUpdate(index_of_element_n, &buffer_for_element_n);
    db.BatchUpdateCommit();


C API
-----

Include capi.h in your c file.

Declare instance:

    LOGDB_CTX db;

Allocate structures:
    logdb_allocate(&db, total_number_of_records, size_of_one_record, number_records_per_data_block);

    high number_records_per_data_block => faster data access, more disk space used wuth update

    low number_records_per_data_block => slower data access, less disk space used wuth update

Associate with new files:

    logdb_init(&db, file_name, function_to_get_initial_values);
    
    creates .logdb and .ix files and populate with initial values
    
    function_to_get_initial_values must have a signature like:
        void get(INT ix, void* buf)

Associate with existing files:

    logdb_open(&db, file_name);

Read latest version of element:

    logdb_read(&db, index_of_element, &buffer_for_element);

Read version of element from specific time:

    logdb_read_historic(&db, index_of_element, &buffer_for_element, time);

Update element:

    logdb_update(&db, index_of_element, &buffer_for_element);

Batch update:

    logdb_batch_update_begin(&db);
    logdb_batch_update(&db, index_of_element_1, &buffer_for_element_1);
    ....
    logdb_batch_update(&db, index_of_element_n, &buffer_for_element_n);
    logdb_batch_update_commit(&db);

Linking a C++ library into a C application may require some fiddling. The supported
way is to have a C++ main and link it as a C++ application. With GCC it may work by
just adding -lstdc++ to the link command.
