aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-05-11 10:00:29 +0200
committertomsmeding <hallo@tomsmeding.nl>2015-05-11 10:01:23 +0200
commit95c5eb96cf65019131a97e93031d4cdf38eca3c2 (patch)
tree06226daa75ef0f5ecf50f58ce620f52e353b74a9
Initial
-rw-r--r--.gitignore1
-rw-r--r--Makefile18
-rw-r--r--README.md3
-rw-r--r--engine.cpp27
-rw-r--r--enginedata.cpp27
-rw-r--r--enginedata.h52
-rw-r--r--enginedata.obin0 -> 7904 bytes
7 files changed, 128 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..45a160d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+engine
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..1f83663
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,18 @@
+CC=gcc
+CXX=g++
+CFLAGS=-Wall -O2
+CPPFLAGS=-Wall -O2 -std=c++11
+
+BINARIES=engine
+
+
+.PHONY: all clean
+
+all: $(BINARIES)
+
+clean:
+ rm $(BINARIES)
+
+
+engine: engine.cpp enginedata.o
+ $(CXX) $(CPPFLAGS) -o $@ $^
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..110d25b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# LinearDB
+
+A simple database program that maintains a linear philosophy: when you can't run stuff in parallel, _don't_ run stuff in parallel. You can send queries in a simple scripting language, and the multiplexer will send them to the database engine _one at a time_, to be evaluated with the utmost care by the engine. Feature: no two queries will run at the same time, and **transactions are not a feature, but a something commonplace and inherent to the protocol**. Everything is a transaction, so don't worry about other programs messing with the database while it's _your turn_.
diff --git a/engine.cpp b/engine.cpp
new file mode 100644
index 0000000..b4753f4
--- /dev/null
+++ b/engine.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+#include <vector>
+#include <map>
+#include <cstdlib>
+#include "enginedata.h"
+
+using namespace std;
+
+map<string,Table> tables;
+
+
+int main(int argc,char **argv){
+ ColHeader *header=new ColHeader[3];
+ header[0]={RH_INT32,0};
+ header[1]={RH_UINT32,0};
+ header[2]={RH_BYTES,10};
+ tables.emplace("hoi",Table("hoi",3,header));
+ Table *hoitb=&tables.at("hoi");
+ Row row(3,hoitb);
+ row.items[0].u.rh_int32=42;
+ row.items[1].u.rh_uint32=42;
+ row.items[2].u.rh_bytes=new unsigned char[10];
+ strcpy((char*)row.items[2].u.rh_bytes,"hallo daar");
+ hoitb->insert(row);
+ cout<<"hoitb has "<<hoitb->rows.size()<<" row"<<(hoitb->rows.size()==1?"":"s")<<endl;
+ return 0;
+}
diff --git a/enginedata.cpp b/enginedata.cpp
new file mode 100644
index 0000000..c4d5e27
--- /dev/null
+++ b/enginedata.cpp
@@ -0,0 +1,27 @@
+#include "enginedata.h"
+
+using namespace std;
+
+Row::Row(const int nc,const Table *const _t):table(_t){items=new RowItem[nc];}
+Row::~Row(void){if(items)delete[] items;}
+Row::Row(Row &&other):table(other.table),items(other.items){ //move constr
+ other.table=NULL;
+ other.items=NULL;
+}
+Row::Row(const Row &other):table(other.table){ //copy constr
+ items=new RowItem[table->nc];
+ memcpy(items,other.items,table->nc*sizeof(RowItem));
+}
+
+
+Table::Table(const string &_n,const int _nc,const ColHeader *const _hd):name(_n),nc(_nc){ //copies from _hd, so you can freely delete it or whatever
+ header=new ColHeader[nc];
+ memcpy(header,_hd,nc*sizeof(ColHeader));
+}
+Table::~Table(void){if(header)delete[] header;}
+Table::Table(Table &&other):name(move(other.name)),nc(other.nc),header(other.header),rows(move(other.rows)){
+ other.header=NULL;
+}
+
+void Table::insert(Row &&row){rows.push_back(move(row));}
+void Table::insert(Row &row){rows.emplace_back(row);}
diff --git a/enginedata.h b/enginedata.h
new file mode 100644
index 0000000..29550f6
--- /dev/null
+++ b/enginedata.h
@@ -0,0 +1,52 @@
+#include <string>
+#include <vector>
+
+using namespace std;
+
+struct RowItem;
+struct Row;
+struct ColHeader;
+struct Table;
+
+
+struct RowItem{
+ union { //watch the pointerness or not-pointerness of the attributes!
+ int rh_int32;
+ unsigned int rh_uint32;
+ unsigned char *rh_bytes;
+ } u;
+};
+
+enum ColHeaderType{
+ RH_INT32,
+ RH_UINT32,
+ RH_BYTES //takes length argument
+};
+struct ColHeader{
+ ColHeaderType type;
+ int arg;
+};
+
+struct Row{
+ const Table *table; //pointer to the parent table; don't delete!
+ RowItem *items;
+
+ Row(const int nc,const Table *const _t);
+ ~Row(void);
+ Row(Row &&other);
+ Row(const Row &other);
+};
+
+struct Table{
+ const string name;
+ const int nc;
+ ColHeader *header;
+ vector<Row> rows;
+
+ Table(const string &_n,const int _nc,const ColHeader *const _hd);
+ ~Table(void);
+ Table(Table &&other);
+
+ void insert(Row &&row);
+ void insert(Row &row);
+};
diff --git a/enginedata.o b/enginedata.o
new file mode 100644
index 0000000..6659665
--- /dev/null
+++ b/enginedata.o
Binary files differ