Example #1
0
static void *
check_malloc (size_t size)
{
  size_t rounded_up_size;
  void *result;

  __free_hook = 0;
  __malloc_hook = 0;
  if (size == 0)
    {
      result = 0;
      goto end;
    }
#ifdef UNMAPPED_FREE
  /* Round up to an even number of pages. */
  rounded_up_size = ROUND_UP_TO_PAGE (size);
#else
  rounded_up_size = size;
#endif
  result = malloc (rounded_up_size);
  if (!pointer_table)
    pointer_table = make_hash_table (FREE_QUEUE_LIMIT * 2);
  puthash (result, (void *)size, pointer_table);
  __free_hook = check_free;
  __malloc_hook = check_malloc;
 end:
  return result;
}
Example #2
0
/* Complete inclusion check. First fast checks to eliminate simple
   cases. Eventually defaults to a complete check */
bool regexp_inclusion(regexp r1, regexp r2) {
  /* a hashtable of visited states (positions in the regexps) */
  //  unsigned char visited[8192];

  /* Fast equality check */
  if (!strcmp((char *)r1->expr,(char *)r2->expr)) {
    return TRUE;
  }		

  /* Fast disinclusion check */
  else if (regexp_fast_disinclusion(r1, r2) == 1) {
    return FALSE;
  }
 
  /* Complete inclusion check */
  else {
    bool result = FALSE;
    region temp = newregion();
    hash_table visited = make_hash_table(temp, 32, state_hash, state_eq);
    /* TODO: I'd prefer to use a worklist instead of recursion */
    result = regexp_complete_inclusion(r1, r2, 0, 0, visited);
    deleteregion(temp);
    return result;
  }

}
Example #3
0
void
initialize_filename_hashing ()
{
  if (hashing_initialized == 0)
    {
      hashed_filenames = make_hash_table (FILENAME_HASH_BUCKETS);
      hashing_initialized = 1;
    }
}
int main()
{
    std::string str;
    int char_set[256] = {0};
    std::getline(std::cin, str);
    //std::cout<<std::endl<<str<<std::endl;
    int max_cnt = make_hash_table(char_set, str);
    std::cout<<std::endl<<"The maximum count is "<<max_cnt<<std::endl;
    return 0;
}
Example #5
0
void mr_dyck_init(bool pn,FILE *rconstraints)
{
  sig_elt s_sig[1] = {{vnc_pos,setif_sort}};

  assert(state == mr_dyck_raw);
  pn_reach = pn;
  mr_dyckregion = newregion();
  mr_all_nodes = new_mr_dyck_node_list(mr_dyckregion);

  mr_k_hash = make_hash_table(mr_dyckregion, 32, ptr_hash, ptr_eq);
  mr_o_hash = make_hash_table(mr_dyckregion, 32, ptr_hash, ptr_eq);
  mr_c_hash = make_hash_table(mr_dyckregion, 32, ptr_hash, ptr_eq);
  mr_seen_indices = make_hash_table(mr_dyckregion,32,ptr_hash,ptr_eq);

  mr_s_constructor = make_constructor("s",setif_sort,s_sig,1);
  mr_p_constructor = make_constructor("p",setif_sort,s_sig,1);
  mr_n_constructor = make_constructor("n",setif_sort,s_sig,1);
  mr_start_constructor = make_constructor("start",setif_sort,s_sig,1);

#ifdef DEBUG_ERRONEOUS_EDGES
  mr_erroneous_sources = new_mr_dyck_node_list(mr_dyckregion);
#endif

#ifdef MINIMIZE_CONSTRAINTS
  if (rconstraints) {
    char buf[100];
    region scratch = newregion();
    relevant_constraints = new_relevant_constraint_list(scratch);

    printf("Reading relevant constraints\n");

    while (fgets(buf,100,rconstraints)) {
      INT_PTR next_relevant = atoi(buf);
      assert(next_relevant);
      // printf("%d\n",next_relevant);
      relevant_constraint_list_cons(next_relevant, relevant_constraints);
    }
    fclose(rconstraints);
  }
#endif

  state = mr_dyck_inited;
}
Example #6
0
/* Serialization */
void serialize_start(FILE *f, serialize_fn_ptr kind_map[], int length)
{
  assert(current_state == persist_raw);
  assert(f); 

  persist_rgn = newregion();
  current_state = persist_serializing;

  serialize_queue = new_persist_entry_queue(persist_rgn);
  serialized_objects = make_hash_table(persist_rgn, 128, ptr_hash, ptr_eq);
  
  current_file = f;
  num_kinds = length;
  serialize_fns = rarrayalloc(persist_rgn, length, serialize_fn_ptr);
  rarraycopy(serialize_fns, kind_map, length, serialize_fn_ptr);
}
Example #7
0
hash_table read_hash_table(char *filename)
{
    word line;
    FILE *kill_file;
    hash_table r;

    kill_file = fopen(filename, "r");
    if (!kill_file) {
	fprintf(stderr, "cannot open kill file (%s)\n", filename);
	exit(1);
    }

    r = make_hash_table(1000);
    x_create(line, 10);
    while (get_line(kill_file, line) != EOF) {
	insert(r, strdup(line->contents), the_int(0));
    }
    x_free(line);
    return r;
}
Example #8
0
static Lisp_Object
hash_get_category_set (Lisp_Object table, Lisp_Object category_set)
{
  struct Lisp_Hash_Table *h;
  ptrdiff_t i;
  EMACS_UINT hash;

  if (NILP (XCHAR_TABLE (table)->extras[1]))
    set_char_table_extras
      (table, 1,
       make_hash_table (hashtest_equal, make_number (DEFAULT_HASH_SIZE),
			make_float (DEFAULT_REHASH_SIZE),
			make_float (DEFAULT_REHASH_THRESHOLD),
			Qnil));
  h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]);
  i = hash_lookup (h, category_set, &hash);
  if (i >= 0)
    return HASH_KEY (h, i);
  hash_put (h, category_set, Qnil, hash);
  return category_set;
}
Example #9
0
static Lisp_Object
hash_get_category_set (Lisp_Object table, Lisp_Object category_set)
{
  Lisp_Object val;
  struct Lisp_Hash_Table *h;
  int i;
  unsigned hash;

  if (NILP (XCHAR_TABLE (table)->extras[1]))
    XCHAR_TABLE (table)->extras[1]
      = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
			 make_float (DEFAULT_REHASH_SIZE),
			 make_float (DEFAULT_REHASH_THRESHOLD),
			 Qnil, Qnil, Qnil);
  h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]);
  i = hash_lookup (h, category_set, &hash);
  if (i >= 0)
    return HASH_KEY (h, i);
  hash_put (h, category_set, Qnil, hash);
  return category_set;
}
Example #10
0
static Lisp_Object
make_log (int heap_size, int max_stack_depth)
{
  /* We use a standard Elisp hash-table object, but we use it in
     a special way.  This is OK as long as the object is not exposed
     to Elisp, i.e. until it is returned by *-profiler-log, after which
     it can't be used any more.  */
  Lisp_Object log = make_hash_table (hashtest_profiler,
				     make_number (heap_size),
				     make_float (DEFAULT_REHASH_SIZE),
				     make_float (DEFAULT_REHASH_THRESHOLD),
				     Qnil);
  struct Lisp_Hash_Table *h = XHASH_TABLE (log);

  /* What is special about our hash-tables is that the keys are pre-filled
     with the vectors we'll put in them.  */
  int i = ASIZE (h->key_and_value) / 2;
  while (i > 0)
    set_hash_key_slot (h, --i,
		       Fmake_vector (make_number (max_stack_depth), Qnil));
  return log;
}
Example #11
0
static void
check_free (void *ptr)
{
  __free_hook = 0;
  __malloc_hook = 0;
  if (!pointer_table)
    pointer_table = make_hash_table (max (100, FREE_QUEUE_LIMIT * 2));
  if (ptr != 0)
    {
      long size;
#ifdef UNMAPPED_FREE
      unsigned long rounded_up_size;
#endif

      EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table,
					       (const void **) &size);

      if (!present)
	{
	/* This can only happen if you try to free something that didn't
	   come from malloc */
#if !defined(__linux__)
	  /* I originally wrote:  "There's really no need to drop core."
	     I have seen the error of my ways. -slb */
	  if (strict_free_check)
	    ABORT ();
#endif
	  printf("Freeing unmalloc'ed memory at %p\n", ptr);
	  __free_hook = check_free;
	  __malloc_hook = check_malloc;
	  goto end;
	}

      if (size < 0)
	{
	  /* This happens when you free twice */
#if !defined(__linux__)
	  /* See above comment. */
	  if (strict_free_check)
	    ABORT ();
#endif
	  printf("Freeing %p twice\n", ptr);
	  __free_hook = check_free;
	  __malloc_hook = check_malloc;
	  goto end;
	}

      puthash (ptr, (void *)-size, pointer_table);
#ifdef UNMAPPED_FREE
      /* Round up size to an even number of pages. */
      rounded_up_size = ROUND_UP_TO_PAGE (size);
      /* Protect the pages freed from all access */
      if (strict_free_check)
	mprotect (ptr, rounded_up_size, PROT_NONE);
#else
      /* Set every word in the block to 0xdeadbeef */
      if (strict_free_check)
	{
	  unsigned long long_length = (size + (sizeof (long) - 1))
	    / sizeof (long);
	  unsigned long i;

	  for (i = 0; i < long_length; i++)
	    ((unsigned long *) ptr)[i] = 0xdeadbeef;
	}
#endif
      free_queue[current_free].address = ptr;
      free_queue[current_free].length = size;

      current_free++;
      if (current_free >= FREE_QUEUE_LIMIT)
	current_free = 0;
      /* Really free this if there's something there */
      {
	void *old = free_queue[current_free].address;

	if (old)
	  {
#ifdef UNMAPPED_FREE
	    unsigned long old_len = free_queue[current_free].length;

	    mprotect (old, old_len,  PROT_READ | PROT_WRITE | PROT_EXEC);
#endif
	    free (old);
	    remhash (old, pointer_table);
	  }
      }
    }
  __free_hook = check_free;
  __malloc_hook = check_malloc;

 end:
  return;
}
Example #12
0
SCM
scm_c_make_hash_table (unsigned long k)
{
  return make_hash_table (k, "scm_c_make_hash_table");
}
Example #13
0
int main(int argc, char *argv[])
{
    int  i, j, k;
    int  history, sentence_bound = 0;
    word_info *old;

    int width, depth, backup, random;

    hash_table kill_file=NULL;

    int error_flag;
    int ch;

    extern int getopt();
    extern char *optarg;
    extern int optind;

    history = 3;
    error_flag = 0;
    print_pairs = 1;

    width = 100000;
    depth = 64;
    backup = 5;
    random = 0;

    while (!error_flag
	   && (ch = getopt(argc, argv, "rb:C:ck:n:s")) != EOF) {
	switch (ch) {
	  case 'r':
	      random = 1;
	      break;
	  case 'b':
	      sscanf(optarg, "%d", &backup);
	      break;
	  case 'C':
	      if (sscanf(optarg, "%dx%d", &width, &depth) != 2) {
		  fprintf(stderr,
			  "%s got bad cache shape specification.  "
			  "Wanted wxd (for example -C 1000x16)\n", argv[0]);
		  error_flag++;
	      }
	      break;
	  case 'c':
	      print_pairs = 0;
	      break;
	  case 'k':
	      kill_file = read_hash_table(optarg);
	      break;
	  case 'n':
	      sscanf(optarg, "%d", &history);
	      break;
	  case 's':
	      sentence_bound = 1;
	      break;
	  default:
	      error_flag = 1;
	}
    }

    if (history <= 0 || (!sentence_bound && history > 30)) {
	error_flag++;
    }
    if (error_flag) {
	fprintf(stderr,
		"usage: cooc [-c] [-C rxc] [-k kill-file] [-s] [-n window] [-s] files...\n"
	    "    where -c means count occurences rather than print them\n"
	    "    -C specifies cache size (rows x columns)\n"
	    "    -k specifies a file with a list of kill words in it\n"
	    "    -s means respect sentence boundaries\n"
	    "    -n specifies window size\n");
	exit(1);
    }

    old = calloc(history, sizeof(old[0]));
    for (i=0;i<history;i++) {
	x_create(old[i].w, 10);
    }

    words = make_hash_table(100000);
    right = make_hash_table(100000);
    pairs = make_leaky_cache(width, depth, backup, random);

    if (optind >= argc) {
	process(stdin, old, history, kill_file, sentence_bound);
    }
    else {
	FILE *f;
	for (i=optind;i<argc;i++) {
	    f = fopen(argv[i], "r");
	    if (!f) {
		fprintf(stderr, "Can't open %s\n", argv[i]);
	    }
	    else {
		process(f, old, history, kill_file, sentence_bound);
		fclose(f);
	    }
	}
    }
    if (!print_pairs) {
	k = 0;
	for (i=0;i<pairs->width;i++) {
	    for (j=0;j<pairs->depth;j++) {
		hash_value v1, v2;
		if (pairs->table[k].w1) {
		    v1 = must_find(words, pairs->table[k].w1);
		    v2 = must_find(right, pairs->table[k].w2);

		    printf("%d %d %d %d %s %s\n",
			   pairs->table[k].count,
			   v2.i - pairs->table[k].count,
			   v1.i,
			   total_count - v1.i,
			   pairs->table[k].w1,
			   pairs->table[k].w2);
		}
		k++;
	    }
	}
    }
    for (i=0;i<history;i++) {
	x_free(old[i].w);
    }
    free(old);
    return 0;
}
Example #14
0
/*
 *  Initialize the command table.
 *
 *  The command table is a global structure (a hash table) which
 *  stores allows commands to be looked up by name, and invoked via a
 *  function pointer.  This function serves only to initilize this
 *  command table, and name each one of the commands availble to the
 *  user.  Note that commands may be added under more that one name,
 *  but that names must be unique.
 */
