//--------------------------------------------------------------------------- static void readIndex(istream& in,map<Register,unsigned>& index,Attribute::Type type,unsigned cardinality) // Read an index { unsigned count; in.read(reinterpret_cast<char*>(&count),sizeof(count)); if (count!=cardinality) { cerr << "index corruption encountered, reload the database" << endl; throw; } index.clear(); switch (type) { case Attribute::Type::Int: for (unsigned index2=0;index2<count;++index2) { int val; unsigned pos; in.read(reinterpret_cast<char*>(&val),sizeof(val)); in.read(reinterpret_cast<char*>(&pos),sizeof(pos)); Register r; r.setInt(val); index[r]=pos; } break; case Attribute::Type::Double: for (unsigned index2=0;index2<count;++index2) { double val; unsigned pos; in.read(reinterpret_cast<char*>(&val),sizeof(val)); in.read(reinterpret_cast<char*>(&pos),sizeof(pos)); Register r; r.setDouble(val); index[r]=pos; } break; case Attribute::Type::Bool: for (unsigned index2=0;index2<count;++index2) { bool val; unsigned pos; in.read(reinterpret_cast<char*>(&val),sizeof(val)); in.read(reinterpret_cast<char*>(&pos),sizeof(pos)); Register r; r.setBool(val); index[r]=pos; } break; case Attribute::Type::String: for (unsigned index2=0;index2<count;++index2) { unsigned valLen,pos; string val; in.read(reinterpret_cast<char*>(&valLen),sizeof(valLen)); val.resize(valLen); in.read(const_cast<char*>(val.data()),valLen); in.read(reinterpret_cast<char*>(&pos),sizeof(pos)); Register r; r.setString(val); index[r]=pos; } break; } }