Skip to content

Commit fcf9374

Browse files
committed
Merge branch 'karatsuba' into devel
2 parents 3a188a9 + 259d230 commit fcf9374

20 files changed

Lines changed: 31024 additions & 105 deletions

.github/workflows/unit_tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
push: # This workflow is triggered by pushing to a git branch specified below
55
branches:
66
- devel # Project's branch name
7+
paths:
8+
- src/**
9+
- test/**
10+
- build/**
711

812
jobs:
913
test-on-ubuntu-linux:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ install/
4141
**/[Dd]ebug/
4242
**/[Rr]elease/
4343

44+
# VS Code
45+
.vscode/settings.json
46+
4447
# CMake
4548
!build/CMake/
4649
build/CMake/*

.vscode/launch.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "WSL Debug",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "${command:extension.vscode-wsl-workspaceFolder}/build/GNUMake/bin/test.exe",
9+
"args": [],
10+
"stopAtEntry": false,
11+
"cwd": "${command:extension.vscode-wsl-workspaceFolder}/test",
12+
"environment": [],
13+
"externalConsole": false,
14+
"MIMode": "gdb",
15+
"miDebuggerPath": "/usr/bin/gdb",
16+
"pipeTransport": {
17+
"pipeProgram": "C:\\Windows\\Sysnative\\bash.exe",
18+
"pipeArgs": ["-c"],
19+
"debuggerPath": "/usr/bin/gdb"
20+
},
21+
"setupCommands": [
22+
{
23+
"description": "Enable pretty-printing for gdb",
24+
"text": "-enable-pretty-printing",
25+
"ignoreFailures": true
26+
}
27+
],
28+
"sourceFileMap": {
29+
"/mnt/c": "c:\\",
30+
"/mnt/d": "d:\\"
31+
}
32+
}
33+
]
34+
}

.vscode/tasks.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "(WSL) build debug version",
6+
"type": "process",
7+
"command": "wsl",
8+
"args": [
9+
"bash", "-c",
10+
"cd \"$(wslpath '${workspaceFolder}')\" && ./make.sh -B DEBUG=yes"
11+
],
12+
"group": {
13+
"kind": "build",
14+
"isDefault": false
15+
},
16+
"problemMatcher": []
17+
}
18+
]
19+
}

ReadMe.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,45 @@ The list of implemented algorithms.
2828
- insertion sort
2929
- bubble sort
3030
- Merge sort ([merge_sort.h](src/merge_sort.h))
31-
- Quick sort ([quick_sort.h](quick_sort.h))
31+
- Quick sort with Lomuto and randomized partitioning ([quick_sort.h](src/quick_sort.h))
32+
- Binary search in a sorted array ([binary_search.h](src/binary_search.h))
3233
- [Trial division](https://en.wikipedia.org/wiki/Trial_division) ([prime.h](src/prime.h))
34+
- Binary search tree, AVL tree ([binary_tree.h](src/binary_tree.h))
35+
- B-tree ([btree.h](src/btree.h))
36+
- Heap (aka pyramid), priority queue, heap sort ([heap.h](src/heap.h))
37+
- Graph algorithms
38+
- Graph data structure ([graph.h](src/graph.h))
39+
- Breadth-first and Depth-first search ([graph_search.h](src/graph_search.h))
40+
- Topological sort and Kosaraju's strongly connected components algorithm ([graph_topology.h](src/graph_topology.h))
41+
- Dijkstra shortest path ([graph_dijkstra.h](src/graph_dijkstra.h))
42+
- Kruskal's Minimal Spanning Tree ([graph_kruskal.h](src/graph_kruskal.h))
43+
- Prim's Minimal Spanning Tree ([graph_prim.h](src/graph_prim.h))
44+
- Bellman-Ford shortest path algorithm (to be implemented)
45+
- Floyd-Warshall shortest path algorithm (to be implemented)
46+
- Johnson's shortest path algorithm (to be implemented)
47+
- Hash map with separate chaining collision resolution ([hash_map.h](src/hash_map.h))
48+
- Bloom filter ([bloom_filter.h](src/bloom_filter.h))
49+
- Greedy algorithms
50+
- Huffman encoding ([huffman_encoding.h](src/huffman_encoding.h))
51+
- Dynamic programming
52+
- Knapsack problem ([knapsack.h](src/knapsack.h))
53+
- Divide and conquer algorithms
54+
- Karatsuba multiplication algorithm ([karatsuba.h](src/karatsuba.h))
55+
- Strassen's matrix multiplication algorithm (to be implemented)
56+
- NP-hard problems
57+
- Travelling salesman problem (to be implemented)
3358

3459
## Prerequisites
3560

36-
On Linux install GNU Make and CMake build systems (example below is given for APT package manager which is used by default in Debian based Linux, e.g. Ubuntu and Linux Mint):
61+
- This project is written in C++, so it needs a C++ compiler like GCC or Clang.
62+
- The project showcases the usage of several build systems (you may use whichever you want): GNU Make, CMake and MSBuild (MS Visual Studio).
63+
- Python is used to generate test vectors, so you might want to install it as well.
64+
65+
On Linux install development tools (GCC, GDB, etc.), GNU Make and CMake build systems (example below is given for APT package manager which is used by default in Debian based Linux, e.g. Ubuntu and Linux Mint):
3766

3867
```bash
39-
sudo apt-get -y install make
40-
sudo apt-get -y install cmake
68+
sudo apt update
69+
sudo apt install build-essential clang gdb make cmake python3
4170
```
4271

4372
On Windows install CMake build system using [Chocolatey](https://chocolatey.org/) package manager:
@@ -67,7 +96,9 @@ If the build is successful, you'll find the binary files in `build/GNUMake/bin`
6796
```bash
6897
./cmake.sh
6998
```
70-
If the build is successful, you'll find a binary executable `computer-science` in `build/CMake/gnumake` directory.
99+
If the build is successful, you'll find a binary executable `computer-science` in `build/CMake/gnumake` directory.
100+
101+
For more information about setting up development environment see [Development.md](docs/Development.md).
71102

72103
## Usage
73104

Testing/Temporary/LastTest.log.tmp

Whitespace-only changes.

docs/Development.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# How to Setup Development Environment
2+
3+
This document will guide you through the process of setting up typical development environment on Linux and Windows.
4+
5+
## On Windows
6+
7+
Install WSL:
8+
```PowerShell
9+
wsl --install
10+
```
11+
12+
## On Linux (including WSL)
13+
14+
Install development tools:
15+
```bash
16+
sudo apt update
17+
sudo apt install build-essential gdb make cmake
18+
```
19+
20+
## Visual Studio Code
21+
22+
1. [Install VS Code](https://code.visualstudio.com/Download)
23+
24+
2. Launch VS Code and install the following extensions:
25+
- [C/C++ Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack)
26+
- [Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)
27+
28+
### Build Command in VS Code
29+
30+
#### WSL
31+
32+
In VS Code you can setup build commands and run them directly from VS Code GUI via menu `Terminal > Run Build Task...` or `Terminal > Run Task...`.
33+
In order to do that you need to create `.vscode/tasks.json` file inside your workspace.
34+
To create a single build task that runs our build script `make.sh` from WSL on Windows you can create the following `.vscode/tasks.json` file:
35+
```json
36+
{
37+
"version": "2.0.0",
38+
"tasks": [
39+
{
40+
"label": "(WSL) build debug version",
41+
"type": "process",
42+
"command": "wsl",
43+
"args": [
44+
"bash", "-c",
45+
"cd \"$(wslpath '${workspaceFolder}')\" && ./make.sh -B DEBUG=yes"
46+
],
47+
"group": {
48+
"kind": "build",
49+
"isDefault": false
50+
},
51+
"problemMatcher": []
52+
}
53+
]
54+
}
55+
```
56+
Note that this task works under Windows only. Here's a detailed explanation of each line in the above file:
57+
58+
- `"label": "(WSL) build debug version"`
59+
- A user-friendly name for the task.
60+
- This label is shown in the Run Task menu and can be used in launch.json (as a preLaunchTask).
61+
- You can choose any string, but it must be unique within the file.
62+
63+
- `"type": "process"`
64+
- Indicates the task runs a process directly, without going through the integrated shell.
65+
- This means that command refers to a system executable (like wsl, make, python, etc.).
66+
67+
- `"command": "wsl"`
68+
- Specifies the executable to run.
69+
- In this case, it's the `wsl` command, which launches a process inside Windows Subsystem for Linux.
70+
- So, everything after this is interpreted inside the WSL environment.
71+
72+
- `"args": [...]`
73+
- An array of arguments to pass to the command.
74+
- In this case:
75+
- `"bash"`: runs the Bash shell inside WSL
76+
- `"-c"`: tells Bash to execute the following command string
77+
- `"cd \"$(wslpath '${workspaceFolder}')\" && ./make.sh -B DEBUG=yes"`: this is the actual shell command being run inside WSL:
78+
- `$(wslpath ...)` converts the Windows path of `${workspaceFolder}` to a Linux-style path (`/mnt/...`)
79+
- `cd` into that path
80+
- then run the script `make.sh` with flags `-B DEBUG=yes`
81+
82+
- `"group": { "kind": "build", "isDefault": false }`
83+
- Organizes the task for VS Code’s UI:
84+
- `"kind": "build"` marks this task as a build task (shown in the Build Task menu).
85+
- `"isDefault": false` means this is not the default build task (i.e., not run automatically when you press `Ctrl+Shift+B`).
86+
87+
- `"problemMatcher": []`
88+
- Defines how VS Code should parse output from the task to detect errors/warnings.
89+
- An empty array [] means no error parsing - output will just go to the terminal, but VS Code won't try to detect errors or navigate to files.
90+
- You could attach a matcher like `$gcc` if you want VS Code to recognize compiler errors.
91+
92+
### Debugging Command in VS Code
93+
94+
#### WSL
95+
96+
1. Install [WSL workspaceFolder](https://marketplace.visualstudio.com/items?itemName=lfurzewaddock.vscode-wsl-workspacefolder) extension in VS Code to be able to convert `"${workspaceFolder}"` to Linux style path.
97+
98+
2. Create `.vscode/launch.json` file inside your workspace with the following content:
99+
```json
100+
{
101+
"version": "0.2.0",
102+
"configurations": [
103+
{
104+
"name": "WSL Debug",
105+
"type": "cppdbg",
106+
"request": "launch",
107+
"program": "${command:extension.vscode-wsl-workspaceFolder}/build/GNUMake/bin/test.exe",
108+
"args": [],
109+
"stopAtEntry": false,
110+
"cwd": "${command:extension.vscode-wsl-workspaceFolder}",
111+
"environment": [],
112+
"externalConsole": false,
113+
"MIMode": "gdb",
114+
"miDebuggerPath": "/usr/bin/gdb",
115+
"pipeTransport": {
116+
"pipeProgram": "C:\\Windows\\Sysnative\\bash.exe",
117+
"pipeArgs": ["-c"],
118+
"debuggerPath": "/usr/bin/gdb"
119+
},
120+
"setupCommands": [
121+
{
122+
"description": "Enable pretty-printing for gdb",
123+
"text": "-enable-pretty-printing",
124+
"ignoreFailures": true
125+
}
126+
],
127+
"sourceFileMap": {
128+
"/mnt/d": "d:\\"
129+
}
130+
}
131+
]
132+
}
133+
```
134+
Note that this task works under Windows only. Here's a detailed explanation of each line in the above file:
135+
136+
- `"name": "WSL Debug"`
137+
Name shown in the Run and Debug panel in VS Code when selecting which debug configuration to run.
138+
139+
- `"type": "cppdbg"`
140+
Debugger type (debugger backend to use), where `cppdbg` is for C++ using the Microsoft C/C++ debugger extension (ms-vscode.cpptools) which supports **gdb**, **lldb** and **Microsoft's C++ debugger**.
141+
142+
- `"request": "launch"`
143+
This is a "launch" request (i.e., start the program), as opposed to an "attach" request (attach to a running process).
144+
145+
- `"program": "${command:extension.vscode-wsl-workspaceFolder}/build/GNUMake/bin/test.exe"`
146+
Path to the executable you want to debug, here using: `${command:extension.vscode-wsl-workspaceFolder}` which resolves to the WSL-style path of your workspace folder (e.g., `/mnt/d/Projects/...`), even if VS Code is running in Windows mode. This avoids issues with backslashes in `${workspaceFolder}` when used across Windows/WSL boundaries.
147+
148+
- `"args": []`
149+
An array of command-line arguments passed to the program being debugged.
150+
151+
- `"stopAtEntry": false`
152+
If `true`, the debugger pauses at the program entry point (`main()`); if `false`, it runs until the first breakpoint or program termination.
153+
154+
- `"cwd": "${command:extension.vscode-wsl-workspaceFolder}/test"`
155+
The current working directory of the launched program. Again, using the WSL path of the workspace.
156+
157+
- `"environment": []`
158+
Set any environment variables to use during the debugging session. Empty means use the default environment.
159+
160+
- `"externalConsole": false`
161+
If `true`, launches a new terminal window for input/output; false uses VS Code's built-in terminal.
162+
163+
- `"MIMode": "gdb"`
164+
- Specifies the debugger engine, `gdb` in this case.
165+
- Enables the machine interface protocol (MI) that VS Code uses to communicate with GDB (i.e., structured messages, not plain CLI).
166+
- Used with GDB in Linux/WSL environments.
167+
168+
- `"miDebuggerPath": "/usr/bin/gdb"`
169+
Absolute path to GDB inside WSL.
170+
171+
- ```json
172+
"pipeTransport": {
173+
"pipeProgram": "C:\\Windows\\Sysnative\\bash.exe",
174+
"pipeArgs": ["-c"],
175+
"debuggerPath": "/usr/bin/gdb"
176+
}
177+
```
178+
- This section tells VS Code to run GDB inside WSL, even if VS Code is running on Windows:
179+
- `"pipeProgram": "C:\\Windows\\Sysnative\\bash.exe"`: This launches the WSL environment from Windows in a low-level way that works even from 32-bit VS Code.
180+
- `"pipeArgs": ["-c"]`: Tells bash to treat the next string as a shell command.
181+
- `"debuggerPath": "/usr/bin/gdb"`: The command `bash -c "/usr/bin/gdb"` gets executed in WSL to start the debugger.
182+
183+
- ```json
184+
"setupCommands": [
185+
{
186+
"description": "Enable pretty-printing for gdb",
187+
"text": "-enable-pretty-printing",
188+
"ignoreFailures": true
189+
}
190+
]
191+
```
192+
This sends a GDB command at startup to enable pretty-printing of STL containers, useful for C++ debugging.
193+
194+
- ```json
195+
"sourceFileMap": {
196+
"/mnt/c": "c:\\",
197+
"/mnt/d": "d:\\"
198+
}
199+
```
200+
Tells VS Code how to map paths between WSL (Linux) and Windows. For example, when GDB says `"breakpoint at /mnt/d/Project/file.cpp"`, VS Code can find and open `d:\Project\file.cpp`.
240 KB
Binary file not shown.
352 KB
Binary file not shown.

0 commit comments

Comments
 (0)