std::string MlSlotStats::to_string() { std::stringstream ss; ss << "stats(" << std::endl; ss << " l1_sizes=" << print_collection(l1_sizes); ss << " l2_sizes=" << print_collection(l2_sizes); ss << " last_size=" << last_size << " l1_compact=" << l1_compact << " wasted=" << wasted_perc; ss << std::endl << ")"; return ss.str(); }
void check_8_bucket_compaction() { auto input = generate_rand_uint_input(8*1000000, 799); auto histo = std::map<uint32_t, uint32_t>(); uint32_t can_fit = 0; for(int i=0; i<input.size(); i+=8) { std::array<uint32_t, 8> arr {{input[i+0], input[i+1], input[i+2], input[i+3], input[i+4], input[i+5], input[i+6], input[i+7], }}; algo_srt(arr); int violations = 0; algo_acc(arr, 0, [&](uint32_t prev, uint32_t cur) { if(cur - prev > 255) violations++; return cur; }); if(!violations) ++can_fit; else ++histo[violations]; } LOG("check_8_bucket_compaction can_fit=" << can_fit << " histo=" << print_collection(histo)); }
int main() { std::vector<char> vec = {'H', 'E', 'L', 'L', 'O'}; std::set<char> el = {'H', 'E', 'L', 'L'}; std::vector<char> v = yal::from(vec).where([&](const char& ch) { return el.find(ch) != el.end(); }).toVector(); print_collection(v); std::vector<std::string> vs = {"hello", "cruel", "world"}; vs = yal::from(vs).where([](const std::string& str) { return str != "cruel"; }).toVector(); print_collection(vs); std::vector<int> vint = {1,2,3,4,5,6,7}; vint = yal::from(vint).foreach([](int& i){ ++i; }).where([](int i){ return i < 5;}).foreach([](int& i) { i += 10; }).toVector(); print_collection(vint); { std::list<int> l1 = {1,2,3,4,5,6,7}; vint = yal::from(l1).foreach([](int& i){ ++i; }).where([](int i){ return i < 5;}).foreach([](int& i) { i += 10; }).toVector(); print_collection(vint); } { std::list<int> l1 = {1,2,3,4,5,6,7}; std::list<int> l2 = yal::from(l1).foreach([](int& i){ ++i; }).where([](int i){ return i < 5;}).foreach([](int& i) { i += 10; }).to<std::list<int>>(); print_collection(l2); } { std::list<int> l1 = {1, 2,3,4,5,6,7,8,9}; std::list<int> l2; yal::from(l1).foreach([](int& i){ ++i; }) .where([](int& i){ return i < 5;}) .where([](int& i){ return i > 3;}) .foreach([](int& i){ ++i; }) .fill(l2); print_collection(l2); } return 0; }