spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column58


The Doc Dialer, Part 2: A Browser Independent Version

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Updating the Display

At any one point in the trie data structure we need to print to the phone display all matching names so far. Even after a single step down the hierarchy, all names stored in that particular branch should be reported. It means that for each object we visit during the descend, we need to print all records that are linked to element at index 1. We change slightly the updateBoard() function from our previous column:

function updateBoard(trieNode) {
  if (trieNode[1]) {
    addEmployeeToDisplay(trieNode[1]);
  }
  for (var i=2; i<=9; i++) {
    memberNode = trieNode[i];
    if (memberNode) {
      updateBoard(memberNode);
    }
  }
  return;
}

First, we check if the head of the link list exists. If it does, we add all employees stored in the link list:

if (trieNode[1]) {
  addEmployeeToDisplay(trieNode[1]);
}

The function addEmployeeToDisplay() just goes over the link list and checks out the proper entries in the printList array:

function addEmployeeToDisplay(leafNode) {
  while (leafNode) {
    printList[leafNode.empIndex] = true;
    leafNode = leafNode.next;
  }
}

Once we are done checking out the names, we continue to descend along the trie data structure, trying all eight possible pointers for the keys 2 through 9. For each found pointer, we call the updateBoard() function recursively, to collect all names that appear under currentTrie.

Next: How to handle events

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: February 28, 2000
Revised: April 26, 2000

URL: http://www.webreference.com/js/column58/8.html