Example #1
0
static HashSet *
frt_get_fields(VALUE rfields)
{
    VALUE rval;
    HashSet *fields;
    char *s, *p, *str;

    if (rfields == Qnil) return NULL;

    fields = hs_new_str(&free);
    if (TYPE(rfields) == T_ARRAY) {
        int i;
        for (i = 0; i < RARRAY(rfields)->len; i++) {
            rval = rb_obj_as_string(RARRAY(rfields)->ptr[i]);
            hs_add(fields, estrdup(RSTRING(rval)->ptr));
        }
    } else {
        rval = rb_obj_as_string(rfields);
        if (strcmp("*", RSTRING(rval)->ptr) == 0) {
            hs_destroy(fields);
            fields = NULL;
        } else {
            s = str = estrdup(RSTRING(rval)->ptr);
            while ((p = strchr(s, '|')) != '\0') {
                *p = '\0';
                hs_add(fields, estrdup(s));
                s = p + 1;
            }
            hs_add(fields, estrdup(s));
            free(str);
        }
    }
    return fields;
}
Example #2
0
void
hs_test (void)
{
  array_t *arr;
  struct hs *a = hs_create (1);
  hs_add (a, array_from_str ("0011xx00"));
  hs_add (a, array_from_str ("10100x0x"));
  arr = array_from_str ("10100x01");
  hs_diff (a, arr);
  hs_print (a);
  struct hs *b = hs_copy_a (a);
  hs_print (b);
  hs_free (b);
  free (arr);

  b = hs_create (1);
  hs_add (b, array_from_str ("xxxx1x00"));
  hs_add (b, array_from_str ("xxxxx1x0"));
  hs_print (b);
  hs_isect (b, a);
  hs_print (b);
  hs_free (b);
  hs_free (a);

  a = hs_create (1);
  hs_add (a, array_from_str ("10xxxxxx"));
  hs_add (a, array_from_str ("xxxxxx10"));
  arr = array_from_str ("11111111");
  hs_diff (a, arr);
  hs_print (a);
  hs_cmpl (a);
  hs_print (a);
  hs_free (a);

  a = hs_create (1);
  hs_add (a, array_from_str ("10xxxxxx"));
  hs_add (a, array_from_str ("xxxxxx10"));
  b = hs_create (1);
  hs_add (b, array_from_str ("11111111"));
  hs_minus (a, b);
  hs_print (a);
  hs_free (a);
  hs_free (b);

  a = hs_create (1);
  hs_add (a, array_from_str ("11111111"));
  //hs_add (a, array_from_str ("xxxxxxx1"));
  hs_diff (a, arr);
  hs_print (a);
  hs_comp_diff (a);
  char *s = hs_to_str (a);
  printf ("S: %s\n", s);
  free (s);
  hs_free (a);
  free (arr);
}
Example #3
0
void cw_add_file(CompoundWriter *cw, char *id)
{
    id = estrdup(id);
    if (hs_add(cw->ids, id) != HASH_KEY_DOES_NOT_EXIST) {
        RAISE(IO_ERROR, "Tried to add file \"%s\" which has already been "
              "added to the compound store", id);
    }

    ary_grow(cw->file_entries);
    ary_last(cw->file_entries).name = id;
}
Example #4
0
File: ind.c Project: dustin/ferret
Query *index_get_query(Index *self, char *qstr)
{
    int i;
    FieldInfos *fis;
    ensure_searcher_open(self);
    fis = self->ir->fis;
    for (i = fis->size - 1; i >= 0; i--) {
        hs_add(self->qp->all_fields, (char *)fis->fields[i]->name);
    }
    return qp_parse(self->qp, qstr);
}
Example #5
0
File: hs.c Project: NetSys/sts
void
hs_cmpl (struct hs *hs)
{
  if (!hs->list.used) {
    hs_add (hs, array_create (hs->len, BIT_X));
    return;
  }

  struct hs_vec *v = &hs->list, new_list = {0};
  for (int i = 0; i < v->used; i++) {
    struct hs_vec tmp = {0};
    tmp.elems = array_cmpl_a (v->elems[i], hs->len, &tmp.used);
    tmp.alloc = tmp.used;

    /* If complement is empty, result will be empty. */
    if (!tmp.elems) {
      vec_destroy (&new_list);
      vec_destroy (&hs->list);
      memset (&hs->list, 0, sizeof hs->list);
      return;
    }

    tmp.diff = xcalloc (tmp.alloc, sizeof *tmp.diff);
    if (v->diff) { /* NULL if called from comp_diff */
      struct hs_vec *d = &v->diff[i];
      for (int j = 0; j < d->used; j++)
        vec_append (&tmp, d->elems[j], false);
    }

    if (!new_list.used) new_list = tmp;
    else {
      vec_isect (&new_list, &tmp, hs->len);
      vec_destroy (&tmp);
    }
  }

  vec_destroy (v);
  hs->list = new_list;
}
Example #6
0
/* scan trajectory and accumulate data */
static int dotrj(hist_t *hsrms, bb_t *bb, int rescnt, FILE *fplog,
    trj_t *trj, const char *fxtc, rvec *xrefbb,
    int nat, matrix box, double *wtot)
{
  int nfr, match, natoms;
  int fpxtc = 0; /* gromacs file handle for trj */
  rvec *x = NULL, *xbb;
  double t1, w, rmsd;
  real t = 0.f;

  xnew(xbb, rescnt * 3);
  /* loop over xtc frames */
  for (nfr = 0; ; nfr++) {
    if (nfr == 0) {
      /* first frame, get the file handle fpxtc, allocate x
       * and check the number of atoms */
      natoms = read_first_x(&fpxtc, fxtc, &t, &x, box);
      if (natoms != nat) {
        fprintf(stderr, "natoms mismatch! top %d, xtc %d\n", nat, natoms);
        return -1;
      }
    } else {
      if (!read_next_x(fpxtc, &t, natoms, x, box))
        break;
    }

    if (ctmd) { /* each frame has a weight */
      w = 1.;
    } else {
      /* for each xtc frame, we search a corresponding
       * frame in trj at the same time */
      for (match = 0; trj->pos < trj->n; trj->pos++) {
        t1 = trj->fr[trj->pos].t;
        if (fabs(t1 - t) < 0.5) {
          match = 1;
          break;
        } else if (t1 > t + 0.5) {
          fprintf(stderr, "time difference %g (trace), %g (xtc)\n", t1, t);
          return -1;
        }
      }
      if (!match) {
        fprintf(stderr, "cannot find a frame for t = %g\n", t);
        break;
      }
      if (!trj->fr[trj->pos].in) {
        w = 0.0;
      } else {
        w = exp(trj->fr[trj->pos].lnw);
      }
    }

    /* skip trivial frames */
    if (fplog == NULL && w < 1e-6) continue;

    /* extract backbone indices */
    xgetbb(xbb, x, bb, rescnt);

    /* fit x to xref */
    rmsd = rv3_rmsd(xbb, NULL, xrefbb, vmass, rescnt*3, 0, NULL, NULL);

    if (fplog) {
      fprintf(fplog, "%10.0f %8.4f %g %d\n", t, rmsd, w, trj->fr[trj->pos].dataid);
    }
    hs_add(hsrms, &rmsd, w, HIST_VERBOSE);
    *wtot += w;
  }
  free(xbb);
  return 0;
}