Example #1
0
GRAPH *make_graph(FUNCTION *func)
{
    GRAPH *graph = CAST_TO_GRAPH(tree_create_node(GRAPH_NODE));
    graph->forward = create_hash(10, key_type_direct);
    graph->backward = create_hash(10, key_type_direct);
    graph->labels = create_hash(10, key_type_direct);
    
    return graph;
}
Example #2
0
void initialize_network_info()
  {
  cache.nc_ra = initialize_resizable_array(INITIAL_HASH_SIZE);

  cache.nc_namekey = create_hash(INITIAL_HASH_SIZE);
  cache.nc_saikey = create_hash(INITIAL_HASH_SIZE);

  cache.nc_mutex = (pthread_mutex_t *)calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(cache.nc_mutex, NULL);
  } /* END initialize_network_info() */
static void
create_transaction_db() {
  debug( "Creating transaction database." );

  assert( transaction_db == NULL );

  transaction_db = xmalloc( sizeof( transaction_table ) );
  transaction_db->xid = create_hash( compare_transaction_id, hash_transaction_id );
  assert( transaction_db->xid != NULL );
  transaction_db->barrier_xid = create_hash( compare_transaction_id, hash_transaction_id );
  assert( transaction_db->barrier_xid != NULL );

  debug( "Transaction database is created ( db = %p, xid = %p, barrier_xid = %p ).", transaction_db, transaction_db->xid, transaction_db->barrier_xid );
}
Example #4
0
int build_name2num(struct rooted_tree *tree, struct hash **name2num_ptr)
{
	/* If the tree is dichotomous and has N nodes, then it has L = (N+1)/2
	 * leaves. But for highly polytomous trees, L is higher, and can
	 * approach N in some cases (e.g. when most leaves are attached to the
	 * root due to low bootstrap support). So we allocate N bins. */
	struct hash *n2n = create_hash(tree->nodes_in_order->count);
	if (NULL == n2n) return NS_MEM_ERROR;
	struct list_elem *el;
	int ord_number = 0;

	for (el = tree->nodes_in_order->head; NULL != el; el = el->next) {
		struct rnode *current = (struct rnode *) el->data;
		if (is_leaf(current)) {
			int *nump;
			if (strcmp("", current->label) == 0)
				return NS_EMPTY_LABEL;
			if (NULL != hash_get(n2n, current->label)) 
				return NS_DUP_LABEL;
			nump = malloc(sizeof(int));
			if (NULL == nump) 
				return NS_MEM_ERROR;
			*nump = ord_number;
			if (! hash_set(n2n, current->label, nump))
				return NS_MEM_ERROR;
			ord_number++;
		}
	}	
	*name2num_ptr = n2n;

	return NS_OK;
}
/* Function to read a file and creates a hash table.
The reading format is set to the model "key = value" line by line.*/
LoadConfig* file2map(const char* FileName)
{
	FILE *Archx = fopen(FileName, "r");

	LoadConfig *conf = Malloc(LoadConfig, 1);

	if(Archx == NULL)
    {
		fatal_error("Error reading file, function file2map. Check it please. \n");
        return NULL;
    }

	int lines = amount_line(Archx);

	conf->table = create_hash(lines);
	conf->getParameterChar = search_str_hash;

	char *key = Malloc(char, MAX_LINE_FILE);
	char *value = Malloc(char, MAX_LINE_FILE);

	for(int i = 0; i < conf->table->TABLE_SIZE; i++)
	{
		fscanf(Archx, "%s = %[^\n]s", key, value);
		insert_str_hash(conf->table, key, value);
	}

	fclose(Archx);
	free(key);
	free(value);

	return conf;
}
//driver code
int main()
{
    // Let cache can hold X pages
    unsigned int X = 4;
    Queue* q = create_queue( X );
 
    // Let Y different pages can be requested (pages to be
    // referenced are numbered from 0 to 9
    unsigned int Y = 10;
    Hash* hash = create_hash( Y );
 
    // Let us refer pages 1, 2, 3, 1, 4, 5
    reference_page( q, hash, 1);
    reference_page( q, hash, 2);
    reference_page( q, hash, 3);
    reference_page( q, hash, 1);
    reference_page( q, hash, 4);
    reference_page( q, hash, 5);
 
    // Let us print cache frames after the above referenced pages
    printf ("%d ", q->front->page_no);
    printf ("%d ", q->front->next->page_no);
    printf ("%d ", q->front->next->next->page_no);
    printf ("%d ", q->front->next->next->next->page_no);
 
    return 0;
}
Example #7
0
static known_switch *
new_switch( uint64_t datapath_id ) {
  known_switch *sw = xmalloc( sizeof( known_switch ) );
  sw->datapath_id = datapath_id;
  sw->forwarding_db = create_hash( compare_mac, hash_mac );
  return sw;
}
Example #8
0
static void
test_lookup_empty_table_returns_NULL() {
  table = create_hash( compare_string, hash_string );

  assert_true( lookup_hash_entry( table, alpha ) == NULL );

  delete_hash( table );
}
Example #9
0
static void
test_nonexistent_entry_returns_NULL() {
  table = create_hash( compare_string, hash_string );

  assert_true( delete_hash_entry( table, "NO SUCH KEY" ) == NULL );

  delete_hash( table );
}
Example #10
0
void initialize_user_info_holder()
  {
  users.ui_ra = initialize_resizable_array(INITIAL_USER_INFO_COUNT);
  users.ui_ht = create_hash(INITIAL_HASH_SIZE);

  users.ui_mutex = calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(users.ui_mutex, NULL);
  } /* END initialize_user_info_holder() */
