Jeethu Rao avatar Jeethu Rao committed 0ca6aab

Replaced all string indexing with string.charAt, removed the dependancy on YUI.

Comments (0)

Files changed (1)

-/*global YAHOO */
 (function() {
-    YAHOO.namespace('tagz.trie');
-
     function Trie() {
         this.root = [null, {}];
     }
-    YAHOO.tagz.trie.Trie = Trie;
 
     Trie.prototype.add = function( key, value ) {
-        var curr_node = this.root;
+        var node, ch, curr_node = this.root;
         for(var i=0,k_len=key.length;i<k_len;i++) {
-            var ch = key[i];
-            var node = curr_node[1];
+            ch = key.charAt(i);
+            node = curr_node[1];
             if(ch in node) {
                 curr_node = node[ch];
             } else {
     };
 
     Trie.prototype.find = function( key ) {
-        var curr_node = this.root;
+        var ch, curr_node = this.root;
         for(var i=0,k_len=key.length; i<k_len; i++) {
-            var ch = key[i];
+            ch = key.charAt(i);
             if(ch in curr_node[1]) {
                 curr_node = curr_node[1][ch];
             } else {
     };
 
     Trie.prototype.find_prefix = function( key ) {
-        var curr_node = this.root;
+        var ch, curr_node = this.root;
         var remainder = key;
         for(var i=0,k_len=key.length;i<k_len;i++) {
-            var ch = key[i];
+            ch = key.charAt(i);
             if(ch in curr_node[1]) {
                 curr_node = curr_node[1][ch];
             } else {
     };
 
     function _find_prefix_match( trie, key ) {
-        var curr_node = trie.root;
+        var ch, curr_node = trie.root;
         var remainder = key;
         for(var i=0,k_len=key.length;i<k_len; i++) {
-            var ch = key[i];
+            ch = key.charAt(i);
             if(ch in curr_node[1]) {
                 curr_node = curr_node[1][ch];
             } else {
         if(l[1].length>0) {
             return [];
         }
-        var stack = [l[0]];
-        var ret = [];
+        var d, stack = [l[0]], ret = [];
         while(stack.length>0) {
-            var d = stack.pop();
+            d = stack.pop();
             if(d[0]) {
                 ret.unshift(d[0]);
             }
         }
         return ret;
     };
+    window['Trie'] = Trie;
 }());
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.