### Install ffi gem for Ruby binding Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Installs the ffi gem, a prerequisite for the Ruby binding example. ```shell $ gem install ffi ``` -------------------------------- ### Install cffi package for Python binding Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Installs the cffi package, a prerequisite for the Python binding example. ```shell $ pip install cffi ``` -------------------------------- ### CMakeLists.txt for cxxopts interface library Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/cxxopts/CMakeLists.txt Defines an INTERFACE library target named cxxopts with include directories for build and install usage. ```cmake cmake_minimum_required(VERSION 3.18) project(cxxopts LANGUAGES CXX) add_library(cxxopts INTERFACE) target_include_directories(cxxopts INTERFACE $ $ ) ``` -------------------------------- ### Ring RingZip: create zip and add file entry Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Ring example using the RingZip library (based on this zip library) to create an archive, add an entry from a file, and close. Requires loading the ziplib.ring file. ```ring load "ziplib.ring" new Zip { setFileName("myfile.zip") open("w") newEntry() { open("test.c") writefile("test.c") close() } close() } ``` -------------------------------- ### Include libnpy header Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/libnpy/README.md Include the npy.hpp header to use the library. The example is a placeholder; actual usage examples are in the test/ directory. Requires C++11 (use -std=c++11 with g++). ```c++ #include "npy.hpp" // TODO: include example code here ``` -------------------------------- ### Build with custom SSE and AVX2 options Source: https://github.com/dhbloo/rapfi/blob/master/Readme.md Builds Rapfi with only SSE and AVX2 support using explicit CMake options. This example uses clang as the compiler and disables AVX512, BMI2, and VNNI. ```bash mkdir -p Rapfi/build/x64-clang-AVX2 && cd Rapfi/build/x64-clang-AVX2 cmake ../.. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DUSE_SSE=ON -DUSE_AVX2=ON -DUSE_AVX512=OFF -DUSE_BMI2=OFF -DUSE_VNNI=OFF cmake --build . ``` -------------------------------- ### Include flat.hpp and use flat_set Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/flat.hpp/README.md Shows how to include the flat_set header and use the flat_hpp namespace to create a flat_set, insert an element, and return from main. ```cpp #include "flat.hpp/flat_set.hpp" using namespace flat_hpp; int main() { flat_set s; s.insert(42); return 0; } ``` -------------------------------- ### List available CMake presets Source: https://github.com/dhbloo/rapfi/blob/master/Readme.md Lists all available CMake presets for building Rapfi with different configurations. ```bash cd Rapfi cmake --list-presets ``` -------------------------------- ### Go cgo binding: create zip and write entry Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Go binding using cgo to create a zip archive, add an entry, write content, and close. Requires the zip library compiled as a shared library and the cgo directives to locate headers and link. ```go package main /* #cgo CFLAGS: -I../src #cgo LDFLAGS: -L. -lzip #include */ import "C" import "unsafe" func main() { path := C.CString("/tmp/go.zip") zip := C.zip_open(path, 6, 'w') entryname := C.CString("test") C.zip_entry_open(zip, entryname) content := "test content" buf := unsafe.Pointer(C.CString(content)) bufsize := C.size_t(len(content)) C.zip_entry_write(zip, buf, bufsize) C.zip_entry_close(zip) C.zip_close(zip) } ``` -------------------------------- ### Build for WebAssembly with Emscripten Source: https://github.com/dhbloo/rapfi/blob/master/Readme.md Builds Rapfi for WebAssembly using the Emscripten SDK. Requires an activated Emscripten environment. Uses SIMD options and disables command modules. ```bash # Make sure you have activated the Emscripten environment mkdir -p Rapfi/build/wasm-multi-simd128 && cd Rapfi/build/wasm-multi-simd128 emcmake cmake ../.. -DCMAKE_BUILD_TYPE=Release -DNO_COMMAND_MODULES=ON -DUSE_WASM_SIMD=ON -DUSE_WASM_SIMD_RELAXED=OFF emmake cmake --build . ``` -------------------------------- ### Build with x64-clang-Native preset Source: https://github.com/dhbloo/rapfi/blob/master/Readme.md Builds Rapfi with multi-threading and native instruction sets for x86-64 (amd64) platforms. Requires CMake and a C++17 compiler. ```bash cd Rapfi cmake --preset x64-clang-Native cmake --build build/x64-clang-Native ``` -------------------------------- ### Create a new zip archive with default compression level Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Creates a new zip archive with default compression level. Shows writing a buffer to one entry and merging three files into another entry using zip_entry_fwrite. ```c struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'w'); { zip_entry_open(zip, "foo-1.txt"); { const char *buf = "Some data here...\0"; zip_entry_write(zip, buf, strlen(buf)); } zip_entry_close(zip); zip_entry_open(zip, "foo-2.txt"); { // merge 3 files into one entry and compress them on-the-fly. zip_entry_fwrite(zip, "foo-2.1.txt"); zip_entry_fwrite(zip, "foo-2.2.txt"); zip_entry_fwrite(zip, "foo-2.3.txt"); } zip_entry_close(zip); } zip_close(zip); ``` -------------------------------- ### Never FFI binding: create zip with file and string entries Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Never FFI binding that declares the zip functions and uses them to create an archive, add entries (one from a file, one from a string), and close. Requires the libzip.so shared library. ```never extern "libzip.so" func zip_open(zipname: string, level: int, mode: char) -> c_ptr extern "libzip.so" func zip_close(zip: c_ptr) -> void extern "libzip.so" func zip_entry_open(zip: c_ptr, entryname: string) -> int extern "libzip.so" func zip_entry_close(zip: c_ptr) -> int extern "libzip.so" func zip_entry_write(zip: c_ptr, buf: string, bufsize: int) -> int extern "libzip.so" func zip_entry_fwrite(zip: c_ptr, filename: string) -> int func main() -> int { let content = "Test content" let zip = zip_open("/tmp/never.zip", 6, 'w'); zip_entry_open(zip, "test.file"); zip_entry_fwrite(zip, "/tmp/test.txt"); zip_entry_close(zip); zip_entry_open(zip, "test.content"); zip_entry_write(zip, content, length(content)); zip_entry_close(zip); zip_close(zip); 0 } ``` -------------------------------- ### Add flat.hpp via CMake Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/flat.hpp/README.md Shows how to add the flat.hpp repository as a subdirectory and link it to your CMake target. ```cmake add_subdirectory(external/flat.hpp) target_link_libraries(your_project_target flat.hpp) ``` -------------------------------- ### Define source lists and build rapfi executable Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/CMakeLists.txt Defines the source file lists (CORE_SOURCES, MODULE_SOURCES, HEADERS) and creates the rapfi executable. The MODULE_SOURCES are conditionally included unless NO_COMMAND_MODULES is enabled, and the output binary is renamed to pbrain-rapfi. ```cmake set(CORE_SOURCES command/argutils.cpp command/benchmark.cpp command/command.cpp command/dbcommand.cpp command/gomocup.cpp core/compressor.cpp core/hash.cpp core/iohelper.cpp core/utils.cpp core/platform.cpp core/version.cpp database/dbclient.cpp database/dbconfig.cpp database/dbutils.cpp database/dbtypes.cpp database/renlib.cpp database/yxdbstorage.cpp eval/eval.cpp eval/evalconfig.cpp eval/evaluator.cpp eval/mix9svqnnue.cpp eval/mix10nnue.cpp game/board.cpp game/movegen.cpp game/pattern.cpp search/hashtable.cpp search/movepick.cpp search/opening.cpp search/searchcommon.cpp search/searchconfig.cpp search/searchengine.cpp search/searchoutput.cpp search/searchthread.cpp search/timecontrol.cpp search/ab/history.cpp search/ab/search.cpp search/mcts/node.cpp search/mcts/search.cpp config.cpp internalConfig.cpp main.cpp ) ``` ```cmake set(MODULE_SOURCES command/database.cpp command/dataprep.cpp command/opengen.cpp command/selfplay.cpp command/tuning.cpp tuning/dataformat.cpp tuning/dataset.cpp tuning/datastream.cpp tuning/datawriter.cpp tuning/featureencoder.cpp tuning/numpywriter.cpp tuning/optimizer.cpp tuning/tunecorpus.cpp tuning/tunedigest.cpp tuning/tuneshard.cpp tuning/tunestore.cpp tuning/tuner.cpp ) ``` ```cmake set(HEADERS command/command.h command/argutils.h command/dbcommand.h core/compressor.h core/filesystem.h core/hash.h core/iohelper.h core/math.h core/platform.h core/pos.h core/random.h core/string.h core/time.h core/types.h core/utils.h core/version.h database/cache.h database/dbclient.h database/dbconfig.h database/dbstorage.h database/dbtypes.h database/dbutils.h database/parallelwalk.h database/renlib.h database/yxdbstorage.h eval/eval.h eval/evalconfig.h eval/evaluator.h eval/mix9svqnnue.h eval/mix10nnue.h eval/mixcommon.h eval/scoretables.h eval/simd/activation.h eval/simd/isa.h eval/simd/linear.h eval/simd/vec.h eval/simdops.h eval/weightloader.h game/bitboard.h game/board.h game/candarea.h game/movegen.h game/pattern.h game/scopedmove.h game/wincheck.h tuning/dataentry.h tuning/dataformat.h tuning/dataset.h tuning/datastream.h tuning/datawriter.h tuning/featureencoder.h tuning/optimizer.h tuning/tunemap.h tuning/tunecorpus.h tuning/tuner.h search/hashtable.h search/history.h search/movepick.h search/opening.h search/searchcommon.h search/searchconfig.h search/searchengine.h search/searcher.h search/searchoutput.h search/searchthread.h search/skill.h search/timecontrol.h search/ab/history.h search/ab/parameter.h search/ab/searcher.h search/ab/searchstack.h search/mcts/node.h search/mcts/nodetable.h search/mcts/searcher.h search/mcts/parameter.h config.h ) ``` ```cmake add_executable(rapfi ${CORE_SOURCES} $<$>:${MODULE_SOURCES}> ${HEADERS}) set_target_properties(rapfi PROPERTIES OUTPUT_NAME "pbrain-rapfi") ``` -------------------------------- ### Rust FFI binding: create zip and write entry Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Rust FFI binding that declares the zip C functions and uses them to create an archive, add an entry, write content, and close. Requires linking against the zip library. ```rust extern crate libc; use std::ffi::CString; #[repr(C)] pub struct Zip { _private: [u8; 0], } #[link(name = "zip")] extern "C" { fn zip_open(path: *const libc::c_char, level: libc::c_int, mode: libc::c_char) -> *mut Zip; fn zip_close(zip: *mut Zip) -> libc::c_void; fn zip_entry_open(zip: *mut Zip, entryname: *const libc::c_char) -> libc::c_int; fn zip_entry_close(zip: *mut Zip) -> libc::c_int; fn zip_entry_write( zip: *mut Zip, buf: *const libc::c_void, bufsize: libc::size_t, ) -> libc::c_int; } fn main() { let path = CString::new("/tmp/rust.zip").unwrap(); let mode: libc::c_char = 'w' as libc::c_char; let entryname = CString::new("test.txt").unwrap(); let content = "test content\0"; unsafe { let zip: *mut Zip = zip_open(path.as_ptr(), 5, mode); { zip_entry_open(zip, entryname.as_ptr()); { let buf = content.as_ptr() as *const libc::c_void; let bufsize = content.len() as libc::size_t; zip_entry_write(zip, buf, bufsize); } zip_entry_close(zip); } zip_close(zip); } } ``` -------------------------------- ### Ruby FFI binding: create zip and write entry Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Ruby FFI binding that attaches the zip functions and uses them to create an archive, add an entry, write content, and close. Requires the ffi gem and the shared library in the current directory. ```ruby require 'ffi' module Zip extend FFI::Library ffi_lib "./libzip.#{::FFI::Platform::LIBSUFFIX}" attach_function :zip_open, [:string, :int, :char], :pointer attach_function :zip_close, [:pointer], :void attach_function :zip_entry_open, [:pointer, :string], :int attach_function :zip_entry_close, [:pointer], :void attach_function :zip_entry_write, [:pointer, :string, :int], :int end ptr = Zip.zip_open("/tmp/ruby.zip", 6, "w".bytes()[0]) status = Zip.zip_entry_open(ptr, "test") content = "test content" status = Zip.zip_entry_write(ptr, content, content.size()) Zip.zip_entry_close(ptr) Zip.zip_close(ptr) ``` -------------------------------- ### Compress folder recursively Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Recursively walks a directory and adds each file to the zip archive using zip_entry_fwrite. Skips "." and ".." entries. ```c void zip_walk(struct zip_t *zip, const char *path) { DIR *dir; struct dirent *entry; char fullpath[MAX_PATH]; struct stat s; memset(fullpath, 0, MAX_PATH); dir = opendir(path); assert(dir); while ((entry = readdir(dir))) { // skip "." and ".." if (!strcmp(entry->d_name, ".\0") || !strcmp(entry->d_name, "..\0")) continue; snprintf(fullpath, sizeof(fullpath), "%s/%s", path, entry->d_name); stat(fullpath, &s); if (S_ISDIR(s.st_mode)) zip_walk(zip, fullpath); else { zip_entry_open(zip, fullpath); zip_entry_fwrite(zip, fullpath); zip_entry_close(zip); } } closedir(dir); } ``` -------------------------------- ### Create a new zip archive in memory (stream API) Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Creates a zip archive in memory using the stream API. The compressed stream is copied to a buffer with zip_stream_copy and must be freed by the caller. ```c char *outbuf = NULL; size_t outbufsize = 0; const char *inbuf = "Append some data here...\0"; struct zip_t *zip = zip_stream_open(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w'); { zip_entry_open(zip, "foo-1.txt"); { zip_entry_write(zip, inbuf, strlen(inbuf)); } zip_entry_close(zip); /* copy compressed stream into outbuf */ zip_stream_copy(zip, (void **)&outbuf, &outbufsize); } zip_stream_close(zip); free(outbuf); ``` -------------------------------- ### Enable LTO with CheckIPOSupported (ENABLE_LTO) Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/CMakeLists.txt Enables link-time optimization (LTO) for the rapfi target when ENABLE_LTO is set. Uses CheckIPOSupported to verify compiler support; if unsupported, prints a STATUS message with the error output instead of failing. ```cmake if(ENABLE_LTO) include(CheckIPOSupported) check_ipo_supported(RESULT IPOSupported OUTPUT error) if(IPOSupported) set_property(TARGET rapfi PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) else() message(STATUS "LTO not supported: <${error}>") endif() endif() ``` -------------------------------- ### Build for ARM64 with NEON support Source: https://github.com/dhbloo/rapfi/blob/master/Readme.md Builds Rapfi for the ARM64 platform with NEON support, using clang and disabling NEON dot product. ```bash mkdir -p Rapfi/build/arm64-clang-NEON && cd Rapfi/build/arm64-clang-NEON cmake ../.. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DUSE_NEON=ON -DUSE_NEON_DOTPROD=OFF cmake --build . ``` -------------------------------- ### flat_multimap constructors and assignment operators Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/flat.hpp/README.md Lists the various constructors and assignment operators, including those taking allocators, sorted_range_t tags, initializer lists, and move/copy semantics. ```cpp flat_multimap(); explicit flat_multimap(const Compare& c); template < typename Allocator > explicit flat_multimap(const Allocator& a); template < typename Allocator > flat_multimap(const Compare& c, const Allocator& a); template < typename InputIter > flat_multimap(InputIter first, InputIter last); template < typename InputIter > flat_multimap(sorted_range_t, InputIter first, InputIter last); template < typename InputIter > flat_multimap(InputIter first, InputIter last, const Compare& c); template < typename InputIter > flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c); template < typename InputIter, typename Allocator > flat_multimap(InputIter first, InputIter last, const Allocator& a); template < typename InputIter, typename Allocator > flat_multimap(sorted_range_t, InputIter first, InputIter last, const Allocator& a); template < typename InputIter , typename Allocator > flat_multimap(InputIter first, InputIter last, const Compare& c, const Allocator& a); template < typename InputIter , typename Allocator > flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a); flat_multimap(std::initializer_list ilist); flat_multimap(sorted_range_t, std::initializer_list ilist); flat_multimap(std::initializer_list ilist, const Compare& c); flat_multimap(sorted_range_t, std::initializer_list ilist, const Compare& c); template < typename Allocator > flat_multimap(std::initializer_list ilist, const Allocator& a); template < typename Allocator > flat_multimap(sorted_range_t, std::initializer_list ilist, const Allocator& a); template < typename Allocator > flat_multimap(std::initializer_list ilist, const Compare& c, const Allocator& a); template < typename Allocator > flat_multimap(sorted_range_t, std::initializer_list ilist, const Compare& c, const Allocator& a); template < typename Allocator > flat_multimap(flat_multimap&& other, const Allocator& a); template < typename Allocator > flat_multimap(const flat_multimap& other, const Allocator& a); flat_multimap(flat_multimap&& other); flat_multimap(const flat_multimap& other); flat_multimap& operator=(flat_multimap&& other); flat_multimap& operator=(const flat_multimap& other); flat_multimap& operator=(std::initializer_list ilist); ``` -------------------------------- ### Element access Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/flat.hpp/README.md Declarations for operator[], at, and their template overloads for heterogeneous lookup. ```cpp mapped_type& operator[](key_type&& key); mapped_type& operator[](const key_type& key); mapped_type& at(const key_type& key); const mapped_type& at(const key_type& key) const; template < typename K > mapped_type& at(const K& key); template < typename K > const mapped_type& at(const K& key) const; ``` -------------------------------- ### flat_set Observer Functions Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/flat.hpp/README.md Declarations for key_comp() and value_comp() returning the comparison objects. ```cpp key_compare key_comp() const; value_compare value_comp() const; ``` -------------------------------- ### CMakeLists.txt: Auto-detect SIMD/ISA capabilities Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/CMakeLists.txt CMake configuration for the rapfi project. Sets C++17 standard and auto-detects SIMD/ISA capabilities on the host using check_cxx_source_compiles with -march=native. When cross-compiling, it prints a message instructing to specify capabilities manually via -DUSE_AVX2=ON. ```cmake cmake_minimum_required(VERSION 3.18.2 FATAL_ERROR) project(rapfi) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) #========================================================== # Auto-detect SIMD/ISA capability of the host include(CheckCXXSourceCompiles) function(bool_to_onoff in_var out_var) if(${in_var}) set(${out_var} ON PARENT_SCOPE) else() set(${out_var} OFF PARENT_SCOPE) endif() endfunction() set(DEFAULT_USE_SSE OFF) set(DEFAULT_USE_AVX2 OFF) set(DEFAULT_USE_AVX512 OFF) set(DEFAULT_USE_BMI2 OFF) set(DEFAULT_USE_VNNI OFF) set(DEFAULT_USE_NEON OFF) set(DEFAULT_USE_NEON_DOTPROD OFF) set(DEFAULT_USE_WASM_SIMD OFF) set(DEFAULT_USE_WASM_SIMD_RELAXED OFF) if(NOT CMAKE_CROSSCOMPILING) set(CMAKE_REQUIRED_FLAGS "-march=native") set(CMAKE_REQUIRED_QUIET TRUE) # ---- x86/AMD64 ---- check_cxx_source_compiles(" #include int main(){ __m128i a = _mm_setzero_si128(); (void)a; return 0; }" HAS_SSE) check_cxx_source_compiles(" #include int main(){ __m256i a = _mm256_setzero_si256(); (void)a; return 0; }" HAS_AVX2) check_cxx_source_compiles(" #include int main(){ __m512i a = _mm512_setzero_si512(); (void)a; return 0; }" HAS_AVX512) check_cxx_source_compiles(" #include int main(){ unsigned long long r = _pext_u64(0xFFFFULL, 0xAAULL); (void)r; return 0; }" HAS_BMI2) check_cxx_source_compiles(" #include int main(){ __m512i z = _mm512_setzero_si512(); __m512i r = _mm512_dpbusd_epi32(z, z, z); (void)r; return 0; }" HAS_AVX512_VNNI) check_cxx_source_compiles(" #include int main(){ __m256i z = _mm256_setzero_si256(); __m256i r = _mm256_dpbusd_avx_epi32(z, z, z); (void)r; return 0; }" HAS_AVX_VNNI) set(HAS_VNNI FALSE) if(HAS_AVX512_VNNI OR HAS_AVX_VNNI) set(HAS_VNNI TRUE) endif() # ---- ARM/ARM64 ---- check_cxx_source_compiles(" #include int main(){ int32x4_t a = vdupq_n_s32(0); (void)a; return 0; }" HAS_NEON) check_cxx_source_compiles(" #include int main(){ int32x4_t acc = vdupq_n_s32(0); int8x16_t a = vdupq_n_s8(0); int8x16_t b = vdupq_n_s8(0); int32x4_t r = vdotq_s32(acc, a, b); (void)r; return 0; }" HAS_NEON_DOTPROD) # ---- WebAssembly ---- check_cxx_source_compiles(" #include int main(){ v128_t x = wasm_i32x4_splat(0); (void)x; return 0; }" HAS_WASM_SIMD) check_cxx_source_compiles(" #include int main(){ v128_t acc = wasm_i32x4_splat(0); v128_t a = wasm_i8x16_splat(0); v128_t b = wasm_i8x16_splat(0); v128_t r = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(acc, a, b); (void)r; return 0; }" HAS_WASM_SIMD_RELAXED) bool_to_onoff(HAS_SSE DEFAULT_USE_SSE) bool_to_onoff(HAS_AVX2 DEFAULT_USE_AVX2) bool_to_onoff(HAS_AVX512 DEFAULT_USE_AVX512) bool_to_onoff(HAS_BMI2 DEFAULT_USE_BMI2) bool_to_onoff(HAS_VNNI DEFAULT_USE_VNNI) bool_to_onoff(HAS_NEON DEFAULT_USE_NEON) bool_to_onoff(HAS_NEON_DOTPROD DEFAULT_USE_NEON_DOTPROD) bool_to_onoff(HAS_WASM_SIMD DEFAULT_USE_WASM_SIMD) bool_to_onoff(HAS_WASM_SIMD_RELAXED DEFAULT_USE_WASM_SIMD_RELAXED) message(STATUS "Detected SIMD/ISA capability of the host:") message(STATUS " SSE: ${DEFAULT_USE_SSE}") message(STATUS " AVX2: ${DEFAULT_USE_AVX2}") message(STATUS " AVX512: ${DEFAULT_USE_AVX512}") message(STATUS " BMI2: ${DEFAULT_USE_BMI2}") message(STATUS " VNNI: ${DEFAULT_USE_VNNI}") message(STATUS " NEON: ${DEFAULT_USE_NEON}") message(STATUS " NEON_DOTPROD: ${DEFAULT_USE_NEON_DOTPROD}") message(STATUS " WASM_SIMD: ${DEFAULT_USE_WASM_SIMD}") message(STATUS " WASM_SIMD_RELAXED: ${DEFAULT_USE_WASM_SIMD_RELAXED}") else() message(STATUS "Cross-compiling detected. Please specify the SIMD/ISA capability manually like -DUSE_AVX2=ON.") endif() ``` -------------------------------- ### flat_set Lookup, Observers, and Non-member Functions Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/flat.hpp/README.md Documentation for the lookup, observer, and non-member functions of the flat_set container. ```APIDOC ## count ### Description Returns the number of elements matching the specified key. ### Signature ```cpp size_type count(const key_type& key) const; template < typename K > size_type count(const K& key) const; ``` ### Parameters - **key** (key_type or K) - The key to count. ### Returns - **size_type** - Number of elements with the given key. ``` ```APIDOC ## find ### Description Finds an element with the specified key. ### Signature ```cpp iterator find(const key_type& key); const_iterator find(const key_type& key) const; template < typename K > iterator find(const K& key); template < typename K > const_iterator find(const K& key) const; ``` ### Parameters - **key** (key_type or K) - The key to search for. ### Returns - **iterator** or **const_iterator** - Iterator to the element, or end() if not found. ``` ```APIDOC ## equal_range ### Description Returns a range containing all elements with the specified key. ### Signature ```cpp std::pair equal_range(const key_type& key); std::pair equal_range(const key_type& key) const; template < typename K > std::pair equal_range(const K& key); template < typename K > std::pair equal_range(const K& key) const; ``` ### Parameters - **key** (key_type or K) - The key to search for. ### Returns - **std::pair** or **std::pair** - Pair of iterators defining the range. ``` ```APIDOC ## lower_bound ### Description Returns an iterator to the first element not less than the given key. ### Signature ```cpp iterator lower_bound(const key_type& key); const_iterator lower_bound(const key_type& key) const; template < typename K > iterator lower_bound(const K& key); template < typename K > const_iterator lower_bound(const K& key) const; ``` ### Parameters - **key** (key_type or K) - The key to compare. ### Returns - **iterator** or **const_iterator** - Iterator to the first element not less than key. ``` ```APIDOC ## upper_bound ### Description Returns an iterator to the first element greater than the given key. ### Signature ```cpp iterator upper_bound(const key_type& key); const_iterator upper_bound(const key_type& key) const; template < typename K > iterator upper_bound(const K& key); template < typename K > const_iterator upper_bound(const K& key) const; ``` ### Parameters - **key** (key_type or K) - The key to compare. ### Returns - **iterator** or **const_iterator** - Iterator to the first element greater than key. ``` ```APIDOC ## key_comp ### Description Returns the key comparison function. ### Signature ```cpp key_compare key_comp() const; ``` ### Returns - **key_compare** - The key comparison function object. ``` ```APIDOC ## value_comp ### Description Returns the value comparison function. ### Signature ```cpp value_compare value_comp() const; ``` ### Returns - **value_compare** - The value comparison function object. ``` ```APIDOC ## swap (non-member) ### Description Swaps the contents of two flat_set containers. ### Signature ```cpp template < typename Key, typename Compare, typename Container > void swap(flat_set& l, flat_set& r); ``` ### Parameters - **l** (flat_set&) - First container. - **r** (flat_set&) - Second container. ``` ```APIDOC ## operator== ### Description Checks if two flat_set containers are equal. ### Signature ```cpp template < typename Key, typename Compare, typename Container > bool operator==(const flat_set& l, const flat_set& r); ``` ### Parameters - **l** (const flat_set&) - Left container. - **r** (const flat_set&) - Right container. ### Returns - **bool** - true if containers are equal. ``` ```APIDOC ## operator!= ### Description Checks if two flat_set containers are not equal. ### Signature ```cpp template < typename Key, typename Compare, typename Container > bool operator!=(const flat_set& l, const flat_set& r); ``` ### Parameters - **l** (const flat_set&) - Left container. - **r** (const flat_set&) - Right container. ### Returns - **bool** - true if containers are not equal. ``` ```APIDOC ## operator< ### Description Checks if the left container is lexicographically less than the right. ### Signature ```cpp template < typename Key, typename Compare, typename Container > bool operator<(const flat_set& l, const flat_set& r); ``` ### Parameters - **l** (const flat_set&) - Left container. - **r** (const flat_set&) - Right container. ### Returns - **bool** - true if l is less than r. ``` ```APIDOC ## operator> ### Description Checks if the left container is lexicographically greater than the right. ### Signature ```cpp template < typename Key, typename Compare, typename Container > bool operator>(const flat_set& l, const flat_set& r); ``` ### Parameters - **l** (const flat_set&) - Left container. - **r** (const flat_set&) - Right container. ### Returns - **bool** - true if l is greater than r. ``` ```APIDOC ## operator<= ### Description Checks if the left container is lexicographically less than or equal to the right. ### Signature ```cpp template < typename Key, typename Compare, typename Container > bool operator<=(const flat_set& l, const flat_set& r); ``` ### Parameters - **l** (const flat_set&) - Left container. - **r** (const flat_set&) - Right container. ### Returns - **bool** - true if l is less than or equal to r. ``` ```APIDOC ## operator>= ### Description Checks if the left container is lexicographically greater than or equal to the right. ### Signature ```cpp template < typename Key, typename Compare, typename Container > bool operator>=(const flat_set& l, const flat_set& r); ``` ### Parameters - **l** (const flat_set&) - Left container. - **r** (const flat_set&) - Right container. ### Returns - **bool** - true if l is greater than or equal to r. ``` -------------------------------- ### flat_multimap Constructors Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/flat.hpp/README.md Constructors and assignment operators for the flat_multimap class. ```APIDOC ## flat_multimap ### Description Constructs a flat_multimap container. The default constructor creates an empty container. Other constructors allow specifying a comparator, an allocator, an initial range of elements, or an initializer list. The `sorted_range_t` tag indicates that the input range is already sorted, allowing for more efficient construction. ### Method Constructor ### Signature ```cpp template < typename Key, typename Value, typename Compare = std::less, typename Container = std::vector> > class flat_multimap; ``` ### Parameters - **Compare** (type) - Optional - Comparison function object type for ordering keys. - **Container** (type) - Optional - Underlying container type, defaults to `std::vector>`. ### Constructors - `flat_multimap()` - Default constructor. - `explicit flat_multimap(const Compare& c)` - Constructs with a comparator. - `template explicit flat_multimap(const Allocator& a)` - Constructs with an allocator. - `template flat_multimap(const Compare& c, const Allocator& a)` - Constructs with comparator and allocator. - `template flat_multimap(InputIter first, InputIter last)` - Constructs from a range. - `template flat_multimap(sorted_range_t, InputIter first, InputIter last)` - Constructs from a sorted range. - `template flat_multimap(InputIter first, InputIter last, const Compare& c)` - Constructs from a range with comparator. - `template flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c)` - Constructs from a sorted range with comparator. - `template flat_multimap(InputIter first, InputIter last, const Allocator& a)` - Constructs from a range with allocator. - `template flat_multimap(sorted_range_t, InputIter first, InputIter last, const Allocator& a)` - Constructs from a sorted range with allocator. - `template flat_multimap(InputIter first, InputIter last, const Compare& c, const Allocator& a)` - Constructs from a range with comparator and allocator. - `template flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)` - Constructs from a sorted range with comparator and allocator. - `flat_multimap(std::initializer_list ilist)` - Constructs from an initializer list. - `flat_multimap(sorted_range_t, std::initializer_list ilist)` - Constructs from a sorted initializer list. - `flat_multimap(std::initializer_list ilist, const Compare& c)` - Constructs from an initializer list with comparator. - `flat_multimap(sorted_range_t, std::initializer_list ilist, const Compare& c)` - Constructs from a sorted initializer list with comparator. - `template flat_multimap(std::initializer_list ilist, const Allocator& a)` - Constructs from an initializer list with allocator. - `template flat_multimap(sorted_range_t, std::initializer_list ilist, const Allocator& a)` - Constructs from a sorted initializer list with allocator. - `template flat_multimap(std::initializer_list ilist, const Compare& c, const Allocator& a)` - Constructs from an initializer list with comparator and allocator. - `template flat_multimap(sorted_range_t, std::initializer_list ilist, const Compare& c, const Allocator& a)` - Constructs from a sorted initializer list with comparator and allocator. - `template flat_multimap(flat_multimap&& other, const Allocator& a)` - Move constructor with allocator. - `template flat_multimap(const flat_multimap& other, const Allocator& a)` - Copy constructor with allocator. - `flat_multimap(flat_multimap&& other)` - Move constructor. - `flat_multimap(const flat_multimap& other)` - Copy constructor. ### Assignment Operators - `flat_multimap& operator=(flat_multimap&& other)` - Move assignment. - `flat_multimap& operator=(const flat_multimap& other)` - Copy assignment. - `flat_multimap& operator=(std::initializer_list ilist)` - Assigns from an initializer list. ### Member Types - `key_type` - `Key` - `mapped_type` - `Value` - `value_type` - `Container::value_type` - `size_type` - `Container::size_type` - `difference_type` - `Container::difference_type` - `key_compare` - `Compare` - `container_type` - `Container` - `reference` - `Container::reference` - `const_reference` - `Container::const_reference` - `pointer` - `Container::pointer` - `const_pointer` - `Container::const_pointer` - `iterator` - `Container::iterator` - `const_iterator` - `Container::const_iterator` - `reverse_iterator` - `Container::reverse_iterator` - `const_reverse_iterator` - `Container::const_reverse_iterator` ### Member Classes - `class value_compare;` - Comparison functor for value_type. ### Example ```cpp flat_multimap fm; fm.emplace(1, "one"); fm.emplace(2, "two"); ``` ``` -------------------------------- ### Append to the existing zip archive Source: https://github.com/dhbloo/rapfi/blob/master/Rapfi/external/zip/README.md Opens an existing zip archive in append mode ('a') and adds a new entry with a buffer write. ```c struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'a'); { zip_entry_open(zip, "foo-3.txt"); { const char *buf = "Append some data here...\0"; zip_entry_write(zip, buf, strlen(buf)); } zip_entry_close(zip); } zip_close(zip); ```