XpandNotes

exploring the intersection of technology and creativity

用 C++ 實作 Trie

Trie 簡介 Trie,又稱字首樹或字典樹,規則為將單字柴成一個一個字元,每個字元代表一個節點,依照字元在單字中的順序往下長成一棵樹。 Trie 實作方式 首先定義節點物件 node,其必須包含可以往下長的節點 child,在這裡我使用了 STL 的 unordered_map 來實作 child。node 還需要包含一個布林值 is_word 判別從根走到這個節點是否能讀作一個...

Debian 11 筆記

將使用者加入 sudoer 剛安裝好 Debian 時,一定會遇到下 sudo apt ... 卻被告知權限不足的問題,此時必須手動修改 /etc/sudoers 將目前的使用者 (lin) 加入 sudoer。 $ su - # gpasswd -a lin sudo # cd /usr/sbin # ./visudo 此時終端機會用 nano 開啟 sudoer.tmp,將下區塊...

使用 Weasyprint 將 HTML 轉成 PDF

在幫 tldr page 修改 pdf 渲染器時偶然發現 Weasyprint 這個好用的函式庫,以下介紹三種使用方法。首先透過 pip 安裝: $ pip3 install weasyprint 讀取 HTML 檔轉換成自動換頁的 PDF 首先我找了一個 HTML 範例 如下: mystyle.css 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...

Leetcode #9 Palindrome Number

Description Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not. Ex...

Leetcode #8 String to Integer (atoi)

Description Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++’s atoi function). The algorithm for myAtoi(string s) is as follows: R...

OS 筆記主頁

使用課本: Operating System Concepts 9th Edition 1 Introduction

OS Chapter 1

Introduction

目前普遍的電腦架構如下圖 CPU 不斷地從記憶體吞吐指令,根據指令操作各種 device,device 跳過 CPU,透過 DMA (Direct Memory Access) 主動向記憶體存取資料,增加電腦效率。CPU、記憶體、devices 互相協同工作下,形成了我們日常使用的電腦系統。 多處理器系統 (Multiprocessor systems, parallel syste...

資結筆記主頁

使用課本: Fundamentals of Data Structures in C 2/e 1 Basic Concepts

資結 Chapter 1

Basic Concepts

演算法 (Algorithm) 以有限的指令完成一個任務,一個演算法必須滿足以下五個條件: 輸入 (Input):演算法必須有 0 個或以上的輸入。 輸出 (Output):演算法應有 1 個或以上輸出。 明確性 (Definiteness):演算法的描述必須無歧義,以保證實際執行結果精確符合要求。 有限性 (Finitense):演算法必須在有限個步驟內完成任務。 ...

用 C++ 實作 Bloom Filter

Bloom Filter 在實作 key value storage 帶給我很大的效能優化,所以想特別做一份筆記紀錄,但是這個 bloom filter 是基於 jserv 老師在 dict 裡的實作,不是我原創的內容。 Bloom Filter 簡介 因為懶得自己措辭,所以以下簡介摘錄自 jserv 的上課教材 https://hackmd.io/@sysprog/2020-dict ...