Ejemplo n.º 1
0
void
com_unlet(wordlist *wl)
{
    while (wl) {
        vec_remove(wl->wl_word);
        wl = wl->wl_next;
    }
}
Ejemplo n.º 2
0
void SMat<CoeffRing>::delete_columns(size_t i, size_t j)
/* Delete columns i .. j from M */
{
  for (size_t c = i; c <= j; c++) vec_remove(columns_[c]);
  sparsevec **tmp = columns_;
  columns_ = 0;
  size_t ndeleted = j - i + 1;
  size_t orig_ncols = ncols_;

  initialize(nrows_, ncols_ - (j - i + 1), 0);
  for (size_t c = 0; c < i; c++) columns_[c] = tmp[c];
  for (size_t c = j + 1; c < orig_ncols; c++) columns_[c - ndeleted] = tmp[c];

  deletearray(tmp);
}
Ejemplo n.º 3
0
void* map_remove(hashmap_t* map, const char* key)
{
	unsigned long pos = map_hash_function(key) % HASHMAP_BUCKET_AMT;
	
	if(!map->buckets[pos])
		return NULL;
	else 
	{
		hashmap_node_t* node = map->buckets[pos];
		hashmap_node_t* prev = NULL;
		
		while(node)
		{
			if(strcmp(node->key, key) == 0)
			{
				if(prev)
					prev->next = node->next;
				else
				{
					map->buckets[pos] = NULL;
					int to_remove = -1;
					for(size_t i = 0; i < map->active_buckets.length; ++i)
					{
						if(*(unsigned long*)vec_get(&map->active_buckets, i) == pos)
						{
							to_remove = i;
							break;
						}
					}
					
					if(to_remove >= 0) vec_remove(&map->active_buckets, to_remove);
				}
				
				void* value = node->value;
				
				free(node->key);
				free(node);
				
				return value;
			}
			
			prev = node;
			node = node->next;
		}
	}
	
	return NULL;
}
Ejemplo n.º 4
0
void SMat<CoeffRing>::vec_divide(sparsevec *&v, const elem &a) const
{
  if (ring().is_zero(a))
    {
      vec_remove(v);
      v = 0;
      return;
    }
  sparsevec head;
  head.next = v;
  for (sparsevec *p = &head; p->next != 0; p = p->next)
    {
      ring().divide(p->next->coeff, p->next->coeff, a);
      if (ring().is_zero(p->next->coeff))
        {
          sparsevec *tmp = p->next;
          p->next = tmp->next;
          vec_remove_node(tmp);
          if (p->next == 0) break;
        }
    }
  v = head.next;
}
Ejemplo n.º 5
0
void
com_compose(wordlist *wl)
{
    double start = 0.0;
    double stop = 0.0;
    double step = 0.0;
    double lin = 0.0;
    double center;
    double span;
    double mean, sd;
    bool startgiven = FALSE, stopgiven = FALSE, stepgiven = FALSE;
    bool lingiven = FALSE;
    bool loggiven = FALSE, decgiven = FALSE, gaussgiven = FALSE;
    bool randmgiven = FALSE;
    bool spangiven = FALSE;
    bool centergiven = FALSE;
    bool meangiven = FALSE;
    bool poolgiven = FALSE;
    bool sdgiven = FALSE;
    int  log, dec, gauss, randm;
    char *pool;
    int i;

    char *s, *var, *val;
    double *td, tt;
    double *data = NULL;
    ngcomplex_t *cdata = NULL;
    int length = 0;
    int dim, type = SV_NOTYPE, blocksize;
    bool realflag = TRUE;
    int dims[MAXDIMS];
    struct dvec *result, *vecs = NULL, *v, *lv = NULL;
    struct pnode *pn, *names = NULL;
    bool reverse = FALSE;

    char *resname = cp_unquote(wl->wl_word);

    vec_remove(resname);
    wl = wl->wl_next;

    if (eq(wl->wl_word, "values")) {
        /* Build up the vector from the rest of the line... */
        wl = wl->wl_next;

        names = ft_getpnames(wl, TRUE);
        if (!names)
            goto done;

        for (pn = names; pn; pn = pn->pn_next) {
            if ((v = ft_evaluate(pn)) == NULL)
                goto done;

            if (!vecs)
                vecs = lv = v;
            else
                lv->v_link2 = v;

            for (lv = v; lv->v_link2; lv = lv->v_link2)
                ;
        }

        /* Now make sure these are all of the same dimensionality.  We
         * can coerce the sizes...
         */
        dim = vecs->v_numdims;
        if (dim < 2)
            dim = (vecs->v_length > 1) ? 1 : 0;

        if (dim == MAXDIMS) {
            fprintf(cp_err, "Error: max dimensionality is %d\n",
                    MAXDIMS);
            goto done;
        }

        for (v = vecs; v; v = v->v_link2)
            if (v->v_numdims < 2)
                v->v_dims[0] = v->v_length;

        for (v = vecs->v_link2, length = 1; v; v = v->v_link2) {
            i = v->v_numdims;
            if (i < 2)
                i = (v->v_length > 1) ? 1 : 0;
            if (i != dim) {
                fprintf(cp_err,
                        "Error: all vectors must be of the same dimensionality\n");
                goto done;
            }
            length++;
            if (iscomplex(v))
                realflag = FALSE;
        }

        for (i = 0; i < dim; i++) {
            dims[i] = vecs->v_dims[i];
            for (v = vecs->v_link2; v; v = v->v_link2)
                if (v->v_dims[i] > dims[i])
                    dims[i] = v->v_dims[i];
        }
        dim++;
        dims[dim - 1] = length;
        for (i = 0, blocksize = 1; i < dim - 1; i++)
            blocksize *= dims[i];

        if (realflag)
            data = TMALLOC(double, length * blocksize);
        else