@@ -37,12 +37,147 @@ See [unordered_map example](./examples/unordered_map_example.cpp) in `examples`
3737
3838WIP
3939
40- ## Copyright
41-
42- License: MIT
43-
4440## Requirements
4541
4642- Compiler which supports C++17
4743- CMake ≥ 3.10
4844
45+ ## Minimal unordered map example
46+
47+ ``` cpp
48+ #include < iostream>
49+ #include < thread>
50+
51+ #include < wfc/unordered_map.hpp>
52+
53+ constexpr int nbr_threads = 16 ;
54+
55+ int main ()
56+ {
57+ wfc::unordered_map<std::size_t, std::size_t> m(4, nbr_threads, nbr_threads);
58+
59+ std::array<std::thread, nbr_threads> threads;
60+ for (std::size_t i = 0; i < nbr_threads; ++i)
61+ {
62+ threads[i] = std::thread([&m, i]() {
63+ m.insert(i, i);
64+ });
65+ }
66+
67+ for (auto& t: threads)
68+ {
69+ t.join();
70+ }
71+
72+ m.visit([](std::pair<const std::size_t, std::size_t> p) {
73+ std::cout << '[' << p.first << '-' << p.second << "]\n";
74+ });
75+
76+ return 0;
77+ }
78+ ```
79+
80+ This should output:
81+
82+ ```
83+ [0-0]
84+ [1-1]
85+ [2-2]
86+ [3-3]
87+ [4-4]
88+ [5-5]
89+ [6-6]
90+ [7-7]
91+ [8-8]
92+ [9-9]
93+ [10-10]
94+ [11-11]
95+ [12-12]
96+ [13-13]
97+ [14-14]
98+ [15-15]
99+ ```
100+
101+ ## How to import the library using CMake
102+
103+ To include the library, you may copy / paste the content of this repository in a subfolder (such as ` externals ` ) or use a git submodule.
104+
105+ Then, in you CMakeLists.txt file, you just have to do something similar to:
106+
107+ ``` cmake
108+ cmake_minimum_required(VERSION 3.10)
109+ project(MyProject)
110+ enable_language(CXX)
111+ set(CMAKE_CXX_STANDARD 17)
112+
113+ add_subdirectory(externals/WaitFreeCollections)
114+
115+ find_package(Threads REQUIRED) # you'll probably need that one too
116+
117+ add_executable(MyTarget src/main.cpp)
118+ target_link_libraries(MyTarget Threads::Threads WaitFreeCollections)
119+ ```
120+
121+ At this point, the project hierarchy looks like:
122+
123+ ```
124+ |- CMakeLists.txt
125+ |- src/
126+ |- main.cpp
127+ |- externals/
128+ |- WaitFreeCollections/
129+ |- ...
130+ ```
131+
132+ You may try to use the minimal example above as your ` main.cpp ` .
133+
134+ Also, since this is a header-only library, you may copy / paste the content of the include folder in your
135+ project to achieve similar results (maybe a little bit less clean though).
136+
137+ ## Build targets
138+
139+ You don't need to actually build the library beforehand to use it in your project due to the "header-only" nature of it.
140+ The build targets in this repository are for tests, exemples and code formatting.
141+ These are good to know should you contribute to this project or play with the exemples.
142+
143+ First, you need to create a sub-directory to run ` cmake ` from it. Then you can build using ` make ` .
144+
145+ ```
146+ $ mkdir build
147+ $ cmake .. -DWFC_BUILD_ALL=1
148+ ```
149+
150+ By default, everything is build in Release mode. You can pass ` -DCMAKE_BUILD_TYPE=Debug ` to ` cmake ` to ask Debug builds.
151+ This will also activate useful features for developing purposes such as the holy warnings.
152+ The ` -DWFC_BUILD_ALL=1 ` parameter will tell CMake to include all our targets in the build process.
153+
154+ CMake will generate several targets that you can build separately using the ` --target ` parameter:
155+
156+ - ` UnorderedMapExample1 `
157+ - ` UtilityTests `
158+ - ` UnorderedMapTests `
159+ - ` Clang-format `
160+
161+ For instance, to build the ` UnorderedMapTests ` run
162+
163+ ```
164+ $ cmake --build . --target UnorderedMapTests
165+ ```
166+
167+ You can also build everything by not giving any specific target.
168+ Produced executables are inside the ` bin ` folder.
169+
170+ Note that the ` Clang-format ` target does not produce anything.
171+ It just run the clang formatter.
172+ Also this target needs to be called explicitly.
173+
174+ For more details, see the [ CMakeLists.txt] ( CMakeLists.txt ) file.
175+
176+ ## Copyright
177+
178+ License: MIT
179+
180+ Main contributors:
181+
182+ - [ Jérôme Boulmier] ( https://github.com/Lomadriel )
183+ - [ Benoît Cortier] ( https://github.com/CBenoit )
0 commit comments