Esempio n. 1
0
int vec_inserted_index(Vector *v, LmnWord w)
{
  int i;
  for (i = 0; i < vec_num(v); i++){
    if (vec_get(v, i) == w) return i;
  }
  vec_push(v, w);
  return vec_num(v) - 1;
}
Esempio n. 2
0
File: state.c Progetto: ysm001/slim
void state_succ_set(State *s, Vector *v)
{
  if (!vec_is_empty(v) && !s->successors) {
    unsigned int i;
    s->successor_num = vec_num(v);
    s->successors    = LMN_NALLOC(succ_data_t, state_succ_num(s));
    for (i = 0; i < state_succ_num(s); i++) {
      s->successors[i] = (succ_data_t)vec_get(v, i);
    }
#ifdef PROFILE
    if (lmn_env.profile_level >= 3) {
      profile_add_space(PROFILE_SPACE__TRANS_OBJECT,
                        sizeof(succ_data_t) * vec_num(v));
      profile_remove_space(PROFILE_SPACE__TRANS_OBJECT, 0);
    }
#endif
  }
}
Esempio n. 3
0
void sp_atom_finalize()
{
  int i;

  for (i = 0; i < vec_num(sp_atom_callback_tbl); i++) {
    LMN_FREE(vec_get(sp_atom_callback_tbl, i));
  }
  vec_free(sp_atom_callback_tbl);
}
Esempio n. 4
0
File: integer.c Progetto: onmsr/slim
/**
 * ($start, $end, $g)
 * where
 *  start, end = integer
 *  g = ground
 *
 * Creates a (multi)set $g[$a], $g[$a+1], ..., $g[$b].
 */
void integer_set(LmnReactCxt *rc,
                 LmnMembrane *mem,
                 LmnAtom a0, LmnLinkAttr t0,
                 LmnAtom a1, LmnLinkAttr t1,
                 LmnAtom a2, LmnLinkAttr t2)
{
  Vector *srcvec;
  int i, j, n;
  int start, end;

  start  = (int)a0;
  end    = (int)a1;
  srcvec = vec_make(16);
  vec_push(srcvec, (LmnWord)LinkObj_make(a2, t2));

  for (i = 0, n = start; n <= end; i++, n++) {
    Vector *dstlovec;
    ProcessTbl atommap;
    LinkObj l;

    lmn_mem_copy_ground(mem, srcvec, &dstlovec, &atommap);

    l = (LinkObj)vec_get(dstlovec, 0);
    lmn_mem_newlink(mem, n, LMN_INT_ATTR, 0,
                    l->ap, t2, LMN_ATTR_GET_VALUE(l->pos));
    lmn_mem_push_atom(mem, n, LMN_INT_ATTR);

    for (j = 0; j < vec_num(dstlovec); j++) LMN_FREE(vec_get(dstlovec, j));
    vec_free(dstlovec);
    proc_tbl_free(atommap);
  }

  lmn_mem_delete_atom(mem, a0, t0);
  lmn_mem_delete_atom(mem, a1, t1);

  lmn_mem_delete_ground(mem, srcvec);

  for (i = 0; i < vec_num(srcvec); i++) LMN_FREE(vec_get(srcvec, i));
  vec_free(srcvec);
}
Esempio n. 5
0
/* 実行膜スタックからmemを削除する。外部関数が膜の削除しようとするとき
   に、その膜がスタックに積まれている事がある。そのため、安全な削除を行
   うために、この手続きが必要になる。外部の機能を使わない通常の実行時に
   はこの手続きは必要ない*/
void lmn_memstack_delete(LmnMemStack memstack, LmnMembrane *mem)
{
  unsigned long i, j, n = vec_num(memstack);

  for (i = n-1; i >= 0; i--) {
    if ((LmnMembrane *)vec_get(memstack, i) == mem) {
      /* 空いた分後ろの要素を前にを詰める */
      for (j = i+1; j < n; j++) {
        vec_set(memstack, j-1, vec_get(memstack, j));
      }
      break;
    }
  }
  vec_pop(memstack);
}
Esempio n. 6
0
int lmn_sp_atom_register(const char *name,
                         f_copy f_copy,
                         f_free f_free,
                         f_eq f_eq,
                         f_dump f_dump,
                         f_is_ground f_is_ground)
{
  struct SpecialAtomCallback *c = LMN_MALLOC(struct SpecialAtomCallback);
  c->name = lmn_intern(name),
  c->copy = f_copy;
  c->free = f_free;
  c->eq = f_eq;
  c->dump = f_dump;
  c->is_ground = f_is_ground;

  vec_push(sp_atom_callback_tbl, (LmnWord)c);
  return vec_num(sp_atom_callback_tbl) - 1;
}
 int numTrees(int n) {
     if(n == 0)
     {
         return 0;
     }
     
     std::vector<int> vec_num(n + 1, 0);
     vec_num[0] = 1;
     vec_num[1] = 1;
     for(int i = 2; i <= n; i++)
     {
         for(int j = 1; j <= i; j++)
         {
             vec_num[i] += vec_num[j - 1] * vec_num[i - j];
         }
     }
     
     return vec_num[n];
 }
Esempio n. 8
0
static void translate_rule(LmnRule rule, const char *header)
{
  Vector *jump_points = vec_make(4);
  int i;

  vec_push(jump_points, (LmnWord)lmn_rule_get_inst_seq(rule));

  for (i = 0; i < vec_num(jump_points) /*変換中にjump_pointsは増えていく*/; i++){
    BYTE *p = (BYTE*)vec_get(jump_points, i);
    fprintf(OUT, "BOOL %s_%d(LmnReactCxt* rc, LmnMembrane* thisisrootmembutnotused, LmnRule rule)\n", header, i); /* TODO m=wt[0]なのでmは多分いらない */
    fprintf(OUT, "{\n");
    /* (変換するスタート地点, 変換する必要のある部分の記録, ルールのシグネチャ:trans_**_**_**, 成功時コード, 失敗時コード, インデント) */
    translate_instructions(p, jump_points, header, "return TRUE", "return FALSE", 1);
    fprintf(OUT, "}\n");
  }

  /* 各関数の前方宣言をすることができないので,関数を呼ぶ時には自分で前方宣言をする */
  /* trans_***(); ではなく { extern trans_***(); trans_***(); } と書くだけ */
}
Esempio n. 9
0
static void workers_free(LmnWorker **pool, unsigned int worker_num)
{
  unsigned int i, j;
  for (i = 0; i < worker_num; i++) {
    LmnWorker *w = pool[i];
    if (worker_group(w)->do_search) {
      vec_free(w->invalid_seeds);

      for (j = 0; j < vec_num(w->cycles); j++) {
        vec_free((Vector *)vec_get(w->cycles, j));
      }
      vec_free(w->cycles);
    }

    if (i == 0) {
      statespace_free(worker_states(w));
    }

    worker_finalize(w);
    lmn_worker_free(w);
  }
  LMN_FREE(pool);
}
Esempio n. 10
0
inline LmnMembrane *lmn_memstack_peek(LmnMemStack memstack)
{
  return (LmnMembrane *)vec_get(memstack, vec_num(memstack)-1);
}
Esempio n. 11
0
inline BOOL lmn_memstack_isempty(LmnMemStack memstack)
{
  return vec_num(memstack) == 0;
}
Esempio n. 12
0
struct SpecialAtomCallback *sp_atom_get_callback(int id)
{
  LMN_ASSERT(vec_num(sp_atom_callback_tbl) > id);
  return (struct SpecialAtomCallback *)vec_get(sp_atom_callback_tbl, id);
}