void init_soar_command_table( void ) {
  
  gSoarCommands = make_hash_table( 6, (hash_function)hash_soar_command );
  
  add_to_hash_table( gSoarCommands,
		     new_soar_command( ".", interface_Source ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "add-wme", soar_AddWme ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "build-info", soar_BuildInfo ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "counter-demo", interface_counter_demo ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "echo", interface_echo ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "excise", soar_Excise ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "indifferent-selection", 
				       soar_IndifferentSelection ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "init-soar",
				       soar_ReInitSoar ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "learn", soar_Learn ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "log", soar_Log ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "matches", soar_Matches ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "multi-attributes", 
				       soar_MultiAttributes ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "p", soar_Print ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "pf", soar_ProductionFind ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "popd", interface_popd ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "pref", soar_Preferences ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "print", soar_Print ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "pushd", interface_pushd ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "quit", soar_Quit ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "remove-wme", soar_RemoveWme ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "rete-net", soar_ReteNet ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "run", soar_Run ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "set", interface_Set ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "source", interface_Source ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "sp", soar_Sp ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "stats", soar_Stats ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "toh-demo", interface_toh_demo ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "v", soar_Verbose ) );  
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "verbose", soar_Verbose ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "w", soar_Watch ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "watch", soar_Watch ) );
#ifdef USE_CAPTURE_REPLAY
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "capture", soar_CaptureInput ) );
  add_to_hash_table( gSoarCommands,
		     new_soar_command( "replay", soar_ReplayInput ) );
#endif
}
Example #15
0
void
initialize_aliases ()
{
  if (!aliases)
    aliases = make_hash_table (0);
}