void KDTree<T>::KDNode::nodeSizes( IntArray &sizes, int idx ) const { while ( idx >= sizes.size() ) { sizes.push_back( 0 ); } sizes[ idx ] = _numElements; if ( _left ) _left->nodeSizes( sizes, 2 * idx + 1 ); if ( _right ) _right->nodeSizes( sizes, 2 * idx + 2 ); }
// Get the PID from the selection list in CLIENT_DATA static int get_pid(Widget, XtPointer client_data, XtPointer) { IntArray pids; Widget processes = Widget(client_data); if (processes != 0) getPIDs(processes, pids); if (pids.size() == 1) return pids[0]; else return 0; }
IntArray NeuralNetworkSimpleInternal::getStructure() const throw() { IntArray structure = IntArray::withSize(getNumLayersIncludingInput(), false); structure[0] = getNumInputs(); for(int i = 1; i < structure.size(); i++) { structure[i] = getNumNodesOnLayer(i-1); } return structure; }
int RasterizerDummy::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const { Mesh *mesh = mesh_owner.get( p_mesh ); ERR_FAIL_COND_V(!mesh,-1); ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 ); Surface *surface = mesh->surfaces[p_surface]; ERR_FAIL_COND_V( !surface, -1 ); IntArray arr = surface->data[VS::ARRAY_INDEX]; return arr.size(); }
bool IntArray::operator!=(const IntArray& rhs) const { if (_size != rhs.size()) { return true; } for (int ii = 0; ii < _size; ii++) { if (ia[ii] == rhs.ia[ii]) { return false; } } return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST(ArrayTest, ConstructorFromValueArray) { MyIntValueArr valArr; ASSERT_EQ(5, valArr.size()); EXPECT_EQ(104, valArr.val(4)); IntArray* ai = new IntArray(valArr); ASSERT_EQ(5u, ai->size()); ASSERT_EQ(100, (*ai)[0]); ASSERT_EQ(101, (*ai)[1]); ASSERT_EQ(102, (*ai)[2]); ASSERT_EQ(103, (*ai)[3]); ASSERT_EQ(104, (*ai)[4]); }
static void BuildEdgesMap(const IntArray& E, const IntArray& U, const IntArray& V, Digraph& dg, IntNodeMap& nodes_map, IntArcMap& edges_map) { for(unsigned int i=0;i<E.size();i++) { if(edges_map.find(E[i]) == edges_map.end()) { Digraph::Node u = nodes_map[U[i]]; Digraph::Node v = nodes_map[V[i]]; Digraph::Arc e = dg.addArc(u, v); edges_map.insert(IntArcMap::value_type(E[i], e)); } } }
SegmentArray graph2SegArray(const Graph &graph, IntArray &pla, const bool *polygonEdge) { IntArray sortedEdgeLabels; graph.topologicalSort(sortedEdgeLabels); SegmentArray sOrder; for (int i = 0; i < sortedEdgeLabels.size(); i++) { if (polygonEdge[sortedEdgeLabels[i]]) sOrder.push_back(Segment(pla[2 * sortedEdgeLabels[i]], pla[2 * sortedEdgeLabels[i] + 1])); } int s = sOrder.size(); return sOrder; }
void testAccess() { const IntArray a = {1, 2, 3}; assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 3); assert(a.at(0) == 1); assert(a.at(1) == 2); assert(a.at(2) == 3); IntArray b; b.assign({7, 7, 7, 7, 7}); assert(b[4] == 7); assert(b.at(4) == 7); b.assign(a.begin(), a.end()); assert(b == a); b.clear(); assert(b.size() == 0); }
bool Galois::calcSyndrome(IntArray &data, int length, IntArray &syn) const { int hasErr = 0; for(unsigned int i = 0, s = symStart; i < syn.size(); i++, s++) { int wk = 0; for(int idx = 0; idx < length; idx++) { if(wk != 0) { wk = expTbl[logTbl[wk] + s]; } wk ^= data[idx]; } syn[i] = wk; hasErr |= wk; } return hasErr == 0; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST(ArrayTest, ConstructorFromPointer) { int* data = new int[3]; data[0] = 1; data[1] = 2; data[2] = 99; IntArray* ai = new IntArray(data, 3); ASSERT_EQ(3u, ai->size()); ASSERT_EQ(1, (*ai)[0]); ASSERT_EQ(2, (*ai)[1]); ASSERT_EQ(99, (*ai)[2]); data[2] = 3; ASSERT_EQ(99, (*ai)[2]); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void GeometryBuilder::addTriangles(const IntArray& indices) { size_t numIndices = indices.size(); CVF_ASSERT(numIndices >= 3); CVF_ASSERT(numIndices % 3 == 0); size_t numTriangles = numIndices/3; CVF_ASSERT(numTriangles >= 1); CVF_ASSERT(3*numTriangles == numIndices); size_t i; for (i = 0; i < numTriangles; i++) { CVF_ASSERT(indices[3*i] >= 0 && indices[3*i + 1] && indices[3*i + 2]); addTriangle(static_cast<uint>(indices[3*i]), static_cast<uint>(indices[3*i + 1]), static_cast<uint>(indices[3*i + 2])); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void GeometryBuilder::addQuads(const IntArray& indices) { size_t numIndices = indices.size(); CVF_ASSERT(numIndices >= 4); CVF_ASSERT(numIndices % 4 == 0); size_t numQuads = numIndices/4; CVF_ASSERT(numQuads >= 1); CVF_ASSERT(4*numQuads == numIndices); size_t i; for (i = 0; i < numQuads; i++) { CVF_ASSERT(indices[4*i] >= 0 && indices[4*i + 1] && indices[4*i + 2] && indices[4*i + 3]); addQuad(static_cast<uint>(indices[4*i]), static_cast<uint>(indices[4*i + 1]), static_cast<uint>(indices[4*i + 2]), static_cast<uint>(indices[4*i + 3])); } }
void testConstructorsAndAssignment() { IntArray a; IntArray b(10000); IntArray c(5, 1); IntArray d(b); IntArray e({1, 1, 1, 1, 1}); assert(a.size() == 0); assert(b == d); assert(b.size() == 10000); assert(c == e); IntArray tmp = c; b = c; assert(b == c); b = e; assert(c == tmp); b = b; assert(b == e); }
static void ApproximatePolygon( const PointArray& cnpts, PointArray& polygon, double tolerance ) { if( cnpts.empty() ) return; int n = cnpts.size(); // 是否封闭等值线??? if( IsPointEqual( cnpts.front(), cnpts.back() ) ) { n--; } int minEdge = n + 1, k = n; IntArray indexes; for( int i = 0; i < ( int )cnpts.size(); i++ ) { indexes.push_back( i ); } while( k < minEdge ) { minEdge = k; int p = 0; while( p < minEdge - ( n % 2 == 0 ? 3 : 2 ) ) { double distance = GetPointDistanceToLine( cnpts[indexes[p + 1]], cnpts[indexes[p]], cnpts[indexes[p + 2]] ); if ( distance < tolerance ) { indexes[p + 1] = -1; k -= 1; } p += 2; } UpdateIndexes( indexes ); } for( int i = 0; i < ( int )indexes.size(); i++ ) { polygon.push_back( cnpts[indexes[i]] ); } }
void CriticalPoint::TraceMinLineFromSaddle(SadPoint& sadP,size_t& minP,IntArray& pathArray) { CoordArray& vCoord = *(Global::p_coord); size_t nextVID = minP; pathArray.push_back(sadP.getId()); double lensum = 0; while (m_vtx[nextVID]->getType() != Global::MINPOINT) { pathArray.push_back(nextVID); double len = (vCoord[pathArray[pathArray.size() - 2]] - vCoord[pathArray[pathArray.size() - 1]]).abs(); lensum += len; if (lensum < Global::maxLineLength) { nextVID = FindMinEigenValueFromVertexNeigh(nextVID); } else return; } pathArray.push_back(nextVID); minP = nextVID; }
struct Num { int value; Num(int val = 100) :value(val) { } bool operator==(const Num& n) const { return value == n.value; } }; typedef Array<int> IntArray; typedef Array<struct Num> NumArray; TEST_CASE("Array constructor", "[Array]") { SECTION("without arguments creates an empty array") { IntArray a; REQUIRE( a.size() == 0 ); } SECTION("allocates an array with the specified size") { IntArray a(10); REQUIRE( a.size() == 10 ); } SECTION("initializes the array") { NumArray a(10); for (int i = 0; i < 10; ++i) { REQUIRE( a.get(i).value == 100 ); } }
static void outputHeightFieldToStream( NxHeightFieldShape* hfShape, NxShape* shape, IntArray& geom_stream, TriArray& world_triangles, TriArray* world_edge_normals, IntArray& edge_flags, const NxExtendedVec3& origin, const NxBounds3& tmpBounds ) { // Do AABB-mesh query NxU32 Nb; const NxU32* TF; // Collide AABB against current mesh if(!hfShape->overlapAABBTriangles(tmpBounds, NX_QUERY_WORLD_SPACE, Nb, TF)) return; NxVec3 tmp = shape->getGlobalPosition(); // LOSS OF ACCURACY NxVec3 MeshOffset; MeshOffset.x = float(tmp.x - origin.x); MeshOffset.y = float(tmp.y - origin.y); MeshOffset.z = float(tmp.z - origin.z); TouchedMesh* touchedMesh = (TouchedMesh*)reserve(geom_stream, sizeof(TouchedMesh)/sizeof(NxU32)); touchedMesh->mType = TOUCHED_MESH; // ptchernev: seems to work touchedMesh->mUserData = shape; touchedMesh->mOffset = origin; touchedMesh->mNbTris = Nb; touchedMesh->mIndexWorldTriangles = world_triangles.size(); touchedMesh->mIndexWorldEdgeNormals = world_edge_normals ? world_edge_normals->size() : 0; touchedMesh->mIndexEdgeFlags = edge_flags.size(); // Reserve memory for incoming triangles NxTriangle* TouchedTriangles = reserve(world_triangles, Nb); NxTriangle* EdgeTriangles = world_edge_normals ? reserve(*world_edge_normals, Nb) : NULL; // Loop through touched triangles while(Nb--) { NxU32 Index = *TF++; // Compute triangle in world space, add to array NxTriangle& CurrentTriangle = *TouchedTriangles++; NxTriangle edgeTri; NxU32 edgeFlags; hfShape->getTriangle(CurrentTriangle, &edgeTri, &edgeFlags, Index, false); CurrentTriangle.verts[0] += MeshOffset; CurrentTriangle.verts[1] += MeshOffset; CurrentTriangle.verts[2] += MeshOffset; if(EdgeTriangles) { *EdgeTriangles++ = edgeTri; } edge_flags.pushBack(edgeFlags); #ifdef VISUALIZE_CCT_TRIS // Visualize debug triangles { // PhysicsSDK::getInstance().getDebugRenderable()->addTriangle((const NxVec3&)CurrentTriangle.mVerts[0], (const NxVec3&)CurrentTriangle.mVerts[1], (const NxVec3&)CurrentTriangle.mVerts[2], NX_ARGB_GREEN); NxGetPhysicsSDK()->getDebugRenderable()->addTriangle((const NxVec3&)CurrentTriangle.mVerts[0], (const NxVec3&)CurrentTriangle.mVerts[1], (const NxVec3&)CurrentTriangle.mVerts[2], NX_ARGB_GREEN); // PhysicsSDK::getInstance().getDebugRenderable()->addLine((const NxVec3&)CurrentTriangle.mVerts[0], (const NxVec3&)CurrentTriangle.mVerts[1], NX_ARGB_GREEN); // PhysicsSDK::getInstance().getDebugRenderable()->addLine((const NxVec3&)CurrentTriangle.mVerts[1], (const NxVec3&)CurrentTriangle.mVerts[2], NX_ARGB_GREEN); // PhysicsSDK::getInstance().getDebugRenderable()->addLine((const NxVec3&)CurrentTriangle.mVerts[2], (const NxVec3&)CurrentTriangle.mVerts[0], NX_ARGB_GREEN); } #endif } }
static void outputConvexToStream( NxConvexShape* convexShape, NxShape* shape, IntArray& geom_stream, TriArray& world_triangles, TriArray* world_edge_normals, IntArray& edge_flags, const NxExtendedVec3& origin, const NxBounds3& tmpBounds ) { // Do AABB-mesh query NxU32 Nb; const NxU32* TF; // Collide AABB against current mesh // The overlap function doesn't exist for convexes so let's just dump all tris NxConvexMesh& cm = convexShape->getConvexMesh(); Nb = cm.getCount(0, NX_ARRAY_TRIANGLES); NX_ASSERT(cm.getFormat(0, NX_ARRAY_TRIANGLES)==NX_FORMAT_INT); TF = (const NxU32*)cm.getBase(0, NX_ARRAY_TRIANGLES); NX_ASSERT(cm.getFormat(0, NX_ARRAY_VERTICES)==NX_FORMAT_FLOAT); const NxVec3* verts = (const NxVec3*)cm.getBase(0, NX_ARRAY_VERTICES); NxMat34 absPose = shape->getGlobalPose(); NxVec3 tmp = shape->getGlobalPosition(); // LOSS OF ACCURACY NxVec3 MeshOffset; MeshOffset.x = float(tmp.x - origin.x); MeshOffset.y = float(tmp.y - origin.y); MeshOffset.z = float(tmp.z - origin.z); TouchedMesh* touchedMesh = (TouchedMesh*)reserve(geom_stream, sizeof(TouchedMesh)/sizeof(NxU32)); touchedMesh->mType = TOUCHED_MESH; touchedMesh->mUserData = shape; touchedMesh->mOffset = origin; touchedMesh->mNbTris = Nb; touchedMesh->mIndexWorldTriangles = world_triangles.size(); touchedMesh->mIndexWorldEdgeNormals = world_edge_normals ? world_edge_normals->size() : 0; touchedMesh->mIndexEdgeFlags = edge_flags.size(); // Reserve memory for incoming triangles NxTriangle* TouchedTriangles = reserve(world_triangles, Nb); NxTriangle* EdgeTriangles = world_edge_normals ? reserve(*world_edge_normals, Nb) : NULL; // Loop through touched triangles while(Nb--) { // Compute triangle in world space, add to array NxTriangle& CurrentTriangle = *TouchedTriangles++; NxU32 vref0 = *TF++; NxU32 vref1 = *TF++; NxU32 vref2 = *TF++; NxVec3 v0 = verts[vref0]; NxVec3 v1 = verts[vref1]; NxVec3 v2 = verts[vref2]; absPose.M.multiply(v0, v0); absPose.M.multiply(v1, v1); absPose.M.multiply(v2, v2); CurrentTriangle.verts[0] = v0; CurrentTriangle.verts[1] = v1; CurrentTriangle.verts[2] = v2; CurrentTriangle.verts[0] += MeshOffset; CurrentTriangle.verts[1] += MeshOffset; CurrentTriangle.verts[2] += MeshOffset; if(EdgeTriangles) { // #### hmmm NxTriangle edgeTri; edgeTri.verts[0].zero(); edgeTri.verts[1].zero(); edgeTri.verts[2].zero(); *EdgeTriangles++ = edgeTri; } // #### hmmm NxU32 edgeFlags = 7; edge_flags.pushBack(edgeFlags); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST(ArrayTest, BasicIntArray) { // IntArray IntArray iA; iA.resize(3); ASSERT_EQ(3u, iA.size()); iA[0] = 99; iA[1] = 10; iA[2] = 3; ASSERT_EQ(99, iA[0]); ASSERT_EQ(10, iA[1]); ASSERT_EQ(3, iA[2]); iA.clear(); ASSERT_EQ(0u, iA.size()); int* data = new int[3]; data[0] = 1; data[1] = 2; data[2] = 99; IntArray* ai = new IntArray(data, 3); ASSERT_EQ(3u, ai->size()); ASSERT_EQ(1, (*ai)[0]); ASSERT_EQ(2, (*ai)[1]); ASSERT_EQ(99, (*ai)[2]); data[2] = 3; ASSERT_EQ(99, (*ai)[2]); IntArray i2(*ai); delete ai; ai = NULL; ASSERT_EQ(3u, i2.size()); ASSERT_EQ(1, i2[0]); ASSERT_EQ(2, i2[1]); ASSERT_EQ(99, i2[2]); IntArray i3(2); i3[0] = 10; i3[1] = 20; ASSERT_EQ(2u, i3.size()); ASSERT_EQ(10, i3[0]); ASSERT_EQ(20, i3[1]); int* p = i3.ptr(); ASSERT_EQ(10, p[0]); ASSERT_EQ(20, p[1]); const IntArray* pi = &i3; const int* cp = pi->ptr(); ASSERT_EQ(10, cp[0]); ASSERT_EQ(20, cp[1]); const IntArray& ci = i3; ASSERT_EQ(10, ci[0]); ASSERT_EQ(20, ci[1]); }
void Contour::searchBoundary( PointArray& bpts, IntArray& bpos ) { // 记录所有边界分支 BoundaryEdgeArray bea; for( int i = 0; i < ( int )eaa.size(); i++ ) { if( eaa[i]->isBoundary() ) { BoundaryEdge be = {i, false}; bea.push_back( be ); } } if( bea.empty() ) return; // 记录搜索得到的点编号 IntArray pia; // 前提:边界必然是闭合的 // 可能存在多个边界(内外边界) while( true ) { // 搜索可用的边界 int bi = -1; for( int i = 0; i < ( int )bea.size(); i++ ) { BoundaryEdge be = bea[i]; if( !be.used ) { bi = i; break; } } if( bi == -1 ) break; // 记录之前已搜索到的边界点个数 int boundPts_num = pia.size(); DT_Edge e = getEdgeObject( bea[bi].ei )->e; bea[bi].used = true; // 标记为使用 pia.push_back( e.s ); pia.push_back( e.t ); int nt = e.t; while( true ) { int nbi = -1; for( int i = 0; i < ( int )bea.size(); i++ ) { if( bea[i].used ) continue; DT_Edge ne = getEdgeObject( bea[i].ei )->e; if( nt == ne.s ) { nt = ne.t; nbi = i; break; } else if( nt == ne.t ) { nt = ne.s; nbi = i; break; } } if( nbi == -1 ) break; bea[nbi].used = true; pia.push_back( nt ); } int n = pia.size() - boundPts_num; if( n >= 3 ) { // 至少是3个点 bpos.push_back( n ); } } // 将点编号转换成实际的点坐标 for( int i = 0; i < ( int )pia.size(); i++ ) { bpts.push_back( pa[pia[i]] ); } }
IntArray::IntArray(const IntArray& rhs) { init(rhs.size(), rhs.ia); }
// Create list of processes static void update_processes(Widget processes, bool keep_selection) { StatusDelay delay("Getting list of processes"); string cmd = sh_command(app_data.ps_command) + " 2>&1"; FILE *fp = popen(cmd.chars(), "r"); if (fp == 0) { delay.outcome = strerror(errno); return; } StringArray all_process_list; int c; string line = ""; bool first_line = true; while ((c = getc(fp)) != EOF) { if (c == '\n') { if (first_line || valid_ps_line(line, app_data.ps_command)) all_process_list += line; #if 0 else std::clog << "Excluded: " << line << "\n"; #endif if (first_line) { // Find first occurrence of `PID' title ps_pid_index = line.index(" PID "); if (ps_pid_index < 0) ps_pid_index = 0; } line = ""; first_line = false; } else { line += c; } } pclose(fp); sortProcesses(all_process_list); DynIntArray pids(all_process_list.size()); // If GDB cannot send a signal to the process, we cannot debug it. // Try a `kill -0' (via GDB, as it may be setuid) and filter out // all processes in the `kill' diagnostic -- that is, all // processes that `kill' could not send a signal. string kill = "kill -0"; if (gdb->has_handler_command()) kill = "/usr/bin/kill -0"; // Bypass built-in SUN DBX command int i; for (i = 0; i < all_process_list.size(); i++) { pids[i] = ps_pid(all_process_list[i]); if (pids[i]) kill += string(" ") + itostring(pids[i]); } #if defined(__sun) // bypass underlying debugger // Fix for Sun: use /usr/bin/kill string kill_result; { std::ostringstream os; kill += " 2>&1"; FILE *fp = popen(kill.chars(), "r"); if (fp != 0) { int c; while ((c = getc(fp)) != EOF) { os << (char)c; } pclose(fp); } kill_result = os; } #else string kill_result = gdb_question(gdb->shell_command(kill)); #endif i = 0; while (i >= 0) { i = kill_result.index(rxint, i); if (i >= 0) { int bad_pid = atoi(kill_result.chars() + i); for (int k = 0; k < all_process_list.size(); k++) { if (pids[k] != 0 && pids[k] == bad_pid) { #if 0 std::clog << "Excluded: " << all_process_list[k] << "\n"; #endif all_process_list[k] = NO_GDB_ANSWER; } } i++; } } StringArray process_list; for (i = 0; i < all_process_list.size(); i++) if (all_process_list[i] != NO_GDB_ANSWER) process_list += all_process_list[i]; // Now set the selection. bool *selected = new bool[process_list.size()]; for (i = 0; i < process_list.size(); i++) selected[i] = false; int pos = -1; if (keep_selection) { // Preserve old selection: each PID selected before will also be // selected after. IntArray selection; getPIDs(processes, selection); for (i = 0; i < selection.size(); i++) { for (int j = 0; j < process_list.size(); j++) if (selection[i] == ps_pid(process_list[j])) { if (pos < 0) pos = j; selected[j] = true; } } } if (pos < 0) { // Create new selection from current file and current pid. ProgramInfo info; // Check for current pid; if found, highlight it. for (i = 0; pos < 0 && i < process_list.size(); i++) { if (info.pid != 0 && ps_pid(process_list[i]) == info.pid) pos = i; } if (pos < 0) { // Not found? Try leftmost occurrence of process base name. string current_base = basename(info.file.chars()); int leftmost = INT_MAX; for (i = 0; i < process_list.size(); i++) { int occurrence = process_list[i].index(current_base); if (occurrence >= 0 && occurrence < leftmost && ps_pid(process_list[i]) > 0) { leftmost = occurrence; pos = i; } } } } if (pos >= 0) selected[pos] = true; setLabelList(processes, process_list.values(), selected, process_list.size(), true, false); if (pos >= 0) ListSetAndSelectPos(processes, pos + 1); delete[] selected; }
int Network::Dinic() { int maxflow = 0; int u,v,e,ee,f; IntArray q; _E.resize(_E.size()+1); _E.back().v = _s; while (true) { for (u = 0;u < _V.size();u++) _V[u].l = -1; _V[_s].l = f = 0; _V[_s].o = _V[_s].e; q.clear(); q.push_back(_s); while (f < (int)q.size()) { u = q[f++]; for (e = _V[u].e;e != -1;e = _E[e].n) { v = _E[e].v; if (_V[v].l == -1 && _E[e].c > 0) { _V[v].o = _V[v].e; _V[v].l = _V[u].l+1; q.push_back(v); } } } if (_V[_t].l == -1) break; q.clear(); q.push_back(_E.size()-1); while (!q.empty()) { u = _E[q.back()].v; if (u == _t) { for (f = INT_MAX,e = 1;e < (int)q.size();e++) if (_E[q[e]].c < f) f = _E[q[e]].c,u = e; for (e = 1;e < q.size();e++) { _E[q[e]].c -= f; _E[q[e]^1].c += f; } maxflow += f; q.resize(u); } else { for (e = _V[u].o;e != -1;e = _E[e].n) { if (_V[_E[e].v].l < 0 || _E[e].c < 1) continue; if (_V[_E[e].v].l == _V[u].l+1) break; } if ((_V[u].o = e) != -1) q.push_back(e); else { q.pop_back(); _V[u].l = -1; } } } } return maxflow; }
void FstLinkedList::initFstLinkedList( string fstPath, string fileName) { listAllFstNodes.clear(); finalFstLinkedList.clear(); string line; StringArray words; ifstream fileIdFile((fstPath + "//" + fileName + ".fst").c_str()); if (!fileIdFile.is_open()) { cout << "FST file missing : " << (fstPath + "//" + fileName + ".fst").c_str() << endl; exit(0); } IntArray lastPhoneArr; while (getline(fileIdFile, line)) { words = Dictionary::string2words(line); FstNode curFstNode; if (words.size() == 5) //FST contains weights { curFstNode.start = atoi(words[0].c_str()); curFstNode.end = atoi(words[1].c_str()); curFstNode.in = words[2]; curFstNode.op = words[3]; curFstNode.wt = AcousticModel::myLog(atof(words[4].c_str())); listAllFstNodes.push_back(curFstNode); // cout <<curFstNode.start << " " << curFstNode.end<<" " << curFstNode.in<<" " << curFstNode.op <<endl; } else if (words.size() == 4) //FST does not contain weights { curFstNode.start = atoi(words[0].c_str()); curFstNode.end = atoi(words[1].c_str()); curFstNode.in = words[2]; curFstNode.op = words[3]; listAllFstNodes.push_back(curFstNode); // cout <<curFstNode.start << " " << curFstNode.end<<" " << curFstNode.in<<" " << curFstNode.op <<endl; } else if (words.size() == 2) // last state has weight { curFstNode.start = atoi(words[0].c_str()); curFstNode.end = -1; curFstNode.wt = atof(words[1].c_str()); listAllFstNodes.push_back(curFstNode); lastPhoneArr.push_back(curFstNode.start); // cout <<curFstNode.start << " " << curFstNode.end<<endl; } else if (words.size() == 1) // last state has no weight { curFstNode.start = atoi(words[0].c_str()); curFstNode.end = -1; listAllFstNodes.push_back(curFstNode); lastPhoneArr.push_back(curFstNode.start); // cout <<curFstNode.start << " " << curFstNode.end<<endl; } else { cout << "ERROR : FST network should not have reached here : " << line << endl; exit(0); } } // cout << listAllFstNodes.size() <<endl; // if the lastPhoneArr points to #0, then make it point the previous phone for (int i = 0; i < (int) listAllFstNodes.size(); i++) { FstNode *curFstNode = &listAllFstNodes[i]; for (int j = 0; j < (int) lastPhoneArr.size(); j++) { if (curFstNode->end == lastPhoneArr[j]) { if (curFstNode->in.compare("#0") == 0) { lastPhoneArr[j] = curFstNode->start; } } } } int currentState = 0; finalFstLinkedList.push_back(listAllFstNodes[0]); for (int i = 1; i < (int) listAllFstNodes.size(); i++) { FstNode *curFstNode = &listAllFstNodes[i]; for (int j = 0; j < (int) lastPhoneArr.size(); j++) { if (curFstNode->end == lastPhoneArr[j]) { curFstNode->lastPhone = 1; if (curFstNode->in.compare("SIL") == 0) { curFstNode->lastSIL = 1; } } } if (curFstNode->start > currentState) { finalFstLinkedList.push_back(*curFstNode); currentState = curFstNode->start; } else { FstNode *endOfLinkedList = &finalFstLinkedList[finalFstLinkedList.size() - 1]; while (endOfLinkedList->nextFstNode != NULL) { endOfLinkedList = endOfLinkedList->nextFstNode; } endOfLinkedList->nextFstNode = curFstNode; } // cout <<curFstNode->start << " " << curFstNode->end<<" " << curFstNode->in<<" " << curFstNode->op << " "<<curFstNode->lastPhone <<" "<<curFstNode->lastSIL <<endl; } }