00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_FRAME_FILTER_OLD_INTERSECTOR_HXX_
00023 # define WIFI_FRAME_FILTER_OLD_INTERSECTOR_HXX_
00024
00025 # include <iostream>
00026
00027 # include "old_intersector.hh"
00028
00029 namespace wifi
00030 {
00031 namespace frame
00032 {
00033 namespace filter
00034 {
00035
00036 namespace internals
00037 {
00038
00039 template <class I1, class I2, class B1, class B2>
00040 old_intersector_iterator<I1, I2, B1, B2>::
00041 old_intersector_iterator(const iterable_type& i, bool end):
00042 super_type (),
00043 iterable_ (&i),
00044 next1_ (end ? i.last1_ : i.first1_),
00045 next2_ (end ? i.last2_ : i.first2_)
00046 # ifndef WP_DONT_USE_HASH
00047 ,
00048 arrivals1_ (hash_bucket_count),
00049 arrivals2_ (hash_bucket_count)
00050 # endif
00051 {
00052 if (not end)
00053 increment();
00054 }
00055
00056 template <class I1, class I2, class B1, class B2>
00057 bool
00058 old_intersector_iterator<I1, I2, B1, B2>::
00059 equal(const old_intersector_iterator& rhs) const
00060 {
00061 if (not rhs.value())
00062 return not this->value();
00063 return next1_ == rhs.next1_ and next2_ == rhs.next2_;
00064 }
00065
00066 template <class I1, class I2, class B1, class B2>
00067 void
00068 old_intersector_iterator<I1, I2, B1, B2>::increment()
00069 {
00070 const I1& last1 = this->iterable_->last1_;
00071 const I2& last2 = this->iterable_->last2_;
00072
00073 while (next1_ != last1 or next2_ != last2)
00074 if ((next1_ != last1 and check<false>(next1_, arrivals1_,
00075 arrivals2_))
00076 or
00077 (next2_ != last2 and check<true>(next2_, arrivals2_,
00078 arrivals1_)))
00079 return;
00080 arrivals1_.clear();
00081 arrivals2_.clear();
00082 this->value() = boost::none_t ();
00083 }
00084
00085 template <class I1, class I2, class B1, class B2>
00086 template <bool SwapResult, class ArrType, class RHSArrType>
00087 bool
00088 old_intersector_iterator<I1, I2, B1, B2>::
00089 check(I1& frm,
00090 ArrType& frm_arrivals,
00091 RHSArrType& rhs_arrivals)
00092 {
00093 typename RHSArrType::iterator i = rhs_arrivals.find(*frm);
00094
00095 if (i == rhs_arrivals.end())
00096 {
00097 frm_arrivals.insert(*frm);
00098 ++frm;
00099 return false;
00100 }
00101
00102
00103
00104
00105 {
00106 const tool::microseconds& t = i->microseconds();
00107 const size_t lhs = SwapResult;
00108 const size_t rhs = not SwapResult;
00109
00110 if (t < last_arrival_[rhs])
00111 {
00112 std::cerr << "WARNING: Unique frame " << i->frame_id()
00113 << " (" << t << " us) anterior to previous unique "
00114 "frame (" << last_arrival_[rhs] << " us), "
00115 "ignoring.\n"
00116 "WARNING: Probably this frame is not really "
00117 "unique inside its trace." << std::endl;
00118 rhs_arrivals.erase(i);
00119 frm_arrivals.insert(*frm);
00120 ++frm;
00121 return false;
00122 }
00123 last_arrival_[lhs] = frm->microseconds();
00124 last_arrival_[rhs] = t;
00125 }
00126
00127 this->value() =
00128 SwapResult ? value_type (*i, *frm) : value_type (*frm, *i);
00129
00130
00131
00132
00133
00134
00135
00136 if (rhs_arrivals.size() > arrivals_max_size)
00137 cleanup_arrivals(i, rhs_arrivals);
00138
00139 frm_arrivals.clear();
00140 rhs_arrivals.erase(i);
00141 ++frm;
00142 return true;
00143 }
00144
00145 template <class I1, class I2, class B1, class B2>
00146 template <class ArrType>
00147 void
00148 old_intersector_iterator<I1, I2, B1, B2>::
00149 cleanup_arrivals(const typename ArrType::iterator& frame,
00150 ArrType& arrivals)
00151 {
00152 typedef typename ArrType::iterator iterator;
00153
00154 const tool::microseconds m = frame->microseconds();
00155 iterator i = arrivals.begin();
00156 const iterator e = arrivals.end();
00157
00158 while (i != e)
00159 {
00160 if (i->microseconds() < m)
00161 arrivals.erase(i++);
00162 else
00163 ++i;
00164 }
00165 }
00166
00167 }
00168
00169
00170 template <class I1, class I2, class B>
00171 old_intersector<I1, I2, B>::old_intersector(const I1& first1,
00172 const I1& last1,
00173 const I2& first2,
00174 const I2& last2):
00175 first1_ (first1),
00176 last1_ (last1),
00177 first2_ (first2),
00178 last2_ (last2)
00179 {
00180 }
00181
00182 }
00183
00184 }
00185
00186 }
00187
00188 #endif // ! WIFI_FRAME_FILTER_OLD_INTERSECTOR_HXX_