/
packet.hpp
69 lines (51 loc) · 1.46 KB
/
packet.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef PACKET_HPP
#define PACKET_HPP
#include <boost/functional/hash.hpp>
#include "close.hpp"
class Packet {
public:
int length; /* bits */
int src, id;
double send_time;
Packet( int s_length, int s_src, int s_id, double s_send_time )
: length( s_length ), src( s_src ), id( s_id ), send_time( s_send_time )
{}
bool operator==( const Packet &x ) const
{
return (length == x.length) && (src == x.src) && (id == x.id) && (send_time == x.send_time);
}
friend size_t hash_value( Packet const & p )
{
size_t seed = 0;
boost::hash_combine( seed, p.length );
boost::hash_combine( seed, p.src );
boost::hash_combine( seed, p.id );
boost::hash_combine( seed, p.send_time );
return seed;
}
void quantize_markovize( double now )
{
length = quantize_length( length );
id = -1;
if ( send_time >= 0 ) {
send_time = quantize_time( send_time - now );
}
}
};
static const Packet DummyPacket( -1, -1, -1, -1 );
struct ScheduledPacket {
double delivery_time;
Packet packet;
ScheduledPacket( double s_time, Packet s_pack )
: delivery_time( s_time ), packet( s_pack )
{}
bool operator==( const ScheduledPacket &x ) const { return (delivery_time == x.delivery_time) && (packet == x.packet); }
friend size_t hash_value( ScheduledPacket const & p )
{
size_t seed = 0;
boost::hash_combine( seed, p.delivery_time );
boost::hash_combine( seed, p.packet );
return seed;
}
};
#endif