예제 #1
0
파일: bmz8.c 프로젝트: biocore/sortmerna
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;
}
예제 #2
0
파일: bmz.c 프로젝트: GregBowyer/cmph-cffi
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;
}