コード例 #1
3
ファイル: fs_lib.c プロジェクト: leaderwing/test_repo
int traverseBFS(Graph graph, int start, Dllist close) {
	Dllist node, queue;
	JRB visited;
	int *output;
	int temp;

	int i, n, counter = 0;

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

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

		if(jrb_find_int(visited, temp) == NULL) {
			counter++;
			// reportFunc(temp);
			jrb_insert_int(visited, temp, new_jval_i(temp));
			
			n = outdegree(graph, temp, output);
			for(i = 0; i < n; i++) {
				if(jrb_find_int(visited, output[i]) == NULL) {
					dll_append(queue, new_jval_i(output[i]));
				}
			}
		}
	}

	return counter;
}
コード例 #2
0
ファイル: dl_lists.c プロジェクト: OPENDAP/bes
int dll_free_list(DLL_NODE_PTR head)
{
	DLL_NODE_PTR node = NULL;
	int count = 0;

	FF_VALIDATE(head);
	if (head == NULL)
		return(0);
	
	dll_rewind(&head);

	node = dll_first(head);
	while (!DLL_IS_HEAD_NODE(node))
	{
		dll_delete_node(node);

		count++;
		node = dll_first(head);
	}

#ifdef DLL_CHK
	assert(DLL_COUNT(head) == 0);
#endif

	head->next = head->previous = NULL;

#ifdef FF_CHK_ADDR
	head->check_address = NULL;
#endif

	memFree(head, "Header Node");          

	return(count);
}
コード例 #3
0
ファイル: makedbin.c プロジェクト: OPENDAP/freeform_handler
static BOOLEAN variable_list_comp
	(
	 VARIABLE_LIST vlist1,
	 VARIABLE_LIST vlist2
	)
{
	VARIABLE_PTR v1;
	VARIABLE_PTR v2;
	
	if (!vlist1 || !vlist2)
		return(FALSE);
	
	vlist1 = dll_first(vlist1);
	v1 = FF_VARIABLE(vlist1);
	
	vlist2 = dll_first(vlist2);
	v2 = FF_VARIABLE(vlist2);
	
	while (v1 || v2)
	{
		if (!(v1 && v2))
			return(FALSE);

		if (!variable_comp(v1, v2))
			return(FALSE);
		
		vlist1 = dll_next(vlist1);
		v1 = FF_VARIABLE(vlist1);
		
		vlist2 = dll_next(vlist2);
		v2 = FF_VARIABLE(vlist2);
	}
	
	return(TRUE);
}
コード例 #4
0
ファイル: scheduler.c プロジェクト: marshallnaito/cs170_lab2
void scheduler()
{

	//readyq = new_dllist();

	if(dll_empty(readyq))
	{
		//printf("empty ready q\n");
		current = NULL;
		noop();
	}


	//takes the first PCB off the readyq and calls run_user_code() on its registers
	else
	{
		// pop off and delete from readyq
		printf("non-empty q\n");
		current = (PCB *) jval_v(dll_val(dll_first(readyq)));
		printf("non-empty q\n");
		dll_delete_node(dll_first(readyq));
		printf("non-empty q\n");
		run_user_code(current->registers);
	}
}
コード例 #5
0
ファイル: util.c プロジェクト: hoangHEDSPI/C-Advanced
Jval* deQueue(Queue q) {
	Jval* v;
	if (dll_empty(q) || dll_empty(dll_first(q))) v = NULL;
	else {
		v = (Jval*)malloc(sizeof(Jval));
		memcpy(v,&dll_first(q)->val, sizeof(Jval));
		dll_delete_node(dll_first(q));
	}
	return v;
}
コード例 #6
0
ファイル: 2.c プロジェクト: namnt1410/Emb_exp
int main (int argc, char **argv)
{
  struct msgbuff{
    long mtype;
    pid_t pid;
  }message;

  pid_t pid, npid;
  int i;

  int           msqid;
  key_t         keyx;
  struct msqid_ds msq;

  Dllist q = new_dllist();
  Dllist n;

  keyx = ftok(KEYFILE_PATH, (int)ID);

  msqid = msgget(keyx, 0666 | IPC_CREAT);

  if (msqid == -1) {
    perror("msgget");
    exit(1);
  }

  while(1) { 
    if((msgrcv(msqid, &message, sizeof(pid_t), 1, 0)) ==
       MSGQ_NG){
      perror("msgrcv");
      exit(1);
    }
    pid = message.pid;
    if(pid != 1) {
      if(dll_empty(q)) kill(pid, SIGUSR1);
      else {
        n = dll_first(q);
        npid = jval_i(dll_val(n));
        if(pid == npid) { 
          kill(pid, SIGUSR1);
          dll_delete_node(n);
        } else dll_append(q, new_jval_i(pid));
      }
    } else {
      if(!dll_empty(q)) { 
        n = dll_first(q);
        npid = jval_i(dll_val(n));
        kill(npid, SIGUSR1);
        dll_delete_node(n);
      }
    }
  }

  return 0;
}
コード例 #7
0
//Each elevator is a while loop. 
//Check the global list and if it’s empty, block on the condition variable for blocking elevators. 
//When the elevator gets a person to service, it moves to the appropriate flo0or and opens its door. 
//It puts itself into the person’s e field, then signals the person and blocks until the person wakes it up. 
//When it wakes up, it goes to the person’s destination floor, opens its door, signals the person and blocks. 
//When the person wakes it up, it closes its door and re-executes its while loop.
//• Your elevator’s should call open door(), close door() from move to floor() appropriately. 
//All sleeping and printing should be done in elevator skeleton.c. 
//Thus, your final program that you hand in should not do any sleeping or any printing.
void *elevator(void *arg)
{
    Person *person_in_transit;
    for(;;)
    {

        pthread_mutex_lock(((Elevator*)arg)->es->lock);
        while (!((Queue*)((Elevator*)arg)->es->v)->count)
            pthread_cond_wait(((Queue*)((Elevator*)arg)->es->v)->cond, ((Elevator*)arg)->es->lock);
            if(!dll_empty(((Queue*)((Elevator*)arg)->es->v)->passengers)){
             person_in_transit = (Person*)jval_v(dll_val(dll_first(((Queue*)((Elevator*)arg)->es->v)->passengers)));
             dll_delete_node(dll_first(((Queue*)((Elevator*)arg)->es->v)->passengers));
            }
        // unlock the critial section.
        pthread_mutex_unlock(((Elevator*)arg)->es->lock);
       //move the elevator.
        --((Queue*)((Elevator*)arg)->es->v)->count;
        person_in_transit->from == ((Elevator*)arg)->onfloor?:move_to_floor(((Elevator*)arg), person_in_transit->from);
        //open the door
        open_door(((Elevator*)arg));
        //add the people to the elevator
        person_in_transit->e = ((Elevator*)arg); 
        //signal the person
        pthread_mutex_lock(person_in_transit->lock);
        pthread_cond_signal(person_in_transit->cond);
        pthread_mutex_unlock(person_in_transit->lock);
        // have the elevator wait
        pthread_mutex_lock(((Elevator*)arg)->lock);
        pthread_cond_wait(((Elevator*)arg)->cond, ((Elevator*)arg)->lock);
        pthread_mutex_unlock(((Elevator*)arg)->lock);
        // close door 
        close_door(((Elevator*)arg));
        // elevator moves
        move_to_floor(person_in_transit->e,person_in_transit->to);
        // open the door once move has completed.
        open_door(((Elevator*)arg));
        // signal the person
        pthread_mutex_lock(person_in_transit->lock);
        pthread_cond_signal(person_in_transit->cond);
        pthread_mutex_unlock(person_in_transit->lock);
        // block the elevator
        pthread_mutex_lock(((Elevator*)arg)->lock);
        pthread_cond_wait(((Elevator*)arg)->cond, ((Elevator*)arg)->lock);
        pthread_mutex_unlock(((Elevator*)arg)->lock);
        // close the door
        close_door(((Elevator*)arg));
        // restart. 
    }
}
コード例 #8
0
ファイル: scheduler.c プロジェクト: Styxx/CS170-W16
void scheduler() {

  // Init no longer has children. Needs to close.
  if (jrb_empty(init->children)) {
    SYSHalt();
  }

  if(dll_empty(readyQ)) {
    noop_flag = 1;
    noop();
  } else {
    PCB *process;
    Dllist node;
    Jval registers;
    
    noop_flag = 0;
    process = (PCB *) malloc(sizeof(PCB));
    node = dll_first(readyQ);       // Get next node in queue
    dll_delete_node(node);          // Node in memory. Delete off readyQ
    
    // Get registers from node
    registers = dll_val(node);
    process = (PCB *)jval_v(registers);
    
    // Update current process
    currentProcess = process;
    User_Base = process->base;
    User_Limit = process->limit;
    
    run_user_code(process->registers);
  }
}
コード例 #9
0
ファイル: dl_lists.c プロジェクト: OPENDAP/bes
int list_replace_items(pgenobj_cmp_t lri_cmp, DLL_NODE_PTR list)
{
	int error = 0;

	FF_VALIDATE(list);

	list = dll_first(list);
	while (!DLL_IS_HEAD_NODE(list))
	{
		DLL_NODE_PTR list_walker = NULL;

		list_walker = dll_next(list);

		while (!DLL_IS_HEAD_NODE(list_walker))
		{
			if ((*lri_cmp)(list->data.u.var, list_walker->data.u.var))
			{
				list = dll_previous(list);
				dll_delete(list->next);
				break;
			}

			list_walker = dll_next(list_walker);
		}

		list = dll_next(list);
	}

	return(error);
}
コード例 #10
0
ファイル: dlltail.c プロジェクト: C24IO/Chatak_Megh_SamVad
main(int argc, char **argv)
{
  IS is;
  int n;
  Dllist l;
  Dllist tmp;

  if (argc != 2) {
    fprintf(stderr, "usage: dlltail n\n");
    exit(1);
  }
  n = atoi(argv[1]);
  if (n < 0) {
    fprintf(stderr, "usage: dlltail n  -- n must be >= 0\n");
    exit(1);
  }

  is = new_inputstruct(NULL);
  l = new_dllist();

  while (get_line(is) >= 0) {
    dll_append(l, new_jval_s(strdup(is->text1)));
    if (is->line > n) {
      tmp = dll_first(l);
      free(jval_s(dll_val(tmp)));
      dll_delete_node(tmp);
    }
  }

  dll_traverse(tmp, l) printf("%s", jval_s(tmp->val));
}
コード例 #11
0
ファイル: fs_lib.c プロジェクト: leaderwing/test_repo
int searchController(Graph graph, int start, int stop, int option) {
	Dllist close;
	Dllist node;

	close = new_dllist();

	switch(option) {
		case BFS_SEARCH:
		breathFirstSearch(graph, start, stop, close);
		break;
		case BFS_TRAVERSE:
		traverseBFS(graph, start, close);
		break;
		case DFS_SEARCH:
		deepFirstSearch(graph, start, stop, close);
		break;
		case DFS_TRAVERSE:
		traverseDFS(graph, start, close);
		break;
		default:
		printf("This is not an option\n");
		free_dllist(close);
		return;
	}

	node = dll_first(close);
	printf("Visit %d\n", jval_i(node->val));

	free_dllist(close);
}
コード例 #12
0
ファイル: makedbin.c プロジェクト: OPENDAP/freeform_handler
static void release_file_handles
	(
	 DATA_BIN_PTR dbin,
	 FF_TYPES_t io
	)
{
	PROCESS_INFO_LIST plist = NULL;
	PROCESS_INFO_PTR pinfo = NULL;

	FF_VALIDATE(dbin);

	if (!db_ask(dbin, DBASK_PROCESS_INFO, io, &plist))
	{
		plist = dll_first(plist);
		pinfo = FF_PI(plist);
		while (pinfo)
		{
			if (PINFO_SUPER_ARRAY(pinfo)->fp)
				fclose(PINFO_SUPER_ARRAY(pinfo)->fp);
			else if (PINFO_SUB_ARRAY(pinfo)->fp)
				fclose(PINFO_SUB_ARRAY(pinfo)->fp);

			plist = dll_next(plist);
			pinfo = FF_PI(plist);
		}

		ff_destroy_process_info_list(plist);
	}
}
コード例 #13
0
ファイル: dllist.c プロジェクト: josborn8/libfdr
void free_dllist(Dllist l)
{
  while (!dll_empty(l)) {
    dll_delete_node(dll_first(l));
  }
  free(l);
}
コード例 #14
0
ファイル: mmusim.c プロジェクト: Dr-Jerm/MemoryManagmentUnit
PhysicalFrame* findFreePhysicalPage(MMUSim* sim){
  Dllist freeFrames;
  freeFrames = sim->freePhysicalFrames;
  Dllist usedFrames;
  usedFrames = sim->usedPhysicalFrames;
  JRB tree;
  tree = sim->frameTree;
  Dllist nil;
  nil = dll_nil(freeFrames);
  Dllist ffp;
  ffp = dll_first(freeFrames);

  if(ffp != nil){
    PhysicalFrame* freeFrame;
    freeFrame = ffp->val.v;
    dll_delete_node(ffp);
    dll_append(usedFrames, new_jval_v(freeFrame));

    if(sim->rep == 2){ // LRU, sort by time
      jrb_insert_int(tree,freeFrame->lastUsed,new_jval_v(freeFrame));
    } else if(sim->rep == 3){ // LFU, sort by lowCount
      jrb_insert_int(tree,freeFrame->useCount,new_jval_v(freeFrame));
    } else if (sim->rep == 4){ // MFU, sort by highCount
      jrb_insert_int(tree,freeFrame->useCount,new_jval_v(freeFrame));
    }  

    return freeFrame;
  } else {
    return -1;
  }

}
コード例 #15
0
ファイル: mmusim.c プロジェクト: Dr-Jerm/MemoryManagmentUnit
MMUProcess* getProcess(MMUSim* sim, int* pid){
  Dllist processList;
  processList = sim->processes;
  Dllist nil;
  nil = dll_nil(processList);
  Dllist s;
  s = dll_first(processList);

  while(s != nil){
    MMUProcess* proc;
    proc = s->val.v;

    if(proc->pid == pid){
      return proc;
    }
    s = s->flink;
  }

  MMUProcess* ps;
  ps = malloc(sizeof(MMUProcess));
  ps->pid = pid;
  ps->stats.pid = pid;
  dll_append(processList, new_jval_v(ps));
  PageTable* pageTable = malloc(sizeof(PageTable));
  PageTableEntry* pageArray = malloc(sim->pageEntries * sizeof(PageTableEntry));
  pageTable->table = pageArray;
  pageTable->size = sim->pageEntries;
  ps->pgtbl = pageTable;

  return ps;
}
コード例 #16
0
ファイル: fs_lib.c プロジェクト: leaderwing/test_repo
int solution(Graph graph, Jval start, Jval stop, Dllist stackVisit, Jval (*cloneFunc)(Jval),
	int (*compare)(Jval, Jval), void (*reportFunc)(Jval)) {

	Dllist stackRes;
	Dllist node;
	Jval nowNode, temp;
	int counter = 0;

	stackRes = new_dllist();
	node = dll_first(stackVisit);
	nowNode = cloneFunc(node->val);
	dll_delete_node(node);
	dll_prepend(stackRes, nowNode);

	while(!dll_empty(stackVisit)) {
		if(isAdjacent(graph, nowNode, start, compare)) {
			dll_prepend(stackRes, start);
			counter++;
			break;
		}

		do {
			node = dll_first(stackVisit);
			temp = cloneFunc(node->val);
			dll_delete_node(node);	

			if(isAdjacent(graph, nowNode, temp, compare)) {
				dll_prepend(stackRes, temp);
				nowNode = temp;
				counter++;
				break;
			}
		} while(!dll_empty(stackVisit));
	}

	printf("Solution: The shortest path between two node: \n");

	while(!dll_empty(stackRes)) {
		node = dll_first(stackRes);
		reportFunc(node->val);
		dll_delete_node(node);
	}

	free_dllist(stackVisit);

	return counter;
}
コード例 #17
0
ファイル: writeprj.c プロジェクト: BackupTheBerlios/hsc-svn
/* append other documents referered */
static VOID append_doc_references(EXPSTR * prjstr, DLLIST * reflist)
{
    DLNODE *nd = dll_first(reflist);
    while (nd)
    {
        append_reference(prjstr, (HSCREF *) dln_data(nd));
        nd = dln_next(nd);
    }
}
コード例 #18
0
ファイル: writeprj.c プロジェクト: BackupTheBerlios/hsc-svn
/* append ids defined within documents */
static VOID append_doc_iddefs(EXPSTR * prjstr, DLLIST * iddefs)
{
    DLNODE *nd = dll_first(iddefs);
    while (nd)
    {
        append_iddef(prjstr, (HSCIDD *) dln_data(nd));
        nd = dln_next(nd);
    }
}
コード例 #19
0
ファイル: writeprj.c プロジェクト: BackupTheBerlios/hsc-svn
/* append included files */
static VOID append_doc_includes(EXPSTR * prjstr, DLLIST * inclist)
{
    DLNODE *nd = dll_first(inclist);
    while (nd)
    {
        append_include(prjstr, (HSCINC *) dln_data(nd));
        nd = dln_next(nd);
    }
}
コード例 #20
0
ファイル: parse.c プロジェクト: BackupTheBerlios/hsc-svn
/*
 * hsc_parse_end
 *
 * check for all tags closed and required
 * tags occured
 */
