예제 #1
0
bool hash_table_remove(hash_table_t* table, entry_t* value) {
	if(table==NULL) { return false; }
	unsigned long position = hash_entry(value->name, value->surname, table->size);
	list_t* list = &table->tab[position];
	if(erase(list,value)==0) { return true; }
	return false;
};
예제 #2
0
void hash_entry(const directory_entry &i, unsigned char (&hash)[crypto_generichash_BYTES])
{
	crypto_generichash_state state;

	crypto_generichash_init(&state, NULL, 0, sizeof(hash));
	hash_entry(i, state);
	crypto_generichash_final(&state, hash, sizeof(hash));
}
예제 #3
0
bool hash_table_insert(hash_table_t* table, entry_t* value) {
	if(table==NULL) { return false; }
	unsigned long position = hash_entry(value->name, value->surname, table->size);
	list_t* list = &table->tab[position];
//	if(!find(*list,value)) {
	if(push_front(list,value)==0) { return true; }
//	}
	return false;	
};
예제 #4
0
파일: jobs.c 프로젝트: petabi/pkgsrc
static struct scan_entry *
find_old_scan(const char *location)
{
	struct scan_entry *e;
	char *dep, *dep2, *path, *fullpath;
	int is_current;
	time_t mtime;

	e = SLIST_FIRST(&hash_table[hash_entry(location)]);
	while (e) {
		if (strcmp(e->location, location) == 0)
			break;
		e = SLIST_NEXT(e, hash_link);
	}
	if (e == NULL)
		return NULL;

	if (e->scan_depends == NULL)
		return e;

	is_current = 1;
	dep2 = dep = xstrdup(e->scan_depends);
	while ((path = strtok(dep, " ")) != NULL) {
		dep = NULL;
		if (*path == '\0')
			continue;
		if (*path == '/') {
			mtime = stat_path(path);
			if (mtime == -1 || mtime >= scan_mtime) {
				is_current = 0;
				break;
			}
			continue;
		}
		if (strncmp("../../", path, 6) == 0) {
			const char *s1 = strrchr(location, '/');
			const char *s2 = strchr(location, '/');
			if (s1 == s2)
				fullpath = xasprintf("%s/%s", pkgsrc_tree,
				    path + 6);
			else
				fullpath = xasprintf("%s/%s/%s", pkgsrc_tree,
				    location, path);
		} else {
			fullpath = xasprintf("%s/%s/%s", pkgsrc_tree,
			    location, path);
		}
		mtime = stat_path(fullpath);
		if (mtime == -1 || mtime >= scan_mtime) {
			is_current = 0;
			break;
		}
	}
	free(dep2);
	return is_current ? e : NULL;
}
예제 #5
0
파일: ir_prof.c 프로젝트: sharugupta/OpenUH
void 
__profile_call(ADDR caller, ADDR callee, char *caller_name, char *callee_name)
{
#ifdef _DEBUG
  return;
#else
  if (num_counts == 0)
    ir_prof_start();

  if (num_counts == sizeof_counts_array) {
    sizeof_counts_array *= 2;
    counts_array = (counts_entry *)REALLOC(
		    counts_array, sizeof_counts_array);
    PR_ASSERT(counts_array, "realloc of counts_array failed");
  }

  hash_entry(caller, callee, caller_name, callee_name);
#endif
}
예제 #6
0
/**
 * Process a call node.
 *
 * @param call    A ir_node to be checked.
 * @param callee  The entity of the callee
 * @param hmap    The quadruple-set containing the calls with constant parameters
 */
