static void DFS(Status fromS, NFA nfa, Array_T closure, int inverse[], int color[], int set) { int i, index, from, to; Edge e; Status toS; from = getStatusID(fromS); color[from] = 1; inverse[from] = set; Array_append(closure, &from); Array_T edgeArray = getEdgeArray(nfa); Array_T outEdges_indice = getOutEdges(fromS); if (!outEdges_indice) return; for (i=0; i<Array_length(outEdges_indice); i++) { index = *(int*)Array_get(outEdges_indice, i); e = (Edge)Array_get(edgeArray, index); if (isEpsilon(e)) { toS = gettoStatus(e); to = getStatusID(toS); if (color[to] == 0) DFS(toS, nfa, closure, inverse, color, set); } } }
Array_T getCharSet(NFA nfa) { int i; ULL128 v; ULL64 a = 1ULL; Edge e; wchar_t c; Array_T charSet; charSet = Array_new(0,sizeof(wchar_t)); setZero(&v); for (i=0; i<Array_length(nfa->edgeArray); i++) { e = Array_get(nfa->edgeArray, i); if (!isEpsilon(e)) { v = Or(getMatchBitVector(e), v); } } for (i=0; i<64; i++) { c = (wchar_t)i; if ((a & v.L64) != 0) Array_append (charSet, &c); a <<= 1; } a = 1ULL; for (i=0; i<64; i++) { c = (wchar_t)(i+64); if ((a & v.H64) != 0) Array_append (charSet, &c); a <<= 1; } return charSet; }
Array_T reach_Status (NFA nfa, StatusSet currSet, int inverse[], wchar_t c) { Array_T toSets; int from, to; toSets = Array_new(0,sizeof(int)); int i; for (i=0; i<Array_length(currSet.epsClosure); i++) { from = *(int*)Array_get(currSet.epsClosure, i); to = reachStatus(nfa, from, c); if (to!=-1) { Array_append(toSets, &inverse[to]); } } return toSets; }
static void get_channels_range(Instance *pi, Range *range) { int i; int rc; ALSAio_private *priv = (ALSAio_private *)pi; if (!priv->c.handle) { fprintf(stderr, "*** device is not open!\n"); return; } Range_clear(range); range->type = RANGE_INT_ENUM; for (i=0; i < table_size(channels); i++) { rc = snd_pcm_hw_params_test_channels(priv->c.handle, priv->c.hwparams, channels[i]); if (rc == 0) { printf(" %d-channel sampling available\n", channels[i]); Array_append(range->int_enums, rates[i]); } } }
void Player_beginner2_think(Player* player, Othello* othello, int* x, int* y, BOOL* isResign){ // 最もたくさんの数が取れる場所に打つ Evaluation eval; PointList list; Othello_moveList(othello, &list); if(list.length > 0){ eval = Player_beginner2_search(player, othello, &list, 5); *x = list.x[eval.index]; *y = list.y[eval.index]; *isResign = FALSE; } else{ *isResign = TRUE; } { Array int_array; int temp; int temp_out; int i; Array_new(&int_array, 5, sizeof(int)); temp = 0; Array_append(&int_array, &temp); temp = 1; Array_append(&int_array, &temp); temp = 2; Array_append(&int_array, &temp); temp = 3; Array_append(&int_array, &temp); temp = 4; Array_append(&int_array, &temp); temp = 5; Array_append(&int_array, &temp); for(i = 0; i < Array_length(&int_array); i++){ temp_out = *(int*)Array_get(&int_array, i); } Array_delete(&int_array); } }
int select_from_atomlist(NLEnergy *p) { char *atomsel = Array_data(&(p->atomsel)); char *nonbsel = Array_data(&(p->nonbsel)); char *bondsel = Array_data(&(p->bondsel)); char *anglesel = Array_data(&(p->anglesel)); char *dihedsel = Array_data(&(p->dihedsel)); char *imprsel = Array_data(&(p->imprsel)); const Topology *topo = &(p->topo); const Bond *bond = Topology_bond_array(topo); const Angle *angle = Topology_angle_array(topo); const Dihed *dihed = Topology_dihed_array(topo); const Impr *impr = Topology_impr_array(topo); const int32 natoms = Topology_atom_array_length(topo); int32 i, id; Idseq seq; int32 numelec, numelec_b, numvdw, numvdw_b; boolean overlap; int s; for (i = 0; i < natoms; i++) { nonbsel[i] |= atomsel[i]; /* select bonds */ if ((s=Idseq_init(&seq, Topology_atom_bondlist(topo, i))) != OK) { return ERROR(s); } while ((id=Idseq_getid(&seq)) >= 0) { if (atomsel[ bond[id].atomID[0] ] && atomsel[ bond[id].atomID[1] ]) { bondsel[id] = TRUE; } } Idseq_done(&seq); /* select angles */ if ((s=Idseq_init(&seq, Topology_atom_anglelist(topo, i))) != OK) { return ERROR(s); } while ((id=Idseq_getid(&seq)) >= 0) { if (atomsel[ angle[id].atomID[0] ] && atomsel[ angle[id].atomID[1] ] && atomsel[ angle[id].atomID[2] ]) { anglesel[id] = TRUE; } } Idseq_done(&seq); /* select dihedrals */ if ((s=Idseq_init(&seq, Topology_atom_dihedlist(topo, i))) != OK) { return ERROR(s); } while ((id=Idseq_getid(&seq)) >= 0) { if (atomsel[ dihed[id].atomID[0] ] && atomsel[ dihed[id].atomID[1] ] && atomsel[ dihed[id].atomID[2] ] && atomsel[ dihed[id].atomID[3] ]) { dihedsel[id] = TRUE; } } Idseq_done(&seq); /* select impropers */ if ((s=Idseq_init(&seq, Topology_atom_imprlist(topo, i))) != OK) { return ERROR(s); } while ((id=Idseq_getid(&seq)) >= 0) { if (atomsel[ impr[id].atomID[0] ] && atomsel[ impr[id].atomID[1] ] && atomsel[ impr[id].atomID[2] ] && atomsel[ impr[id].atomID[3] ]) { imprsel[id] = TRUE; } } Idseq_done(&seq); } /* check validity of nonbonded selection */ numelec = 0; numelec_b = 0; numvdw = 0; numvdw_b = 0; overlap = TRUE; //INT(natoms); for (i = 0; i < natoms; i++) { if ((nonbsel[i] & (ASEL_ELEC | ASEL_ELEC_B)) == (ASEL_ELEC | ASEL_ELEC_B) || (nonbsel[i] & (ASEL_VDW | ASEL_VDW_B)) == (ASEL_VDW | ASEL_VDW_B)) { return ERROR(ERR_EXPECT); } if (overlap && nonbsel[i] != 0 && nonbsel[i] != ASEL_NONB && nonbsel[i] != ASEL_NONB_B) { overlap = FALSE; } //INT(i); //HEX(nonbsel[i]); if (nonbsel[i] & ASEL_ELEC) numelec++; if (nonbsel[i] & ASEL_VDW) numvdw++; if (nonbsel[i] & ASEL_ELEC_B) numelec_b++; if (nonbsel[i] & ASEL_VDW_B) numvdw_b++; } if ((0==numelec && numelec_b > 0) || (0==numvdw && numvdw_b > 0)) { INT(numelec); INT(numelec_b); INT(numvdw); INT(numvdw_b); return ERROR(ERR_EXPECT); } INT(numvdw); p->nb_overlap = overlap; //INT(p->nb_overlap); p->fnbcut_all = (natoms==numelec ? FNBCUT_ELEC : 0) | (natoms==numvdw ? FNBCUT_VDW : 0); //HEX(p->fnbcut_all); p->fnbcut_subset = (0 < numelec && numelec < natoms && 0==numelec_b ? FNBCUT_ELEC : 0) | (0 < numvdw && numvdw < natoms && 0==numvdw_b ? FNBCUT_VDW : 0); //HEX(p->fnbcut_subset); p->fnbcut_disjoint = (numelec > 0 && numelec_b > 0 ? FNBCUT_ELEC : 0) | (numvdw > 0 && numvdw_b > 0 ? FNBCUT_VDW : 0); //HEX(p->fnbcut_disjoint); /* start by resetting all index array lengths */ if ((s=Array_resize(&(p->idnonb), 0)) != OK) return ERROR(s); if ((s=Array_resize(&(p->idnonb_b), 0)) != OK) return ERROR(s); if ((s=Array_resize(&(p->idnbvdw), 0)) != OK) return ERROR(s); if ((s=Array_resize(&(p->idnbvdw_b), 0)) != OK) return ERROR(s); if ((p->fnbcut_all & FNBCUT_ELEC)==0) { if ((p->fnbcut_subset & FNBCUT_ELEC) || (p->fnbcut_disjoint & FNBCUT_ELEC)) { if ((s=Array_resize(&(p->idnonb), numelec)) != OK) return ERROR(s); /* reset uselen for Array_append() */ if ((s=Array_resize(&(p->idnonb), 0)) != OK) return ERROR(s); for (i = 0; i < natoms; i++) { if ((nonbsel[i] & ASEL_ELEC) && (s=Array_append(&(p->idnonb), &i)) != OK) { return ERROR(s); } } } if ((p->fnbcut_disjoint & FNBCUT_ELEC)) { if ((s=Array_resize(&(p->idnonb_b), numelec_b)) != OK) return ERROR(s); /* reset uselen for Array_append() */ if ((s=Array_resize(&(p->idnonb_b), 0)) != OK) return ERROR(s); for (i = 0; i < natoms; i++) { if ((nonbsel[i] & ASEL_ELEC_B) && (s=Array_append(&(p->idnonb_b), &i)) != OK) { return ERROR(s); } } } } if (!overlap && (p->fnbcut_all & FNBCUT_VDW)==0) { if ((p->fnbcut_subset & FNBCUT_VDW) || (p->fnbcut_disjoint & FNBCUT_VDW)) { if ((s=Array_resize(&(p->idnbvdw), numvdw)) != OK) return ERROR(s); /* reset uselen for Array_append() */ if ((s=Array_resize(&(p->idnbvdw), 0)) != OK) return ERROR(s); for (i = 0; i < natoms; i++) { if ((nonbsel[i] & ASEL_VDW) && (s=Array_append(&(p->idnbvdw), &i)) != OK) { return ERROR(s); } } } if ((p->fnbcut_disjoint & FNBCUT_VDW)) { if ((s=Array_resize(&(p->idnbvdw_b), numvdw_b)) != OK) return ERROR(s); /* reset uselen for Array_append() */ if ((s=Array_resize(&(p->idnbvdw_b), 0)) != OK) return ERROR(s); for (i = 0; i < natoms; i++) { if ((nonbsel[i] & ASEL_VDW_B) && (s=Array_append(&(p->idnbvdw_b), &i)) != OK) { return ERROR(s); } } } } return OK; }