BOOL hsc_parse_end(HSCPRC * hp)
{
    if (!hp->fatal)
    {
        /* remember current file position */
        INFILEPOS *infpos = new_infilepos(hp->inpf);
        DLNODE *nd = NULL;

        /* check for unclosed containers:
         * for every container tag still on stack launch a message,
         * exept for autoclose tags */
        nd = hp->container_stack->last;
        while (nd)
        {
            HSCTAG *endtag = (HSCTAG *) dln_data(nd);

            if (!(endtag->option & HT_AUTOCLOSE))
            {
                set_infilepos(hp->inpf, endtag->start_fpos);
                hsc_message(hp, MSG_MISS_CTAG,
                            "%c missing", endtag->name);
            }

            nd = dln_prev(nd);
        }

        /* restore file position */
        set_infilepos(hp->inpf, infpos);
        del_infilepos(infpos);

        /* check for required and recommended tags missing */
        nd = dll_first(hp->deftag);
        while (nd)
        {
            HSCTAG *tag = (HSCTAG *) dln_data(nd);

            if ((tag->option & HT_REQUIRED
                 && (tag->occured == FALSE)))
            {
                hsc_message(hp, MSG_MISS_REQTAG,
                            "required %T missing", tag);
            }
            else if ((tag->option & HT_RECOMMENDED
                      && (tag->occured == FALSE)))
            {
                hsc_message(hp, MSG_MISS_RCMDTAG,
                            "recommended %T missing", tag);
            }
            nd = dln_next(nd);
        }

        /* output last white spaces at eof */
        hsc_output_text(hp, "", "");
    }
    return (BOOL) (!hp->fatal);
}
コード例 #21
0
ファイル: kt.c プロジェクト: jtmurphy89/OSClassProject
void
FreeFinishedThreads()
{
	Dllist curr;

        while (!dll_empty(ktFree_me)) 
        {
                curr = dll_first(ktFree_me);
		FreeKThread((K_t)curr->val.v);
		dll_delete_node(curr);
        }
        return;
}
コード例 #22
0
ファイル: posteval.c プロジェクト: mbethke/hsc
/*
 * postprocess_attributes
 *
 * This function scans a tag's list of attributes for URI-attributes
 * referring to an external URI. If it succeeds, and the hsc-process
 * has it's hp->strip_ext flag enabled, the function exits.
 *
 * Otherwise, it scans the attributes for new IDs and references
 * and updates the document data if neccessary (but only for start tags)
 *
 * params:
 *   hp ........ hsc-process
 *   tag ....... tag whose attribute list should be examined
 *   open_tag .. for end tags, the document-data should not be
 *               updated again
 * result:
 *   TRUE, if tag should NOT be stripped
 */
