The AATT Programming Language
å
æ¥ãkinabaããã¨æèªåã観ã«è¡ã£ãã¨ãã«è©±ãã¦ãããã¿è¨èªãå®è£
ãã¦ã¿ã¾ããã
å
ãã¿ï¼ãkinaba ããã Cryolite ãæ´è³ãã¦ãã¿ã¼ã³ãããå¨ã«ä»ç«ã¦ä¸ãããªã¹ãã
http://togetter.com/li/6990
確ãã«ãã¿ã¼ã³ããããããã°æ¨ã®æä½ãç°¡æ½ã«æ¸ããã®ã§ããã
ã³ã¡ã³ãã«AAã§æ¨ãæ¸ãã¦ãããªãã¨ä½ããã£ã¦ããã®ãããåãããªãã®ã§ã
AAããã®ã¾ã¾ããã°ã©ã ã«ãªãã°ãããã§ã¯ãªããã¨ããçºæ³ã§ãã
ã¨ããããããASCII Art Tree Transformããç¥ãã¦AATTã¨å¼ã¶ãã¨ã«ãã¾ãã
ãTreeãã¨è¨ã£ã¦ãä»ã®ã¨ããã赤é»æ¨ãå°ç¨ã§ãã
AATTã®ã½ã¼ã¹ã³ã¼ãã¯æ¬¡ã®ããã«ãªãã¾ãã
G P / \ / \ p U -> n g / \ / \ n 3 3 U ^
大æåãé»ãã¼ããå°æåã赤ãã¼ããæ°åã¯ä»»æã®ãã¼ã(空ãã¼ãå«ã)ã§ãããããã®ãã¼ãã¯ã/ããã\ãã§ç¹ãã¾ãã
å¤å½¢åã¨å¤å½¢å¾ã®æ¨ã¯ã->ãã®ããåã§åºåããã¾ãã
ã赤é»æ¨ãã®æ¿å
¥æä½ã§ã¯è¿½å ãããã¼ãããæ¢ç´¢ããå¿
è¦ããããããã^ãã§æ¢ç´¢éå§ãã¼ããæå®ã§ããããã«ãã¦ãã¾ãã
ã^ãããªãå ´åã¯(é¨åæ¨ã®)ã«ã¼ãããæ¢ç´¢ãã¾ãã
ãã®ã½ã¼ã¹ã³ã¼ããã³ã³ãã¤ã«ããã¨ã以ä¸ã®ãããªC++ã³ã¼ããåºåããã¾ãã
inline tree_node* balance(tree_node* root, tree_node* node) { // G P // / \ / \ // U p -> g n // / \ / \ // 3 n U 3 // ^ { tree_node* pN = node; if ((pN != 0) && (pN->color == RED)) { tree_node* pP = pN->parent; if ((pP != 0) && (pP->right == pN) && (pP->color == RED)) { tree_node* p3 = pP->left; tree_node* pG = pP->parent; if ((pG != 0) && (pG->right == pP) && (pG->color == BLACK)) { tree_node* pU = pG->left; if ((pU != 0) && (pU->color == BLACK)) { tree_node* parent = pG->parent; pP->parent = parent; pP->color = BLACK; pP->left = pG; pG->color = RED; pG->parent = pP; pG->right = p3; if (p3 != 0) { p3->parent = pG; } if (parent != 0) { if (parent->left == pG) parent->left = pP; else parent->right = pP; } else root = pP; return root; } } } } } return root; }
é¢æ°åã¯ã½ã¼ã¹ãã¡ã¤ã«åããèªåçæããã¾ãã
å
ã®AAã¯ã³ã¡ã³ãã¨ãã¦æ®ãã¾ãã
å¼æ°rootã¯æ¨ã®ã«ã¼ããnodeã¯æ¢ç´¢éå§ãã¼ãã§ãæ»ãå¤ã¯å¤å½¢å¾ã®ã«ã¼ãã«ãªãã¾ãã空è¡åºåãã§ãã¿ã¼ã³ãæ¸ãã¦ããã°ãä¸ããé ã«ãããã³ã°ãè¡ãã³ã¼ããåºåããã¾ãã
ãtree_nodeãã¨ããBLACKãã¨ã決ãæã¡ãªã®ã¯ææãã§ãã
å帰ãæ¸ãã¾ãã
G g / \ /^\ p u -> P U / / n n ^
å¤å½¢å¾ã®æ¨ã®ãã¼ãã«ã^ãã§ãã¼ã¯ããã¨ããã®ä½ç½®ãnodeã¨ãã¦åã³å¤æãè¡ãã¾ãã
ã¾ããã«ã¼ããã©ããã®å¤å®æ©è½ãããã¾ãã
* n -> N ^
ãã¼ãã®ä¸ã«ã*ããä»ããã¨ããã®ãã¼ãã(é¨åæ¨ã§ãªãå ¨ä½ã®)ã«ã¼ãã®å ´åã®ã¿ãããããããã«ãªãã¾ãã
ã¡ãªã¿ã«ã
- ã¨ãã£ã¿ã®è¨å®ã§å¤§æåã®èæ¯ãé»ãå°æåã®èæ¯ã赤ã«ãã
- ãã£ã©ã¯ã¿ã»ãããã欧æããªã©ã«ãã
ã¨ã½ã¼ã¹ãèªã¿ããããªãã¾ãã
ä¸å¿ãã½ã¼ã¹ã³ã¼ããç½®ãã¦ããã¾ãã
http://www12.ocn.ne.jp/~dante98/zip/aattc.zip (CR/LFæ¹è¡)
http://www12.ocn.ne.jp/~dante98/zip/aattc.tar.bz2 (LFæ¹è¡)
(23:30 追è¨)
#以éè¡æ«ã¾ã§ã¯ã³ã¡ã³ãã§ã
ããã¯ã¹ã©ãã·ã¥ãåºãªãã®ã§ã·ã³ã¿ãã¯ã¹ãã¤ã©ã¤ããããã®ããã¡ãã«è²¼ãã¾ãã
http://www12.ocn.ne.jp/~dante98/balance.aatt.html