Cat Pig
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# prefix-search contributed by <`f74034067`>, <`catpig1630`> :::warning TODO: 嘗試導入 [Bloom Filter](https://en.wikipedia.org/wiki/Bloom_filter),實作快速字串搜尋機制。如果字串根本不存在於資料庫中,我們根本不需走訪 ternary search tree * [Bloom Filters by Example](https://llimllib.github.io/bloomfilter-tutorial/) * [A cache efficient thread safe bloom filter](https://github.com/thomas-dean/bloomfilter) * [Approximate matching using Hierarchical Bloom Filter Trees](https://github.com/ishnid/mrsh-hbft) * [Golomb-coded map (GCM)](https://github.com/0xcb/Golomb-coded-map) :notes: jserv ::: [功能描述](https://hackmd.io/s/ByFWoR_tz) ## Trie (字典樹) & Ternary search tree (TST) [rex662624](https://hackmd.io/s/SJbHD5sYM#) 的解說十分詳盡完整 ### Trie trie 與 binary search tree 不同在於,不是把整個字串包在同一個node 中 ,而是根據 node 的位置決定代表的字串為何。也就是一個看結果( 最終 node ),一個看過程(經過的node)。因此利用 trie,可以快速的找出有相同 prefix 的字串。以下將舉例示範 trie 如何儲存 data。 :::info 一開始,trie tree 起始於一個空的root - ◎ ::: ``` ◎ ``` :::info 若今插入一個字串 and 1. 首先將 and 拆解成 a, n ,d 2. 因為 a 第一次出現,所以在 root 建立一個新children node ,value= a 3. 接下來從node "a" 出發,剩下 n,d 4. n 也是第一次出現,因此在 a 建立一個新 children node ,value= n 5. d 比照 4 作法。 ::: ``` ◎ / a / n / d ``` :::info 若此時插入一個字串 ant 1. ant 拆解成 a , n , t,從 root 出發 2. node "a" 已經存在,因此不再在 root 創造新的 children 3. 再來看 n , node "a" 往 children 看發現 node "n"已存在,因此也不創造 children 4. 再來看 t 發現 n 的 children 中沒有此 node,因此創造新 children "t" ::: ``` ◎ / a / n / \ d t ``` :::info 如此再插入 bear ,bea 就會產生像這樣子的 tree 1. 有 value 的就是有 string 存在的 node 2. 因此 search "ant" 會 return 值 0 ,表示 trie 內有此string 3. 而 search "be" 會 retrun NULL , 因為並沒有值在 node "e"。 ::: ``` ◎ / \ a b / \ n e / \ \ d t a (3) (0) (1) \ r (2) ``` 以上,我們注意到 Trie 中,若有儲存的字串有許多相同的 prefix ,那麼 trie 可以節省大量儲存空間,因為 Trie 中每個字串都是經由 character by character 方法進行儲存,所以具有相同 prefix 的部份都會有共同的 node 。 相對的,若是資料非常大量,而且幾乎沒有相同的 prefix 將會非常浪費儲存空間。因為 trie 在 memory 的 儲存方式其實是像下圖這樣,每個 node 建立時,都必須同時創造26個值為NULL的子節點。(下圖的 universal set ={a,b,c,d,e}5所以只創造了 5 個) ![](https://i.imgur.com/S7VQnPf.png) ### Ternary search tree 因此用此 Ternary search tree ,就能解決上面的問題。這種樹的每個節點最多只會有3個 children,分別代表小於,等於,大於。以下範例解釋 Ternary search tree 。 :::info 插入一個字串 and 1. 與 trie 概念相同,但是在root 是直接擺 "a" 而不需要一個null 。 ::: ``` a | n | d ``` :::info 接著插入單字ant 1. 我們先比對 a ,發現 a 和 root 的字母相同(a=a) 2. 因此 pointer 往下,來到 n 節點,發現 n 節點和 ant 的第二個字母相同(n=n) 3. 因此 pointer 再往下,來到 d 節點,發現 d 節點和 ant 的第三個字母不同,而且 **t>d** 4. 因此 d 節點的 right child 成為 t ,成功將 ant 放入原本的 TST 中 ::: ``` a | n- | | d t ``` :::info 接著插入單字age 1. 我們先比對 a ,發現 a 和 root 的字母相同(a=a) 2. 因此 pointer 往下,來到 n 節點,發現 n 節點和 age 的第二個字母不同,而且 **g<n** 3. 因此 n 節點的 left child 成為 g ,成功將 age 放入原本的 TST 中 ::: ``` a | -n | | g d- | | e t ``` [ Ternary Search Tree ](https://www.cs.usfca.edu/~galles/visualization/TST.html) 此網址提供了用動畫表示的方式,可以清楚看到如何加入與刪除 string 的流程。 從 Ternary Search Tree 中,我們可以發現幾種特性。 1. 解決 trie tree 中大量佔用記憶體的情況,因為 TST 中,每個 node 最多只會有3個 child 2. 但尋找時間在有些 case 中 , 會比 trie 慢 ,而這是因為 TST 插入的順序會影響比較的次數。例如以下兩張圖,上圖是用 `aa->ac->ae->af->ag->ah` 的次序插入,而下圖是 `af->ae->ac->aa->ag->ah`的順序。試想今天要尋找 ah ,則上圖要比較6次,下圖則是只要比較3次。而若是建立 trie ,只需要2次。 ![](https://i.imgur.com/2ZZy7ym.png) ![](https://i.imgur.com/fPkOILf.png) ## 程式碼修正 ### 修改 Makefile,`$ make bench` 進行效能評比 參考 [raygoah](https://hackmd.io/dwDOR7H2Q8qyxGxSOsc-vA?view) 的作法 * `Makefile` ```clike= TEST_INPUT = f Taiwan bench: $(TESTS) echo 3 | sudo tee /proc/sys/vm/drop_caches perf stat --repeat 100 \ -e cache-misses,cache-references,instructions,cycles \ ./test_cpy --bench $(TEST_INPUT) echo 3 | sudo tee /proc/sys/vm/drop_caches perf stat --repeat 100 \ -e cache-misses,cache-references,instructions,cycles \ ./test_ref --bench $(TEST_INPUT) ``` * `$ make bench` 執行結果 ``` Performance counter stats for './test_cpy --bench f Taiwan' (100 runs): 488,395 cache-misses # 29.139 % of all cache refs ( +- 1.26% ) 1,676,097 cache-references ( +- 0.47% ) 449,033,851 instructions # 1.08 insn per cycle ( +- 0.01% ) 417,234,828 cycles ( +- 0.48% ) 0.148296779 seconds time elapsed ( +- 0.56% ) ``` ### 修改 FIXME * 首先修改 `test_ref.c` 標注 `FIXME` 的地方 ```clike= - res = tst_ins_del(&root, &p, INS, CPY); + res = tst_ins_del(&root, &p, INS, REF); ``` * 執行 `test_ref.c`,會發現搜尋結果有誤 ``` Commands: a add word to the tree f find word in tree s search words matching prefix d delete word from the tree q quit, freeing all data choice: s find words matching prefix (at least 1 char): Tain Tain - searched prefix in 0.000010 sec suggest[0] : Tain suggest[1] : Tain suggest[2] : Tain suggest[3] : Tain suggest[4] : Tain suggest[5] : Tain suggest[6] : Tain suggest[7] : Tain suggest[8] : Tain suggest[9] : Tain suggest[10] : Tain suggest[11] : Tain ``` * `tst.c` 中與 CPY 有關的程式碼 ```clike= if (*p++ == 0) { if (cpy) { /* allocate storage for 's' */ const char *eqdata = strdup(*s); if (!eqdata) return NULL; curr->eqkid = (tst_node *) eqdata; return (void *) eqdata; } else { /* save pointer to 's' (allocated elsewhere) */ curr->eqkid = (tst_node *) *s; return (void *) *s; } } ``` CPY 的版本由於 strdup(*s) 會先用 malloc() 配置與參數 s 字串相同大小的空間,然後將 s 字串的內容複製到該空間,所以每次回傳的地址都不相同。 REF 的版本中,每次傳入 tst_ins_del() 的 *p 都相同,curr -> eqkid 當然也就都指向同一個位址。 ### 修正 REF 版本 searching 功能 參考 [tina0405](https://hackmd.io/s/SkEFpwh2-#) 的作法 * 建立一個叫 word_arr 二維陣列 ,每次讀入一個新的城市就依序存入 word_arr[ ][ WRDMAX ] 中,如此一來每次傳入 tst_ins_del() 的 *p 就不會一樣了。 * 若是在 main() 裡面建立一個 word_arr[ 259112 ][ WRDMAX ] 會造成程序 core dumped ,所以我選擇宣告成全域變數。 ```clike= char word_arr[259112][WRDMAX]; int main() { ... while ((rtn = fscanf(fp, "%s", word_arr[idx])) != EOF) { char *p = word_arr[idx]; /* FIXME: insert reference to each string */ if (!tst_ins_del(&root, &p, INS, REF)) { fprintf(stderr, "error: memory exhausted, tst_insert.\n"); fclose(fp); return 1; } idx++; } ... } ``` * 執行 delete 的結果發現仍然有誤 ``` ternary_tree, loaded 259112 words in 0.166198 sec Commands: a add word to the tree f find word in tree s search words matching prefix d delete word from the tree q quit, freeing all data choice: d enter word to del: China deleting China China (refcnt: 1099) not removed. delete failed. ``` * 執行 quit 的結果發現仍然有誤 ``` ternary_tree, loaded 259112 words in 0.153593 sec Commands: a add word to the tree f find word in tree s search words matching prefix d delete word from the tree q quit, freeing all data choice: q *** Error in `./test_ref': free(): invalid pointer: 0x0000000000fb8000 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f2bbcc487e5] /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f2bbcc5137a] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f2bbcc5553c] ./test_ref[0x4021e4] ./test_ref[0x4021b9] ./test_ref[0x4021b9] ./test_ref[0x4021b9] ./test_ref[0x4021b9] ./test_ref[0x4021b9] ./test_ref[0x4021b9] ./test_ref[0x40219e] ./test_ref[0x40219e] ./test_ref[0x40219e] ./test_ref[0x4021b9] ./test_ref[0x40219e] ./test_ref[0x40219e] ./test_ref[0x4021b9] ./test_ref[0x40219e] ./test_ref[0x40219e] ./test_ref[0x40219e] ./test_ref[0x40219e] ./test_ref[0x40219e] ./test_ref[0x401348] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f2bbcbf1830] ./test_ref[0x400979] ======= Memory map: ======== 00400000-00403000 r-xp 00000000 08:08 261623 /home/suchihhan/prefix-search/test_ref 00602000-00603000 r--p 00002000 08:08 261623 /home/suchihhan/prefix-search/test_ref 00603000-00604000 rw-p 00003000 08:08 261623 /home/suchihhan/prefix-search/test_ref 00604000-04546000 rw-p 00000000 00:00 0 0511e000-06831000 rw-p 00000000 00:00 0 [heap] 7f2bb8000000-7f2bb8021000 rw-p 00000000 00:00 0 7f2bb8021000-7f2bbc000000 ---p 00000000 00:00 0 7f2bbc9bb000-7f2bbc9d1000 r-xp 00000000 08:07 136362 /lib/x86_64-linux-gnu/libgcc_s.so.1 7f2bbc9d1000-7f2bbcbd0000 ---p 00016000 08:07 136362 /lib/x86_64-linux-gnu/libgcc_s.so.1 7f2bbcbd0000-7f2bbcbd1000 rw-p 00015000 08:07 136362 /lib/x86_64-linux-gnu/libgcc_s.so.1 7f2bbcbd1000-7f2bbcd91000 r-xp 00000000 08:07 135915 /lib/x86_64-linux-gnu/libc-2.23.so 7f2bbcd91000-7f2bbcf91000 ---p 001c0000 08:07 135915 /lib/x86_64-linux-gnu/libc-2.23.so 7f2bbcf91000-7f2bbcf95000 r--p 001c0000 08:07 135915 /lib/x86_64-linux-gnu/libc-2.23.so 7f2bbcf95000-7f2bbcf97000 rw-p 001c4000 08:07 135915 /lib/x86_64-linux-gnu/libc-2.23.so 7f2bbcf97000-7f2bbcf9b000 rw-p 00000000 00:00 0 7f2bbcf9b000-7f2bbcfc1000 r-xp 00000000 08:07 135871 /lib/x86_64-linux-gnu/ld-2.23.so 7f2bbd1a3000-7f2bbd1a6000 rw-p 00000000 00:00 0 7f2bbd1bf000-7f2bbd1c0000 rw-p 00000000 00:00 0 7f2bbd1c0000-7f2bbd1c1000 r--p 00025000 08:07 135871 /lib/x86_64-linux-gnu/ld-2.23.so 7f2bbd1c1000-7f2bbd1c2000 rw-p 00026000 08:07 135871 /lib/x86_64-linux-gnu/ld-2.23.so 7f2bbd1c2000-7f2bbd1c3000 rw-p 00000000 00:00 0 7ffc4547e000-7ffc4549f000 rw-p 00000000 00:00 0 [stack] 7ffc455c9000-7ffc455cc000 r--p 00000000 00:00 0 [vvar] 7ffc455cc000-7ffc455ce000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] 已經終止 (core dumped) ``` ### 修正 REF 版本 delete 功能 * 修改 `tst.c` 中 tst_del_word() 的最後一個參數,將原本寫死的 1 改為 cpy ```clike= -tst_del_word(root, curr, &stk, 1); +tst_del_word(root, curr, &stk, cpy); ``` ### 修正 REF 版本 quit 功能 * quit 功能會出錯則是因為 `test_ref.c` 中 tst_free_all(root) 會 free 到 REF 版本中宣告的二維陣列的位址,若改成 tst_free(root) 就不會出錯了 ```clike= -tst_free_all(root); +tst_free(root) ``` ## 比較 REF 與 CPY 的效能 先來測試一下兩種版本的效能,以執行 `s Tai` 100次為例 * $ make bench ``` Performance counter stats for './test_cpy --bench s Tai' (100 runs): 405,229 cache-misses # 25.640 % of all cache refs ( +- 1.07% ) 1,580,480 cache-references ( +- 0.32% ) 449,637,901 instructions # 1.17 insn per cycle ( +- 0.00% ) 385,322,883 cycles ( +- 0.22% ) 0.132403198 seconds time elapsed ( +- 0.32% ) ``` ``` Performance counter stats for './test_ref --bench s Tai' (100 runs): 715,608 cache-misses # 35.563 % of all cache refs ( +- 1.47% ) 2,012,240 cache-references ( +- 0.42% ) 469,495,339 instructions # 1.00 insn per cycle ( +- 0.00% ) 470,839,058 cycles ( +- 0.49% ) 0.162691614 seconds time elapsed ( +- 0.62% ) ``` * CPY 優於 REF 在 REF 版本,使用陣列儲存 ternary search tree 中的某些節點,cache 的 spatial locality 特性反而有機會在搜尋中將許多尚不需用到的 data 搬到 cache 中,造成 cache-misses 較高,並且由於陣列宣告成固定大小,還會產生 memory fragmentation 的問題。 ## 實做 memory pool 參考 [ChiuYiTang](https://hackmd.io/s/ByeocUhnZ#) 的作法 * 只紀錄兩個指標,一個 pPool 指向整個 memory pool 的開頭,一個 pTop 則指向下一次要分配出的記憶體位址。 ```clike= int main() { ... char *pPool = (char *) malloc(poolSize * sizeof(char)); char *pTop = pPool; while ((rtn = fscanf(fp, "%s", pTop)) != EOF) { t1 = tvgetf(); char *p = pTop; /* FIXME: insert reference to each string */ if (!tst_ins_del(&root, &p, INS, REF)) { fprintf(stderr, "error: memory exhausted, tst_insert.\n"); fclose(fp); return 1; } idx++; pTop += (strlen(pTop) + 1); } ... case 'a': printf("enter word to add: "); if (bench_flag == 0) { if (!fgets(pTop, sizeof word, stdin)) { fprintf(stderr, "error: insufficient input.\n"); break; } rmcrlf(pTop); } else { strcpy(pTop, argv[3]); } p = pTop; t1 = tvgetf(); /* FIXME: insert reference to each string */ res = tst_ins_del(&root, &p, INS, REF); t2 = tvgetf(); if (res) { idx++; pTop += (strlen(pTop) + 1); printf(" %s - inserted in %.6f sec. (%d words in tree)\n",(char *) res, t2 - t1, idx); } else printf(" %s - already exists in list.\n", (char *) res); } ... case 'q': tst_free(root); free(pPool); return 0; ... ``` * $ make bench ``` Performance counter stats for './test_cpy --bench s Tai' (100 runs): 444,998 cache-misses # 27.656 % of all cache refs ( +- 1.78% ) 1,609,058 cache-references ( +- 0.60% ) 480,816,403 instructions # 1.09 insn per cycle ( +- 0.02% ) 442,471,864 cycles ( +- 0.50% ) 0.152579698 seconds time elapsed ( +- 0.61% ) ``` ``` Performance counter stats for './test_ref --bench s Tai' (100 runs): 404,904 cache-misses # 25.170 % of all cache refs ( +- 1.48% ) 1,608,690 cache-references ( +- 0.46% ) 464,059,245 instructions # 1.10 insn per cycle ( +- 0.00% ) 422,942,275 cycles ( +- 0.47% ) 0.145401520 seconds time elapsed ( +- 0.56% ) ``` 參考 [rex662624](https://hackmd.io/s/SJbHD5sYM#) 將 insert 的時間抓出來比較 * $ make plot ![](https://i.imgur.com/Qw5JCoh.png) memory pool 的好處在於省去了頻繁的 malloc() 與 free(),可以看到在建立 ternary search tree 的效能上 REF 略優於 CPY。 ## Prefix 缺陷 ### 搜尋城市名問題 * 城市中間有空白會被分開 * 逗號會被加到城市名稱裡面 可以利用 fscanf 裡類似正規表達式的特殊寫法直接找出字串裡的程式名稱和國家名稱 把原本的%s 改成 %256[^,], %256[^\n]\n 其中[^\n]代表的是不包含 \n 字元,詳細說明可以參考 fprintf 的 man page ### 刪除不存在的字串會變成輸入 ### 發現 prefix search 查詢 A 的時候會 segmentation fault ### reference [afcidk](https://hackmd.io/s/HynvxMxcM#) [bauuuu1021](https://hackmd.io/s/rJd31ZRYz#Prefix-%E7%BC%BA%E9%99%B7) [2017重做同學](https://hackmd.io/s/r1nQinIbz#) ## tst_traverse_fn [TingL7](https://hackmd.io/s/r11sE83cz#)的解說十分詳盡完整 * callback function * 根據維基百科定義:a **callback** is any executable code that is passed as an argument to other code, which is expected to _call back_ (execute) the argument at a given time. * 在 c 語言中, callback function 就是將 function pointer 當作參數傳入另一個 function 中執行。 * `tst_traverse_fn` function * 就是一個遞迴的 callback function , 它將 fn() 當作參數。 ```c /** tst_traverse_fn(), traverse tree calling 'fn' on each word. * prototype for 'fn' is void fn(const void *, void *). data can * be NULL if unused. */ void tst_traverse_fn(const tst_node *p, void(fn)(const void *, void *), void *data) { if (!p) return; tst_traverse_fn(p->lokid, fn, data); if (p->key) tst_traverse_fn(p->eqkid, fn, data); else fn(p, data); tst_traverse_fn(p->hikid, fn, data); } ``` * 這個函式的功能就是走訪整個樹的節點,並且在 leaves 執行使用者自訂函式 fn()。 * 應用: * 計算 leaves 數量 ``` void fn(const void *p, void *data) { ++*(int *)data; } tst_traverse_fn(root, fn, &data); printf("data: %d\n", data); ``` 結果 ``` data: 85500 ``` * 效能評比 可以比較兩者的走訪速度。 ``` t1 = tvgetf(); tst_traverse_fn(root, fn, &data); t2 = tvgetf(); printf("cpy time: %.6f\n", t2-t1); ``` 結果 ``` cpy time: 0.015064 ref time: 0.015275 ``` * 印出資料庫中所有的國家、城市 ``` void fn(const void *p, void *data){ printf("%s\n", tst_get_string(p)); } tst_traverse_fn(root, fn, &data); ``` 結果 ``` ... Tufino, Tuftonboro, Tuganay, Tugas, Tugaya, Tugbong, Tugdan, Tuggen, Tuglie, Tugolesskiy Tugos, Tuguegarao Tugulym, Tugun, ... ```

Import from clipboard

Paste your webpage below. It will be converted to Markdown.

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template is not available.
Upgrade
All
  • All
  • Team
No template found.

Create custom template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

How to use Slide mode

API Docs

Edit in VSCode

Install browser extension

Get in Touch

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

No updates to save
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully