Created
January 1, 2009 06:48
-
-
Save chromakode/42198 to your computer and use it in GitHub Desktop.
Storing IP addresses in a tree using a lightweight defaultdict implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function defaultdict(default) { | |
this._default = default; | |
}; | |
defaultdict.prototype = { | |
get: function(key) { | |
if (!key in this) { this[key] = this._default(key); } | |
return this[key]; | |
} | |
} | |
addrs = defaultdict(function() { | |
return defaultdict(function() { | |
return defaultdict(function() { | |
return []; | |
}); | |
}); | |
}); | |
addrs.get(ip[0]).get(ip[1]).get(ip[2]).push(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment