void clique::copyClique(const clique & old_clique) { const size_t newSize = old_clique.size(); nodes.resize(newSize); for (size_t i = 0; i < newSize; i++) nodes.at(i) = old_clique.at(i); }
bool clique::operator< ( const clique & clique2) const { const size_t cliqueSize = size(); if ( cliqueSize == clique2.size() ) { bool definetelySmaller = false, know_answer = false; for (size_t i = 0; i < cliqueSize && !know_answer; ++i) { if ( (*this).at(i) < clique2.at(i) ) { definetelySmaller = true; know_answer = true; } else if ( (*this).at(i) > clique2.at(i) ) { definetelySmaller = false; know_answer = true; } } return definetelySmaller; } else { std::cerr << "comparing cliques of different sizes!\n"; return false; } }
void add_clique_to_bloom(const clique &new_clique, int32_t branch_identifier) { while(branch_identifier > 1) { // we shouldn't bother populating the root node for(size_t n = 0; n < new_clique.size(); n++) { const int32_t node_id = new_clique.at(n); const int64_t a = (int64_t(branch_identifier) << 32) + node_id; this->bl.set(a); } branch_identifier >>= 1; } }
int32_t overlap_estimate(const clique &new_clique, const int32_t branch_identifier) const { assert(branch_identifier > 1); // never call this on the root node, it hasn't been populated int32_t potential_overlap = 0; for(size_t n = 0; n < new_clique.size(); n++) { const int32_t node_id = new_clique.at(n); const int64_t a = (int64_t(branch_identifier) << 32) + node_id; potential_overlap += this->bl.test(a) ? 1 : 0; } return potential_overlap; }
bool clique::operator!= ( const clique & clique2 ) const // tän vois korvata operator==:n avulla { const size_t cliqueSize = size(); if ( cliqueSize == clique2.size() ) { bool anyDifferent = false; for ( size_t i = 0; !anyDifferent && i < cliqueSize; i++) { if ( nodes.at(i) != clique2.at(i) ) anyDifferent = true; } return anyDifferent; } else return true; }
bool clique::operator== ( const clique & clique2 ) const { const size_t cliqueSize = size(); if ( cliqueSize == clique2.size() ) { bool allEqual = true; for ( size_t i = 0; allEqual && i < cliqueSize; i++) { if ( nodes.at(i) != clique2.at(i) ) allEqual = false; } return allEqual; } else return false; }
size_t cliqueHash::hash_function(const clique key) { const size_t keySize = key.size(); // std::cerr << "clique size for hash_function is " << key.size() << "\n"; size_t hash_key; size_t newInd[keySize]; for (size_t i = 0; i < keySize; i++) newInd[i] = key.at(keySize-1-i) & b; // for (size_t i = 1; i < keySize; i++) new_ind[i] = A*key.at(i); hash_key = newInd[0] << hash_bits - offSet; // move to the left size_t move; for (size_t i = 1; i < keySize; i++) { move = hash_bits - (i+1)*offSet; newInd[i] = newInd[i] << move; hash_key = hash_key | newInd[i] ; // take } hash_key = hash_key | ( key.at(keySize-2) & c ); // now take only the last hash_bits bits // hash_key = hash_key & a; // std::cerr << "hash key is: " << hash_key << "\n"; /* hash_key = key.at(0)+1; for (size_t i = 1; i < key.size(); i++) hash_key *= key.at(i); hash_key = hash_key%size; // hash_key = (key.at(0)+1)*key.at(1)*key.at(2)*key.at(3)%size; // hash_key = ( key.at(0) * key.at(3) + key.at(1) * key.at(2) )%size; */ if (hash_key >= size || hash_key < 0 ) { std::cerr << "hash function did not work!\n"; // std::cerr << "nodes were: " << key.at(0) << " " << key.at(1) << " " << key.at(2) << " " << key.at(3) << "\n"; std::cerr << "hash key was: " << hash_key << "\n"; std::cerr << "hash key size was: " << keySize << "\n"; } return hash_key; }
int32_t overlap_estimate(const clique &new_clique, const int32_t branch_identifier, int32_t t) const { assert(branch_identifier > 1); // never call this on the root node, it hasn't been populated // we're interested *only* in whether the overlap is >= t. We'll short-circuit once the answer is known. int32_t potential_overlap = 0; const size_t sz = new_clique.size(); for(size_t n = 0; n < sz; n++) { const int32_t node_id = new_clique.at(n); const int64_t a = (int64_t(branch_identifier) << 32) + node_id; potential_overlap += this->bl.test(a) ? 1 : 0; if(potential_overlap >= t) return t; if(potential_overlap + int32_t(sz - n - 1) < t) return 0; } return potential_overlap; }