From 95c5eb96cf65019131a97e93031d4cdf38eca3c2 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 11 May 2015 10:00:29 +0200 Subject: Initial --- .gitignore | 1 + Makefile | 18 ++++++++++++++++++ README.md | 3 +++ engine.cpp | 27 +++++++++++++++++++++++++++ enginedata.cpp | 27 +++++++++++++++++++++++++++ enginedata.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ enginedata.o | Bin 0 -> 7904 bytes 7 files changed, 128 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 engine.cpp create mode 100644 enginedata.cpp create mode 100644 enginedata.h create mode 100644 enginedata.o 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 +#include +#include +#include +#include "enginedata.h" + +using namespace std; + +map 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 "<rows.size()<<" row"<<(hoitb->rows.size()==1?"":"s")<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 +#include + +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 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 Binary files /dev/null and b/enginedata.o differ -- cgit v1.2.3-70-g09d2