æåãªæ¬ãªã®ã§ãããªã¨ãè¦ã¦ã人ã¯ããã¦ãç¥ã£ã¦ããã¨æãã®ã§ãããJoel on Softwareã«ãããªè©±ãè¼ã£ã¦ãã(æã¡ç´ãã®ãé¢åãªã®ã§æ¤ç´¢ãããここã§è¦ã¤ãã£ãã®ã§ã³ãã)ã
ã·ã¥ã¬ãã¼ã«ã¯éè·¯ã®çãä¸ã«ç ´ç·ãæããã³ãå¡ãã®ä»äºãå¾ããæåã®æ¥ããã³ãã®ç¼¶ãéè·¯ã«æã¡åºãã¨ãå½¼ã¯300ã¤ã¼ãæãä¸ãããããããã£ãï¼åã¯ä»äºãæ©ããªï¼ãã¨ãã¹ã¯è¨ã£ã¦ã1ã³ãã¤ã«ãããã
次ã®æ¥ãã·ã¥ã¬ãã¼ã«ã¯150ã¤ã¼ãããé²ã¾ãªãã£ãããã¾ããæ¨æ¥ã»ã©ãããªãããããã§ãæ©ãã»ãã ã150ã¤ã¼ããªãç«æ´¾ãªããã ãã¨è¨ã£ã¦ã1ã³ãã¤ã«ãããã
ãã®æ¬¡ã®æ¥ãã·ã¥ã¬ãã¼ã«ã¯30ã¤ã¼ãæãããããã£ã30ï¼ãã¨ãã¹ã¯å«ãã ãããããªããããã¡ã ï¼æåã®æ¥ã«ã¯ãã®10åããã£ããããªããï¼ãã£ããã©ãããã£ã¦ãããã ï¼ã
ãä»æ¹ããã§ããã·ã¥ã¬ãã¼ã«ã¯çããããæ¯æ¥ãã³ãã®ç¼¶ããé ããªã£ã¦ããã§ï¼ã
ãã¡ããããã¯ãã¨ã話ã§ããªã¼ãã¼ãæ¬æ¥O(N)ã«ãªãã¯ããªã®ã«O(N2)ããã£ã¦ãã¾ãè
ããã¢ã«ã´ãªãºã ã«ã¤ãã¦è¿°ã¹ããã®ã ããã§ãæ¬ã§åãä¸ãããã¦ããå
·ä½ä¾ã¯ãstrcat()ã§æååã次ã
ã«ç¹ãã§ããä¾ã確ãã«strcat()ã¯æååãæ¯åé ããã¹ãã£ã³ããã®ã§ããã³ãå±ã·ã¥ã¬ãã¼ã«ã¨åãããã«å¹çãæªãã
ã§ã¯ãcrowbarãDiksamã¯ã©ããªã£ã¦ãããã¨ããã¨â¦
http://kmaebashi.com/programmer/devlang/diksam_src_0_2/S/18.html#234
static DVM_Object * chain_string(DVM_VirtualMachine *dvm, DVM_Object *str1, DVM_Object *str2) { int result_len; DVM_Char *left; DVM_Char *right; DVM_Char *result; DVM_Object *ret; if (str1 == NULL) { left = NULL_STRING; } else { left = str1->u.string.string; } if (str2 == NULL) { right = NULL_STRING; } else { right = str2->u.string.string; } /* åé¡ã¯ããã®ã¸ããã */ result_len = dvm_wcslen(left) + dvm_wcslen(right); result = MEM_malloc(sizeof(DVM_Char) * (result_len + 1)); dvm_wcscpy(result, left); dvm_wcscat(result, right); /* ãã®ã¸ãã¾ã§ */ ret = dvm_create_dvm_string_i(dvm, result); return ret; }
ãã¯ã¯ã
ã ããè¨ã訳ããããã§ã¯ãªããããã®åé¡ã解決ããããã°DVM_Stringæ§é ä½ã«æååé·ãæãããã°ãããã°ã©ã ã®ã»ã¨ãã©ã®ç®æã«ã¯ä¿®æ£ãå ããã«ç´ããã¨ãã§ãã(ã¦ãããã ããããç§ã¯ãã®åé¡ãç¥ã£ã¦ããªããæ¾ç½®ããããã§)ãããããæ¹æ³ã®ã»ãããJoel on Softwareã§ç´¹ä»ããã¦ãã1ãã¤ãç®ã«æååé·ãåãè¾¼ãæ¹å¼(ã ãããExcelã§ã¯ãã¡ãã¡ã§æååé·ã255æåã«å¶éããã¦ããã®ã ãããªâ¦*1 )ãããã£ã¨ãã·ãªã®ã§ã¯ãªããã
ç¾å ´ã®ãããã§ããç§ã®ç®ããè¦ã¦ããã®æ¬ã¯æè¿ããè¦ãããããã«ã¼ãã³ã»ã¼çãªä¸»å¼µã«æ¯ã¹ã¦åæã§ããç¹ãå¤ãã¨æããã ããã©ããã¨ããã©ããé¦ãã²ããã¨ããããã£ããããããã®ãã¿ã¯ããæ°åæ¸ããããã
*1:ãã¡ãããããã¡ã¢ãªãªãã¦è ãã»ã©ããããããã¦65535æåã¾ã§è¨±ããããã¨æã£ã¦ããéå»ã®ãã¼ã¿ãã¡ã¤ã«ã®äºææ§ãèããã°ããã¯ãããªããã¨ããäºæ ããããã¨æããã