Skip to content

Commit 814b7f9

Browse files
authored
Merge pull request #1276 from trcrsired/next
[deque] Try to finish deque implementation
2 parents e14aeaf + 9bd5817 commit 814b7f9

35 files changed

Lines changed: 4975 additions & 797 deletions

File tree

CLAUDE.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
**fast_io** is a header-only C++20 I/O library designed to replace `<iostream>` and `<cstdio>` with dramatically better performance. It makes direct system calls, bypassing intermediary layers, and uses C++20 concepts extensively for type abstraction.
8+
9+
## Build & Development
10+
11+
### Prerequisites
12+
- C++20 compiler: GCC >= 15, Clang >= 21, or MSVC
13+
- CMake >= 3.15
14+
15+
### Build Tests, Benchmarks, and Examples
16+
17+
```bash
18+
# Prebuild: generate test files (only needed once)
19+
cmake -B fast_io_prebuild -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=On -DTESTS_PREBUILD=On
20+
cmake --build fast_io_prebuild
21+
./fast_io_prebuild/tests_prebuild linux # or "windows msvc"
22+
23+
# Build tests/examples/benchmarks
24+
cmake -B fast_io_build -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=On
25+
cmake --build fast_io_build
26+
27+
# Run tests
28+
cmake --build fast_io_build --target test
29+
```
30+
31+
### Run a Single Test
32+
33+
Tests are located under `tests/`. After building, individual test binaries are in the `fast_io_build/tests/` subdirectories. Run them directly.
34+
35+
### CI
36+
37+
GitHub Actions (`.github/workflows/c-cpp.yml`) runs:
38+
- **Linux**: GCC with `-fsanitize=address,undefined -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror`
39+
- **Windows**: MSVC with `/EHsc /W3 /WX /sdl`
40+
- Uses Ninja generator on both platforms
41+
42+
## Architecture
43+
44+
The library uses a layered architecture:
45+
46+
| Layer | Header | Description |
47+
|-------|--------|-------------|
48+
| Concepts | `fast_io_concept.h` | C++20 concepts for I/O device abstraction |
49+
| Core | `fast_io_core.h` | Freestanding-capable: bit ops, integer formatting, codecvt, SIMD |
50+
| Freestanding | `fast_io_freestanding.h` | Adds buffered I/O, decorators, serializers, transcoders |
51+
| Hosted | `fast_io_hosted.h` | Full features: platform abstractions, filesystem, threads, process/IPC |
52+
| Main | `fast_io.h` | Entry point: combines hosted + legacy stream interop |
53+
54+
### Key Directories
55+
56+
- `include/fast_io_core_impl/` — Core implementation internals (operations: `printimpl`, `readimpl`, `writeimpl`, `transmitimpl`, `transcodeimpl`)
57+
- `include/fast_io_hosted/` — Hosted platform implementations (console, filesystem, mmap, threads, process)
58+
- `include/fast_io_freestanding_impl/` — Buffered I/O, decorators, scanners, serialization
59+
- `include/fast_io_legacy_impl/` — FILE*/streambuf hacks for glibc, MSVCRT, UCRT, MUSL, BSD libc, libstdc++, libc++, MSVC STL
60+
- `include/fast_io_dsal/` — Data Structure Abstraction Layer (vector, string, deque, list, etc.)
61+
- `include/fast_io_driver/` — Third-party integrations (Boost.Asio, OpenSSL, Qt, MFC, LLVM, Python, zlib)
62+
- `include/fast_io_crypto/` — SHA-1, SHA-256, SHA-512, HMAC, ciphers
63+
- `share/fast_io/` — C++20 module files
64+
65+
### Header Organization
66+
67+
- `fast_io.h` — Primary entry point (most common include)
68+
- `fast_io_device.h` — Device types (files, pipes, sockets)
69+
- `fast_io_crypto.h` — Cryptographic hash functions
70+
- `fast_io_i18n.h` — Internationalization/locale
71+
- `fast_io_legacy.h` — Legacy C/C++ stream compatibility
72+
73+
### fast_io's 6 layers of files from bottom to top
74+
- wine_file
75+
- nt_file
76+
- win32_file
77+
- posix_file
78+
- c_file
79+
- filebuf_file
80+
81+
From bottom to top we do a move.
82+
From top to bottom we do a static cast to the
83+
lower level of io_observer.
84+
85+
## Testing
86+
87+
- Tests are organized into numbered categories under `tests/`
88+
- `.test_prop.toml` controls which tests run per platform/compiler
89+
- Test files are generated by `tests/0000.tests_prebuild/gentests.cc`
90+
- Some tests are ignored for incomplete features or platform requirements
91+
92+
## Benchmarking
93+
94+
Benchmarks live under `benchmark/` with numbered categories (integer I/O, floating-point, file I/O, concat, containers, codecvt, syscalls, etc.). Many have standalone `Makefile`s using `clang++ -Ofast -march=native -std=c++20` with precompiled headers.
95+
96+
## Style & Conventions
97+
98+
- `.clang-format` and `.editorconfig` are present — format code before committing
99+
- This is a header-only library — no `.cpp` source files in `include/`
100+
- The library targets both freestanding (no OS) and hosted environments
101+
- Consistent error handling via exceptions only (no `std::error_code` or `std::system_error`)
102+
- License: Anti-Tivo License (ATL) v1.0

