unsigned int search::short_list_in_bucket() const { unsigned int nb = 0; std::list<contact_proto>::const_iterator ite; for (ite = short_list.begin(); ite != short_list.end(); ++ite) { assert(ite->ep().address() != std::string("")); assert(ite->ep().port() != std::string("")); if (common_bits( string_to_key<KEY_SIZE>(ite->key()), string_to_key<KEY_SIZE>(destination)) == bucket_nb) ++nb; } return nb; }
search::search( const search::key_t& src, const search::key_t& dest, search_type_t t) : ttl(update_time()), destination(dest), source(src), search_type(t), node_callback_valid(false), buffer() { short_list.clear(); bucket_nb = common_bits( string_to_key<KEY_SIZE>(destination), string_to_key<KEY_SIZE>(source)); }
/* Return a number between 0 and 1 as a measure of similarity of two signals, 0=no similarity, 1=same. I am going to use the same metric as for meanings */ double signal_similarity(signal_t s1, signal_t s2) { return s1 == s2 ? 1.0 : (double)common_bits(s1,s2,bits) / (double)bits; }
/* Return a number between 0 and 1 as a measure of similarity of two meanings, 0=no similarity, 1=same. I am going to use the number of bits that are the same */ double meaning_similarity(meaning_t m1, meaning_t m2) { return m1 == m2 ? 1.0 : (double)common_bits(m1,m2,bits) / (double)bits; }