static void process_call(ir_node *call, ir_entity *callee, q_set *hmap)
{
	/* TODO
	 * Beware: We cannot clone variadic parameters as well as the
	 * last non-variadic one, which might be needed for the va_start()
	 * magic. */

	/* In this for loop we collect the calls, that have
	   a constant parameter. */
	size_t const n_params = get_Call_n_params(call);
	for (size_t i = n_params; i-- > 0;) {
		ir_node *const call_param = get_Call_param(call, i);
		if (is_Const(call_param)) {
			/* we have found a Call to collect and we save the information
			 * we need.*/
			if (!hmap->map)
				hmap->map = new_pset(entry_cmp, 8);

			entry_t *const key = OALLOC(&hmap->obst, entry_t);
			key->q.ent   = callee;
			key->q.pos   = i;
			key->q.tv    = get_Const_tarval(call_param);
			key->q.calls = NULL;
			key->weight  = 0.0F;
			key->next    = NULL;

			/* Insert entry or get existing equivalent entry */
			entry_t *const entry = (entry_t*)pset_insert(hmap->map, key, hash_entry(key));
			/* Free memory if entry already is in set */
			if (entry != key)
				obstack_free(&hmap->obst, key);

			/* add the call to the list */
			if (!entry->q.calls) {
				entry->q.calls = NEW_ARR_F(ir_node*, 1);
				entry->q.calls[0] = call;
			} else {
				ARR_APP1(ir_node *, entry->q.calls, call);
			}
		}
예제 #7
0
static int add_task(void *data, void *param)
{
	rec_driver_t driver;
	channel_t *channel = (channel_t *)data;
	if (channel->rec != 1)
		return -1;

	driver.type = channel->storage_type;
	if (hash_entry(driver_table, (void *)&driver, cmp_func_driver, 
			(void *)channel->storage_type, 
			(void **)&channel->rec_driver) == -1) {
		syslog(LOG_DEBUG, "none rec driver: %d", channel->storage_type);
		channel->rec = 0;
		return -1;
	}

	if (channel->id == 1)
		snprintf(channel->rec_name, sizeof(channel->rec_name), 
				"IPC_%04d", ((device_t *)channel->pdevice)->id);
	else
		snprintf(channel->rec_name, sizeof(channel->rec_name), 
				"IPC_%04d-%d", 
				((device_t *)channel->pdevice)->id,
				channel->id);

	((rec_driver_t *)channel->rec_driver)->record_callback =
		record_callback;
	set_nonestate(channel->rec_state);
	channel->rec_error = 0;
	if (dlist_add(&rec_task_list, (void *)channel) == -1) {
		channel->rec = 0;
		return -1;
	}
	syslog(LOG_DEBUG, "add rec task:%d %s", 
			channel->storage_type, channel->rec_name);
	return 0;
}
예제 #8
0
파일: bloom.c 프로젝트: hagemt/bloom
int
main(int argc, char *argv[])
{
	size_t path_len, total_files;
	off_t bytes_wasted, total_wasted;
	char path_buffer[PATH_MAX_LEN], *hash_value;
	struct file_entry_t *file_entry, *trie_entry;

	SListIterator slist_iterator;
	SetIterator set_iterator;

	/* Step 0: Session data */
	struct file_info_t file_info;
	clear_info(&file_info);

	/* Step 1: Parse arguments */
	while (--argc) {
		/* Being unable to record implies insufficient resources */
		if (!record(argv[argc], &file_info)){
			fprintf(stderr, "[FATAL] out of memory\n");
			destroy_info(&file_info);
			return (EXIT_FAILURE);
		}
	}

	/* Step 2: Fully explore any directories specified */
	#ifndef NDEBUG
	printf("[DEBUG] Creating file list...\n");
	#endif
	while (slist_length(file_info.file_stack) > 0) {
		/* Pick off the top of the file stack */
		file_entry = (struct file_entry_t *)(slist_data(file_info.file_stack));
		slist_remove_entry(&file_info.file_stack, file_info.file_stack);
		assert(file_entry->type == DIRECTORY);
		/* Copy the basename to a buffer */
		memset(path_buffer, '\0', PATH_MAX_LEN);
		path_len = strnlen(file_entry->path, PATH_MAX_LEN);
		memcpy(path_buffer, file_entry->path, path_len);
		/* Ignore cases that would cause overflow */
		if (path_len < PATH_MAX_LEN) {
			/* Append a trailing slash */
			path_buffer[path_len] = '/';
			/* Record all contents (may push onto file stack or one of the lists) */
			DIR *directory = opendir(file_entry->path);
			if (traverse(&file_info, directory, path_buffer, ++path_len)) {
				fprintf(stderr, "[FATAL] out of memory\n");
				destroy_info(&file_info);
				return (EXIT_FAILURE);
			} else if (closedir(directory)) {
				fprintf(stderr, "[WARNING] '%s' (close failed)\n", file_entry->path);
			}
		}
		/* Discard this entry */
		destroy_entry(file_entry);
	}

	/* Step 3: Warn about any ignored files */
	if (slist_length(file_info.bad_files) > 0) {
		slist_iterate(&file_info.bad_files, &slist_iterator);
		while (slist_iter_has_more(&slist_iterator)) {
			file_entry = slist_iter_next(&slist_iterator);
			fprintf(stderr, "[WARNING] '%s' ", file_entry->path);
			switch (file_entry->type) {
			case INVALID:
				++file_info.invalid_files;
				fprintf(stderr, "(invalid file)\n");
				break;
			case INACCESSIBLE:
				++file_info.protected_files;
				fprintf(stderr, "(protected file)\n");
				break;
			default:
				++file_info.irregular_files;
				fprintf(stderr, "(irregular file)\n");
				break;
			}
		}
		fprintf(stderr, "[WARNING] %lu file(s) ignored\n",
			(long unsigned)(num_errors(&file_info)));
	}
	#ifndef NDEBUG
	if (num_errors(&file_info) > 0) {
		fprintf(stderr, "[FATAL] cannot parse entire file tree\n");
		destroy_info(&file_info);
		return (EXIT_FAILURE);
	}
	printf("[DEBUG] Found %lu / %lu valid files\n",
		(unsigned long)(num_files(&file_info)),
		(unsigned long)(file_info.total_files));
	#endif

	/* Step 4: Begin the filtering process */
	#ifndef NDEBUG
	printf("[DEBUG] Creating file table...\n");
	#endif
	if (slist_length(file_info.good_files) > 0) {
		file_info.hash_trie = trie_new();
		file_info.shash_trie = trie_new();
		optimize_filter(&file_info);
		/* Extract each file from the list (they should all be regular) */
		slist_iterate(&file_info.good_files, &slist_iterator);
		while (slist_iter_has_more(&slist_iterator)) {
			file_entry = slist_iter_next(&slist_iterator);
			assert(file_entry->type == REGULAR);
			/* Perform a "shallow" hash of the file */
			hash_value = hash_entry(file_entry, SHALLOW);
			#ifndef NDEBUG
			printf("[SHASH] %s\t*%s\n", file_entry->path, hash_value);
			#endif
			/* Check to see if we might have seen this file before */
			if (bloom_filter_query(file_info.shash_filter, hash_value)) {
				/* Get the full hash of the new file */
				hash_value = hash_entry(file_entry, FULL);
				#ifndef NDEBUG
				printf("[+HASH] %s\t*%s\n", file_entry->path, hash_value);
				#endif
				archive(&file_info, file_entry);
				/* Check to see if bloom failed us */
				trie_entry = trie_lookup(file_info.shash_trie, file_entry->shash);
				if (trie_entry == TRIE_NULL) {
					#ifndef NDEBUG
					printf("[DEBUG] '%s' (false positive)\n", file_entry->path);
					#endif
					trie_insert(file_info.shash_trie, file_entry->shash, file_entry);
				} else {
					/* Get the full hash of the old file */
					hash_value = hash_entry(trie_entry, FULL);
					#ifndef NDEBUG
					if (hash_value) {
						printf("[-HASH] %s\t*%s\n", trie_entry->path, hash_value);
					}
					#endif
					archive(&file_info, trie_entry);
				}
			} else {
				/* Add a record of this shash to the filter */
				bloom_filter_insert(file_info.shash_filter, hash_value);
				trie_insert(file_info.shash_trie, hash_value, file_entry);
			}
		}
		persist("bloom_store", &file_info);
	}

	/* Step 5: Output results and cleanup before exit */
	printf("[EXTRA] Found %lu sets of duplicates...\n",
		(unsigned long)(slist_length(file_info.duplicates)));
	slist_iterate(&file_info.duplicates, &slist_iterator);
	for (total_files = total_wasted = bytes_wasted = 0;
		slist_iter_has_more(&slist_iterator);
		total_wasted += bytes_wasted)
	{
		Set *set = slist_iter_next(&slist_iterator);
		int size = set_num_entries(set);
		if (size < 2) { continue; }
		printf("[EXTRA] %lu files (w/ same hash):\n", (unsigned long)(size));
		set_iterate(set, &set_iterator);
		for (bytes_wasted = 0;
			set_iter_has_more(&set_iterator);
			bytes_wasted += file_entry->size,
			++total_files)
		{
			file_entry = set_iter_next(&set_iterator);
			printf("\t%s (%lu bytes)\n",
				file_entry->path,
				(unsigned long)(file_entry->size));
		}
	}
	printf("[EXTRA] %lu bytes in %lu files (wasted)\n",
		(unsigned long)(total_wasted),
		(unsigned long)(total_files));
	destroy_info(&file_info);
	return (EXIT_SUCCESS);
}
예제 #9
0
/*
 * c_entries --
 *	read .c and .h files and call appropriate routines
 */
void
c_entries(void)
{
	int	c;			/* current character */
	int	level;			/* brace level */
	int	token;			/* if reading a token */
	int	t_def;			/* if reading a typedef */
	int	t_level;		/* typedef's brace level */
	char	*sp;			/* buffer pointer */
	char	tok[MAXTOKEN];		/* token buffer */

	lineftell = ftell(inf);
	sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1;
	while (GETC(!=, EOF)) {
		switch (c) {
		/*
		 * Here's where it DOESN'T handle: {
		 *	foo(a)
		 *	{
		 *	#ifdef notdef
		 *		}
		 *	#endif
		 *		if (a)
		 *			puts("hello, world");
		 *	}
		 */
		case '{':
			++level;
			goto endtok;
		case '}':
			/*
			 * if level goes below zero, try and fix
			 * it, even though we've already messed up
			 */
			if (--level < 0)
				level = 0;
			goto endtok;

		case '\n':
			SETLINE;
			/*
			 * the above 3 cases are similar in that they
			 * are special characters that also end tokens.
			 */
	endtok:			if (sp > tok) {
				*sp = EOS;
				token = YES;
				sp = tok;
			}
			else
				token = NO;
			continue;

		/*
		 * We ignore quoted strings and character constants
		 * completely.
		 */
		case '"':
		case '\'':
			skip_string(c);
			break;

		/*
		 * comments can be fun; note the state is unchanged after
		 * return, in case we found:
		 *	"foo() XX comment XX { int bar; }"
		 */
		case '/':
			if (GETC(==, '*') || c == '/') {
				skip_comment(c);
				continue;
			}
			(void)ungetc(c, inf);
			c = '/';
			goto storec;

		/* hash marks flag #define's. */
		case '#':
			if (sp == tok) {
				hash_entry();
				break;
			}
			goto storec;

		/*
		 * if we have a current token, parenthesis on
		 * level zero indicates a function.
		 */
		case '(':
			if (!level && token) {
				int	curline;

				if (sp != tok)
					*sp = EOS;
				/*
				 * grab the line immediately, we may
				 * already be wrong, for example,
				 *	foo\n
				 *	(arg1,
				 */
				getline();
				curline = lineno;
				if (func_entry()) {
					++level;
					pfnote(tok, curline);
				}
				break;
			}
			goto storec;

		/*
		 * semi-colons indicate the end of a typedef; if we find a
		 * typedef we search for the next semi-colon of the same
		 * level as the typedef.  Ignoring "structs", they are
		 * tricky, since you can find:
		 *
		 *	"typedef long time_t;"
		 *	"typedef unsigned int u_int;"
		 *	"typedef unsigned int u_int [10];"
		 *
		 * If looking at a typedef, we save a copy of the last token
		 * found.  Then, when we find the ';' we take the current
		 * token if it starts with a valid token name, else we take
		 * the one we saved.  There's probably some reasonable
		 * alternative to this...
		 */
		case ';':
			if (t_def && level == t_level) {
				t_def = NO;
				getline();
				if (sp != tok)
					*sp = EOS;
				pfnote(tok, lineno);
				break;
			}
			goto storec;

		/*
		 * store characters until one that can't be part of a token
		 * comes along; check the current token against certain
		 * reserved words.
		 */
		default:
			/* ignore whitespace */
			if (c == ' ' || c == '\t') {
				int save = c;
				while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
					;
				if (c == EOF)
					return;
				(void)ungetc(c, inf);
				c = save;
			}
	storec:		if (!intoken(c)) {
				if (sp == tok)
					break;
				*sp = EOS;
				if (tflag) {
					/* no typedefs inside typedefs */
					if (!t_def &&
						   !memcmp(tok, "typedef",8)) {
						t_def = YES;
						t_level = level;
						break;
					}
					/* catch "typedef struct" */
					if ((!t_def || t_level < level)
					    && (!memcmp(tok, "struct", 7)
					    || !memcmp(tok, "union", 6)
					    || !memcmp(tok, "enum", 5))) {
						/*
						 * get line immediately;
						 * may change before '{'
						 */
						getline();
						if (str_entry(c))
							++level;
						break;
						/* } */
					}
				}
				sp = tok;
			}
			else if (sp != tok || begtoken(c)) {
				if (sp == tok + sizeof tok - 1)
					/* Too long -- truncate it */
					*sp = EOS;
				else 
					*sp++ = c;
				token = YES;
			}
			continue;
		}

		sp = tok;
		token = NO;
	}
예제 #10
0
static void destroy_page (struct hash_elem *p_, void *aux);
static struct page *page_for_addr (const void *address);
static bool do_page_in (struct page *p);
static bool set_page(struct thread *t, void * upage, void *frame, bool writable);
static bool load_from_exec(page *p);

static void page_do_evict (page *p);
static bool load_from_file(page *p);

//Hash tables functions

unsigned
page_hash(const struct hash_elem *e, void *aux UNUSED) 
{
  page *p = hash_entry(e, page, hash_elem);
  unsigned o = hash_int((int)p->addr);
  return o;
}

bool
page_less(const struct hash_elem *a, const struct hash_elem *b, void *aux UNUSED)
{
  page *p1 = hash_entry(a, page, hash_elem);
  page *p2 = hash_entry(b, page, hash_elem);
  if (p1->addr < p2->addr) 
  {
    return true;
  } else 
  {
    return false;