示例#1
0
gpy_object_t * gpy_obj_list_new (gpy_typedef_t * type,
				 gpy_object_t ** args)
{
  gpy_object_t * retval = NULL_OBJECT;

  bool check = gpy_args_check_fmt (args, "i,V.");
  gpy_assert (check);

  int len = gpy_args_lit_parse_int (args [0]);
  gpy_object_t ** vec = gpy_args_lit_parse_vec (args [1]);

  struct gpy_object_list * self = (struct gpy_object_list *)
    gpy_malloc (sizeof (struct gpy_object_list));

  int size = gpy_threshold_alloc (len);
  self->vector = (gpy_object_t **)
    gpy_calloc (size, sizeof (gpy_object_t *));

  self->length = len;
  self->size = size;

  int i;
  for (i = 0; i < len; ++i)
    self->vector[i] = vec [i];
  retval = gpy_create_object_state (type, self);

  return retval;
}
示例#2
0
inline
void gpy_vec_init (gpy_vector_t * const v)
{
  v->size = gpy_threshold_alloc (0);
  v->vector = (void **) gpy_calloc (v->size, sizeof (void *));
  v->length = 0;
}
示例#3
0
void gpy_vec_push (gpy_vector_t * const v, void * const s)
{
  if (s)
    {
      if (v->length >= v->size)
	{
	  signed long size = gpy_threshold_alloc (v->size);
	  v->vector = (void**) gpy_realloc (v->vector, size * sizeof (void *));
	  v->size = size;
	}
      v->vector[v->length] = s;
      v->length++;
    }
}
示例#4
0
static gpy_object_t *
gpy_obj_list_add (gpy_object_t * o1, gpy_object_t * o2)
{
  gpy_assert (o1->T == TYPE_OBJECT_STATE);
  gpy_assert (o2->T == TYPE_OBJECT_STATE);

  gpy_object_state_t * x = o1->o.object_state;
  gpy_object_state_t * y = o2->o.object_state;

  if (strcmp (x->identifier, "List") != 0 ||
      strcmp (y->identifier, "List") != 0)
    {
      fatal ("invalid object types for '+': <%s> and <%s>\n",
             x->identifier, y->identifier);
    }

  struct gpy_object_list * l1 = (struct gpy_object_list *) x->state;
  struct gpy_object_list * l2 = (struct gpy_object_list *) y->state;

  int n = l1->length + l2->length;
  int ns = gpy_threshold_alloc (n + 1);
  gpy_object_t ** elems = (gpy_object_t **)
    gpy_calloc (ns, sizeof (gpy_object_t *));

  int i, z;
  for (i = 0; i < l1->length; ++i)
      elems [i] = l1->vector [i];
  for (z = 0; z < l2->length; ++z)
    {
      elems [i] = l2->vector [z];
      i++;
    }
  elems [n] = NULL;

  struct gpy_object_list * self = (struct gpy_object_list *)
    gpy_malloc (sizeof (struct gpy_object_list));

  self->vector = elems;
  self->length = n;
  self->size = ns;

  gpy_object_t * retval = gpy_create_object_state (__gpy_list_type_node, self);
  gpy_assert (retval->T == TYPE_OBJECT_STATE);

  return retval;
}
示例#5
0
static
gpy_object_t * gpy_obj_list_append (gpy_object_t * self,
				    gpy_object_t ** args)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t * x = self->o.object_state;
  struct gpy_object_list * state = (struct gpy_object_list *)
    x->state;

  gpy_object_t * append = *args;
  gpy_assert (append);

  if (state->length >= state->size)
    {
      signed long size = gpy_threshold_alloc (state->size);
      state->vector = (gpy_object_t **)
	gpy_realloc (state->vector, size * sizeof (gpy_object_t *));
      state->size = size;
    }
  state->vector [state->length] = append;
  state->length++;

  return NULL;
}
示例#6
0
void gpy_dd_hash_grow_table (gpy_hash_tab_t * tbl)
{
  unsigned int prev_size = tbl->size, size = 0, i;
  gpy_hash_entry_t *prev_array = tbl->array, *array;

  size = gpy_threshold_alloc (prev_size);
  array = (gpy_hash_entry_t *)
    gpy_calloc (size, sizeof (gpy_hash_entry_t));

  tbl->length = 0;
  tbl->size = size;
  tbl->array = array;

  for (i = 0; i < prev_size; ++i)
    {
      gpy_hashval_t h = prev_array[i].hash;
      void * s = prev_array[i].data;

      if (s)
        gpy_dd_hash_insert (h, s, tbl);
    }
  if (prev_array)
    gpy_free (prev_array);
}