Discussion Board

Results 1 to 9 of 9

Hybrid View

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    41

    Unhappy 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

    Blackberry's PIM extension provides this mechanism that I am looking for: http://www.blackberry.com/developers...a.lang.String)

    Many thanks,
    Jim
    Last edited by lordbritishix1982; 2013-08-22 at 18:47.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

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

    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    41

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

    Hi,

    According to the example that you have posted, this also uses the items(..) method:

    Code:
                
    Contact searchItem = contacts.createContact();
    String[] name = new String[contacts.stringArraySize(Contact.NAME)];
    if (contacts.isSupportedArrayElement(
      Contact.NAME, Contact.NAME_FAMILY)) {
      name[Contact.NAME_FAMILY] = searchName.getString();
    }
    searchItem.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name);
     
    //Get enumeration of matching contacts.
    result = contacts.items(searchItem);
    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.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    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.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    41

    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.

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

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

    Perhaps you may need to backup all to RMS on first launch of the app... and then Synchronize further on demand...for better UX.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

Similar Threads

  1. Replies: 0
    Last Post: 2009-10-09, 11:18
  2. Replies: 5
    Last Post: 2009-06-23, 12:43
  3. Replies: 3
    Last Post: 2008-12-10, 09:54
  4. Finding a Contact using a string of words
    By jp4symbian in forum Symbian
    Replies: 4
    Last Post: 2007-02-10, 10:40
  5. Replies: 3
    Last Post: 2006-10-09, 12:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×