1

I have a feeling of missing something obvious. UDP receiver application. It holds a collection of valid UDP sender IPs - only guys with IP on that list will be considered. Since that list must be looked at on every packet and UDPs are so volatile, that operation must be maximum fast. Good choice is Dictionary but it is a key-value structure and what I actually need here is a dictionary-like (hash lookup) key only structure. Is there something like that? Small annoyance rather than a bug but still. I can still use Dictionary

Thanks, M.

Maciej
  • 7,871
  • 1
  • 31
  • 36
  • "Since that list must be looked at on every packet and UDPs are so volatile, that operation must be maximum fast" - is this really true? Wouldn't you already have consumed the UDP packet and thus have it in safe storage by the time you are ready to inspect the IP address of the sender? – bzlm Apr 13 '10 at 14:07
  • Yes, packet you got is safe but if you spend too much time processing it you might loose next packet. There is a TCP buffer of course but it can get filled in if you process slower that packets are coming in. – Maciej Apr 13 '10 at 14:16

2 Answers2

6

Perhaps you want HashSet<T>. It is like a dictionary but only stores the key as the value.

LBushkin
  • 129,300
  • 32
  • 216
  • 265
4

You can use HashSet<T> if on .NET 3.5, or Dictionary<T, object>, storing null in all the values, for .NET 2. This will give you O(1) lookup & retrieval time.

thecoop
  • 45,220
  • 19
  • 132
  • 189