Skip to content

Instantly share code, notes, and snippets.

@chromakode
Created January 1, 2009 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chromakode/42198 to your computer and use it in GitHub Desktop.
Save chromakode/42198 to your computer and use it in GitHub Desktop.
Storing IP addresses in a tree using a lightweight defaultdict implementation.
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