BOOL postprocess_tagattr(HSCPRC * hp, HSCTAG * tag, BOOL open_tag) {
    BOOL dontstrip = TRUE;

    if (tag->attr) {

        /*
         * find out, if list should be refused
         */
        if (hp->strip_ext
            && tag->uri_stripext
            && get_vartext(tag->uri_stripext)
            && (uri_kind(get_vartext(tag->uri_stripext)) == URI_ext)
            )
        {
            D(fprintf(stderr, DHL "strip external\n"));
            dontstrip = FALSE;
        } else if (open_tag) {
            /*
             * search for new IDs and references
             */
            DLNODE *nd = dll_first(tag->attr);
            while (nd) {
                HSCATTR *attrib = (HSCATTR *) dln_data(nd);
                STRPTR value = get_vartext(attrib);

                if (value) {
                    if (attrib->vartype == VT_URI) {
                        /* new reference */
                        INFILEPOS *fpos = new_infilepos(hp->inpf);
                        CALLER *newcaller = fpos2caller(fpos);
                        HSCREF *newref =
                        app_reference(hp->project->document, value);

                        newref->caller = newcaller;

                        del_infilepos(fpos);
                        D(fprintf(stderr, DHL "new REFERENCE: `%s'\n", value));

                    } else if (attrib->vartype == VT_ID) {
                        /* new id defined */
                        D(fprintf(stderr, DHL "new ID: `%s'\n", value));
                        add_local_iddef(hp, value);
                    }
                }
                nd = dln_next(nd);
            }
        }
    }
    return (dontstrip);
}
コード例 #23
0
ファイル: server.c プロジェクト: aacalfa/ramseysearch
/* parseResult
 * Parses a message containing the graph adjacency matrix
 * Message format "[graphsize]:[graph adjacency matrix]"
 */
