views:

25

answers:

1

Which is the best way to determine whether a Hashtable contains all keys/values of another Hashtable ?

This can also be interpreted as: how to determine whether a Hashtable is a subset of another Hashtable.

+1  A: 

Iterate over all the key/value pairs in the "smaller" hashtable and check whether they exist (with the right values) in the "bigger" hashtable, basically. You could do a Count check to start with to check that the "smaller" table really is smaller (or the same size) to start with, of course.

This will be O(n) where n is the size of the smaller hashtable, assuming reasonable hashes in the larger one and constant time equality checking. You can't do better than that.

Jon Skeet
Thanks, it looks like there is no such built-in functionality so I'll have to write it myself
thelost