-1

I want to create a data structure to efficiently store and retrieve IP packets. I need to use four tuple (IP addresses and port numbers) as a key for the data structure. I have searched and I found map data structure but it seems it cannot search on four tuple as a key, so I decide to serialize IP addresses and port numbers into a string or any other value then use it as a key for map data structure.

How can I use four tuple as a key in map data structure? If its better to change four tuple to single value what conversion is better? (I mean serialize into number or string or any other data type at the point of store and retrieve performance )

Assumption: IP addresses are unsigned int 32 bit values.

kikilinux
  • 61
  • 1
  • 7
  • http://en.cppreference.com/w/cpp/utility/tuple ? – Michael Gopshtein Apr 21 '16 at 07:19
  • `std::tuple` have lexical ordering (assuming its compounds have). so `std::tuple` can be used as key. (but using a dedicated struct with better name would be better IMO). – Jarod42 Apr 21 '16 at 10:47
  • This syntax std::tuple do well, now I want to brief this syntax. It is very long to be as an index for map data structure. How can I do this ? – kikilinux Apr 22 '16 at 10:51

1 Answers1

0

You can use your own type as a key and provide a comparison operator '<' for ordering in the map.

steiner
  • 170
  • 7