vector<double> get_Q(int i) { for(vector<double> rows : tempQ) { if(rows[0] == i) { rows.erase(rows.begin()); return rows; } } vector<double> column; column.push_back(i);//id if(tempQ.size() < 1000) { for(int j = 0; j < train_num; j++) { double temp; temp = kernel(trainData[j], trainData[i]); column.push_back(temp); } tempQ.push_back(column); } else { tempQ.erase(tempQ.begin()); for(int j = 0; j < train_num; j++) { double temp; temp = kernel(trainData[j], trainData[i]); column.push_back(temp); } tempQ.push_back(column); } column.erase(column.begin()); return column; }
void run () { beast::manual_clock <std::chrono::seconds> clock; clock.set (0); typedef std::string Key; typedef KeyCache <Key> Cache; // Insert an item, retrieve it, and age it so it gets purged. { Cache c ("test", clock, 1, 2); expect (c.size () == 0); expect (c.insert ("one")); expect (! c.insert ("one")); expect (c.size () == 1); expect (c.exists ("one")); expect (c.touch_if_exists ("one")); ++clock; c.sweep (); expect (c.size () == 1); expect (c.exists ("one")); ++clock; c.sweep (); expect (c.size () == 0); expect (! c.exists ("one")); expect (! c.touch_if_exists ("one")); } // Insert two items, have one expire { Cache c ("test", clock, 2, 2); expect (c.insert ("one")); expect (c.size () == 1); expect (c.insert ("two")); expect (c.size () == 2); ++clock; c.sweep (); expect (c.size () == 2); expect (c.touch_if_exists ("two")); ++clock; c.sweep (); expect (c.size () == 1); expect (c.exists ("two")); } // Insert three items (1 over limit), sweep { Cache c ("test", clock, 2, 3); expect (c.insert ("one")); ++clock; expect (c.insert ("two")); ++clock; expect (c.insert ("three")); ++clock; expect (c.size () == 3); c.sweep (); expect (c.size () < 3); } }
inline size_t CertificateCacheTtl::getSize() { return m_cache.size(); }
void run () { TestStopwatch clock; clock.set (0); using Key = std::string; using Cache = KeyCache <Key>; // Insert an item, retrieve it, and age it so it gets purged. { Cache c ("test", clock, 1, 2); BEAST_EXPECT(c.size () == 0); BEAST_EXPECT(c.insert ("one")); BEAST_EXPECT(! c.insert ("one")); BEAST_EXPECT(c.size () == 1); BEAST_EXPECT(c.exists ("one")); BEAST_EXPECT(c.touch_if_exists ("one")); ++clock; c.sweep (); BEAST_EXPECT(c.size () == 1); BEAST_EXPECT(c.exists ("one")); ++clock; c.sweep (); BEAST_EXPECT(c.size () == 0); BEAST_EXPECT(! c.exists ("one")); BEAST_EXPECT(! c.touch_if_exists ("one")); } // Insert two items, have one expire { Cache c ("test", clock, 2, 2); BEAST_EXPECT(c.insert ("one")); BEAST_EXPECT(c.size () == 1); BEAST_EXPECT(c.insert ("two")); BEAST_EXPECT(c.size () == 2); ++clock; c.sweep (); BEAST_EXPECT(c.size () == 2); BEAST_EXPECT(c.touch_if_exists ("two")); ++clock; c.sweep (); BEAST_EXPECT(c.size () == 1); BEAST_EXPECT(c.exists ("two")); } // Insert three items (1 over limit), sweep { Cache c ("test", clock, 2, 3); BEAST_EXPECT(c.insert ("one")); ++clock; BEAST_EXPECT(c.insert ("two")); ++clock; BEAST_EXPECT(c.insert ("three")); ++clock; BEAST_EXPECT(c.size () == 3); c.sweep (); BEAST_EXPECT(c.size () < 3); } }