Please note that as of October 24, 2014, we will be archiving some of the Nokia Developer discussion boards. The Nokia Asha and Nokia X sections will remain open for continued use. The "Windows Phone/Lumia" and "Other Platforms" sections will become read-only. For your Windows Phone development questions, we invite you to visit the Microsoft Developer Network (MSDN) discussion forums.

If this is your first visit, be sure to check out the FAQ. To start viewing messages, select the forum that you want to visit from the selection below.

O(c) way of finding a contact if contact ID is known using PIM API?

Hi Experts,

Is there a constant-time way to find a contact from the contact list using the PIM api if the contact ID is known? Finding a contact using ContactList::items(..) is slow as it seems that it would go to each contact in the contact list in order to find the correct contact even if I provided a filter with a contact containing the exact contact ID (I tested it on 400 contacts and the search did get painfully slow). I thought about building a search index in memory at startup but I'd like to avoid that as it might not scale well for a phonebook that has thousands of contacts without putting in tons of work

whose search speed is at least O(n) in nature based on my experiments. I tried to actually do better by providing a contact filter object and specifying the contact id as opposed to the contact name as what was done on the example with the hopes that the items(..) method would be smart enough to detect that I am providing an id and that it should be able to search quickly based on that as contact id's are unique and are probably indexed but the performance was the same.

Re: O(c) way of finding a contact if contact ID is known using PIM API?

In one of the projects in past on S40, when I faced this Issue - this was what I did:

I copied all contacts from PIM to a recordstore, kept it updated with all add/deleted from the app and running a background process from time to time.

Created an in memory hashtable of all contact names & their RMS record ID - on every launch of the app - and use this RMS record ID to directly reading the contact record for faster search getting it from Hasttable.

Re: O(c) way of finding a contact if contact ID is known using PIM API?

Yeah, actually, I do this process too. However, I do the synchronization on demand (as contacts appear on the list) as opposed to a one-shot top to bottom scan. What I am basically doing is I am fetching the contact's photo image and display it on a list view, together with the contact name. Only when the contact item needs to be drawn on the screen is the time that I fetch it from the system address book and put it into disk. Having said that, if the contact is not cached to RMS yet, caching it becomes an expensive operation as the items(...) method needs to scan the system address book from top to bottom and so that is why I was looking if there was a way to do an O(c) fetch from the address book in order to support this on-demand fetching of contact items. If there is no such thing as that, then I would probably just need to revise my function in order to provide a better UX.