void initialize_alps_reservations()

  {
  alps_reservations.rh_mutex = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(alps_reservations.rh_mutex, NULL);

  alps_reservations.rh_alps_rsvs = initialize_resizable_array(INITIAL_RESERVATION_HOLDER_SIZE);
  alps_reservations.rh_ht = create_hash(INITIAL_RESERVATION_HOLDER_SIZE + 1);
  } /* END initialize_alps_reservations() */
Example #12
0
static void
test_insert_and_lookup() {
  table = create_hash( compare_string, hash_string );

  insert_hash_entry( table, alpha, alpha );
  assert_string_equal( lookup_hash_entry( table, alpha ), "alpha" );

  delete_hash( table );
}
void initialize_batch_request_holder()

  {
  brh.brh_ra = initialize_resizable_array(INITIAL_REQUEST_HOLDER_SIZE);

  brh.brh_mutex = calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(brh.brh_mutex, NULL);

  brh.brh_ht = create_hash(INITIAL_HASH_SIZE);
  } /* initialize_batch_request_holder() */
Example #14
0
static void
test_insert_and_lookup_by_atom_hash() {
  key mykey = { "alpha" };
  table = create_hash( compare_atom, hash_atom );

  insert_hash_entry( table, &mykey, alpha );
  assert_string_equal( lookup_hash_entry( table, &mykey ), "alpha" );

  delete_hash( table );
}
Example #15
0
static void
test_iterate_empty_hash() {
  hash_iterator iter;
  table = create_hash( compare_atom, hash_atom );
  init_hash_iterator( table, &iter );

  while ( iterate_hash_next( &iter ) != NULL ) { UNREACHABLE(); }

  delete_hash( table );
}
Example #16
0
/* initializes the all_jobs array */
void initialize_all_jobs_array(
    
  struct all_jobs *aj)

  {
  aj->ra = initialize_resizable_array(INITIAL_JOB_SIZE);
  aj->ht = create_hash(INITIAL_HASH_SIZE);

  aj->alljobs_mutex = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(aj->alljobs_mutex, NULL);
  } /* END initialize_all_jobs_array() */
Example #17
0
static void populate_keywords()
{
    KEYWORD *k;
    
    keyword_map = create_hash(20, key_type_indirect);

    for (k = keywords; k->word; k++)
    {
        add_to_hash(keyword_map, k->word, strlen(k->word), (void *) k->id);
    }    
}
Example #18
0
File: lru_cache.c Project: pharic/c
int main() {
	dll *d = create_dll(5);
	hash *h = create_hash(10);
	req_page(d, h, 1);
	req_page(d, h, 2);
	req_page(d, h, 5);
	req_page(d, h, 1);
	printf("%d\n", d->head->data);
	printf("%d\n", d->head->next->data);
	printf("%d\n", d->head->next->next->data);
}
Example #19
0
void
init_match_table( void ) {
  match_table_head.exact_table = create_hash( compare_match_entry, hash_match_entry );
  create_list( &match_table_head.wildcard_table );

  pthread_mutexattr_t attr;
  pthread_mutexattr_init( &attr );
  pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE_NP );
  match_table_head.mutex = xmalloc( sizeof( pthread_mutex_t ) );
  pthread_mutex_init( match_table_head.mutex, &attr );
}
Example #20
0
static void
create_http_transaction_db() {
  debug( "Creating HTTP transaction database." );

  assert( transactions == NULL );

  transactions = create_hash( compare_http_transaction, hash_http_transaction );
  assert( transactions != NULL );

  debug( "HTTP transaction database is created ( %p ).", transactions );
}
Example #21
0
void initialize_allques_array(

  all_queues *aq)

  {
  aq->ra = initialize_resizable_array(INITIAL_QUEUE_SIZE);
  aq->ht = create_hash(INITIAL_HASH_SIZE);

  aq->allques_mutex = calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(aq->allques_mutex,NULL);
  } /* END initialize_all_ques_array() */
