Last active
July 30, 2023 12:12
-
-
Save kenwebb/c6d7223397cd63bd46fbf3d201bd3f8d to your computer and use it in GitHub Desktop.
Binary Trees - Root and Constructor Functions
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Sun Jul 30 2023 08:12:33 GMT-0400 (GMT-04:00)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Binary Trees - Root and Constructor Functions | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: c6d7223397cd63bd46fbf3d201bd3f8d | |
Keywords: | |
My Notes | |
-------- | |
23 July 2023 | |
- see notes in my notebook for 23 July 2023 | |
### TODO | |
- construct a binary tree, starting from Root, from an array or set of Binary Strings | |
- it could also be a csv string where the binary strings are separated by commas | |
- ex: ["1011", "1010", "11001010"] or "1011,1010,11001010" | |
- construct a binary tree, starting from Root, from a single Ternary Strings | |
- ex: "1002110122011010" | |
### Example of a set of binary strings that can generate an entire binary tree | |
- see ref[2] | |
21 July 2023 | |
Getting a cup of coffee - with Binary Tree focus | |
Regenerate the CSH structure using just the externals array: | |
[ | |
"100001", | |
"100010", | |
"1000110" | |
] | |
const externalsSet = new Set(["100001", "100010", "1000110"]) | |
console.log(externalsSet[0]) | |
OR | |
const externalsSet = new Set("100001,100010,1000110".split(",")) | |
### References | |
---------- | |
(1) https://translate.google.com/?sl=en&tl=uk&text=Node&op=translate | |
Node -> Вузол | |
It doesn't matter what label or name I use. | |
Вузол works just as well as any other. | |
Maybe better because most people won't be able to pronounce it, | |
so it's just a nondescript symbol. | |
(2) ~/gwtspace/Xholon/Xholon/script/javascript/btreeLabeling.js | |
(3) search: binary tree diagram generator | |
(4) | |
]]></Notes> | |
<_-.XholonClass> | |
<ВузолSystem/> <!-- This is the Root node. --> | |
<Вузол/> <!-- Ukrainian for Node. --> | |
<_101/> <!-- test; can't use just 101, id=5 --> | |
<_110/> <!-- test; id=6 --> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
</xholonClassDetails> | |
<ВузолSystem strs="100001,100010,1000110"> | |
</ВузолSystem> | |
<ВузолSystembehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var root, nodename, externalsSet, beh = { | |
postConfigure: function() { | |
root = this.cnode.parent(); | |
root.println(root.strs); | |
nodename = "Вузол"; | |
externalsSet = new Set(root.strs.split(",")); | |
const xhroot = $wnd.xh.root(); | |
// give roleName to Chameleon and ВузолSystem nodes at top | |
xhroot.role("1"); | |
xhroot.first().role("0"); | |
xhroot.append(this.cnode.remove()); | |
}, | |
act: function() { | |
externalsSet.forEach((str) => { | |
this.genFromBinString(str); | |
}); | |
}, | |
// Generate a subtree from a binary string | |
genFromBinString: function(bstr) { | |
var node = root; | |
// start with index i = 2 to skip Chameleon and ВузолSystem nodes at top | |
for (var i = 2; i < bstr.length; i++) { | |
const bit = bstr[i]; | |
var xmlstr = `<${nodename} roleName="${bit}"/>`; // ` | |
switch (bit) { | |
case "0": // first/left | |
if (!node.first()) { | |
node.append(xmlstr); | |
} | |
node = node.first(); | |
break; | |
case "1": // next/right | |
if (!node.next()) { | |
node.after(xmlstr); | |
} | |
node = node.next(); | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} | |
//# sourceURL=ВузолSystembehavior.js | |
]]></ВузолSystembehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>Вузол</title> | |
<rect id="ВузолSystem/Вузол" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>Вузол ...</title> | |
<rect id="ВузолSystem/Вузол/Вузол" fill="#6AB06A" height="50" width="10" x="80" y="0"/> | |
</g> | |
</g> | |
</svg> | |
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient> | |
</XholonWorkbook> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment