/*============================================================================= # Filename: Signature.cpp # Author: Bookug Lobert # Mail: zengli-bookug@pku.edu.cn # Last Modified: 2016-04-11 13:18 # Description: =============================================================================*/ #include "Signature.h" using namespace std; std::string Signature::BitSet2str(const EntityBitSet& _bitset) { std::stringstream _ss; bool any = false; for (unsigned i = 0; i < _bitset.size(); i++) { if (_bitset.test(i)) { _ss << "[" << i << "] "; any = true; } } if (!any) { _ss << "empty" << endl; } _ss << endl; return _ss.str(); } void Signature::encodeEdge2Entity(EntityBitSet& _entity_bs, int _pre_id, int _neighbor_id, const char _type) { Signature::encodePredicate2Entity(_entity_bs, _pre_id, _type); #ifdef DEBUG //if(_neighbor_id == 438460) //{ //cout<<"predicate encoded"<0 && _str[0] == '?') //return; //int length = (int)strlen(_str); //unsigned int hashKey = 0; //unsigned int pos = 0; //char *str2 = (char*)calloc(length + 1, sizeof(char)); //strcpy(str2, _str); //char *str = str2; //unsigned base = Signature::STR_SIG_BASE * (Signature::HASH_NUM - 1); //for (int i = Signature::HASH_NUM - 1; i >= 0; --i) //{ //HashFunction hf = Util::hash[i]; //if (hf == NULL) //break; //hashKey = hf(str); //str = str2; //pos = base + hashKey % Signature::STR_SIG_BASE; //base -= Signature::STR_SIG_BASE; //if (_str[0] == '"') //{ //pos += Signature::STR_SIG_LENGTH2; //} //else if (_str[0] != '<') //{ //#ifdef DEBUG_VSTREE //cerr << "error in encodeStr2Entity(): neighbor is neither a literal or entity!" << endl; //#endif //} //_entity_bs.set(pos); //} //BETTER: use multiple threads for different hash functions #ifdef DEBUG_VSTREE //std::stringstream _ss; //_ss << "encodeStr2Entity:" << str2 << endl; //Util::logging(_ss.str()); #endif //free(str2); } //void //Signature::encodeStrID2Entity(int _str_id, EntityBitSet& _entity_bs) //{ ////NOT USED NOW //} EntitySig::EntitySig() { this->entityBitSet.reset(); } EntitySig::EntitySig(const EntitySig* _p_sig) { this->entityBitSet.reset(); this->entityBitSet |= _p_sig->entityBitSet; } EntitySig::EntitySig(const EntitySig& _sig) { this->entityBitSet.reset(); this->entityBitSet |= _sig.entityBitSet; } EntitySig::EntitySig(const EntityBitSet& _bitset) { this->entityBitSet.reset(); this->entityBitSet |= _bitset; } EntitySig& EntitySig::operator|=(const EntitySig& _sig) { this->entityBitSet |= _sig.entityBitSet; return *this; } bool EntitySig::operator==(const EntitySig& _sig)const { return (this->entityBitSet == _sig.entityBitSet); } bool EntitySig::operator!=(const EntitySig& _sig)const { return (this->entityBitSet != _sig.entityBitSet); } EntitySig& EntitySig::operator=(const EntitySig& _sig) { this->entityBitSet.reset(); this->entityBitSet |= _sig.getBitset(); return *this; } const EntityBitSet& EntitySig::getBitset()const { return this->entityBitSet; } //EdgeSig::EdgeSig() //{ //this->edgeBitSet.reset(); //} //EdgeSig::EdgeSig(const EdgeSig* _p_sig) //{ //this->edgeBitSet.reset(); //this->edgeBitSet |= _p_sig->edgeBitSet; //} //EdgeSig::EdgeSig(const EdgeSig& _sig) //{ //this->edgeBitSet.reset(); //this->edgeBitSet |= _sig.edgeBitSet; //} //EdgeSig::EdgeSig(const EdgeBitSet& _bitset) //{ //this->edgeBitSet.reset(); //this->edgeBitSet |= _bitset; //} //EdgeSig& //EdgeSig::operator|=(const EdgeSig& _sig) //{ //this->edgeBitSet |= _sig.edgeBitSet; //return *this; //} string EntitySig::to_str() const { std::stringstream _ss; _ss << Signature::BitSet2str(this->entityBitSet); return _ss.str(); }