Radix Tree
How do I make an radix tree?
What is a radix tree? How do you make a radix tree? This script and codes were developed by Keyvan Akbary on 29 September 2022, Thursday.
Radix Tree - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Radix Tree</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Radix Tree - Script Codes JS Codes
(function() { var RadixTree, debug, t; RadixTree = (function() { var createNode, find, isLeaf, isPrefix, path, sharedPrefix, split; function RadixTree() { this.root = createNode(""); } createNode = function(label) { return { label: label, children: [] }; }; RadixTree.prototype.insertAll = function(values) { var j, len, results, value; results = []; for (j = 0, len = values.length; j < len; j++) { value = values[j]; results.push(this.insert(value)); } return results; }; RadixTree.prototype.insert = function(key) { var child, common, index, node, p, prefix, ref, ref1, ref2; ref = path(this.root, key, this.root.label), node = ref[0], prefix = ref[1]; ref1 = node.children; for (index in ref1) { child = ref1[index]; common = sharedPrefix(key, prefix + child.label); if (common === "") { continue; } ref2 = split(node, index, child, common), node = ref2[0], prefix = ref2[1]; break; } p = key.substr(prefix.length); if (p) { return node.children.push(createNode(p)); } }; split = function(parent, index, node, prefix) { node.label = node.label.substr(prefix.length); node = parent.children[index] = { label: prefix, children: [node] }; return [node, prefix]; }; sharedPrefix = function(str1, str2) { var c, i; for (i in str1) { c = str1[i]; if (c !== str2[i]) { return str1.substr(0, i); } } return str1; }; path = function(node, key, prefix, parent, index) { var child, p, ref; ref = node.children; for (index in ref) { child = ref[index]; p = prefix + child.label; if (isPrefix(p, key)) { return path(child, key, p, node, index); } } return [node, prefix, parent, index]; }; isPrefix = function(prefix, word) { return word.indexOf(prefix) === 0 && prefix !== ""; }; RadixTree.prototype.contains = function(key) { return find(this.root, key) !== null; }; find = function(root, key) { var node, prefix, ref, result; result = (ref = path(root, key, root.label), node = ref[0], prefix = ref[1], ref); if (prefix === key && isLeaf(node)) { return result; } return null; }; isLeaf = function(node) { return true; return node.children.length === 0; }; RadixTree.prototype.remove = function(key) { var index, node, parent, prefix, ref, result; result = (ref = find(this.root, key), node = ref[0], prefix = ref[1], parent = ref[2], index = ref[3], ref); if (!(result && isLeaf(node))) { return; } return parent.children.splice(index, 1); }; return RadixTree; })(); debug = function(node, ind) { var child, j, len, ref, results; if (ind == null) { ind = ""; } console.log(ind + node.label); ref = node.children; results = []; for (j = 0, len = ref.length; j < len; j++) { child = ref[j]; results.push(debug(child, ind + "--")); } return results; }; t = new RadixTree(); t.insertAll(["foo", "foox", "fooxy", "f", "food", "foom", "foot", "foor"]); debug(t.root); console.log(t.root);
}).call(this);
Developer | Keyvan Akbary |
Username | keyvanakbary |
Uploaded | September 29, 2022 |
Rating | 3 |
Size | 3,161 Kb |
Views | 36,432 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Functional Inheritance | 2,266 Kb |
Trie | 2,756 Kb |
A Pen by Keyvan Akbary | 2,866 Kb |
A Pen by Keyvan Akbary | 3,541 Kb |
A Pen by Keyvan Akbary | 3,684 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Toolbar | Onsen | 5,414 Kb |
Prototype Responsive Homepage | Heyitsolivia | 7,677 Kb |
Free css icon set v2 - one div | Ben_jammin | 0 Kb |
Simple CSS loader. | Cabrera | 2,574 Kb |
Css color for svg | Ademilter | 2,392 Kb |
DevCamp 2014 - Denver Public Library | See8ch | 5,033 Kb |
Drag in vanilla js using dotval math instead of translate | Paulq | 2,662 Kb |
Mega Menu by Joni | Asakasinsky | 3,171 Kb |
Simple blog concept | Drew_mc | 2,666 Kb |
Update CSS Variables with JS | Wesbos | 2,335 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!