The Core of graph4

At the core of graph4 is a double linked list (dll). Everything can be put into a dll:

  • the bases
  • the nodes in a base
  • the attributes of a node
  • the relations between nodes
  • the attributes for a relation

Within the dll header (dll.h) the dll is defined as:

struct dll
{
    struct dll * prev;
    struct dll * next;
    void * payload;
};

The payload can be anything: a node, an attribute…..

The beginning of it all is a dll of bases. A base is defined as :

struct base
{
    int current_id;
    struct dll * nodes;
    struct dll * attributes;
};

As displayed, the base is the current id, a dll of nodes and a dll of attributes cor the base.

A shown above a base consists of nodes. A node is defined as:

struct node
{
    int id;
    struct dll * attributes;
    struct dll * relations;
};

As you can see, a node consists of an id, a list (a dll again) of attributes (or even none) and a list (again a dll) of relations (or even none).

Attributes are defined as:

struct attribute
{
    int id;
    char * name;
    char * value;
};

It’s an id (unique within it’s base), a key and a value. That’s is, an attribute is just that.

And then finally a relation is defined to be:

struct relation
{
    int id;
    struct node * relates_to;
    struct dll * attributes;
};

A relation is the (to me) most difficult of the objects there are in graph4. This because it belongs to a node, and then has a relation with/to another node (in the type_definition : relates_to). And of course you can add attributes to a relation.

Somewhat simplified the whole graph-structure (in graph4) can be pitcured as:

bases
   base
      nodes
         node
            atributes
               attribtue
               ...
            relations
              relation
              ...
         ...
      ...
      attributes
         attribute
         ...
   ...

“…” in the above means 1 or more of the “object” above it.

And somewhat more articulated:

bases (dll)
|- base (base)
|  |- nodes (dll)
|  |  |- node (node)
|  |  |  |- attributes (dll)
|  |  |  |  |- attribute (attribute)
|  |  |  |  |  |- key / value (string/string)
|  |  |  |  |- attribute (attribute)
|  |  |  |     |- key / value (string/string)
|  |  |  |- relations (dll)
|  |  |     |- relation (relation)
|  |  |     |  |- relates_to (node)
|  |  |     |  |- attributes (dll)
|  |  |     |     |- attribute (attribute)
|  |  |     |     |  |- key / value (string/string)
|  |  |     |     |- attribute (attribute)
|  |  |     |        |- key / value (string/string)
|  |  |     |- relation (relation)
|  |  |        |- relates_to (node)
|  |  |        |- attributes (dll)
|  |  |           |- attribute (attribute)
|  |  |           |  |- key / value (string/string)
|  |  |           |- attribute (attribute)
|  |  |              |- key / value (string/string)
|  |  |- node (node)
|  |     |- attributes (dll)
|  |     |   |- attribute (attribute)
|  |     |   |  |- key / value (string/string)
|  |     |   |- attribute (attribute)
|  |     |      |- key / value (string/string)
|  |     |- relations (dll)
|  |        |- relation (relation)
|  |        |  |- relates_to (node)
|  |        |  |- attributes (dll)
|  |        |     |- attribute (attribute)
|  |        |     |  |- key / value (string/string)
|  |        |     |- attribute (attribute)
|  |        |        |- key / value (string/string)
|  |        |- relation (relation)
|  |           |- relates_to (node)
|  |           |- attributes (dll)
|  |              |- attribute (attribute)
|  |              |  |- key / value (string/string)
|  |              |- attribute (attribute)
|  |                 |- key / value (string/string)
|  |- attributes (dll)
|     |- attribute (attribute)
|     |  |- key / value (string/string)
|     |- attribute (attribute)
|        |- key / value (string/string)
|- base (base)
   |- nodes (dll)
   |  |- node (node)
   |  |  |- attributes (dll)
   |  |  |  |- attribute (attribute)
   |  |  |  |  |- key / value (string/string)
   |  |  |  |- attribute (attribute)
   |  |  |     |- key / value (string/string)
   |  |  |- relations (dll)
   |  |     |- relation (relation)
   |  |     |  |- relates_to (node)
   |  |     |  |- attributes (dll)
   |  |     |     |- attribute (attribute)
   |  |     |     |  |- key / value (string/string)
   |  |     |     |- attribute (attribute)
   |  |     |        |- key / value (string/string)
   |  |     |- relation (relation)
   |  |        |- relates_to (node)
   |  |        |- attributes (dll)
   |  |           |- attribute (attribute)
   |  |           |  |- key / value (string/string)
   |  |           |- attribute (attribute)
   |  |              |- key / value (string/string)
   |  |- node (node)
   |    |- attributes (dll)
   |    |   |- attribute (attribute)
   |    |   |  |- key / value (string/string)
   |    |   |- attribute (attribute)
   |    |      |- key / value (string/string)
   |    |- relations (dll)
   |       |- relation (relation)
   |       |  |- relates_to (node)
   |       |  |- attributes (dll)
   |       |     |- attribute (attribute)
   |       |     |  |- key / value (string/string)
   |       |     |- attribute (attribute)
   |       |        |- key / value (string/string)
   |       |- relation (relation)
   |          |- relates_to (node)
   |          |- attributes (dll)
   |             |- attribute (attribute)
   |             |  |- key / value (string/string)
   |             |- attribute (attribute)
   |                 |- key / value (string/string)
   |- attributes (dll)
      |- attribute (attribute)
      |  |- key / value (string/string)
      |- attribute (attribute)
         |- key / value (string/string)

Within a ddl object only two children arediplayes. However….there is no restrictions (a node can have as many attributes a necessary)

graph databases

For some time now I’m very interested in graph databases. Time to create one myself. Is that reinventing the wheel …yes, it probably is. But…in that way I learn something about the subject.

I will develop in Netbeans with the C/C++ Plugin. Mind you….I’m not a professional programmer, so there will be a lot of NONO’s to the professional eye, I do not mind, I would love it, if you tell me about the quirks that out find.

Code can be found at https://github.com/maboc/graph4 (the git-repo is on the free plan).