From 648a47211578617d228c22fac44b1ccc1f8f521d Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 21 May 2015 09:51:07 +0200 Subject: FindQuery --- enginedata.cpp | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'enginedata.cpp') diff --git a/enginedata.cpp b/enginedata.cpp index ecb4c82..95a2b11 100644 --- a/enginedata.cpp +++ b/enginedata.cpp @@ -13,7 +13,6 @@ Row::~Row(void){ if(items)delete[] items; } Row::Row(Row &&other):nc(other.nc),table(other.table),items(other.items){ //move constr - other.table=nullptr; other.items=nullptr; } Row::Row(const Row &other):nc(other.nc),table(other.table){ //copy constr @@ -39,6 +38,9 @@ Table::Table(const string &_n,const int _nc,const ColHeader *const _hd):name(_n) Table::~Table(void){ if(header)delete[] header; } +Table::Table(const Table &other):name(other.name),nc(other.nc),rows(other.rows){ + memcpy(header,other.header,nc*sizeof(ColHeader)); +} Table::Table(Table &&other):name(move(other.name)),nc(other.nc),header(other.header),rows(move(other.rows)){ other.header=nullptr; } @@ -54,30 +56,34 @@ bool Table::insert(Row &row){ return rows.emplace(key,row).second; } -list Table::find(const string &key){ - typedef map::const_iterator cit_t; - cit_t end=rows.cend(); - list ret; - for(cit_t it=rows.cbegin();it!=end;it++){ - if(serialise(it->second.table->header[0],it->second.items[0])==key) - ret.emplace_back(it->second); - } - return ret; -} - string serialise(const ColHeader &header,const RowItem &rowitem){ switch(header.type){ - case RH_INT32: - return serialise(rowitem.u.rh_int32); - case RH_UINT32: - return serialise(rowitem.u.rh_uint32); - case RH_BYTES: - return serialise(rowitem.u.rh_bytes,header.arg); - default: - assert(false); + case RH_INT32: return serialise(rowitem.rh_int32); + case RH_UINT32: return serialise(rowitem.rh_uint32); + case RH_BYTES: return serialise(rowitem.rh_bytes,header.arg); + default: assert(false); } } string serialise(int32_t v){return to_string(v);} string serialise(uint32_t v){return to_string(v);} string serialise(unsigned char *v,int len){return string((char*)v,len);} + +int riCompare(const ColHeader &header,const RowItem &ri1,const RowItem &ri2){ + switch(header.type){ + case RH_INT32: return riCompare(ri1.rh_int32,ri2.rh_int32); + case RH_UINT32: return riCompare(ri1.rh_uint32,ri2.rh_uint32); + case RH_BYTES: return riCompare(ri1.rh_bytes,ri2.rh_bytes,header.arg); + default: assert(false); + } +} +int riCompare(int32_t v1,int32_t v2){return v1-v2;} +int riCompare(uint32_t v1,uint32_t v2){return v1-v2;} +int riCompare(unsigned char *v1,unsigned char *v2,int len){ + int i; + cerr<<"Comparing "<<(void*)v1<<" ("<