コード例 #1
0
ファイル: tlb.c プロジェクト: Cybuster/cpu
int add_tlb_entry (uint32 va, uint32 pa, uint8 perms)
{
	uint32 h;
	tlb_entry *t;

	h = hash (va);
	
	if (size_of_hash_list (h) < 8) {
		t = malloc (sizeof (tlb_entry));
		if (t == NULL) {
			return (-1);
		}
		t->va = va & 0xFFFFF000;
		t->pa = pa;
		t->perms = perms;
		add_to_hash_list (&tlb[h], t);
		return 0;
	}
	else {
		/*Right now, just replacing the first one*/
		/*TODO:decide which entry to replace*/
		tlb_entry *entry_to_modify = tlb[h];
		entry_to_modify->va = va;
		entry_to_modify->pa = pa;
		entry_to_modify->perms = perms;
		return 0;
	}
}
コード例 #2
0
ファイル: database.c プロジェクト: Hersh500/C-Programs
main()
{
	FILE *fp; 
	int i,rc;
	DB_PTR entry;
	char name_to_search [16];

	fp = fopen ("file.in", "r");
	if (fp == NULL) {
		printf ("failed to open file.in\n");
		exit (-1);
	}

	for (i = 0; i  < MAX_HASH_BUCKETS; i++) {
		hashtable[i] = NULL;
	}

	while (1) {
		entry = malloc (sizeof (struct database));
		if (entry == NULL) {
			printf ("malloc failed\n");
			exit (-2);
		}
		rc = read_entry (fp, entry);
		if (rc == -1) {
			free (entry);
			break;
		}
		int index = hash (entry->name); 
		add_to_hash_list (&hashtable[index], entry); 
	}

	
	printf("%s\n", hashtable[0]->name); 

	while (1) {
		printf ("entry name to search: ");
		scanf ("%s", name_to_search);
		printf ("\n");
		if (strcmp (name_to_search, "exit") == 0) {
			printf ("bye\n");
			exit (0);
		}
		entry = search_hash_list (hashtable, name_to_search);
		if (entry) {
			printf ("weight = %d height = %d\n", entry->weight, entry->height);
		}
		else {
			printf ("Name not found\n"); 
		}
	}
}