size_t //file size FileSystemMap::ChunkFile( FileDescType& FileObj) { ifstream ifl; ifl.open(FileObj.Name().c_str(), ifstream::in | ifstream::binary); if (!ifl.good()) { BOOST_THROW_EXCEPTION(std::exception()); } if (FileObj.Name().compare("/home/kcratie/Documents/include/mntent.h") == 0) int i =0; Digest md; // the hash object //Digest::value_type sha; // the hash value size_t const length = 1 << 8; std::array<byte, length> buf; size_t chunkOffset = 0; while (!ifl.eof()) { ifl.read((char*) buf.data(), length); size_t cnt = ifl.gcount(); DataChunkType chunk; chunk.Hash(buf.data(), cnt, md); auto p = ChunkMap.insert(std::make_pair(chunk.Hash(), chunk)); DataChunkType & dc = p.first->second; dc.AddDescriptor(FileObj.Name(), chunkOffset, cnt, &FileObj); //if (p.second) //add chunk to file object only if unique FileObj.AddChunk(dc); chunkOffset += cnt; auto pfl = dc.ChunksFirstLast(); if (pfl.first != pfl.second){ FileDescType * fd1 = static_cast<FileDescType *>(pfl.first.FileDescObj()); FileDescType * fd2 = static_cast<FileDescType *>(pfl.second.FileDescObj()); if(fd1!=fd2){ FMGraph::VertexDescriptor v1 = static_cast<FMGraph::VertexDescriptor>(fd1->VertexDesc()); FMGraph::VertexDescriptor v2 = static_cast<FMGraph::VertexDescriptor>(fd2->VertexDesc()); mCntGraph.AddEdge(v1, v2, EdgeProperties(dc.Length())); fd1->AddSharedBytesTotal(dc.Length()); fd2->AddSharedBytesTotal(dc.Length()); if (FileObj.Name().compare("/home/kcratie/Documents/include/mntent.h") == 0) int i =0; } // EdgeProperties ep(dc.Length()); // mCntGraph.AddEdge(v1, v2, ep); } } ifl.close(); return chunkOffset; }
void BondGraph::_SetBond (const Vertex& vi, const Vertex& vj, const double bondlength, const bondtype btype) { bool b; Edge e; tie(e, b) = add_edge(vi, vj, EdgeProperties(bondlength, btype), _graph); /* if (!b) { std::cout << "BondGraph::SetBond() - Tried to add a bond to an already-bonded atom pair" << std::endl; v_atom[vi]->Print(); v_atom[vj]->Print(); exit(1); } */ return; }
int MainWindow::buildNetwork(const QString& description) { int result = Success; // Split into lines QStringList lines = description.split(QRegExp("[\\n|\\r]"), QString::SkipEmptyParts); if (lines.isEmpty()) { postErrorMessage("Problem specification is empty after whitespace " "removed!"); return ErrorEmpty; } // Validate the length of the specification int nodeCount = lines[0].toInt(); postInfoMessage(QString("Expecting %1x%1 adjacency matrix...") .arg(nodeCount)); if (lines.length() != (nodeCount + 2)) { postErrorMessage(QString("Expecting %1 lines in specification; read %2") .arg(nodeCount + 2) .arg(lines.length())); return ErrorSpecTooSmall; } // Clear the existing graph and scene if (boost::num_vertices(m_graph) != 0) { postWarningMessage("Existing network already loaded; must be cleared " "in order to continue."); int response = QMessageBox::question(this, "NetRoute", "There is " "already a graph in the explorer; the current data will have to " "be discared. Continue?"); if (response == QMessageBox::No) { postErrorMessage("Aborted by user."); return WarningAbort; } postInfoMessage("Discarding network."); clearNetwork(); } // Create the nodes postInfoMessage("Creating nodes..."); for (int i = 0; i < nodeCount; ++i) { QString name = QString("%1").arg(QChar('A' + i)); NodeItem* node = new NodeItem; node->setText(name); m_graphNodes[name] = node; boost::add_vertex(NodeProperties(node), m_graph); m_graphScene->addItem(node); } // Create the edges postInfoMessage("Creating edges from adjacency matrix..."); for (int i = 0; i < nodeCount; ++i) { QString line = lines[i + 1].trimmed(); QStringList weights = line.split(',', QString::SkipEmptyParts); // Sanity check if (weights.length() != nodeCount) { postErrorMessage( QString("Matrix row %1 has %2 columns; expecting %3.") .arg(i) .arg(weights.length()) .arg(nodeCount)); return ErrorRowTooShort; } // Actually create the edges postInfoMessage(QString("Creating edges for node %1") .arg(QChar('A' + i))); DigraphVertex vStart = boost::vertex(i, m_graph); for (int j = 0; j < nodeCount; ++j) { bool ok; int weight = weights[j].trimmed().toInt(&ok); if (ok && weight >= 0) { DigraphVertex vEnd = boost::vertex(j, m_graph); // Create the new edge item EdgeItem* edge = new EdgeItem; edge->setStartNode(m_graph[vStart].item); edge->setEndNode(m_graph[vEnd].item); edge->setWeight(weight); m_graphScene->addItem(edge); // Add it to the graph boost::add_edge(vStart, vEnd, EdgeProperties(edge), m_graph); } else if (!ok) { postWarningMessage(QString("Weight (%1,%2) is malformed: %3.") .arg(i) .arg(j) .arg(weights[j])); result |= WarningBadCell; } } } // Parse the final line of the description: the start/end nodes QStringList nodes = lines[lines.length() - 1].split(QRegExp("\\s+"), QString::SkipEmptyParts); if (nodes.length() != 2) { postWarningMessage("Start and end nodes line is malformed; " "routing will not take place."); result |= WarningBadStartEnd; } else { QString startNodeName = nodes[0]; QString endNodeName = nodes[1]; m_routeStart = m_graphNodes[startNodeName]; m_routeEnd = m_graphNodes[endNodeName]; if (!m_routeStart) { postWarningMessage(QString("Failed to find start node '%1'; " "routing will not take place.") .arg(startNodeName)); result |= WarningNoStartNode; } if (!m_routeEnd) { postWarningMessage(QString("Failed to find end node '%1'; " "routing will not take place.") .arg(endNodeName)); result |= WarningNoEndNode; } } // Graph was built successfully, even if some parsing errors arose. return result; }