原创 無鎖隊列 SPSC Queue

在多線程編程中,一個著名的問題是生產者-消費者問題 (Producer Consumer Problem, PC Problem)。 對於這類問題,通過信號量加鎖 (https://www.cnblogs.com/sinkinben/p/1

原创 Random Walk Problem

Notice: This article is just a short discussion on Random Walk problem, I compute \(E(X^2)\) in this article. After I r

原创 General Matrix Multiplication

GEMM is "General Matrix Multiplication", that is we won't consider optimizing some special cases, e.g. sparse matrix. In

原创 Architecture of GPU and CUDA

In this blog, we will introduce the architecture of GPU from the programmers' perspective, and give some examples of CUD

原创 Architecture of Modern CPU

In this blog, we will take a look on the architecture of modern CPU, from a programmer's perspective. Intro Each comput

原创 Implement Thread Pool in C++

Implementing a thread pool is a producer-consumer problem: the enqueue function is the producer(s), it put some tasks i

原创 push_back v.s. emplace_back

What are the differences between push_back and emplace_back? Intro Let's see an example in C++98. push_back Suppose ther

原创 RTTI and Casts

What is "RTTI"? Run Time Type Information RTTI is a mechanism that allows the type of an object to be determined during

原创 Introduction to Flex and Bison

Before you read this article, you should know the basis prerequisites knowledge: Regular Expression Usage of makefile T

原创 Cantor Expansion

Before we introduce the Cantor Expansion, let me show you a problem. Given a group of numbers, such as nums = [1, 2, 3],

原创 [CPP] 類的內存佈局

本文討論的是下面 3 個問題: 以不同方式繼承之後,類的成員變量是如何分佈的? 虛函數表及虛函數表指針,在可執行文件中的位置? 單一繼承、多繼承、虛擬繼承之後,類的虛函數表的內容是如何變化的? 在這裏涉及的變量有:有無繼承、有無虛函數、

原创 線段樹 (Segment Tree)

預備知識:樹狀數組 。 與樹狀數組 (Binary Index Tree, BIT, aka "二叉索引樹") 類似,線段樹適用於以下場景: 給定數組 a[n], 並且要求 w 次修改數組,現有 q 次區間查詢,每次區間查詢包括 [l,

原创 [Kick Start] 2021 Round B

題目:Kick Start 2021 Round-B . Increasing Substring 輸出字符串中每個字符的最長 Increasing Substring 的長度,非常簡單的動態規劃問題。 定義 dp[i] 是以 str[i]

原创 3-Partition 問題

這是算法考試的最後一題,當時匆匆寫了個基於 Subset Sum 的解法,也沒有考慮是否可行。 問題描述如下: 給定 \(n\) 個正整數 \(a_1 \dots a_n\) ,設下標的整數集合 \(V=\{1,2,3,\dots,n\}

原创 最大流最小割問題

本節的內容是最大流 (Max Flow) - 最小割 (Mini-Cut) 問題,涉及的算法是 Ford-Fulkerson 算法。 Definitions Flow Network 流網絡 (Flow Network) ,即圖 \(G =