aboutsummaryrefslogtreecommitdiff
path: root/enginedata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'enginedata.cpp')
-rw-r--r--enginedata.cpp46
1 files changed, 26 insertions, 20 deletions
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<Row> Table::find(const string &key){
- typedef map<string,Row>::const_iterator cit_t;
- cit_t end=rows.cend();
- list<Row> 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<<" ("<<v1<<") and "<<(void*)v2<<" ("<<v2<<')'<<endl;
+ for(i=0;i<len;i++){
+ if(v1[i]!=v2[i])return v1[i]-v2[i];
+ }
+ return 0;
+}