Example #22
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  hash_table *forwarding_db = create_hash( compare_forwarding_entry, hash_forwarding_entry );
  add_periodic_event_callback( AGING_INTERVAL, update_forwarding_db, forwarding_db );
  set_packet_in_handler( handle_packet_in, forwarding_db );

  start_trema();

  return 0;
}
static bool
create_transaction_db() {
  debug( "Creating transaction database for overlay network manager." );

  assert( transactions == NULL );

  transactions = create_hash( compare_transaction, hash_transaction );
  assert( transactions != NULL );

  debug( "Transaction database is created ( %p ).", transactions );

  return true;
}
Example #24
0
int
nhash_set_ptr(NHASH hash, const char *key, void *val)
{
  struct nhash *h;

  h = create_hash(hash, key);

  if (h == NULL)
    return 1;

  h->val.p = val;

  return 0;
}
Example #25
0
int
nhash_set_int(NHASH hash, const char *key, int val)
{
  struct nhash *h;

  h = create_hash(hash, key);

  if (h == NULL)
    return 1;

  h->val.i = val;

  return 0;
}
Example #26
0
void
start_midi_hooks()
/*
 * Entering LIVE mode
 * Create a hash table for all of the MIDI hooks
 */
{
    if(LIST_LEN(midihooks) == 0)		 /* No hooks?		      */
        return;				 /* Nothing to do	      */

    create_hash();				 /* Assign hooks to hashes    */

    return;
}						 /* start_midi_hooks()	      */
Example #27
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  hash_table *switch_db = create_hash( compare_datapath_id, hash_datapath_id );
  add_periodic_event_callback( AGING_INTERVAL, update_all_switches, switch_db );
  set_switch_ready_handler( handle_switch_ready, switch_db );
  set_switch_disconnected_handler( handle_switch_disconnected, switch_db );
  set_packet_in_handler( handle_packet_in, switch_db );

  start_trema();

  return 0;
}
struct item *asymmetric_authenticated_decryption(char recipient,
                                                 struct item *public_key,
                                                 struct item *private_key, 
                                                 struct item *message)
  /*@ requires [?f]world(?pub) &*&
               generated_values(?principal1, ?count1) &*&
               item(public_key, ?pub_k, pub) &*& 
                 pub_k == public_key_item(?principal2, ?count2) &*&
               item(private_key, ?priv_k, pub) &*& 
                 priv_k == private_key_item(?principal3, ?count3) &*&
               item(message, ?msg, pub); @*/
  /*@ ensures  [f]world(pub) &*&
               generated_values(principal1, count1 + 1) &*&
               item(public_key, pub_k, pub) &*&
               item(private_key, priv_k, pub) &*&
               item(message, msg, pub) &*&
               item(result, ?decrypted, pub) &*& 
               collision_in_run() ?
                 true
               :
                 msg == pair_item(?enc, ?sig) &*& 
                 enc == asymmetric_encrypted_item(?principal4, ?count4, 
                                                  ?pay, _) &*&
                 sig == asymmetric_signature_item(principal2, count2, 
                                                  some(?msg_id), _) &*&
                 msg_id == pair_item(data_item(cons(recipient, nil)), 
                                     hash_item(some(enc))) &*&
                 principal4 == principal3 && count4 == count3 ?
                   pay == some(decrypted)
                 :
                   [_]pub(decrypted)
               ; @*/
{
  check_is_pair(message);
  struct item* encrypted = pair_get_first(message);
  check_is_asymmetric_encrypted(encrypted);
  struct item* signature = pair_get_second(message);
  struct item* rcp = create_data_item_from_char(recipient);  
  struct item* hash = create_hash(encrypted);
  struct item* pair = create_pair(rcp, hash);
  asymmetric_signature_verify(public_key, pair, signature);
  struct item *result = asymmetric_decryption(private_key, encrypted);
  item_free(encrypted);
  item_free(rcp);
  item_free(pair);
  item_free(hash);
  item_free(signature);
  
  return result;
}
Example #29
0
void initialize_all_jobs_array(struct all_jobs *aj)
  {
  if (aj == NULL)
    {
    log_err(PBSE_BAD_PARAMETER,__func__,"null input job array");
    return;
    }

  aj->ra = initialize_resizable_array(INITIAL_JOB_SIZE);
  aj->ht = create_hash(INITIAL_HASH_SIZE);

  aj->alljobs_mutex = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(aj->alljobs_mutex, NULL);
  }
Example #30
0
static void
test_delete_entry() {
  table = create_hash( compare_string, hash_string );

  insert_hash_entry( table, alpha, alpha );
  insert_hash_entry( table, bravo, bravo );
  insert_hash_entry( table, charlie, charlie );

  delete_hash_entry( table, bravo );
  assert_string_equal( lookup_hash_entry( table, alpha ), "alpha" );
  assert_true( lookup_hash_entry( table, bravo ) == NULL );
  assert_string_equal( lookup_hash_entry( table, charlie ), "charlie" );

  delete_hash( table );
}