std::unique_ptr<ArchiveKeys> ArchiveKeys::create_and_save(std::ostream &stream, RsaKeyPair *keypair){ std::unique_ptr<ArchiveKeys> ret; if (keypair){ ret = make_unique(new ArchiveKeys(CryptoPP::Twofish::MAX_KEYLENGTH, CryptoPP::Twofish::BLOCKSIZE)); CryptoPP::RSA::PublicKey pub; auto &public_key = keypair->get_public_key(); pub.Load(CryptoPP::ArraySource((const byte *)&public_key[0], public_key.size(), true)); typedef CryptoPP::RSAES<CryptoPP::OAEP<CryptoPP::SHA>>::Encryptor encryptor_t; typedef CryptoPP::PK_EncryptorFilter filter_t; encryptor_t enc(pub); CryptoPP::SecByteBlock buffer(ret->get_size()); size_t offset = 0; for (size_t i = 0; i < ret->key_count; i++){ auto &key = ret->get_key(i); auto &iv = ret->get_iv(i); memcpy(buffer.data() + offset, key.data(), key.size()); offset += key.size(); memcpy(buffer.data() + offset, iv.data(), iv.size()); offset += iv.size(); } CryptoPP::ArraySource(buffer.data(), buffer.size(), true, new filter_t(*random_number_generator, enc, new CryptoPP::FileSink(stream))); } return ret; }
SEXP make_index_unique (SEXP x_, SEXP eps_) { SEXP result; PROTECT(result = coredata_xts(x_)); copyAttributes(x_, result); /* copy all attrib except index, and dim-related */ setAttrib(result, xts_IndexSymbol, make_unique(getAttrib(x_, xts_IndexSymbol), eps_)); UNPROTECT(1); return(result); }
static INT_PTR CALLBACK MainWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_INITDIALOG) { winHandler = make_unique(new DialogHandler(hDlg)); } if (winHandler) { return winHandler->windowProc(message, wParam, lParam); } return (INT_PTR) FALSE; }
std::shared_ptr<BackupStream> BackupSystem::check_and_maybe_add(FileSystemObject &fso, known_guids_t &known_guids){ std::shared_ptr<BackupStream> ret; if (!this->should_be_added(fso, known_guids)){ this->fix_up_stream_reference(fso, known_guids); return ret; } auto &filish = static_cast<FilishFso &>(fso); auto existing_version = invalid_version_number; if (filish.get_backup_mode() == BackupMode::Full && !this->file_has_changed(existing_version, filish)) filish.set_backup_mode(BackupMode::Unmodified); switch (filish.get_backup_mode()){ case BackupMode::Unmodified: { auto temp = make_unique(new UnmodifiedStream); temp->set_unique_id(filish.get_stream_id()); temp->set_containing_version(existing_version); temp->set_virtual_size(filish.get_size()); ret = std::move(temp); } ret->add_file_system_object(&filish); break; case BackupMode::ForceFull: case BackupMode::Full: { auto temp = make_unique(new FullStream); temp->set_unique_id(filish.get_stream_id()); temp->set_physical_size(filish.get_size()); temp->set_virtual_size(filish.get_size()); ret = std::move(temp); } ret->add_file_system_object(&filish); break; case BackupMode::Rsync: throw NotImplementedException(); default: throw InvalidSwitchVariableException(); } zekvok_assert(!!ret); auto &guid = filish.get_file_system_guid(); if (guid.valid) known_guids[guid.data] = ret; return ret; }
/* * Generate plan for a UNION or UNION ALL node */ static Plan * generate_union_plan(SetOperationStmt *op, Query *parse, List *refnames_tlist) { List *planlist; List *tlist; Plan *plan; /* * If any of my children are identical UNION nodes (same op, all-flag, * and colTypes) then they can be merged into this node so that we * generate only one Append and Sort for the lot. Recurse to find * such nodes and compute their children's plans. */ planlist = nconc(recurse_union_children(op->larg, parse, op, refnames_tlist), recurse_union_children(op->rarg, parse, op, refnames_tlist)); /* * Generate tlist for Append plan node. * * The tlist for an Append plan isn't important as far as the Append is * concerned, but we must make it look real anyway for the benefit of * the next plan level up. */ tlist = generate_append_tlist(op->colTypes, false, planlist, refnames_tlist); /* * Append the child results together. */ plan = (Plan *) make_append(planlist, false, tlist); /* * For UNION ALL, we just need the Append plan. For UNION, need to * add Sort and Unique nodes to produce unique output. */ if (!op->all) { List *sortList; tlist = copyObject(tlist); sortList = addAllTargetsToSortList(NULL, NIL, tlist, false); plan = (Plan *) make_sort_from_sortclauses(parse, tlist, plan, sortList); plan = (Plan *) make_unique(tlist, plan, sortList); } return plan; }
void Device::initTaskingSystem(size_t numThreads) { Lock<MutexSys> lock(g_mutex); if (numThreads == 0) g_num_threads_map[this] = std::numeric_limits<size_t>::max(); else g_num_threads_map[this] = numThreads; /* create task scheduler */ size_t maxNumThreads = getMaxNumThreads(); TaskScheduler::create(maxNumThreads,State::set_affinity,State::start_threads); #if USE_TASK_ARENA arena = make_unique(new tbb::task_arena((int)min(maxNumThreads,TaskScheduler::threadCount()))); #endif }
bool is_continuous(std::vector<int> A) { std::sort(A.begin(), A.end()); make_unique(A); std::vector<int>::iterator begin = A.begin(), end = A.end(); int size = A.size(); unsigned long int sum = std::accumulate(begin, end, 0); unsigned long int sum_squared = std::accumulate(begin, end, 0, square); unsigned expected_sum = static_cast<float>(*std::max_element(begin, end) + *std::min_element(begin, end)) / 2 * size; unsigned expected_squared_sum = size * (size + 1) * (2 * size + 1) / 6; if (sum != expected_sum || sum_squared != expected_squared_sum) { return false; } return true; }
void set_corrected_position (position_type const &pos_) { make_unique(); data->set_corrected_position(pos_); }
void set_value (string_type const &value_) { make_unique(); data->set_value(value_); }
void set_token_id (boost::wave::token_id id_) { make_unique(); data->set_token_id(id_); }
Device::Device (const char* cfg) { /* check CPU */ if (!hasISA(ISA)) throw_RTCError(RTC_ERROR_UNSUPPORTED_CPU,"CPU does not support " ISA_STR); /* initialize global state */ State::parseString(cfg); if (!ignore_config_files && FileName::executableFolder() != FileName("")) State::parseFile(FileName::executableFolder()+FileName(".embree" TOSTRING(RTC_VERSION_MAJOR))); if (!ignore_config_files && FileName::homeFolder() != FileName("")) State::parseFile(FileName::homeFolder()+FileName(".embree" TOSTRING(RTC_VERSION_MAJOR))); State::verify(); /*! do some internal tests */ assert(isa::Cylinder::verify()); /*! enable huge page support if desired */ #if defined(__WIN32__) if (State::enable_selockmemoryprivilege) State::hugepages_success &= win_enable_selockmemoryprivilege(State::verbosity(3)); #endif State::hugepages_success &= os_init(State::hugepages,State::verbosity(3)); /*! set tessellation cache size */ setCacheSize( State::tessellation_cache_size ); /*! enable some floating point exceptions to catch bugs */ if (State::float_exceptions) { int exceptions = _MM_MASK_MASK; //exceptions &= ~_MM_MASK_INVALID; exceptions &= ~_MM_MASK_DENORM; exceptions &= ~_MM_MASK_DIV_ZERO; //exceptions &= ~_MM_MASK_OVERFLOW; //exceptions &= ~_MM_MASK_UNDERFLOW; //exceptions &= ~_MM_MASK_INEXACT; _MM_SET_EXCEPTION_MASK(exceptions); } /* print info header */ if (State::verbosity(1)) print(); if (State::verbosity(2)) State::print(); /* register all algorithms */ bvh4_factory = make_unique(new BVH4Factory(enabled_builder_cpu_features, enabled_cpu_features)); #if defined(EMBREE_TARGET_SIMD8) bvh8_factory = make_unique(new BVH8Factory(enabled_builder_cpu_features, enabled_cpu_features)); #endif /* setup tasking system */ initTaskingSystem(numThreads); /* ray stream SOA to AOS conversion */ #if defined(EMBREE_RAY_PACKETS) RayStreamFilterFuncsType rayStreamFilterFuncs; SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512KNL_AVX512SKX(enabled_cpu_features,rayStreamFilterFuncs); rayStreamFilters = rayStreamFilterFuncs(); #endif }
void set_token_id (token_id id_) { make_unique(); data->set_token_id(id_); }
void SubsetTopologicalMapping::init() { sofa::core::topology::TopologicalMapping::init(); this->updateLinks(); if (fromModel && toModel) { const Index npS = (Index)fromModel->getNbPoints(); const Index npD = (Index) toModel->getNbPoints(); helper::WriteAccessor<Data<SetIndex> > pS2D(pointS2D); helper::WriteAccessor<Data<SetIndex> > pD2S(pointD2S); helper::WriteAccessor<Data<SetIndex> > eS2D(edgeS2D); helper::WriteAccessor<Data<SetIndex> > eD2S(edgeD2S); helper::WriteAccessor<Data<SetIndex> > tS2D(triangleS2D); helper::WriteAccessor<Data<SetIndex> > tD2S(triangleD2S); helper::WriteAccessor<Data<SetIndex> > qS2D(quadS2D); helper::WriteAccessor<Data<SetIndex> > qD2S(quadD2S); helper::WriteAccessor<Data<SetIndex> > teS2D(tetrahedronS2D); helper::WriteAccessor<Data<SetIndex> > teD2S(tetrahedronD2S); helper::WriteAccessor<Data<SetIndex> > heS2D(hexahedronS2D); helper::WriteAccessor<Data<SetIndex> > heD2S(hexahedronD2S); const Index neS = (Index)fromModel->getNbEdges(); const Index neD = (Index) toModel->getNbEdges(); const Index ntS = (Index)fromModel->getNbTriangles(); const Index ntD = (Index) toModel->getNbTriangles(); const Index nqS = (Index)fromModel->getNbQuads(); const Index nqD = (Index) toModel->getNbQuads(); const Index nteS = (Index)fromModel->getNbTetrahedra(); const Index nteD = (Index) toModel->getNbTetrahedra(); const Index nheS = (Index)fromModel->getNbHexahedra(); const Index nheD = (Index) toModel->getNbHexahedra(); if (!samePoints.getValue()) { pS2D.resize(npS); pD2S.resize(npD); } if (handleEdges.getValue()) { eS2D.resize(neS); eD2S.resize(neD); } if (handleTriangles.getValue()) { tS2D.resize(ntS); tD2S.resize(ntD); } if (handleQuads.getValue()) { qS2D.resize(nqS); qD2S.resize(nqD); } if (handleTetrahedra.getValue()) { teS2D.resize(nteS); teD2S.resize(nteD); } if (handleHexahedra.getValue()) { heS2D.resize(nheS); heD2S.resize(nheD); } if (!samePoints.getValue()) { if (fromModel->hasPos() && toModel->hasPos()) { std::map<sofa::defaulttype::Vec3d,Index> pmapS; for (Index ps = 0; ps < npS; ++ps) { defaulttype::Vec3d key(fromModel->getPX(ps),fromModel->getPY(ps),fromModel->getPZ(ps)); pmapS[key] = ps; pS2D[ps] = core::topology::Topology::InvalidID; } for (Index pd = 0; pd < npD; ++pd) { defaulttype::Vec3d key(toModel->getPX(pd),toModel->getPY(pd),toModel->getPZ(pd)); std::map<sofa::defaulttype::Vec3d,Index>::const_iterator it = pmapS.find(key); if (it == pmapS.end()) { serr << "Point " << pd << " not found in source topology" << sendl; pD2S[pd] = core::topology::Topology::InvalidID; } else { Index ps = it->second; pD2S[pd] = ps; pS2D[ps] = pd; } } } else if (npS == npD) { for (Index pd = 0; pd < npD; ++pd) { Index ps = pd; pD2S[pd] = ps; pS2D[ps] = pd; } } else { serr << "If topologies do not have the same number of points then they must have associated positions" << sendl; return; } } if (handleEdges.getValue() && neS > 0 && neD > 0) { std::map<core::topology::Topology::Edge,Index> emapS; for (Index es = 0; es < neS; ++es) { core::topology::Topology::Edge key(make_unique(fromModel->getEdge(es))); emapS[key] = es; eS2D[es] = core::topology::Topology::InvalidID; } for (Index ed = 0; ed < neD; ++ed) { core::topology::Topology::Edge key(make_unique(apply_map(toModel->getEdge(ed), pD2S))); std::map<core::topology::Topology::Edge,Index>::const_iterator it = emapS.find(key); if (it == emapS.end()) { serr << "Edge " << ed << " not found in source topology" << sendl; eD2S[ed] = core::topology::Topology::InvalidID; } else { Index es = it->second; eD2S[ed] = es; eS2D[es] = ed; } } } if (handleTriangles.getValue() && ntS > 0 && ntD > 0) { std::map<core::topology::Topology::Triangle,Index> tmapS; for (Index ts = 0; ts < ntS; ++ts) { core::topology::Topology::Triangle key(make_unique(fromModel->getTriangle(ts))); tmapS[key] = ts; tS2D[ts] = core::topology::Topology::InvalidID; } for (Index td = 0; td < ntD; ++td) { core::topology::Topology::Triangle key(make_unique(apply_map(toModel->getTriangle(td), pD2S))); std::map<core::topology::Topology::Triangle,Index>::const_iterator it = tmapS.find(key); if (it == tmapS.end()) { serr << "Triangle " << td << " not found in source topology" << sendl; tD2S[td] = core::topology::Topology::InvalidID; } else { Index ts = it->second; tD2S[td] = ts; tS2D[ts] = td; } } } if (handleQuads.getValue() && nqS > 0 && nqD > 0) { std::map<core::topology::Topology::Quad,Index> qmapS; for (Index qs = 0; qs < nqS; ++qs) { core::topology::Topology::Quad key(make_unique(fromModel->getQuad(qs))); qmapS[key] = qs; qS2D[qs] = core::topology::Topology::InvalidID; } for (Index qd = 0; qd < nqD; ++qd) { core::topology::Topology::Quad key(make_unique(apply_map(toModel->getQuad(qd), pD2S))); std::map<core::topology::Topology::Quad,Index>::const_iterator it = qmapS.find(key); if (it == qmapS.end()) { serr << "Quad " << qd << " not found in source topology" << sendl; qD2S[qd] = core::topology::Topology::InvalidID; } else { Index qs = it->second; qD2S[qd] = qs; qS2D[qs] = qd; } } } if (handleTetrahedra.getValue() && nteS > 0 && nteD > 0) { std::map<core::topology::Topology::Tetrahedron,Index> temapS; for (Index tes = 0; tes < nteS; ++tes) { core::topology::Topology::Tetrahedron key(make_unique(fromModel->getTetrahedron(tes))); temapS[key] = tes; teS2D[tes] = core::topology::Topology::InvalidID; } for (Index ted = 0; ted < nteD; ++ted) { core::topology::Topology::Tetrahedron key(make_unique(apply_map(toModel->getTetrahedron(ted), pD2S))); std::map<core::topology::Topology::Tetrahedron,Index>::const_iterator it = temapS.find(key); if (it == temapS.end()) { serr << "Tetrahedron " << ted << " not found in source topology" << sendl; teD2S[ted] = core::topology::Topology::InvalidID; } else { Index tes = it->second; teD2S[ted] = tes; teS2D[tes] = ted; } } } if (handleHexahedra.getValue() && nheS > 0 && nheD > 0) { std::map<core::topology::Topology::Hexahedron,Index> hemapS; for (Index hes = 0; hes < nheS; ++hes) { core::topology::Topology::Hexahedron key(make_unique(fromModel->getHexahedron(hes))); hemapS[key] = hes; heS2D[hes] = core::topology::Topology::InvalidID; } for (Index hed = 0; hed < nheD; ++hed) { core::topology::Topology::Hexahedron key(make_unique(apply_map(toModel->getHexahedron(hed), pD2S))); std::map<core::topology::Topology::Hexahedron,Index>::const_iterator it = hemapS.find(key); if (it == hemapS.end()) { serr << "Hexahedron " << hed << " not found in source topology" << sendl; heD2S[hed] = core::topology::Topology::InvalidID; } else { Index hes = it->second; heD2S[hed] = hes; heS2D[hes] = hed; } } } if (!samePoints.getValue()) sout << " P: "<<fromModel->getNbPoints() << "->" << toModel->getNbPoints() << "/" << (fromModel->getNbPoints() - toModel->getNbPoints()); if (handleEdges.getValue()) sout << " E: "<<fromModel->getNbEdges() << "->" << toModel->getNbEdges() << "/" << (fromModel->getNbEdges() - toModel->getNbEdges()); if (handleTriangles.getValue()) sout << " T: "<<fromModel->getNbTriangles() << "->" << toModel->getNbTriangles() << "/" << (fromModel->getNbTriangles() - toModel->getNbTriangles()); if (handleQuads.getValue()) sout << " Q: "<<fromModel->getNbQuads() << "->" << toModel->getNbQuads() << "/" << (fromModel->getNbQuads() - toModel->getNbQuads()); if (handleTetrahedra.getValue()) sout << " TE: "<<fromModel->getNbTetrahedra() << "->" << toModel->getNbTetrahedra() << "/" << (fromModel->getNbTetrahedra() - toModel->getNbTetrahedra()); if (handleHexahedra.getValue()) sout << " HE: "<<fromModel->getNbHexahedra() << "->" << toModel->getNbHexahedra() << "/" << (fromModel->getNbHexahedra() - toModel->getNbHexahedra()); sout << sendl; } }
std::unique_ptr<std::istream> ArchiveReader::get_stream(){ auto ret = make_unique((std::istream *)new boost::filesystem::ifstream(path, std::ios::binary)); if (!*ret) throw FileNotFoundException(path); return ret; }
/* * Generate plan for a UNION or UNION ALL node */ static Plan * generate_union_plan(SetOperationStmt *op, PlannerInfo *root, double tuple_fraction, List *refnames_tlist, List **sortClauses) { List *planlist; List *tlist; Plan *plan; /* * If plain UNION, tell children to fetch all tuples. * * Note: in UNION ALL, we pass the top-level tuple_fraction unmodified to * each arm of the UNION ALL. One could make a case for reducing the * tuple fraction for later arms (discounting by the expected size of the * earlier arms' results) but it seems not worth the trouble. The normal * case where tuple_fraction isn't already zero is a LIMIT at top level, * and passing it down as-is is usually enough to get the desired result * of preferring fast-start plans. */ if (!op->all) tuple_fraction = 0.0; /* * If any of my children are identical UNION nodes (same op, all-flag, and * colTypes) then they can be merged into this node so that we generate * only one Append and Sort for the lot. Recurse to find such nodes and * compute their children's plans. */ planlist = list_concat(recurse_union_children(op->larg, root, tuple_fraction, op, refnames_tlist), recurse_union_children(op->rarg, root, tuple_fraction, op, refnames_tlist)); /* * Generate tlist for Append plan node. * * The tlist for an Append plan isn't important as far as the Append is * concerned, but we must make it look real anyway for the benefit of the * next plan level up. */ tlist = generate_append_tlist(op->colTypes, false, planlist, refnames_tlist); /* * Append the child results together. */ plan = (Plan *) make_append(planlist, false, tlist); /* * For UNION ALL, we just need the Append plan. For UNION, need to add * Sort and Unique nodes to produce unique output. */ if (!op->all) { List *sortList; sortList = addAllTargetsToSortList(NULL, NIL, tlist, false); if (sortList) { plan = (Plan *) make_sort_from_sortclauses(root, sortList, plan); plan = (Plan *) make_unique(plan, sortList); } *sortClauses = sortList; } else *sortClauses = NIL; return plan; }