示例#1
0
文件: hash.c 项目: Lanozavr/pvs
HASHTAB *make_hashtab (int index)
{
  HASHTAB *tab;
  int size = primes[index];

  tab = MALLOC_STRUCT (HASHTAB);

/* Current maximum size (i.e. number of entries) of hash table: */
  tab->size          = size;

/* This reflects the number of items currently held by the hash table: */
  tab->nr_items      = 0;

/* This counts the number of times an insert of an item is done, i.e.
   number of times `lookup (,,, INSERT)' is called. */
  tab->nr_inserts    = 0;

/* We count as collisions the fact that when an item has to be inserted
   the entry at its hash index is occupied by a different one. Subsequent
   tries to resolve this collision are not counted as new collisions.
   Merely looking up an item will never increase the collision count.
*/
  tab->nr_collisions = 0;

/* Number of rehashes undertaken for this table: */
  tab->nr_rehashes   = 0;

/* Current index in primes table: */
  tab->primes_index  = index;

#ifdef ALLOW_REHASH
/* Function called when non-NULL to process change of entry
   when rehashing in process.
*/
  tab->rehash_function = 0;
#ifdef USE_SHADOW
  {
    register int i;
    register int *p;

    tab->shadow_free_index = 0;
    tab->shadow_table = MALLOC_ARRAY (size, int);
    for (i = 0, p = tab->shadow_table; i < size; i++)
      *p++ = NOT_PRESENT;
  }
#endif
#endif

/* Allocate an array of empty entries: */
  tab->entries = CALLOC_ARRAY (size, HASHTAB_ENTRY_PTR);

  return tab;
}
示例#2
0
LOCAL cl_context
cl_create_context(const cl_context_properties *  properties,
                  cl_uint                        num_devices,
                  const cl_device_id *           devices,
                  void (CL_CALLBACK * pfn_notify) (const char*, const void*, size_t, void*),
                  void *                         user_data,
                  cl_int *                       errcode_ret)
{
  /* cl_platform_id platform = NULL; */
  struct _cl_context_prop props;
  cl_context ctx = NULL;
  cl_int err = CL_SUCCESS;
  cl_uint prop_len = 0;
  /* XXX */
  FATAL_IF (num_devices != 1, "Only one device is supported");

  /* Check that we are getting the right platform */
  if (UNLIKELY(((err = cl_context_properties_process(properties, &props, &prop_len)) != CL_SUCCESS)))
    goto error;

  /* We are good */
  if (UNLIKELY((ctx = cl_context_new(&props)) == NULL)) {
    err = CL_OUT_OF_HOST_MEMORY;
    goto error;
  }

  if(properties != NULL && prop_len > 0) {
    TRY_ALLOC (ctx->prop_user, CALLOC_ARRAY(cl_context_properties, prop_len));
    memcpy(ctx->prop_user, properties, sizeof(cl_context_properties)*prop_len);
  }
  ctx->prop_len = prop_len;
  /* Attach the device to the context */
  ctx->device = *devices;

  /* Save the user callback and user data*/
  ctx->pfn_notify = pfn_notify;
  ctx->user_data = user_data;

exit:
  if (errcode_ret != NULL)
    *errcode_ret = err;
  return ctx;
error:
  cl_context_delete(ctx);
  ctx = NULL;
  goto exit;
}