static void parseResult(char *pch) {
	/* Get gsize */
	pch = strtok(NULL, ":");
	int gsize = atoi(pch);

	/* Get Clique Count */
	pch = strtok(NULL, ":");
	int clCount = atoi(pch);

	/* Get matrix */
	pch = strtok(NULL, ":");
	int *g = ChartoGraph(pch, gsize);

	/* Verify integrity of g */
	int realCount = CliqueCount(g, gsize);

	/* Message is invalid */
	if (realCount != clCount) {
		fprintf(stderr, "Message could not be validated!\n");
		fprintf(stderr, "Clique count from message: %d, actual clique count: %d!\n", clCount, realCount);
		return;
	}

	/* Update scheduler */
	if(clCount == 0) {
		fprintf(stderr, "Counterexample successfully received!\n");
		if(gsize > _Scheduler->currCEsize) { /* Found a counterexample */
			/* Update Scheduler */
			_Scheduler->currCEsize = gsize;
			/* clear list and add new counterexample */
			free_dllist(_Scheduler->counterExamples);
			_Scheduler->counterExamples = new_dllist();
			_Scheduler->listSize = 0;
			addCounterExample(g);
			/* Update current pointer */
			_Scheduler->currPtr = dll_first(_Scheduler->counterExamples);
			/*print only when save a counterexample*/
			fprintf(stderr, "get a counterexample with bigger size, size: %d\n, currCEsize: %d\n", gsize, _Scheduler->currCEsize);
			/* Save counterexample into a file */
			SaveGraph(g,gsize, "../../../counterexamples");
		}
		/* Just add new counterexample */
		else if(gsize == _Scheduler->currCEsize) {
				fprintf(stderr, "Saving a counterexample with same size\n");
				addCounterExample(g);
				SaveGraph(g,gsize, "../../../counterexamples");
		}
	}
}
コード例 #24
0
ファイル: server.c プロジェクト: aacalfa/ramseysearch
/* initializeScheduler
 * Initializes scheduler if it has not been initialized yet.
 * Returns 0 if the scheduler was initialized correctly.
 * Returns 1 if the scheduler already exists.
 * Returns -1 if the initialization was unsuccessful.
 */
