10 2015 档案
摘要:int foo(int n){ if (n < 1){ return 0; } int result = 0; for(int i = 1, factor = 1; i <= n; (factor += (pow(10.0, i))), ++i){ ...
阅读全文
摘要:templateT parallelAccumulate(Iterator first, Iterator last, T init){ size_t const length = std::distance(first, last); if (length == 0){ ...
阅读全文
摘要:templatestruct AccumulateBlock{ T operator()(Iterator first, Iterator last) { return std::accumulate(first, last, T()); }};class Threa...
阅读全文
摘要:while(static_cast(std::cin.get()) != '\n') { //若读取的字符串不是换行符,则将其放回流内。 std::cin.unget(); cin >> input; // ... }
阅读全文
摘要:在知乎上看到一个问题,说自己的函数分明是对的,输入少量数据验证表明也是对的,可是当数据量达到一定规模的时候,程序会变得特别特别的慢,不知为什么。后来发现是因为他把函数声明和数组声明都写在 main 函数里了,声明在 main 函数中的变量都是分配在栈上的,因此当数据过多的时候,就会出现栈溢出的情况。...
阅读全文
摘要:templatestruct Sorter{ struct ChunkToSort { std::list data; std::promise> promise; }; ThreadSafeStack chun...
阅读全文
摘要:templateclass ThreadSafeStack{private: std::stack data; mutable std::mutex m;public: ThreadSafeStack() = default; ThreadSafeStack(con...
阅读全文
摘要:templateclass LockFreeStack{private: struct Node; struct CountedNode { int externalCount = 0; Node* ptr = nullp...
阅读全文
摘要:constexpr size_t maxHazardPointers = 100;struct HazardPointer{ std::atomic id; std::atomic pointer;};array hazardPointers;class Hazard...
阅读全文