bool FileProjections::isProjectionExist(unsigned nodeId) const { if (isMemoryUsed()) { return Projections::isProjectionExist(nodeId); } Projection* pr = nullptr; if (loadedProjection && loadedProjection->getId() == nodeId) pr = loadedProjection; else pr = Projections::getProjection(nodeId); return !pr ? false : pr->fileExist(); }
void FileProjections::createAllProjections() { if (graph->isEmpty()) { return; } if(isMemoryUsed()) { Projections::createAllProjections(); return; } // Prepare nodes NodeMap* nodeList = graph->getNodeMap(); unsigned count = nodeList->size(); if (!count) return; ProjectionsWriter writer(*this); setWorker(&writer, true); startProcess(0u, count - 1); unsigned oldSize = projectionsList->size(); bool isWasEmpty = !oldSize; projectionsList->resize(count, nullptr); projectionsList->shrink_to_fit(); auto oldStart = projectionsList->begin(); auto oldEnd = projectionsList->begin() + oldSize; auto it = nodeList->begin(); Projection* pr; std::string saveName(graphFileName); unsigned nameSize = saveName.size(); unsigned currentId; unsigned pos = oldSize; for(unsigned i = 0u; i < count; ++i, ++it) { if (isInterrupted()) { projectionStatus = Status::PARTIAL; // if interrupted on null filled projections, shrink list projectionsList->resize(pos); break; } updateProgress(i); currentId = it->first; pr = nullptr; // Projection exist - skip if (!isWasEmpty) { auto e = std::lower_bound(oldStart, oldEnd, currentId, Projection::lessById); if (e != oldEnd && (*e)->getId() == currentId) { pr = *e; if (pr->fileExist()) continue; } } if (!pr) { pr = new Projection(currentId); (*projectionsList)[pos] = pr; ++pos; } pr->createProjection(*graph); if (pr->isInterrupted()) { continue; } ProjectionsReader::projectionFileName(saveName, nameSize, currentId); bool result = writer.saveProjection(saveName.data(), pr); if (result) { pr->setFileExist(true); } // stay loaded last projection if (count - i > 1) { pr->clear(); } else { loadedProjection = pr; } } if (!isWasEmpty) { auto end = projectionsList->end(); std::sort(oldStart, end, Projection::less); } if (!isInterrupted()) projectionStatus = Status::ALL; completeProcess(); }