views:

30

answers:

1

Hello fellow Computer People!

I could do this myself, but was just wondering if there was a more efficient way that I haven't though of:

I have two NSMutableDictionaries. Let us use these as an example:

Dictionary 'Madrid'

 Bob     : 54
 Thomas  : 32
 Frank   : 20


Dictionary 'Barcelona'

 Bob     : 1100
 Thomas  : 32
 Ed      : 55
 Frank   : 20

What I want to get from comparing these two is:

  1. The fact that the value for Bob is different between the two Dictionaries
  2. That Frank has a value in Barcelona, but was not at all in Madrid.

This is for monitoring a sort of time series to see if any activity is happening from one iteration to the next.

Obviously this should be dealt with in Objective-C.

Any opinions on the most efficient way of doing this?

Thanks so much!

+2  A: 

Probably the best way would involve a simple loop through one of the dictionaries, then check to see if you missed any keys in the other dictionary. Since dictionaries are involved it would only be O(N)

cobbal
This didn't blow my mind in terms of concept, but I guess the most obvious answer is sometimes the best. Thanks! :)
Eric Brotto