File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 2626
2727#include < algorithm>
2828
29+ #include " fragmentationCache/timevalUtils.hpp"
30+
2931namespace ipxp {
3032
3133CacheRowSpan::CacheRowSpan (FlowRecord** begin, size_t count) noexcept
@@ -45,6 +47,10 @@ std::optional<size_t> CacheRowSpan::find_by_hash(uint64_t hash) const noexcept
4547
4648void CacheRowSpan::advance_flow_to (size_t from, size_t to) noexcept
4749{
50+ if (from < to) {
51+ std::rotate (m_begin + from, m_begin + from + 1 , m_begin + to + 1 );
52+ return ;
53+ }
4854 std::rotate (m_begin + to, m_begin + from, m_begin + from + 1 );
4955}
5056
@@ -75,6 +81,22 @@ std::optional<size_t> CacheRowSpan::find_if_export_timeout_expired(const timeval
7581 }
7682 return it - m_begin;
7783}
84+
85+ size_t CacheRowSpan::find_victim (const timeval& now) const noexcept
86+ {
87+ const FlowRecord** victim = const_cast <const FlowRecord**>(m_begin) + m_count - 1 ;
88+ auto it = std::find_if (m_begin, m_begin + m_count, [&](const FlowRecord* flow) {
89+ if (!flow->is_in_ctt ) {
90+ victim = &flow;
91+ }
92+ return flow->is_waiting_for_export && now > flow->export_time ;
93+ });
94+ if (it == m_begin + m_count) {
95+ return victim - const_cast <const FlowRecord**>(m_begin);
96+ }
97+ return it - m_begin;
98+ }
99+
78100#endif /* WITH_CTT */
79101
80102} // ipxp
Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ class CacheRowSpan {
7272 * \return Index of the flow record with an expired export timeout if found, std::nullopt otherwise.
7373 */
7474 std::optional<size_t > find_if_export_timeout_expired (const timeval& now) const noexcept ;
75+
76+ size_t find_victim (const timeval& now) const noexcept ;
7577#endif /* WITH_CTT */
7678private:
7779 FlowRecord** m_begin;
You can’t perform that action at this time.
0 commit comments