I have many different NSArray‘s stored in .dat files, in the Documents folder of my iPhone application, like so:
john.dat
mary.dat
bob.dat etc...
The number of .dat files is unknown and it will increase or decrease according to a number of factors related to the user’s manipulation of the app.
What are the contents of these NSArray's stored in the.dat files? They contain NSString's. It is important to say that the countfor each NSArray my vary, like so:
john.dat Contains this array of strings:
"Mon, 11 Jun 2012 04:52:06 GMT",
"Tue, 12 Jun 2012 04:51:59 GMT",
"Wed, 13 Jun 2012 04:52:30 GMT",
"Thu, 07 Jun 2012 04:52:00 GMT",
mary.dat Contains this array of strings:
"Mon, 11 Jun 2012 04:52:06 GMT",
"Tue, 12 Jun 2012 04:51:59 GMT",
bob.dat Contains this array of strings:
"Mon, 11 Jun 2012 04:52:06 GMT",
"Tue, 12 Jun 2012 04:51:59 GMT",
"Wed, 13 Jun 2012 04:52:30 GMT",
"Thu, 07 Jun 2012 04:52:00 GMT",
"Fri, 08 Jun 2012 04:51:59 GMT",
"Sun, 10 Jun 2012 04:50:55 GMT"
etc..
I have to periodically verify if each NSString of these NSArray's has been modified, to notify the user of certain events. After doing a XML parsing from the Internet I’m already able to have in memory the new NSArray's corresponding to its respective .dat file previously stored in the Documents folder.
Since I have many .dat files, my question is:
How do I compare EFFICIENTLY AND AT ONCE the new NSArray's (NSArray *john, *mary, *bob, etc…) that I have in memory (as a result of this XML parsing), with the old ones stored in its corresponding john.dat, mary.dat, bob.dat, etc… files in the Documents folder and notify the user if any of the NSString's ("Mon, 11 Jun 2012 04:52:06 GMT","Tue, 12 Jun 2012 04:51:59 GMT", etc…) has been modified?
Thanks for your help!
If you’re happy to change the format of your .dat file you could compute a hash of each array’s contents and store that at the beginning of the file. When you get new data you can compute its hash and compare that with the hash stored in your file.
Your choice of hashing function will determine the computational efficiency, but the I/O would be minimized.