int initializeScheduler(void) {
	if(_Scheduler == NULL) {
		_Scheduler = (Scheduler*) malloc(sizeof(Scheduler));
		if(_Scheduler == NULL)
			return -1;

		/* Set the Scheduler pointer to be shared */
#ifdef __APPLE__
		_Scheduler = mmap(NULL, sizeof(_Scheduler), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
#else
		_Scheduler = mmap(NULL, sizeof(_Scheduler), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
#endif

		/* Initialize fields */
		_Scheduler->counterExamples = new_dllist();
		_Scheduler->listSize = 0;

		/* Load best graph counterexamples */
		int file_count;
		char **CEfiles = getCounterExamplesFromFolder("../../../counterexamples/more121", &file_count);
		int i;
		for(i = 0; i < file_count; i++) {
			int *g;
			char *fname;
			asprintf(&fname, "../../../counterexamples/more121/%s", CEfiles[i]);
			if(ReadGraph(fname, &g, &(_Scheduler->currCEsize))) {
				fprintf(stderr, "Loaded graph %s successfully!\n", fname);
				addCounterExample(g);
			}
		}
		/*Print list size*/
		fprintf(stderr, "List size after initialization: %d\n", _Scheduler->listSize);
		/* Initialize current list pointer */
		_Scheduler->currPtr = dll_first(_Scheduler->counterExamples);

		/* free CEfiles */
		for(i = 0; i < _Scheduler->listSize; i++) {
			free(CEfiles[i]);
		}
		free(CEfiles);

		return 0;
	}
	else
		return 1;
}
コード例 #25
0
ファイル: makedbin.c プロジェクト: OPENDAP/freeform_handler
static int make_unique_format_titles(DATA_BIN_PTR dbin)
{
	PROCESS_INFO_LIST plist = NULL;
	PROCESS_INFO_PTR pinfo = NULL;

	int error = 0;
	int SCRATCH = strlen("Binary Output Separate Varied Record Header: ") + 1; /* Longest */

	char *cp = NULL;

	FF_VALIDATE(dbin);

	db_ask(dbin, DBASK_PROCESS_INFO, 0, &plist);

	plist = dll_first(plist);
	pinfo = FF_PI(plist);
	while (pinfo && !error)
	{
		FF_VALIDATE(pinfo);

		cp = (char *)memRealloc(PINFO_FORMAT(pinfo)->name, strlen(PINFO_FORMAT(pinfo)->name) + SCRATCH + 1, "PINFO_FORMAT(pinfo)->name");
		if (cp)
		{
			PINFO_FORMAT(pinfo)->name = cp;
			memmove(cp + SCRATCH, cp, strlen(cp) + 1);
		}
		else
		{
			error = err_push(ERR_MEM_LACK, "");
			break;
		}

		error = get_format_type(PINFO_FORMAT(pinfo), cp);
		if (error)
			break;

		memmove(cp + strlen(cp), cp + SCRATCH, strlen(cp + SCRATCH) + 1);

		plist = dll_next(plist);
		pinfo = FF_PI(plist);
	}

	ff_destroy_process_info_list(plist);

	return error;
}
コード例 #26
0
ファイル: cache.c プロジェクト: gqjjqg/android-extend
int PullCache(INT h, int hash, int *width, int *height, int *format, unsigned char ** data)
{
	LPCACHE_NODE pNode;
	LPCACHE_HANDLE handle = (LPCACHE_HANDLE)h;
	int ret = 0;
	if (handle == GNull) {
		return PARAM_INVALID;
	}

	// search in rb-tree
	pNode = rbt_search(&handle->mRBRoot, hash);

	if (pNode != GNull) {
		//remove out.
		dl_remove_node(&(pNode->mDLNode), &(handle->mDLRoot));

		//add node
		dl_insert_node(&(pNode->mDLNode), GNull, &(handle->mDLRoot));

		cache_data_parse(&(pNode->mData), width, height, format, data);

	} else {
		//not found.
#if defined( _DEBUG )
		LPRB_NODE node;
		LPDLL_NODE link;
		LPCACHE_NODE data;
		LOGI("not found %ld\n", hash);
		for (node = rb_first(&(handle->mRBRoot)); node != GNull; node = rb_next(node)) {
			container_of(data, node, CACHE_NODE, mRBNode);
			LOGI("%ld\n", data->mKey);
		}
		LOGI("double link list:\n");
		for (link = dll_first(&(handle->mDLLRoot)); link != GNull; link = dll_next(link)) {
			container_of(data, link, CACHE_NODE, mDLLNode);
			LOGI("%ld\n", data->mKey);
		}

#endif
		return -1;
	}

	return ret;
}
コード例 #27
0
ファイル: fs_lib.c プロジェクト: leaderwing/test_repo
int UShortestPath(Graph graph, Jval start, Jval stop, 
	Jval (*cloneFunc)(Jval), int (*compare)(Jval, Jval), void (*reportFunc)(Jval)) {

	Dllist node, queue, stackVisit;
	JRB visited;
	Jval *output;
	Jval temp, tmp;

	int i, n;

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

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

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

		if(jrb_find_gen(visited, temp, compare) == NULL) {
			jrb_insert_gen(visited, temp, temp, compare);
			dll_prepend(stackVisit, temp);
			
			if(compare(temp, stop) == 0) {
				return solution(graph, start, stop, stackVisit, cloneFunc, compare, reportFunc);
			}

			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]);
				}
			}
		}
	}

	return -1;
}
コード例 #28
0
ファイル: fs_lib.c プロジェクト: leaderwing/test_repo
void DFS(Graph graph, Jval start, Jval stop, 
	Jval (*cloneFunc)(Jval), int (*compare)(Jval, Jval), void (*reportFunc)(Jval)) {
	Dllist node, stack;
	JRB visited;
	Jval *output;
	Jval temp, tmp;

	int i, n;

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

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

	while(!dll_empty(stack)) {
		node = dll_first(stack);
		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(stack);
				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_prepend(stack, output[i]);
				}
			}
		}
	}
}
コード例 #29
0
ファイル: fs_lib.c プロジェクト: leaderwing/test_repo
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;
}
コード例 #30
0
void BFS_Visit(Graph_Struct Graph,char start[])
{
	Graph_Symbol_Table *Table;
	char *u,*v;
	JRB node_rbt,tree,ele;
	Dllist node_queue,queue = new_dllist();
	printf("%s ",start);
	
	u = malloc(MAX_LENGTH_STRING);
	v = malloc(MAX_LENGTH_STRING);
	
	Table = Search_On_Table(Graph,start);
	Table->colour = 'g';
	
	dll_append(queue, new_jval_s(start));
	while(!dll_empty(queue))
	{
		node_queue = dll_first(queue);
		u = jval_s(node_queue->val);
		dll_delete_node(node_queue);
		node_rbt = jrb_find_str(Graph.Edges,u);
		if(node_rbt != NULL)
		{
			tree = (JRB)jval_v(node_rbt->val);
			jrb_traverse(ele,tree)
			{
				v = jval_s(ele->key);
				Table = Search_On_Table(Graph,v);
				if(Table->colour == 'w')
				{
					printf("%s ",v);
					Table->colour = 'g';
					if(Table->previous == NULL)
					{
						Table->previous = malloc(MAX_LENGTH_STRING);
					}
					strcpy(Table->previous,u);
					dll_append(queue, new_jval_s(v));
				}
			}
		}