static int chm_gen_edges(cmph_config_t *mph) { cmph_uint32 e; chm_config_data_t *chm = (chm_config_data_t *)mph->data; int cycles = 0; DEBUGP("Generating edges for %u vertices with hash functions %s and %s\n", chm->n, cmph_hash_names[chm->hashfuncs[0]], cmph_hash_names[chm->hashfuncs[1]]); graph_clear_edges(chm->graph); mph->key_source->rewind(mph->key_source->data); for (e = 0; e < mph->key_source->nkeys; ++e) { cmph_uint32 h1, h2; cmph_uint32 keylen; char *key; mph->key_source->read(mph->key_source->data, &key, &keylen); h1 = hash(chm->hashes[0], key, keylen) % chm->n; h2 = hash(chm->hashes[1], key, keylen) % chm->n; if (h1 == h2) if (++h2 >= chm->n) h2 = 0; if (h1 == h2) { if (mph->verbosity) fprintf(stderr, "Self loop for key %u\n", e); mph->key_source->dispose(mph->key_source->data, key, keylen); return 0; } DEBUGP("Adding edge: %u -> %u for key %s\n", h1, h2, key); mph->key_source->dispose(mph->key_source->data, key, keylen); graph_add_edge(chm->graph, h1, h2); } cycles = graph_is_cyclic(chm->graph); if (mph->verbosity && cycles) fprintf(stderr, "Cyclic graph generated\n"); DEBUGP("Looking for cycles: %u\n", cycles); return ! cycles; }
static int bmz8_gen_edges(cmph_config_t *mph) { cmph_uint8 e; bmz8_config_data_t *bmz8 = (bmz8_config_data_t *)mph->data; cmph_uint8 multiple_edges = 0; DEBUGP("Generating edges for %u vertices\n", bmz8->n); graph_clear_edges(bmz8->graph); mph->key_source->rewind(mph->key_source->data); for (e = 0; e < mph->key_source->nkeys; ++e) { cmph_uint8 h1, h2; cmph_uint32 keylen; char *key = NULL; mph->key_source->read(mph->key_source->data, &key, &keylen); // if (key == NULL)fprintf(stderr, "key = %s -- read BMZ\n", key); h1 = (cmph_uint8)(hash(bmz8->hashes[0], key, keylen) % bmz8->n); h2 = (cmph_uint8)(hash(bmz8->hashes[1], key, keylen) % bmz8->n); if (h1 == h2) if (++h2 >= bmz8->n) h2 = 0; if (h1 == h2) { if (mph->verbosity) fprintf(stderr, "Self loop for key %u\n", e); mph->key_source->dispose(mph->key_source->data, key, keylen); return 0; } //DEBUGP("Adding edge: %u -> %u for key %s\n", h1, h2, key); mph->key_source->dispose(mph->key_source->data, key, keylen); // fprintf(stderr, "key = %s -- dispose BMZ\n", key); multiple_edges = graph_contains_edge(bmz8->graph, h1, h2); if (mph->verbosity && multiple_edges) fprintf(stderr, "A non simple graph was generated\n"); if (multiple_edges) return 0; // checking multiple edge restriction. graph_add_edge(bmz8->graph, h1, h2); } return !multiple_edges; }
static int bmz_gen_edges(cmph_config_t *mph) { cmph_uint32 e; bmz_config_data_t *bmz = (bmz_config_data_t *)mph->data; cmph_uint8 multiple_edges = 0; DEBUGP("Generating edges for %u vertices\n", bmz->n); graph_clear_edges(bmz->graph); mph->key_source->rewind(mph->key_source->data); for (e = 0; e < mph->key_source->nkeys; ++e) { cmph_uint32 h1, h2; cmph_uint32 keylen; char *key = NULL; mph->key_source->read(mph->key_source->data, &key, &keylen); h1 = hash(bmz->hashes[0], key, keylen) % bmz->n; h2 = hash(bmz->hashes[1], key, keylen) % bmz->n; if (h1 == h2) if (++h2 >= bmz->n) h2 = 0; DEBUGP("key: %.*s h1: %u h2: %u\n", keylen, key, h1, h2); if (h1 == h2) { cmph_logger.info("Self loop for key %u\n", e); mph->key_source->dispose(mph->key_source->data, key, keylen); return 0; } DEBUGP("Adding edge: %u -> %u for key %.*s\n", h1, h2, keylen, key); mph->key_source->dispose(mph->key_source->data, key, keylen); multiple_edges = graph_contains_edge(bmz->graph, h1, h2); if (multiple_edges) { cmph_logger.warn("A non simple graph was generated\n"); } if (multiple_edges) return 0; // checking multiple edge restriction. graph_add_edge(bmz->graph, h1, h2); } return !multiple_edges; }