norian: (Default)
[personal profile] norian
Гибридная Графовая База Данных (ака отвертка с моторчиком для моделирования моделей)

День 3. Узлы данных: типы, шаблоны, блюпринты.

Типы данных полей не сохраняются в базе данных, поэтому блюпринт содержит только имена полей узла или линка. Также в блюпринте содержится информация об индексах полей.

При редактировании типа требуются значительные изменения всей структуры базы данных, поэтому предполагается дата пампинг для подобных операций, то есть создание нового блюпринта, автоматизированная перекачка данных существующих узлов и апдейт индексов если они есть. Поэтому имена полей узла добавляются в виде транзакции, то есть старт - добавление всех полей - коммит и после коммита не могут быть изменены.

source egDataNodeBlueprint.h:

#pragma once

#include "../indexes/egCoreIndexTypes.h"
#include "../service/egByteArray.h"
#include "../service/egFileType.h"

const int egBlueprintInit   {1}; // int blueprintMode
const int egBlueprintActive {2};

class EgDataNodeBlueprintType
{
public:
    int blueprintMode {egBlueprintActive};   // blueprint can't be edited freely, data pumping on changes is required
    EgBlueprintIDType   blueprintID;                    // Data Nodes Blueprint (DNL) ID for graph DB
    std::string         blueprintName;                  // == dataNodesTypeName

    EgHamSlicerType     theHamSlicer;                   // memory allocator for data nodes (node has only blueprint out connect)
    EgFileType          blueprintFile;                  // local files load & store support (if local files used)    

    // EgNodeBlueprintSettingsType    blueprintSettings;   // add-ons for blueprint type
    EgFieldsCountType              fieldsCount {0};

    std::unordered_map < std::string, EgFieldsCountType >   dataFieldsNames;    // map  data node field names to fields indexes for dataFieldsPtrs
    std::unordered_map < std::string, EgIndexSettingsType > indexedFields;

    EgByteArrayAbstractType egNotFound;
    const char* egNotFoundStr {"<Data Not Found>"};

    EgDataNodeBlueprintType(std::string a_blueprintName): blueprintName(a_blueprintName), blueprintFile(a_blueprintName) 
        { egNotFound.dataSize = strlen(egNotFoundStr)+1; egNotFound.dataChunk = (unsigned char *) egNotFoundStr; }
    ~EgDataNodeBlueprintType() { /* std::cout << "EgDataNodeBlueprintType destructor " << std::endl; */ clear(); }

    void clear() { dataFieldsNames.clear(); indexedFields.clear(); }

    int  BlueprintInitStart();
    void AddDataFieldName(std::string fieldName);
    void AddIndex(std::string indexName, uint8_t indexSizeBytes = 4, uint8_t indexSubType = egIndexesSpace::egIntFT); // default int32
    void BlueprintInitCommit();

    bool isIndexedField(std::string& name);
    
    inline void writeDataFieldsNames();
    inline void readDataFieldsNames();
    inline void writeIndexedFields();
    inline void readIndexesFields();
    
    int  LocalStoreBlueprint();
    int  LocalLoadBlueprint();
};

// ======================== Debug ========================

void PrintDataNodeBlueprint(EgDataNodeBlueprintType& blueprint);



Для проверки функциональности блюпринта написана тестовая утилита (кое как левой задней, имко нет смысла серьёзно вкладываться в тесты на ранних этапах, но чем раньше они появятся, тем проще контролировать процесс).



source testDataNodeBlueprint.cpp:

#include "../nodes/egDataNodeBlueprint.h"
#include <iostream>
#include <cstring>
using namespace std;


bool testDataNodeBlueprint() {

    cout << "===== Test DataNodeBlueprint (2 errors must appear in negative tests) " << " =====" << endl;

    EgDataNodeBlueprintType testBlueprint("testNodes");
    EgIndexSettingsType indexSettings;

    std::remove("testNodes.dnl"); // delete file

    testBlueprint.BlueprintInitStart();

    testBlueprint.AddDataFieldName("field_1");
    testBlueprint.AddDataFieldName("testField 2");
    testBlueprint.AddDataFieldName("field 3");

    testBlueprint.AddIndex("field 3", 4, egIndexesSpace::egIntFT);
    testBlueprint.AddIndex("bad index name", 4, egIndexesSpace::egFloatFT);

    testBlueprint.BlueprintInitCommit();
    testBlueprint.AddDataFieldName("try to add field after commit");
    
    testBlueprint.LocalStoreBlueprint();
    int res = testBlueprint.LocalLoadBlueprint();
    
    // PrintDataNodeBlueprint(testBlueprint);

    return (res == 0);
}

int main() {
    if (testDataNodeBlueprint())
        cout << "PASS" << endl;
    else
        cout << "FAIL" << endl;    
}

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

norian: (Default)
Norian

January 2026

S M T W T F S
    1 2 3
456 78 910
11121314 151617
18 19 20 21222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 21st, 2026 09:46 pm
Powered by Dreamwidth Studios