예제 #1
0
Py_LOCAL(PyObject *) avl_tree_clear(avl_tree_Object * self,
									PyObject * noarg)
{
	(void) noarg;
	avl_empty(self->tree);
	Py_INCREF(Py_None);
	return Py_None;
}
예제 #2
0
파일: spmatrix.c 프로젝트: FMX/gsl
int
gsl_spmatrix_set_zero(gsl_spmatrix *m)
{
  m->nz = 0;

  if (GSL_SPMATRIX_ISTRIPLET(m))
    {
      /* reset tree to empty state and node index pointer to 0 */
      avl_empty(m->tree_data->tree, NULL);
      m->tree_data->n = 0;
    }

  return GSL_SUCCESS;
} /* gsl_spmatrix_set_zero() */
예제 #3
0
	avl_tree_load_list(avl_tree_Object * self, PyObject * list,
				   avl_bool_t unique)
{
	PyObject *iter;
	int err = 0;

	if ((iter = PyObject_GetIter(list)) == NULL) {
		PyErr_Clear();
		PyErr_SetString(avlErrorObject, "Couldn't get list iterator !");
		err = 1;
	}

	else {
		PyObject *val;
		int rc;
		self->compare_err = 0;

		while ((val = PyIter_Next(iter)) != NULL) {
			rc = avl_ins((void *) val, self->tree, !unique);
			Py_DECREF(val);		/* PyIter_Next returns a new reference */
			if (rc < 0) {
				if (self->compare_err == 0)
					PyErr_SetString(avlErrorObject,
									"Couldn't insert item retrieved from list !");
#       if 0==1
				avl_empty(self->tree);
#       endif
				err = 1;
				break;
			}
		}

		Py_DECREF(iter);
	}
	return err;
}
예제 #4
0
파일: spmatrix.c 프로젝트: FMX/gsl
int
gsl_spmatrix_realloc(const size_t nzmax, gsl_spmatrix *m)
{
  int s = GSL_SUCCESS;
  void *ptr;

  if (nzmax < m->nz)
    {
      GSL_ERROR("new nzmax is less than current nz", GSL_EINVAL);
    }

  ptr = realloc(m->i, nzmax * sizeof(size_t));
  if (!ptr)
    {
      GSL_ERROR("failed to allocate space for row indices", GSL_ENOMEM);
    }

  m->i = (size_t *) ptr;

  if (GSL_SPMATRIX_ISTRIPLET(m))
    {
      ptr = realloc(m->p, nzmax * sizeof(size_t));
      if (!ptr)
        {
          GSL_ERROR("failed to allocate space for column indices", GSL_ENOMEM);
        }

      m->p = (size_t *) ptr;
    }

  ptr = realloc(m->data, nzmax * sizeof(double));
  if (!ptr)
    {
      GSL_ERROR("failed to allocate space for data", GSL_ENOMEM);
    }

  m->data = (double *) ptr;

  /* rebuild binary tree */
  if (GSL_SPMATRIX_ISTRIPLET(m))
    {
      size_t n;

      /* reset tree to empty state, but don't free root tree ptr */
      avl_empty(m->tree_data->tree, NULL);
      m->tree_data->n = 0;

      ptr = realloc(m->tree_data->node_array, nzmax * sizeof(struct avl_node));
      if (!ptr)
        {
          GSL_ERROR("failed to allocate space for AVL tree nodes", GSL_ENOMEM);
        }

      m->tree_data->node_array = ptr;

      /*
       * need to reinsert all tree elements since the m->data addresses
       * have changed
       */
      for (n = 0; n < m->nz; ++n)
        {
          ptr = avl_insert(m->tree_data->tree, &m->data[n]);
          if (ptr != NULL)
            {
              GSL_ERROR("detected duplicate entry", GSL_EINVAL);
            }
        }
    }

  /* update to new nzmax */
  m->nzmax = nzmax;

  return s;
} /* gsl_spmatrix_realloc() */