Thursday, October 4, 2018

I wrote code!

I got interested in this idea of a simple join engine:
output equals left join right 

with left and right graph databases defined externally, in different contexts. It seems to be the basic join process simply loops through pointers into the database  and manages the recursion.  The externally defined grammar determines the rest.  It is trivial, in a way.


// simple loop
// executed methods will recursively call this
// It mainly does push and pop of the cursort stack
// the grammar defined externally
//
int joinLoop(Cursor* left, Cursor* right, Cursor* result) {
 Element elem;
 Cursor * newCursor;
 int status;
  do {
  if(status = right->exec(right,Fetch,&elem) !=End); // Extract left node
   status=left->exec(left,Eval,&elem);  
   if(status == Left) {
    newCursor = dup_cursor(left);
    status = joinLoop(newCursor,right,result);
    delete_cursor(newCursor);
   }
   else if(status == Left) {
    newCursor = dup_cursor(left);
    status = joinLoop(newCursor,right,result);
    delete_cursor(newCursor);
  }
  result->exec(result,Append,&elem); 
      } while(status != End);   
  return status;
}


No comments: