문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top