Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.