benchmark/0011.containers/deque/0001.push_back/fast_io.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ int main()
2222
sum += e;
2323
}
2424
}
25-
::fast_io::io::perrln("sum=",sum);
25+
::fast_io::io::perrln("sum=", sum);
2626
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <fast_io.h>
2+
#include <fast_io_driver/timer.h>
3+
#include <fast_io_dsal/deque.h>
4+
5+
int main()
6+
{
7+
fast_io::timer tm(u8"fast_io::deque resize_for_overwrite");
8+
fast_io::deque<std::size_t> deq;
9+
constexpr std::size_t n{100000000};
10+
{
11+
fast_io::timer tm1(u8"push_back");
12+
deq.resize(n, ::fast_io::for_overwrite);
13+
::std::size_t idx{};
14+
for (::std::size_t i{}, segs{deq.segments_count()}; i != segs; ++i)
15+
{
16+
for (auto &e : deq.nth_segment(i))
17+
{
18+
e = idx;
19+
++idx;
20+
}
21+
}
22+
}
23+
::std::size_t sum{};
24+
{
25+
fast_io::timer tm1(u8"loop");
26+
for (::std::size_t i{}, segs{deq.segments_count()}; i != segs; ++i)
27+
{
28+
for (auto const e : deq.const_nth_segment(i))
29+
{
30+
sum += e;
31+
}
32+
}
33+
}
34+
::fast_io::io::perrln("sum=", sum);
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <fast_io.h>
2+
#include <fast_io_driver/timer.h>
3+
#include <fast_io_dsal/deque.h>
4+
5+
int main()
6+
{
7+
fast_io::timer tm(u8"fast_io::deque segments");
8+
fast_io::deque<std::size_t> deq;
9+
constexpr std::size_t n{100000000};
10+
{
11+
fast_io::timer tm1(u8"push_back");
12+
for (std::size_t i{}; i != n; ++i)
13+
{
14+
deq.push_back(i);
15+
}
16+
}
17+
::std::size_t sum{};
18+
{
19+
fast_io::timer tm1(u8"loop");
20+
for (::std::size_t i{}, segs{deq.segments_count()}; i != segs; ++i)
21+
{
22+
for (auto const e : deq.const_nth_segment(i))
23+
{
24+
sum += e;
25+
}
26+
}
27+
}
28+
::fast_io::io::perrln("sum=", sum);
29+
}

benchmark/0011.containers/deque/0001.push_back/std.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main()
2020
for (auto const e : deq)
2121
{
2222
sum += e;
23-
}
23+
}
2424
}
25-
::fast_io::io::perrln("sum=",sum);
25+
::fast_io::io::perrln("sum=", sum);
2626
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <fast_io.h>
2+
#include <fast_io_driver/timer.h>
3+
#include <vector>
4+
5+
int main()
6+
{
7+
fast_io::timer tm(u8"std::vector");
8+
std::vector<std::size_t> vec;
9+
constexpr std::size_t n{100000000};
10+
{
11+
fast_io::timer tm1(u8"push_back");
12+
for (std::size_t i{}; i != n; ++i)
13+
{
14+
vec.push_back(i);
15+
}
16+
}
17+
::std::size_t sum{};
18+
{
19+
fast_io::timer tm1(u8"loop");
20+
for (auto const e : vec)
21+
{
22+
sum += e;
23+
}
24+
}
25+
::fast_io::io::perrln("sum=", sum);
26+
}

examples/.test_prop.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@ ignore = true
4343
["0040.wifianalyzer"]
4444
ignore = true
4545

46+
["0041.keepwinealive"]
47+
ignore = true
48+
4649
["0042.scn_ip_port"]
4750
interactive = true
51+
52+
["0043.scanwinprocesspasswords"]
53+
ignore = true
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include<fast_io.h>
2+
#define NOMINMAX 1
3+
#define _WIN32_LEAN_AND_MEAN
4+
#include<windows.h>
5+
#undef min
6+
#undef max
7+
8+
int main()
9+
{
10+
::fast_io::io::perrln("keep wine alive: ", utc(::fast_io::posix_clock_gettime(::fast_io::posix_clock_id::realtime)));
11+
WaitForSingleObject(GetCurrentProcess(), INFINITE);
12+
}

0 commit comments

Comments
 (0)