예제 #1
0
파일: error.c 프로젝트: steve-m/m8cutils
void error_cleanup(void)
{
    JRB entry;

    jrb_traverse(entry,file_names)
	free(jval_v(jrb_val(entry)));
    jrb_free_tree(file_names);
}
예제 #2
0
int deepFirstSearch(Graph graph, int start, int stop, Dllist close) {
	Dllist node, stack;
	JRB visited;
	int output[100];
	int temp;

	int i, n;

	visited = make_jrb();
	stack = new_dllist();
	dll_prepend(stack, new_jval_i(start));

	while(!dll_empty(stack)) {
		node = dll_first(stack);
		temp = jval_i(node->val);
		dll_delete_node(node);

		if(jrb_find_int(visited, temp) == NULL) {
			// reportFunc(temp);
			dll_append(close, new_jval_i(temp));
			jrb_insert_int(visited, temp, new_jval_i(temp));
			
			if(compare(temp, stop) == 0) {
				jrb_free_tree(visited);
				free_dllist(stack);
				return 1;
			}

			n = outdegree(graph, temp, output);
			for(i = 0; i < n; i++) {
				if(jrb_find_int(visited, output[i]) == NULL) {
					dll_prepend(stack, new_jval_i(output[i]));
				}
			}
		}
	}

	jrb_free_tree(visited);
	free_dllist(stack);

	return 0;
}
예제 #3
0
void finesleep_free(void *a)
{
  Finesleep *fs;

  fs = (Finesleep *) a;
  close(fs->fd[0]);
  close(fs->fd[1]);
  jrb_free_tree(fs->tree);
  pthread_mutex_destroy(fs->lock);
  free(fs->lock);
  free(fs);
}
예제 #4
0
int solve(char *fileName) {
	JRB tree;
	int choice;
	int case1Flag = 0;

	JRB anotherTree;

  	while(1) {
      choice = menuSpellChecking();

      switch(choice) {
        case 1:
        printf("You choose option %d\n", choice);
        if(case1Flag) {
        	printf("You already choose this option\n");
        	continue;
        }
        if((tree = buildTree(fileName)) == NULL) {
			return 1;
		}
		printf("Build tree successfully.\n");

		jrb_traverse(anotherTree, tree) {
		    printf("%s - %s\n", jval_s(anotherTree->key), jval_s(anotherTree->val));
		}
        case1Flag = 1;
        continue;
        case 2:
        printf("You choose option %d\n", choice);
        if(!case1Flag) {
        	printf("Please enter the first option first!\n");
        	continue;
        }
		checkingSpell(tree);
        continue;
        case 3:
        printf("You choose option %d\n", choice);
        printf("Bye bye\n");
        if(case1Flag) {
			jrb_free_tree(tree);
        }
        break;
        default:
        printf("It is not an option\n");
        continue;
      }
      break;
    }
예제 #5
0
int solve(FILE *f) {
	Graph g;
	JRB stationList;

	String startName, stopName;
	JRB startCode, stopCode, node;
	int n;
	Jval output[SIZE];

	g = createGraph();
	stationList = make_jrb();

	if(readFile(f, g, stationList) == -1) {
		return 1;
	}

	printf("Please enter the start station name:\n");
	fscanf(stdin, "%[^\n]", startName.content);
	while(getchar() != '\n');

	printf("Please enter the stop station name:\n");
	fscanf(stdin, "%[^\n]", stopName.content);
	while(getchar() != '\n');

	if((startCode = jrb_find_gen(stationList, new_jval_v(&startName), stringCompare)) == NULL) {
		return 1;
	}

	if((stopCode = jrb_find_gen(stationList, new_jval_v(&stopName), stringCompare)) == NULL) {
		return 1;
	}

	printf("Movement between station \"%s\" to station \"%s\"\n", startName.content, stopName.content);
	n = UShortestPath(g, startCode->val, stopCode->val, cloneNode, stringCompare, myPrint);

	if(n == 0) {
		printf("Cannot move from station \"%s\" to station \"%s\"\n", startName.content, stopName.content);
	} else {
		printf("Path length between station \"%s\" to station \"%s\": %d\n", startName.content, stopName.content, n);
	}


	freeGraph(g);
	jrb_free_tree(stationList);
	return 0;
}
예제 #6
0
void BFS(Graph graph, Jval start, Jval stop, 
	Jval (*cloneFunc)(Jval), int (*compare)(Jval, Jval), void (*reportFunc)(Jval)) {
	Dllist node, queue;
	JRB visited;
	Jval *output;
	Jval temp, tmp;

	int i, n;

	visited = make_jrb();
	queue = new_dllist();
	dll_append(queue, start);

	if((output = myMalloc(sizeof(Jval), 100)) == NULL) {
		return;
	}

	while(!dll_empty(queue)) {
		node = dll_first(queue);
		temp = cloneFunc(node->val);
		dll_delete_node(node);

		if(jrb_find_gen(visited, temp, compare) == NULL) {
			reportFunc(temp);
			jrb_insert_gen(visited, temp, temp, compare);
			
			if(compare(temp, stop) == 0) {
				jrb_free_tree(visited);
				free_dllist(queue);
				free(output);
				return;
			}

			n = getAdjacentVertices(graph, temp, output, compare);
			for(i = 0; i < n; i++) {
				if(jrb_find_gen(visited, output[i], compare) == NULL) {
					dll_append(queue, output[i]);
				}
			}
		}
	}
}
예제 #7
0
파일: vcd2fst.c 프로젝트: Pidbip/egtkwave
static void dealloc_scope(void)
{
#ifdef _WAVE_HAVE_JUDY
PPvoid_t PPValue;

if(PJArray)
        {
        char Index[65537];
	Index[0] = 0;

        for (PPValue  = JudySLFirst (PJArray, (uint8_t *)Index, PJE0);
                 PPValue != (PPvoid_t) NULL;
                 PPValue  = JudySLNext  (PJArray, (uint8_t *)Index, PJE0))
            {
		free(*(char **)PPValue);
            }

        JudySLFreeArray(&PJArray, PJE0);
        PJArray = NULL;
        }
#else
if(comp_name_jrb)
	{
        JRB node;
	char *Index;

        jrb_traverse(node, comp_name_jrb)
            {
                Index = node->key.s;
                free(Index);
                Index = node->val.s;
                free(Index);
            }

        jrb_free_tree(comp_name_jrb);
        comp_name_jrb = NULL;
	}