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
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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