uint64 RoomyGraphAlg_degreePrestige(RoomyGraph *g, uint64 node) {
  prestigeNode = node;
  prestigeCount = 0;
  RoomyHashTable_map(g->graph, computePrestige);
  RoomyGraph_sync(g);
  return prestigeCount;
}
/* Returns RGTRUE if the RoomyGraph contains a node equal to the provided node, or RGFALSE
   if no node can be found.
	 NOTE: It is recommended to ensure that the RoomyGraph has been sync'd before
	   calling this function. */
int RoomyGraph_containsNode(RoomyGraph *g, uint64 node) {
	searchNode = node;
	count = 0;
	RoomyHashTable_map(g->graph, countMatches);
	RoomyGraph_sync(g);
	if(count > 0) { return RGTRUE; }
	else { return RGFALSE; }
}
/* Returns 1 if an edge originating at from and terminating at to is contained
		within the RoomyGraph */
int RoomyGraph_containsEdge(RoomyGraph *g, uint64 from, uint64 to) {
	glo_from = from;
	glo_to = to;
	count = 0;
	RoomyHashTable_map(g->graph, countEdges);
	RoomyGraph_sync(g);
	if(count > 0) return RGTRUE;
	else return RGFALSE;
}
/* Prints the contents of the RoomyGraph to the console */
void RoomyGraph_print(RoomyGraph *g) {
	RoomyHashTable_map(g->graph, printNodeAndChildren);
	RoomyGraph_sync(g);
}
uint64 RoomyGraph_nodeCount(RoomyGraph *g) {
	count = 0;
	RoomyHashTable_map(g->graph, increaseCount);
	RoomyGraph_sync(g);
	return count;
}
Пример #6
0
// Top level function for method using one RoomyHashTable
void pancakeHashTable() {
    Roomy_log("BEGINNING %i PANCAKE BFS: RoomyHashTable version\n", PERM_LEN);

    // Set element counters (assuming level 0 has been completed).
    uint64 levelSize = 1;  // number of elements in curRHT
    uint64 totalElts = 1;  // total number of elements see so far

    // Create hash tables
    CUR_LEVEL = 0;
    allRHT = RoomyHashTable_make("allRHT",
                                  sizeof(uint64),
                                  sizeof(uint8),
                                  N_STATES);
    curRHT = RoomyHashTable_make("lev0RHT",
                                  sizeof(uint64),
                                  sizeof(uint8),
                                  levelSize);
    nextRHT = RoomyHashTable_make("lev1RHT",
                                   sizeof(uint64),
                                   sizeof(uint8),
                                   levelSize * PERM_LEN);

    // Set identity element
    Perm ident;
    getIdentPerm(ident);
    uint64 identPos = rank(ident);
    RoomyHashTable_insert(allRHT, &identPos, &CUR_LEVEL);
    RoomyHashTable_sync(allRHT);
    RoomyHashTable_insert(curRHT, &identPos, &CUR_LEVEL);
    RoomyHashTable_sync(curRHT);

    Roomy_log("Level %i done: %lli elements\n", CUR_LEVEL, levelSize);

    // While current level is not empty
    while (levelSize > 0) {
        // map over cur level, add neighbors to next level
        RoomyHashTable_map(curRHT, generateNextLevel);
        RoomyHashTable_sync(nextRHT);

        // remove all elts in seen from next (by mapping over seen and calling
        // remove)
        RoomyHashTable_map(allRHT, removeDupes);
        RoomyHashTable_sync(nextRHT);

        // add all elts in next to seen (by mapping over next and calling update)
        RoomyHashTable_map(nextRHT, recordNewElts);
        RoomyHashTable_sync(allRHT);

        // rotate levels
        RoomyHashTable_destroy(curRHT);
        curRHT = nextRHT;
        levelSize = RoomyHashTable_size(curRHT);
        CUR_LEVEL++;
        char levName[1024];
        sprintf(levName, "lev%iRHT", CUR_LEVEL + 1);

        // New table size is 30% bigger than the next level, to avoid doubling
        // of hash table capacity. But, it doesn't need to be bigger than the
        // entire search space. (PERM_LEN-1 is the branching factor.)
        uint64 tableSize = levelSize * (PERM_LEN-1) * 13 / 10;
        if (tableSize > N_STATES) {
            tableSize = N_STATES;
        }

        nextRHT = RoomyHashTable_make(levName,
                                      sizeof(uint64),
                                      sizeof(uint8),
                                      tableSize);

        // Confirm size reported by reduction matches level size.
        uint64 numEltsFromReduce = 0;
        RoomyHashTable_reduce(curRHT, &numEltsFromReduce, sizeof(uint64),
                              addOneToAns, sumAns);
        assert(numEltsFromReduce == levelSize);

        totalElts = RoomyHashTable_size(allRHT);

        Roomy_log("Level %i done: %lli elements\n", CUR_LEVEL, levelSize);
    }

    Roomy_log("PANCAKE BFS DONE\n");
}