1197 Commits
Author SHA1 Message Date
Patrick Pelissier 46759b5f2c Rename _push_raw method to _push_back_raw method (Cleaner semantic) 2025-07-26 10:35:48 +02:00
Patrick Pelissier 8c8a1e2822 Fix bug reported by florommel on dict's reserve 2025-07-18 20:11:13 +02:00
Patrick Pelissier ad646f5e04 Update links 2025-07-01 22:17:49 +02:00
Patrick Pelissier 9ecc031fd7 Fix doc 2025-06-10 22:18:24 +02:00
Patrick Pelissier ea3c2c5019 Update doc 2025-06-10 22:15:34 +02:00
Patrick Pelissier a9dc2eef12 Update doc 2025-05-31 00:11:49 +02:00
Patrick Pelissier 39a0a4f672 Fix format 2025-05-29 15:06:36 +02:00
Patrick Pelissier 4ffa4a15ac Rename example 2025-05-29 15:01:21 +02:00
Patrick Pelissier 2d5c9e71ae Add new example 2025-05-29 14:58:25 +02:00
Patrick Pelissier e802e22b7b Port to new API 2025-05-29 14:58:09 +02:00
Patrick Pelissier 3fbe8ec0b6 Update _transform, _reduce and _map_reduce to be more flexible
Rename _map_reduce to _transform_reduce
2025-05-29 10:41:20 +02:00
Patrick Pelissier 34085aa637 WIP to allow recursive variant 2025-05-29 10:40:19 +02:00
Patrick Pelissier 77033e2020 Move to V0.8.1 2025-05-29 10:39:42 +02:00
Patrick Pelissier 5c57ad1f51 Add example on tree 2025-05-24 17:40:29 +02:00
Patrick Pelissier 27621db95d Add method _left, right, _up and _down for tree to get directly an iterator to the requested element 2025-05-24 17:38:57 +02:00
Patrick Pelissier eab3f701a8 Fix displayed size in case of overflow computation 2025-05-24 10:18:15 +02:00
Patrick Pelissier cbc5f17cf0 Update Makefile and dependencies 2025-05-11 11:22:49 +02:00
PpHd 02a39fce3f Merge pull request #134 from P-p-H-d/feature/new-memory-model
New memory model
2025-05-08 22:14:17 +02:00
Patrick Pelissier 7c4f94a674 Remove obsolete m-mempool.h header 2025-05-07 22:09:56 +02:00
Patrick Pelissier 8c70a1f96c Remove obsolete m-concurrent.h header 2025-05-07 22:01:38 +02:00
Patrick Pelissier 25dcdeed69 Remove obsolete m-i-shared.h header 2025-05-07 21:57:53 +02:00
Patrick Pelissier 7e8cb07a6c Port to shared-ptr interface 2025-05-07 21:50:26 +02:00
Patrick Pelissier 2296f203fd Remove obsolete m-shared.h header 2025-05-07 21:34:18 +02:00
Patrick Pelissier 790ae33334 Remove obsolete m-c-mempool.h header 2025-05-07 21:28:13 +02:00
Patrick Pelissier d795476157 Update version 2025-05-07 21:02:55 +02:00
Patrick Pelissier 6a2bdc49fb Update API incompatibility & documentation 2025-05-07 21:02:24 +02:00
Patrick Pelissier 725f42852e Update markdown 2025-05-07 21:02:24 +02:00
Patrick Pelissier bfcc4134d6 Fix markdown 2025-05-07 21:02:24 +02:00
Patrick Pelissier de6ccc293e Update doc
Update M_USE_GLOBAL_CONTEXT definition to be simpler.
2025-05-07 21:02:24 +02:00
Patrick Pelissier d9953daf59 Update doc 2025-05-07 21:02:24 +02:00
Patrick Pelissier 1a62f5a4ed Update doc 2025-05-07 21:02:24 +02:00
Patrick Pelissier 3721129da1 Update prototype of memory functions
to always get the memory context parameter
(even if it is not needed) to provide a cleaner
and simpler user interface
(instead of requesting the user to use directly m_context).
2025-05-07 21:02:24 +02:00
Patrick Pelissier f585167fa8 Simplify code (remove redundant intermediary macro) 2025-05-07 21:02:24 +02:00
Patrick Pelissier 6d5d34fb72 Update 2025-05-07 21:02:24 +02:00
Patrick Pelissier 196db1cf62 Improve test suite 2025-05-07 21:02:24 +02:00
Patrick Pelissier 174c62015b Workaround wrong analyze by GCC analyzer 2025-05-07 21:02:24 +02:00
Patrick Pelissier fb3140e645 Fix warning of unused variable. 2025-05-07 21:02:24 +02:00
Patrick Pelissier 431e3a1228 Update doc (WIP) 2025-05-07 21:02:24 +02:00
Patrick Pelissier 3ddf9438da Update 2025-05-07 21:02:24 +02:00
Patrick Pelissier 6e8aa58bd6 Update doc 2025-05-07 21:02:24 +02:00
Patrick Pelissier df37a5d8f1 Fix 2025-05-07 21:02:24 +02:00
Patrick Pelissier 2ad8d42401 Update summary 2025-05-07 21:02:24 +02:00
Patrick Pelissier 8f47fb35ae Use of context for nearly all M*LIB 2025-05-07 21:02:24 +02:00
Patrick Pelissier a1a5ae749d Fix oplist of bitset 2025-05-07 21:02:24 +02:00
Patrick Pelissier 147bc0a363 Fix ALGO and oplist doesn't providing IT_REF 2025-05-07 21:02:24 +02:00
Patrick Pelissier 33aa102b7c Port DualPush list to new format 2025-05-07 21:02:24 +02:00
Patrick Pelissier bd9485a3fe Port algo to new memory format 2025-05-07 21:02:24 +02:00
Patrick Pelissier 0de3c622e3 Port algo to new memory format 2025-05-07 21:02:24 +02:00
Patrick Pelissier 93a1be616d Rename parameter pool to context 2025-05-07 21:02:24 +02:00
Patrick Pelissier 692c0487af Update oplist for new memory model 2025-05-07 21:02:24 +02:00
Patrick Pelissier 22ccae74c3 Minor optimization of stable_sort 2025-05-07 21:02:24 +02:00
Patrick Pelissier 586d0ae13a Update documentation 2025-05-07 21:02:24 +02:00
Patrick Pelissier c7bad98a7e Port ARRAY oplist to support local memcontext 2025-05-07 21:02:24 +02:00
Patrick Pelissier 8e3a06b852 Simplify OPLIST definition as INIT_MOVE is mandatory for arrays 2025-05-07 21:02:24 +02:00
Patrick Pelissier d548117538 Make M*LIB stricter for INIT_MOVE operator:
* either the default INIT_MOVE operator works ('=')
* either an INIT_MOVE method is defined
* or it is disabled.
As a consequence, fix usage of testobj_t and mpz_t in the repository

The emulation layer of INIT_MOVE using INIT_SET+CLEAR is removed:
it wasn't working correctly with the local memory context
(INIT_MOVE doesn't need any local memory context to work,
 whereas INIT_SET/CLEAR does)
Remove macro M_DO_INIT_MOVE as it is now useless and uses M_CALL_INIT_MOVE.

The INIT_MOVE default method no longer sets the old 'src' to '0':
it was useless (it doesn't catch any error) and complicates compiler parsing.

Fix POD & A1 & CSTR & classic oplists definition (missing INIT_MOVE operators).
2025-05-07 21:02:24 +02:00
Patrick Pelissier 3a39ce5a4a Reformat 2025-05-07 21:02:24 +02:00
Patrick Pelissier fa41f3affd M_INIT_VAI supports API 2025-05-07 21:02:24 +02:00
Patrick Pelissier 0d0747dea9 Update oplists 2025-05-07 21:02:24 +02:00
Patrick Pelissier ab75397e21 TCC now supports m-generic 2025-05-07 21:02:24 +02:00
Patrick Pelissier cc97aa887f Fix reference 2025-05-07 21:02:24 +02:00
Patrick Pelissier b275859a37 Fix issue if BString is empty 2025-05-07 21:02:24 +02:00
Patrick Pelissier 256ff916a2 Port serial to new memory format 2025-05-07 21:02:24 +02:00
Patrick Pelissier 77195fb1d0 Remove m-mutex header 2025-05-07 21:02:24 +02:00
Patrick Pelissier c2cfb2f0a0 Cleanup & support of M_USE_GLOBAL_POOL 2025-05-07 21:02:24 +02:00
Patrick Pelissier 03cceafd73 Update 2025-05-07 21:02:24 +02:00
Patrick Pelissier 505e2c4a62 Fix spelling 2025-05-07 21:02:24 +02:00
Patrick Pelissier daadf693f7 Update doc 2025-05-07 21:02:24 +02:00
Patrick Pelissier 98b3bbd7a1 Fix for MACOS 2025-05-07 21:02:24 +02:00
Patrick Pelissier decec8f7ae Fix for tcc 2025-05-07 21:02:24 +02:00
Patrick Pelissier ce3f674ba8 Add new header m-queue (Doc to do) 2025-05-07 21:02:24 +02:00
Patrick Pelissier 01f5228a36 Port to new memory model:
Communication thread buffer needs to use the global pool,
and not a local pool, since the allocation is done accross
several threads.
Therefore the non thread fixed queue & stack interfaces are moved into
a dedicated header (m-queue)
and remove support for non thread stack & queue into m-buffer
Remove also deprecated policy too.
2025-05-07 21:02:24 +02:00
Patrick Pelissier a7294abe0c Update documentation and error message 2025-05-07 21:02:24 +02:00
Patrick Pelissier 77e5666802 Update string oplist definition with pool 2025-05-07 21:02:24 +02:00
Patrick Pelissier 689527c2dc Port m-shared-ptr to new memory model
(use global pool)
2025-05-07 21:02:24 +02:00
Patrick Pelissier 5d1ebdf5bb Update obsolete header files:
* remove obsolete m-mutex header file
* mark m-concurrent, m-shared and m-i-shared as obsolete (They won't support new memory model)
2025-05-07 21:02:24 +02:00
Patrick Pelissier 10d918bbc9 Port to new memory model (add global context 0) 2025-05-07 21:02:24 +02:00
Patrick Pelissier 8069fae3d5 Remove use of invalid representation, which is refused by clang & C++ 2025-05-07 21:02:24 +02:00
Patrick Pelissier 94dd0a5571 Add example of using pool 2025-05-07 21:02:24 +02:00
Patrick Pelissier 32a3d95104 Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier d08aeb32fe Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier 26fc2bcffe Port tree to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier 7617048073 Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier 57e7510ae7 Format 2025-05-07 21:02:23 +02:00
Patrick Pelissier 324ba5d256 Port to new memory model: M_MEMORY_FULL cannot return anymore 2025-05-07 21:02:23 +02:00
Patrick Pelissier 8939b4d046 New memory model is for 0.8.0 version 2025-05-07 21:02:23 +02:00
Patrick Pelissier 1cf7c4fa4d Port to new memory model: M_MEMORY_FULL cannot return anymore 2025-05-07 21:02:23 +02:00
Patrick Pelissier 839e7c2957 Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier 06e3046268 Port to new memory interface 2025-05-07 21:02:23 +02:00
Patrick Pelissier e959c001aa Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier bcc9f2c894 Port B+TREE to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier 6e828eabaf Port list to new memory pool
Remove support for mempool. A new support for mempool should be provided later through the new memory context parameter (TODO / better API)
2025-05-07 21:02:23 +02:00
Patrick Pelissier 7677b13d8a Update contract comment. 2025-05-07 21:02:23 +02:00
Patrick Pelissier e16c6987e4 Port to new memory interface (remove mempool support, but it was undocumented) 2025-05-07 21:02:23 +02:00
Patrick Pelissier aa4cbfebdb Port to new memory interface 2025-05-07 21:02:23 +02:00
Patrick Pelissier 66f376ea80 Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier 6de8eab5c3 Add comments, rename macro for maintenance 2025-05-07 21:02:23 +02:00
Patrick Pelissier 9e63289a38 Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier bf617ab6ab Port to new memory interface (WIP) 2025-05-07 21:02:23 +02:00
Patrick Pelissier 3f8c30e592 Port ARRAY & STRING to new memory model with memory context support 2025-05-07 21:02:23 +02:00
Patrick Pelissier 37b2f4d2ac Update test suite to properly allocation & deallocation 2025-05-07 21:02:23 +02:00
Patrick Pelissier 50e8d1f469 Fix old size parameter for memory allocation 2025-05-07 21:02:23 +02:00
Patrick Pelissier d40a6e5bc3 Document limitation 2025-05-07 21:02:23 +02:00
Patrick Pelissier b4c29d5423 Update spec 2025-05-07 21:02:23 +02:00
Patrick Pelissier 9f4f9d1d5d Update 2025-05-07 21:02:23 +02:00
Patrick Pelissier 1e196fe22a Port to new spec M_MEMORY_FULL 2025-05-07 21:02:23 +02:00
Patrick Pelissier 450d2c9000 Update spec of M_MEMORY_FULL 2025-05-07 21:02:23 +02:00
Patrick Pelissier 93112a5a7c Update example 2025-05-07 21:02:23 +02:00
Patrick Pelissier 1f2584ccea Port to new memory model 2025-05-07 21:02:23 +02:00
Patrick Pelissier 5b4c9cd618 Update spec of memory functions 2025-05-07 21:02:23 +02:00
Patrick Pelissier f4e3d9cd4c Release V0.7.4 2025-05-07 21:02:01 +02:00
Patrick Pelissier 4988661b7d Fix target armv6 (2) for Continuous Integration 2025-05-06 00:47:29 +02:00
Patrick Pelissier 7033a922c7 Fix target armv6 for Continuous Integration 2025-05-05 23:50:43 +02:00
Patrick Pelissier dd607252eb Add target risc64, ppc64le and armv6 for Continuous Integration 2025-05-05 23:46:09 +02:00
Patrick Pelissier 73da9a4316 Update obsolete header section 2025-04-18 21:58:15 +02:00
Patrick Pelissier b3a0d70147 Fix memory safety errors in examples. 2025-04-08 21:46:16 +02:00
Patrick Pelissier c55bb6b9ad Fix random segfault on AARCH64 CI 2025-03-13 22:24:13 +01:00
Patrick Pelissier 68fdc2dde1 Fix undefined behavior in using setjmp 2025-03-06 15:38:44 +01:00
Patrick Pelissier 8877af10b0 Update copyright 2025-03-03 23:45:04 +01:00
Patrick Pelissier 782963dec5 Add example of disabling small name usage 2025-03-01 12:20:28 +01:00
Patrick Pelissier 36d11bc2bd Fix small name usage 2025-03-01 12:19:35 +01:00
Patrick Pelissier 6d621703eb Copyright go to 2025 year 2025-03-01 11:03:38 +01:00
Patrick Pelissier 76b40d247d Fix #133 : forgotten const for second argument (reported by Brian Sipos) 2025-02-03 23:12:22 +01:00
Patrick Pelissier 033deac9f5 Workaround for GCC 12 bug in warning 2025-02-03 23:06:41 +01:00
Patrick Pelissier b60553165d Fix usage of M_USE_SMALL_NAME (Reported by Brian Sipos) 2025-02-03 22:33:07 +01:00
Patrick Pelissier e1a4d359a2 Update doc 2025-02-02 10:50:41 +01:00
Patrick Pelissier 4ab2615a1c Clarify constraint on _splice 2024-12-25 20:48:34 +01:00
Patrick Pelissier 9136a4a972 Update 2024-12-08 19:34:15 +01:00
Patrick Pelissier 55dcf0e438 Fix example 2024-11-30 13:04:45 +01:00
Patrick Pelissier fb604f02b7 Update / add todo 2024-11-30 10:26:11 +01:00
Patrick Pelissier 1db417e30e Rename _new_copy into _clone 2024-11-30 10:25:51 +01:00
Patrick Pelissier 5b77fe7207 Add some missing const in the interface 2024-11-30 10:25:36 +01:00
Patrick Pelissier dd509f2b7e Update documentation of new shared pointer interface. 2024-11-30 10:25:15 +01:00
Patrick Pelissier 50d4e15297 Simplify lock as mutex should be released by the thread that performed the initial lock to be portable 2024-11-26 22:26:25 +01:00
Patrick Pelissier f6d1b16338 Fix C++ warning 2024-11-25 00:04:54 +01:00
Patrick Pelissier 64a035559d Update test suite 2024-11-24 23:57:22 +01:00
Patrick Pelissier c4bc37560c Improve testing of new shared pointer
Adding measure of coverage. Need to move some codes outside the main C file, to avoid polluting the measure of the coverage by some functions we don't need to measure.
2024-11-24 18:21:21 +01:00
Patrick Pelissier e7309b7d3a Add forgotten "const" attribute to string_length_u and string_utf8_p 2024-11-24 18:20:19 +01:00
Patrick Pelissier c461b4eca4 Update shared pointer new interface 2024-11-24 11:26:30 +01:00
Patrick Pelissier f21d427de1 Convert example to new shared ptr interface 2024-11-16 18:02:13 +01:00
Patrick Pelissier 0f9edaa7ee Fix oplist usage of new shared-ptr 2024-11-16 18:01:58 +01:00
Patrick Pelissier 64888127c4 Update to get the lastest v2 2024-11-16 16:55:42 +01:00
Patrick Pelissier d5b4ec249b Update test suite 2024-11-16 13:26:21 +01:00
Patrick Pelissier 0bcd78a8f5 Fix warning. 2024-11-12 22:31:05 +01:00
Patrick Pelissier 27b0850af4 Fix case of the same variable is passed as 2/3 arguments of a function. 2024-11-12 22:26:45 +01:00
Patrick Pelissier ae55ccfc40 Update test to consider change of default for deque 2024-11-11 23:56:33 +01:00
Patrick Pelissier 5bf644ccf0 Improve test suite 2024-11-11 22:38:10 +01:00
Patrick Pelissier 3f09adc507 Fix ADD/SUB/MUL/DIV methods of a shared pointer 2024-11-11 22:38:02 +01:00
Patrick Pelissier 4e851142c2 Change the operator POP of a DEQUE to pop_front instead of pop_back:
it is more inline with what we expects / uses a deque for.
(buffer FIFO)
2024-11-11 22:36:56 +01:00
Patrick Pelissier fec6b42260 Add comment 2024-11-11 21:47:54 +01:00
Patrick Pelissier 9dbc48aa5d Update 2024-11-09 19:07:08 +01:00
Patrick Pelissier b92bae34eb Update comments 2024-11-09 14:54:16 +01:00
Patrick Pelissier 8faf7f79c4 Add first test cases for m-shared-ptr 2024-11-09 14:27:16 +01:00
Patrick Pelissier c3e29a16df Fix warnings 2024-11-09 14:26:57 +01:00
Patrick Pelissier 1bc33a10fc Fix issues (WIP) 2024-11-09 11:12:12 +01:00
Patrick Pelissier b7074d1c69 Fix some issues 2024-11-06 23:13:23 +01:00
Patrick Pelissier 26d541fe06 Move internal functions to internal namespace 2024-11-05 23:17:28 +01:00
Patrick Pelissier 2991c7cc5a Add oplist 2024-11-02 23:35:21 +01:00
Patrick Pelissier 4e7cbae766 Add short name support 2024-11-02 17:35:25 +01:00
Patrick Pelissier d5e0620e4c Minor fix 2024-11-02 17:21:59 +01:00
Patrick Pelissier 32cfbd23bc Update comments. 2024-11-02 16:59:40 +01:00
Patrick Pelissier 0e09681a6a Move m_typeof to core module. 2024-10-30 23:42:45 +01:00
Patrick Pelissier bc8098b337 Update comments. 2024-10-30 23:31:47 +01:00
Patrick Pelissier c5692e7e9f Update comment 2024-10-28 17:46:48 +01:00
Patrick Pelissier f43db93791 Adding first WIP version of the new shared pointer header. 2024-10-27 22:01:00 +01:00
Patrick Pelissier 14c954c6ce Adding new property:
multithread safety if the container handles itself the multi thread
2024-10-27 20:38:36 +01:00
Patrick Pelissier 60280087c7 Fix default of FULL_P 2024-10-27 20:37:57 +01:00
Patrick Pelissier 1e57d9c6d6 Fix default of FULL_P 2024-10-27 19:48:47 +01:00
Patrick Pelissier eeaf74d24f Add FULL_P operator
Add M_EMPLACE_LIST_TYPE_VAR_ALTER which doesn't put a comma before.
2024-10-26 16:56:54 +02:00
Patrick Pelissier a318d36c35 Fix concurrent access. 2024-10-19 11:55:41 +02:00
Patrick Pelissier edcf8ee37a Final update of the byte string 2024-10-05 11:40:23 +02:00
Patrick Pelissier 8a1f30eeff Finish implementation of Byte String 2024-10-05 10:23:47 +02:00
Patrick Pelissier 2995b119b7 Add precision 2024-10-05 10:21:19 +02:00
Patrick Pelissier 08bd5a888b Fix formatting 2024-10-05 10:21:09 +02:00
Patrick Pelissier 2f1b17f805 Fix for clang 2024-09-26 22:36:45 +02:00
Patrick Pelissier 0379f5f1c6 Add header for handling Byte String as per #123
API designed for streaming bytes and easy integration with other libraries.
2024-09-26 22:33:03 +02:00
Patrick Pelissier 45b11fb49b Fix #129:
Support of incomplete type in m-shared.
2024-09-21 12:39:29 +02:00
Patrick Pelissier 82ea4341de Fix documentation (#128) 2024-08-19 22:02:56 +02:00
Patrick Pelissier 341d145b4d Fix internal terminoligy 2024-07-26 23:22:58 +02:00
Patrick Pelissier 847f52fa5e Fix clang warning 2024-07-11 22:07:51 +02:00
Patrick Pelissier 02828a0109 Fix interface of Intrusive List
(Reported by Brian Sipos):
* incorrect clear operator usage
* useless prototype of _insert, inconsistent with the policy of other functions
* syntax error in _insert
2024-07-11 21:41:14 +02:00
Patrick Pelissier 0f7d5bf366 Update doc 2024-06-15 09:51:51 +02:00
Patrick Pelissier 1277c75ea3 Update doc 2024-06-15 09:47:10 +02:00
Patrick Pelissier 47a51ee5c4 Update doc 2024-06-15 09:45:13 +02:00
Patrick Pelissier 3f102c2270 Use of memcmp instead of strcmp for string_equal_p 2024-06-12 23:15:56 +02:00
Patrick Pelissier 4ba55dc3ca Rename new USE directive to be uniform with string one. 2024-06-08 00:08:27 +02:00
Patrick Pelissier 2c0db40158 Simplify logic for set_at of both dict,
(after analyzing which condition is likely)
which should help code size & performance
a little bit.
2024-06-01 23:49:08 +02:00
Patrick Pelissier 8987288a10 Fix spelling 2024-06-01 11:05:35 +02:00
Patrick Pelissier cf8c2afddd Fix warning on previous modification 2024-06-01 11:03:39 +02:00
Patrick Pelissier 0a8e336037 Fix internal & subtil issue
when comparing two methods to check for their presence in an oplist, we may generate the name of an already existing macro.
For example, in the oplist (SIZE())
when we expanded we get the macro M_ADD_SIZE to check if ADD is present,
but M_ADD_SIZE is an already existing macro, which generates an error.
To avoid this issue, define a prefix for the definition of the operators (M_X)
2024-06-01 10:47:21 +02:00
Patrick Pelissier e7e29d913e Add new example of variant 2024-06-01 10:16:59 +02:00
Patrick Pelissier f3ebc8c7eb Update comments 2024-06-01 10:16:47 +02:00
Patrick Pelissier 2d4fc9dc97 Allow generation of EMPLACE_TYPE
for variant if all oplists defined a FIELD operator.
2024-06-01 10:16:39 +02:00
Patrick Pelissier afedb06dee Fix buffer overflow in 32 bits mode 2024-05-28 23:31:26 +02:00
Patrick Pelissier 3fd2146bbe Fix issue in 32 bits mode 2024-05-28 23:31:16 +02:00
Patrick Pelissier 8e70b6175a Fix clang warning 2024-05-28 23:14:44 +02:00
Patrick Pelissier 67e9c8ff06 New internal string format:
* maximum size of a string is 2^32-1 now by default on a 64 bits system (can be increased using M_USE_STRING_LARGE_INDEX if needed).
* This reduce consumption of a string_t from 24 bytes to 16 bytes.
* Change the stack representation of a string, so that it lets 15 allocated bytes for the user even in 64 bytes mode. For 32 bits system, it increases to 15 allocated byte for stack representation.
* synthetic performance benchmark shows a little bit of decrease of performance. But performance in real application shows a significant increase (probably due to the reduced size of the type).
*Augment test suite to be sure to test all corner cases of the new representaiton.
2024-05-28 23:05:54 +02:00
Patrick Pelissier bf59c53921 Migrate to V0.7.4 2024-05-27 00:39:00 +02:00
Patrick Pelissier 5589105f5c Update comments 2024-05-27 00:34:24 +02:00
Patrick Pelissier 66d2aa26d3 Fix clang warning 2024-05-15 21:19:43 +02:00
Patrick Pelissier 1ae904dff2 Add support of INITçWITH for variant
in C11 / provided all types of the variant are exclusive.
2024-05-15 20:46:20 +02:00
Patrick Pelissier 4549f4ab91 Improve comments 2024-05-14 21:29:47 +02:00
Patrick Pelissier 75d5627378 Simplify logic and should increase performance 2024-05-13 23:25:11 +02:00
Patrick Pelissier 8cbd27e629 Fix overflow 2024-05-12 22:59:58 +02:00
Patrick Pelissier 333cc2ccf8 Provide prefetch on non GCC target & compatible 2024-05-12 22:59:58 +02:00
Patrick Pelissier 000dba1da5 Correct API documentation 2024-05-11 09:43:20 +02:00
Patrick Pelissier 11946f155d Update 2024-05-11 09:21:10 +02:00
Patrick Pelissier 99713e873c Add example of multi B+Tree 2024-05-11 09:19:10 +02:00
Patrick Pelissier ea5c993ff0 Add bulk_update for DICT OA 2024-05-09 19:28:46 +02:00
Patrick Pelissier 22d62f94bb Add WIP bulk functions for DICT/OA 2024-05-09 14:10:22 +02:00
Patrick Pelissier 8fd79f07d5 Mark the functions to be optimized
those that shall not be.
2024-05-07 10:05:49 +02:00
Patrick Pelissier 29fe80a6af Adding M_HOT_ATTRIBUTE 2024-05-07 10:05:23 +02:00
Patrick Pelissier e787b64978 Fix issue in C wrapper 2024-05-07 09:51:33 +02:00
Patrick Pelissier 4f9db5eba6 Remove unused header 2024-05-07 08:20:59 +02:00
Patrick Pelissier db5990de03 DICT:
* Reduce  memory allocation usage
2024-05-05 19:26:07 +02:00
Patrick Pelissier d4383ef854 DICT:
* Reduce  memory allocation usage
* Add more assertions
2024-05-05 11:32:28 +02:00
Patrick Pelissier d10c8c1b41 Fix comment 2024-05-05 10:18:26 +02:00
Patrick Pelissier 3c669548a2 Update to dev version 0.7.3 2024-05-04 19:56:51 +02:00
Patrick Pelissier ec11230b5e Fix shrink_to_fit for dict 2024-05-03 19:16:51 +02:00
Patrick Pelissier 567473869b Update documentation 2024-05-03 16:42:51 +02:00
Patrick Pelissier 0b6733fdcb Ass _reserve method for standard dict 2024-05-03 16:40:35 +02:00
Patrick Pelissier 8e330862e1 [Coverage] Adding missing tests 2024-05-03 10:03:22 +02:00
Patrick Pelissier b2adc77d76 Update issues 2024-05-02 22:47:03 +02:00
Patrick Pelissier 82cbe9e282 Reformat 2024-05-02 17:12:48 +02:00
Patrick Pelissier 93429c8bf3 Simplify GET OA_DICT code 2024-05-02 16:25:03 +02:00
Patrick Pelissier 150bef4d4d Add more assertion and control for new dict. 2024-05-02 14:05:00 +02:00
Patrick Pelissier 562fd875e9 Improve test suite 2024-05-02 14:04:38 +02:00
Patrick Pelissier 5513a9df1b Fix issue in new dict for case of erase all / reset scenario 2024-05-02 01:15:15 +02:00
Patrick Pelissier 6fd2610eec Fix valgrind warning 2024-05-01 23:39:49 +02:00
Patrick Pelissier 11bf5e4691 Fix C++ compatibility and compound literals... 2024-05-01 23:08:29 +02:00
Patrick Pelissier cf0d82a706 Update 2024-05-01 22:57:33 +02:00
Patrick Pelissier b0cc17ea86 Update documentation with newest dictionary properties 2024-05-01 22:56:14 +02:00
Patrick Pelissier 04d4bf6866 Complete new version of normal dictionary :
* limits: max elements is 0.75*2^32
* much faster
* use less memory
2024-05-01 22:39:36 +02:00
Patrick Pelissier 738123d4a7 Fix the example 2024-05-01 22:17:59 +02:00
Patrick Pelissier a3ece09e66 Add new tests for exception and bitsets 2024-04-29 22:44:02 +02:00
Patrick Pelissier 8109c094db Update comments 2024-04-29 22:43:46 +02:00
Patrick Pelissier 2c81582419 Improve static analyzer report 2024-04-29 22:35:27 +02:00
Patrick Pelissier f8c79d9259 Add support for exception for emplace function for list/array 2024-04-27 09:04:47 +02:00
Patrick Pelissier c7a894b34e Fix format 2024-04-27 09:04:20 +02:00
Patrick Pelissier 5c36e045ff Add proper support for exception for DEQUE 2024-04-27 08:55:51 +02:00
Patrick Pelissier 0f883d2ecf Simplify code 2024-04-26 23:59:11 +02:00
Patrick Pelissier 9dfcf41b64 Improve detection of error 2024-04-23 21:14:36 +02:00
Patrick Pelissier 1416f4e225 Fix issue 2024-04-23 21:13:37 +02:00
Patrick Pelissier 16c6a13fb1 Make string functions exception aware 2024-04-22 23:41:23 +02:00
Patrick Pelissier 9382cdc0f7 Improve exception integration tests 2024-04-22 23:00:04 +02:00
Patrick Pelissier ced2719760 Make string functions exception aware 2024-04-22 22:59:54 +02:00
Patrick Pelissier 1798530284 Fix issue in string_fgets
where it could be blocked infinity in the parsing
2024-04-22 22:51:59 +02:00
Patrick Pelissier 68f890a015 Improve exception integration tests 2024-04-22 22:47:11 +02:00
Patrick Pelissier 5805038943 Make string functions exception aware 2024-04-22 22:47:00 +02:00
Patrick Pelissier 2395ceb3d2 Remove obsolete and undocumented STRING_DECL_INIT macro 2024-04-20 00:42:38 +02:00
Patrick Pelissier 2b455c5c6b Fix test issue in C++ 2024-04-20 00:42:07 +02:00
Patrick Pelissier d466e76702 Factorize common test function 2024-04-13 08:19:05 +02:00
Patrick Pelissier 9d33c85e13 Fix issue in _push_front_new
Make list services compatible with exception
2024-04-13 08:02:07 +02:00
Patrick Pelissier 4e24e7a533 Improve exception integration tests 2024-04-13 08:01:36 +02:00
Patrick Pelissier 0914c26b8d Update test suite
testing more functions in exception scenario
2024-04-11 01:00:06 +02:00
Patrick Pelissier c245285123 Make more array/list functions exception aware 2024-04-11 00:55:47 +02:00
Patrick Pelissier be4ff6f94d Make list functions exception aware 2024-04-08 23:12:23 +02:00
Patrick Pelissier aa055d0b00 Add tests for exception + lists 2024-04-08 23:10:14 +02:00
Patrick Pelissier e7d6e0d6ac Generate dependency for new files 2024-04-08 23:08:39 +02:00
Patrick Pelissier 8f97a194ae Add m_volatile 2024-04-08 23:08:16 +02:00
Patrick Pelissier b191baec8b Make array functions exception aware 2024-04-06 19:14:36 +02:00
Patrick Pelissier e4a85cdc61 Add tests for exception+array 2024-04-06 19:13:38 +02:00
Patrick Pelissier 12ee3213b0 Simplify M_ON_EXCEPTION / M_IF_EXCEPTION 2024-04-06 19:13:08 +02:00
Patrick Pelissier 6cba7ad8ba Update 2024-04-06 19:12:35 +02:00
Patrick Pelissier 955c8bfb81 Adding new example of generic 2024-04-04 22:35:08 +02:00
Patrick Pelissier 8602a259fd Adding let & print as synonymous in m-generic mode 2024-04-04 22:31:27 +02:00
Patrick Pelissier 7404e63b53 Fix C++ / G++ introduced issue 2024-03-31 22:22:41 +02:00
Patrick Pelissier c539eb57b7 Prepare exception aware integration 2024-03-31 21:55:02 +02:00
Patrick Pelissier 3c4943015b Fix introduced issue with TCC 2024-03-27 00:28:06 +01:00
Patrick Pelissier c9fef6d80a Fix issues in reworked lock:
* starving of writer threads by reader threads
* monopolization of memory bus by reader threads.
2024-03-26 23:11:57 +01:00
Patrick Pelissier 5174781a7a Improve internal backoff to perform
lazy initialization of the seed.
2024-03-26 23:11:03 +01:00
Patrick Pelissier 7bf9f6a377 Update comments 2024-03-26 22:47:13 +01:00
Patrick Pelissier 7575681e27 Rewrite Read / Write lock to be less costly 2024-03-26 22:41:41 +01:00
Patrick Pelissier cfab3cf0cf Add m_mutex_trylock function 2024-03-26 22:41:04 +01:00
Patrick Pelissier a523a97a0e Update doc 2024-03-18 22:44:53 +01:00
Patrick Pelissier 6f75bb938b Update doc 2024-03-18 22:32:16 +01:00
Patrick Pelissier a22046bc2a Update doc 2024-03-15 14:40:47 +01:00
Patrick Pelissier 84ee15b2e7 Remove workaround
This header is already quite demanding on compiler compliance , so there is no need to implement workaround for old compilers.
2024-03-15 14:40:36 +01:00
Patrick Pelissier fd6a8f1361 Update doc 2024-03-14 23:27:23 +01:00
Patrick Pelissier d22e75d7a0 Make I/O functions exception aware.
Simplify their logic
Fix other bugs.
2024-03-08 00:15:08 +01:00
Patrick Pelissier ca25dfb537 Add missing TYPE operator name in the error message if it is missing in the oplist 2024-02-27 01:12:29 +01:00
Patrick Pelissier e2159109b3 Update analysis of issues 2024-02-24 12:17:30 +01:00
Patrick Pelissier cc6bdbf06c Add missing method name in the error message
if the method is missing.
2024-02-23 22:52:05 +01:00
PpHd cd37efc69d Merge pull request #115 from derskythe/feat-styled-readme
Refine explanations and improve formatting in README.md
2024-02-08 13:32:47 +01:00
DerSkythe db08e62f1a Fix incorrect word-wrap of defines 2024-02-08 15:31:52 +04:00
DerSkythe 3be653d55a Improve README.md formatting and clarifications
Corrections were made according PR #115
2024-02-08 11:48:40 +04:00
DerSkythe e351730ad0 Refine explanations and improve formatting in README.md
Several corrections and readability enhancements were applied to the README.md file. This includes fixing typos, changing the format of code examples, refining links to sections, and adjusting the indenting of API documentation listings for better readability. General explanations and instructions about the API usage and the constructor and destructor behavior were also improved.
2024-02-07 00:58:25 +04:00
Patrick Pelissier d7a232364f Update infrastructure to the fact that the bench directory has been deleted 2024-01-19 22:27:33 +01:00
Patrick Pelissier f7580e7ce9 Move bench directory to https://github.com/P-p-H-d/c-stl-comparison
since it is better to have the comparison centralized in one place.
2024-01-19 21:53:20 +01:00
Patrick Pelissier 26cec1591a * Remove some obsolete macros
* Fix spelling
* A little bit of refactoring
2024-01-19 21:37:47 +01:00
Patrick Pelissier 52b58c5a51 Happy new year 2024 2024-01-19 21:37:47 +01:00
Patrick Pelissier 8902a752f5 Migrate to V0.7.2 2023-12-31 13:02:42 +01:00
PpHd 3445da13f3 Merge generic interface (WIP) 2023-12-31 12:53:10 +01:00
Patrick Pelissier 127530abaa Fix format 2023-12-30 16:27:25 +01:00
Patrick Pelissier ed0f538fb7 Add documentation of generic interface 2023-12-30 16:23:02 +01:00
Patrick Pelissier 76ef061dec Add basic example of generic interface 2023-12-30 16:23:02 +01:00
Patrick Pelissier c98786a3b3 Update TODO items 2023-12-30 16:23:02 +01:00
Patrick Pelissier 422f3c2c04 Add GENTYPE operator to all oplists 2023-12-30 16:23:02 +01:00
Patrick Pelissier 5ceb34d980 Cosmetics changes 2023-12-30 16:23:02 +01:00
Patrick Pelissier 73e3d1d1bd Register string_t globally 2023-12-30 16:23:02 +01:00
Patrick Pelissier 044a085fb6 Fix support for pop generic macro function 2023-12-30 16:23:02 +01:00
Patrick Pelissier 5344423ad9 Reorder header / comment 2023-12-30 16:23:02 +01:00
Patrick Pelissier 76ea989865 Fix warnings 2023-12-30 16:23:02 +01:00
Patrick Pelissier 29c4ba3dcc Add support for M_PRINT 2023-12-30 16:23:02 +01:00
Patrick Pelissier 42184f69db Disable generic tests for TCC 2023-12-30 16:23:02 +01:00
Patrick Pelissier fb8bf65233 Worlaround for warning with clang 2023-12-30 16:23:02 +01:00
Patrick Pelissier 1d86e51f4a Improve test suite 2023-12-30 16:23:02 +01:00
Patrick Pelissier 53c35a22d7 First version of Generic header 2023-12-30 16:23:02 +01:00
Patrick Pelissier 722737d60c Add M_QUAD internal macros 2023-12-30 16:23:02 +01:00
Patrick Pelissier f951a947ec Adding a try catch example 2023-12-30 13:42:47 +01:00
Patrick Pelissier d9401371a6 Fix warnings reported by CLANG,
the C warning generator.
2023-12-23 13:16:42 +01:00
Patrick Pelissier 690fd72c8b Fix documentation 2023-12-23 11:24:25 +01:00
Patrick Pelissier d318493c6c Remove M_PRINT_ARG macro to simplify maintenance
(M_FPRINT_MACRO with stdout can be used instead)
2023-12-22 23:46:07 +01:00
Patrick Pelissier fecece19cb Add retry for TCC due the random segfault it generates 2023-12-22 23:45:39 +01:00
Patrick Pelissier ea640482a7 Add new examples with custom allocation 2023-12-20 19:25:27 +01:00
Patrick Pelissier 3e558af559 Remove unused function 2023-12-20 19:24:57 +01:00
Patrick Pelissier 91a602f774 Add bench of boost unordered flat hashmap 2023-12-19 20:58:02 +01:00
Patrick Pelissier 6a5c136c72 Complete bench-verstable with bench on big structure 2023-12-13 19:35:08 +01:00
Patrick Pelissier e50fdc82ef Add benchmark for verstable 2023-12-12 23:59:17 +01:00
Patrick Pelissier ec0a082701 Update ISSUE 2023-12-12 22:57:13 +01:00
Patrick Pelissier 7bf3ea3a87 Update Function Object interface
to make interface trivially copiable

There is no need to perform a copy-protected type as there is no init/clear for this type.
It is always created through an instance.
2023-12-09 12:40:45 +01:00
Patrick Pelissier 15492394ad Update list of exported files 2023-12-08 20:58:47 +01:00
Patrick Pelissier 09f40b5695 Fix format 2023-12-08 20:58:33 +01:00
Patrick Pelissier eabfcd1d49 Update list of ignored files 2023-12-08 00:25:53 +01:00
Patrick Pelissier 00aeafc616 Update comments 2023-12-06 23:55:11 +01:00
Patrick Pelissier f512051807 Migrate to actions/checkout@v4 2023-12-06 23:52:04 +01:00
Patrick Pelissier 4e8b929da9 Migrate to vmactions/freebsd-vm v1 2023-12-06 23:51:40 +01:00
Patrick Pelissier 5841f936e6 Work around static analyzer
that raise an issue on freeing non heap pointer
2023-12-02 13:48:21 +01:00
Patrick Pelissier 2ee40339b0 Using emplace to generate init_with for shared_ptr:
Equivalent to C++ make_shared)
2023-12-02 13:21:45 +01:00
Patrick Pelissier 0c8eca893d Add example of REST client
by using libcurl for HTTP connection
and M*LIB for JSON formating.
2023-11-25 13:33:27 +01:00
Patrick Pelissier b16048a55b Add test cases for tuple emplace 2023-11-25 13:32:57 +01:00
Patrick Pelissier 9dc582c6bc Add emplace set functions for tuple 2023-11-25 13:30:08 +01:00
Patrick Pelissier 1df8bf84fb Fix oplist definition for tuple.
The oplist didn't include as many sub-oplists as the number of variables.
2023-11-25 13:29:48 +01:00
Patrick Pelissier e017a90e5c Fix format 2023-11-04 19:28:32 +01:00
Patrick Pelissier 58b317b759 Add timeout for run in VM 2023-11-04 18:50:43 +01:00
Patrick Pelissier 3a057fc319 M_STATIC_ASSERT: provide expression compatible
macro even in pure C11 mode
(Remove GCC extension)

Add M_OPL_AS_STR to display the oplist conditionnaly as the generated string may be too big for some compilers.

Translate some M_STATIC_FAILURE into M_STATIC_ASSERT
as M_STATIC_FAILURE is not an expression whereas M_STATIC_ASSERT is an expression.
2023-11-04 18:48:13 +01:00
Patrick Pelissier 703ab6ff9c Update examples 2023-11-04 18:48:13 +01:00
Patrick Pelissier f7f5db61d3 Fix formatting 2023-11-01 11:13:54 +01:00
Patrick Pelissier 32b00eb433 Add new operator GENTYPE 2023-10-21 19:05:08 +02:00
Patrick Pelissier 796f2619e5 Change M_BY_NARGS semantics:
simplify suffix by __ # NARGS
instead of __NARGS_ # NARGS

Driver: reduce macro name length.
2023-10-20 00:02:38 +02:00
Patrick Pelissier 268192138a WIP M_ON_EXCEPTION 2023-10-19 22:54:51 +02:00
Patrick Pelissier 0671a2ea41 Update doc 2023-10-15 22:21:12 +02:00
Patrick Pelissier 07dce84e51 Tuple init: handle case of exception
during construction of tuple
2023-10-14 20:15:14 +02:00
Patrick Pelissier 5f4303624f Adding macro M_CHAIN_OBJ 2023-10-14 15:55:59 +02:00
Patrick Pelissier 19e61467d5 Adding tuple generation
for analysis of generated code.
2023-10-14 15:31:37 +02:00
Patrick Pelissier 1454bcebe4 Add unique name identifier
in order to avoid Wshadow warning
in generated code.
2023-10-14 15:30:57 +02:00
Patrick Pelissier d48f2ff84d Update comment 2023-10-06 22:38:36 +02:00
Patrick Pelissier 269636b4d8 Update doc with new macro M_CHAIN_INIT 2023-09-09 18:40:59 +02:00
Patrick Pelissier bf68340106 Add macro M_CHAIN_INIT for support of partially constructed object. 2023-09-09 18:40:32 +02:00
Patrick Pelissier 5dba526e29 Update ISSUES 2023-09-08 22:12:16 +02:00
Patrick Pelissier 469239adcd Update comments 2023-08-24 23:32:47 +02:00
Patrick Pelissier 589abda0c2 Fix bug in list insertion:
The output iterator has its previous field incorrect.
2023-08-13 23:27:12 +02:00
Patrick Pelissier 8f141896ba Clarify operators for memory allocation 2023-08-02 23:20:02 +02:00
Patrick Pelissier a0cbec4329 Support of output failure for serialization of strings 2023-08-02 23:20:02 +02:00
Patrick Pelissier df66db562d Add comments 2023-08-01 00:33:43 +02:00
Patrick Pelissier 1829a70601 Update documentation 2023-07-20 23:42:15 +02:00
Patrick Pelissier e9b25f2414 Rename internal field size to capacity
to match what it is used for.
2023-07-13 21:48:33 +02:00
Patrick Pelissier c9bb739f24 Fix format 2023-07-10 00:59:18 +02:00
Patrick Pelissier e049b83a9e Rename M_SUFFIX_FUNCTION_BY_NARGS in M_BY_NARGS
and updates suffix with __NARGS_
in order to be more explicit.
2023-07-10 00:58:31 +02:00
Patrick Pelissier 31ac3999a1 Add new operators 2023-07-07 22:17:39 +02:00
Patrick Pelissier a0818419ab Fix format 2023-07-04 01:08:40 +02:00
Patrick Pelissier 496f885a84 Add threads backend for FreeRTOS tasks. 2023-07-04 01:07:59 +02:00
Patrick Pelissier d5d9a4bd5c Update documentation of threads 2023-07-04 00:46:32 +02:00
Patrick Pelissier ca9571a110 Fix no stdio:
M_CSTR macro cannot be available if there is no stdio
2023-06-29 21:26:22 +02:00
Patrick Pelissier 4497214b9c Fix spelling 2023-06-29 00:32:23 +02:00
PpHd ccb1658afd Provide way of avoiding code duplication for multiple source C files
Use of compiler extension for that, only compatible for GCC /CLANG.
This provides easy and total customization (for example non template functions like strings can also avoid code duplication).
2023-06-13 23:46:58 +02:00
Patrick Pelissier eaf2783f1a Synchro with master branch 2023-06-11 23:32:42 +02:00
Patrick Pelissier 5705819814 Update doc 2023-06-11 23:32:02 +02:00
Patrick Pelissier 91f5f513c4 Update macro names
Make global logic easier.
2023-06-11 23:32:02 +02:00
Patrick Pelissier 3dec4e2cbe Fix example 2023-06-11 23:32:02 +02:00
Patrick Pelissier e70766beaa Update list of ignored file 2023-06-11 23:32:02 +02:00
Patrick Pelissier d7639f0ae0 Update example to match new semantic 2023-06-11 23:32:02 +02:00
Patrick Pelissier c63ce84e45 Update logic to select which linkage to use
so that user code can be written easily
M_USE_EXTERN_DECL / M_USE_DECL activates functions that are not inlined.
If M_USE_EXTERN_DEF / M_USE_DEF is also defined, then the definition is emitted instead of the declaration.
2023-06-11 23:32:02 +02:00
Patrick Pelissier a043c379c0 Update user code as per new liberty 2023-06-11 23:32:02 +02:00
Patrick Pelissier 92bb380117 Rewrite order in preprocessing if to simplify user code 2023-06-11 23:32:02 +02:00
Patrick Pelissier 6bb7a184db Fix compil rules 2023-06-11 23:32:02 +02:00
Patrick Pelissier fa9163be9d Make linker options optional 2023-06-11 23:32:02 +02:00
Patrick Pelissier 0bade1563c Also build exn.exe by default 2023-06-11 23:32:02 +02:00
Patrick Pelissier 1278d2f8a0 Implement noinline another way 2023-06-11 23:32:02 +02:00
Patrick Pelissier 53af2aae68 Add example of separating inline & function code 2023-06-11 23:32:02 +02:00
Patrick Pelissier 17ded6fcc8 Update M_USE_EXTERN_FINE_GRAINED to avoid warnings 2023-06-11 23:32:02 +02:00
Patrick Pelissier 19ce371533 Add support for M_USE_EXTERN_FINE_GRAINED to enable / disable inline semantics alongside the translation unit by redefining it when needed 2023-06-11 23:32:02 +02:00
Patrick Pelissier 0bd1bcb68e Another way to request the desired semantics, compatible with clang 2023-06-11 23:32:02 +02:00
Patrick Pelissier b50813713a Define internal M_INLINE:
it is used to control the inline semantics.
By combining it with optimize option "-fno-inline"
for the internal M*LIB function (using _Pragma optimize)
we can control easily if we want to use an inline version
or call of an external function.

Define new user API:
* M_USE_EXTERN_DECL : define it before including any MLIB header to requests to call the M*LIB functions and don't inline then.
* M_USE_EXTERN_DEF  : define it once in a translation unit to define the M*LIB functions. This translation unit shall contain all templated macro too.
If you use one option, you need to use the other one too for another translation unit.
2023-06-11 23:32:02 +02:00
Patrick Pelissier 2628536d20 Add +m_string_it_set_ref 2023-06-10 01:50:14 +02:00
Patrick Pelissier ecfa4a9152 Add new function string_pop_u
to pop the last unicode code point
of a string.
2023-06-03 00:59:34 +02:00
Patrick Pelissier dafe4bcec5 Add basic test for M_DEFAULT_ARGS
Print hint to developper in case of incorrect usage
2023-06-03 00:56:13 +02:00
Patrick Pelissier 8544a7f289 Update example 2023-05-30 14:01:30 +02:00
Patrick Pelissier aa18915d61 Fix overflow computation 2023-05-21 00:15:58 +02:00
Patrick Pelissier df4bc0a56c Remove alloc warning for analyzer:
it is not able to track allocations correctly and only give false warnings.
valgraind or memory sanitizer are much more reliable to track memory errors.
2023-05-13 00:52:06 +02:00
Patrick Pelissier b6046e5e23 Fix new warnings with GCC13 2023-05-13 00:52:06 +02:00
Patrick Pelissier b487bfe5ad Adding missing inline 2023-05-08 23:54:16 +02:00
PpHd 408272c810 Merge pull request
Add m_string_cat_vprintf
2023-05-08 23:35:54 +02:00
kitterion 6a9ee17eca Add tests 2023-05-08 23:17:19 +03:00
kitterion 05c5a94634 Add m_string_cat_vprintf 2023-05-08 20:52:47 +03:00
Patrick Pelissier b1b0927e9f Update examples 2023-05-06 21:54:08 +02:00
Patrick Pelissier 37770365a1 Fix several bugs:
* in case of some invalid format starting with ']' directly it wrongly assume that the parsing was valid.
* incase of exception handling, and an exception was raised during the internal parsing, some destructors wern't called.
2023-05-05 22:16:39 +02:00
Patrick Pelissier 82bdcc685a Add internal macro MQLET for internal M_LET use 2023-05-05 22:15:13 +02:00
Patrick Pelissier 26fa733f70 Fix format 2023-05-05 22:14:41 +02:00
Patrick Pelissier cd2fc05573 Add FIXED_SIZE property 2023-05-05 21:41:05 +02:00
Patrick Pelissier 33430d4359 Update 2023-04-29 18:46:09 +02:00
Patrick Pelissier dc95b49f05 Update 2023-04-29 12:07:10 +02:00
Patrick Pelissier 3ec24cfa40 Update 2023-04-29 11:41:08 +02:00
Patrick Pelissier 12b099dcf8 Update 2023-04-29 11:25:56 +02:00
Patrick Pelissier b885d6136c Update 2023-04-29 11:20:00 +02:00
Patrick Pelissier b51c4bea2b Update 2023-04-29 11:19:54 +02:00
Patrick Pelissier 302c5eb300 Remove export passthrough of NEW/DEL/REALLOC/FREE interface
from the container oplist.
It has no real practical purpose.
NEW/DEL/REALLOC/FREE shall be a property of the container
to be defined, and not a property for an already defined container.
2023-04-29 10:50:04 +02:00
Patrick Pelissier 6d2900a2bd Improve coverage of test suite. 2023-04-27 00:04:44 +02:00
Patrick Pelissier 573e09c56e Remove variable number of elements support which was not working.
Request an explicit number of elements.
2023-04-27 00:04:03 +02:00
Patrick Pelissier 0a39a17d36 The undefined number of element value of serial _array_start
is now (size_t)-1 and no longer 0.
Moreoever, a serialization interface may refuse outputting data
if it doesn't know the number of elements.
In which case, the container shall explictly compute the number
of elements and recall the serial object _array_start method.
2023-04-27 00:01:50 +02:00
Patrick Pelissier a913d0947c Rewrite code to fix coverage 2023-04-26 23:34:13 +02:00
Patrick Pelissier abbd8ad6ce Update 2023-04-26 22:56:23 +02:00
Patrick Pelissier a09c9fe1c3 Update 2023-04-26 22:56:23 +02:00
Patrick Pelissier 219c62ff5d Provide a way to alter the standard naming convention for the functions
Close #72
2023-04-22 09:33:08 +02:00
Patrick Pelissier 272a326375 Fix warning issue for coverage 2023-04-22 09:23:18 +02:00
Patrick Pelissier eca79f2c80 Improve coverage of test suite 2023-04-21 22:44:34 +02:00
Patrick Pelissier 2feda4059f Fix issue in case of invalid IO 2023-04-21 22:44:23 +02:00
Patrick Pelissier de0ef67cf2 Fix build issue with VC++ 2023-04-19 23:06:23 +02:00
Patrick Pelissier 95762a058c Fix const attribute of _get_emplace 2023-04-19 22:42:21 +02:00
Patrick Pelissier acd8671017 Fix test case according to contract. 2023-04-19 22:37:54 +02:00
Patrick Pelissier a6c1688f23 Fix issue in remove root node for tree (part 2) 2023-04-19 22:37:40 +02:00
Patrick Pelissier f6ed549ce5 Fix issue in tree_remove for root node index (Part 2)
Enable support of removing root node
In this case, it considers the first child of the root as the new root (breaking symetry)
2023-04-18 23:24:48 +02:00
Patrick Pelissier 8639fdbd98 Fix issue in tree_remove when it is root node (part 1) 2023-04-18 22:56:56 +02:00
Patrick Pelissier 693b09387f Improve coverage of test suite. 2023-04-18 22:19:41 +02:00
Patrick Pelissier 4052d3794b Tree: Transform runtime tests into assertion
as it is proven that it cannot happen.
2023-04-18 22:19:28 +02:00
Patrick Pelissier 044e9c3bf7 Fix benchmark 2023-04-17 16:56:57 +02:00
Patrick Pelissier 45a2a1afb2 Add bench for CC 2023-04-16 21:16:04 +02:00
Patrick Pelissier b44e4e09dd Don't use builtin for clang as they are not properly supported. 2023-04-16 20:11:56 +02:00
Patrick Pelissier 5158059ec4 Make m_throw a classic "cold" function rather than a static inline function.
Since the function shall be rarely called, there is no point in inlining/duplicating it
in several units.
2023-04-16 19:26:15 +02:00
Patrick Pelissier 7279011f0a Use of the builtin versions of setjmp /longjmp for GCC / CLANG
They are more than twice faster on extreme bench of M\_LET / M\_TRY scenario
(and still twice slower than C++).
They also use less stack usage.
2023-04-16 19:18:04 +02:00
Patrick Pelissier 79369e9b05 Update README 2023-04-16 19:16:08 +02:00
Patrick Pelissier 58a7a7c214 Add gene TRY 2023-04-16 19:15:54 +02:00
Patrick Pelissier e3e94ca238 Add M_ATTR_COLD_FUNCTION attribute 2023-04-16 19:15:22 +02:00
Patrick Pelissier ae81271b2a Fix name of internal variable for M_DEFER 2023-04-16 08:33:45 +02:00
Patrick Pelissier d9c3724cff Compatiblity with C++ 2023-04-15 23:18:45 +02:00
Patrick Pelissier 1ff9848384 Update test so that it tests also the case of throwing without any try section (override M_RAISE_FATAL) 2023-04-15 22:51:57 +02:00
Patrick Pelissier 83e7f2a641 Use of new M_ATTR_NO_RETURN attribute 2023-04-15 22:50:47 +02:00
Patrick Pelissier 6580601969 Add M_ATTR_NO_RETURN attribute support (not C23 compatible yet) 2023-04-15 22:50:27 +02:00
Patrick Pelissier ad023bb09d Improve coverage of the test suite 2023-04-13 23:27:01 +02:00
Patrick Pelissier b5df21f9c5 Simplify function: for LCA both iterators shall be in the same tree 2023-04-13 23:26:12 +02:00
Patrick Pelissier d2dccbf514 Add table of contents 2023-04-12 20:35:22 +02:00
Patrick Pelissier a8075cbb05 Transform runtime test into assertion
as it is proven that it cannot happen.
2023-04-11 21:57:56 +02:00
Patrick Pelissier 1322afc4c9 Improve coverage of test suite 2023-04-11 21:53:14 +02:00
Patrick Pelissier 0f885fb158 Fix coverage source for m-core 2023-04-11 21:32:57 +02:00
Patrick Pelissier 25a2eb0875 Correct syntax 2023-04-11 21:32:38 +02:00
Patrick Pelissier 6bcd51f10f Complete coverage synthesis
with branch coverage information
2023-04-11 21:09:40 +02:00
Patrick Pelissier 9c1cb9c835 Update doc 2023-04-11 00:07:33 +02:00
Patrick Pelissier 19cb329ae6 Simplfy example 2023-04-11 00:05:41 +02:00
Patrick Pelissier 8099e6a94f Update doc 2023-04-11 00:04:46 +02:00
Patrick Pelissier ce6cc080d6 Improve coverage of test suite 2023-04-10 23:09:18 +02:00
Patrick Pelissier a27b0b4014 Fix wrong parsing of malformed dict. 2023-04-10 23:08:51 +02:00
Patrick Pelissier e74f80cc59 Update doc 2023-04-08 11:32:15 +02:00
Patrick Pelissier bafd307247 Update performance chapter 2023-04-08 11:27:37 +02:00
Patrick Pelissier 6bed3ac697 Print time with 2 digits after the decimal 2023-04-08 11:25:59 +02:00
Patrick Pelissier b8a9073fc9 Fix issue to generate graph without any repetition 2023-04-08 11:25:05 +02:00
Patrick Pelissier da3e71c676 Fix introduced warning in release mode 2023-04-08 11:23:32 +02:00
Patrick Pelissier 4ea83e129e Improve coverage of test suite 2023-04-08 00:17:33 +02:00
Patrick Pelissier fc34fa80b5 Properly mark condition for entering memory failure. 2023-04-07 23:50:03 +02:00
Patrick Pelissier 4f608ec266 Fix target of run 2023-04-06 22:02:49 +02:00
Patrick Pelissier ccaa54d2a5 Improve coverage of the tet suite 2023-04-06 21:55:21 +02:00
Patrick Pelissier 095bf7070d Rewrite loop to avoid final assert(0) 2023-04-06 21:55:06 +02:00
Patrick Pelissier 676b12d5d2 Fix warnings 2023-04-05 23:15:39 +02:00
Patrick Pelissier f858aa2cb5 Improve coverage of the test suite. 2023-04-05 23:07:52 +02:00
Patrick Pelissier 9d77448a25 Reduce optimization level to 0
Otherwise the coverage results are not reliable:
* some uncovered lines are not reported as uncovered
* some covered lines are reported as uncovered (!)
2023-04-05 23:04:22 +02:00
Patrick Pelissier 8babc33b91 Rewrite code differently to be more robust
and improve coverage of the test suite
2023-04-05 22:41:33 +02:00
Patrick Pelissier 352d7cf725 Improve coverage of the test suite 2023-04-05 22:22:49 +02:00
Patrick Pelissier a6993ab758 Overload assert in coverage mode
to avoid polluting the report with untaken branch by the assert macro.
2023-04-05 22:22:01 +02:00
Patrick Pelissier 48260ac2a6 Ignore temporary coverage files 2023-04-05 22:21:23 +02:00
Patrick Pelissier e4afb024b9 Improve coverage of test suite 2023-04-05 00:38:44 +02:00
Patrick Pelissier 63008af30f Add assertions 2023-04-05 00:38:32 +02:00
Patrick Pelissier 1828aca65e Fix preprocessing 2023-04-05 00:38:16 +02:00
Patrick Pelissier 9354e9717d Remove unused test function 2023-04-04 01:06:32 +02:00
Patrick Pelissier 100c0f22fe Improve test coverage 2023-04-04 00:48:03 +02:00
Patrick Pelissier ff778528f8 Improve coverage of the test suite 2023-04-04 00:22:49 +02:00
Patrick Pelissier 8f1a1df617 Improve coverage of test suite 2023-04-03 16:38:54 +02:00
Patrick Pelissier 28faf815d7 Improve robustness against broken I/O file 2023-04-03 14:09:34 +02:00
Patrick Pelissier fe3b703d0a Don't expand isspace for coverage tests 2023-04-03 14:09:07 +02:00
Patrick Pelissier 0aa6a9f0cf Update comments 2023-04-03 13:19:50 +02:00
Patrick Pelissier 67832ac918 Add more tests case for IO parsing 2023-04-03 13:18:28 +02:00
Patrick Pelissier 669a3297c7 Fix issue in ispace usage and allow more space in formating (to be more uniform. The allowed spaces before were in strange place only) 2023-04-03 13:18:10 +02:00
Patrick Pelissier 25d4829d7b Add utilities function for parsing FILE or char* while skipping space character 2023-04-03 13:17:25 +02:00
Patrick Pelissier ebab05a789 Improve coverage of test suite 2023-04-03 12:36:35 +02:00
Patrick Pelissier 727df5b7bf Fix coverage 2023-04-03 00:36:18 +02:00
Patrick Pelissier aebe1308fc Improve coverage computation 2023-04-03 00:23:05 +02:00
Patrick Pelissier 1d163a396e Replace assert by M_ASSERT 2023-04-03 00:12:00 +02:00
Patrick Pelissier 7534aa0d61 Add internal M_UNLIKELY_NOMEM to help coverage computation 2023-04-03 00:05:29 +02:00
Patrick Pelissier 6976d4e23d Remove (broken) auto check of coverage 2023-04-02 23:02:48 +02:00
Patrick Pelissier 6b7954e141 Fix coverage for new files 2023-04-02 22:52:40 +02:00
Patrick Pelissier c27d76a83b Remove assert & contract from coverage to avoid polluting reports 2023-04-02 22:45:56 +02:00
Patrick Pelissier 0e3081bfc6 Include branch probabilities in report 2023-04-02 22:45:35 +02:00
Patrick Pelissier d754e9a15f Update doc for _get_emplace functions for associative array 2023-03-29 22:59:54 +02:00
Patrick Pelissier 4e4e21793c Add _get_emplace functions for associative array 2023-03-29 22:59:43 +02:00
Patrick Pelissier c515da9f37 Update documentation 2023-03-29 22:50:51 +02:00
Patrick Pelissier 961b93bd4c Add test for M_LET + associative array 2023-03-28 23:43:49 +02:00
Patrick Pelissier 39a719c3f0 Fix warnings 2023-03-28 23:43:21 +02:00
Patrick Pelissier 8b643b4878 Add support for emplace detection in associative array + M_LET 2023-03-28 23:43:08 +02:00
Patrick Pelissier 876c394fba Fix format 2023-03-28 23:42:25 +02:00
Patrick Pelissier 81439c9437 Fix grammar 2023-03-27 01:05:53 +02:00
Patrick Pelissier 191ef7d09e Fix grammar 2023-03-27 00:55:08 +02:00
Patrick Pelissier bd4131dd8f Fix typo 2023-03-27 00:53:31 +02:00
Patrick Pelissier cfe8293c64 Cleanup documentation 2023-03-25 10:25:52 +01:00
Patrick Pelissier ea2715aa75 Remove static assert. Some old compilers failed to simplify into a constant expression, resulting in build failure 2023-03-24 23:54:49 +01:00
Patrick Pelissier f69cec6820 Fix warning with clang+const char * type 2023-03-24 21:53:23 +01:00
Patrick Pelissier 085f371693 Update doc 2023-03-24 21:12:28 +01:00
Patrick Pelissier 16a0a5c1a3 Add new examples 2023-03-24 21:11:15 +01:00
Patrick Pelissier 3953f81884 Update 2023-03-24 21:10:59 +01:00
Patrick Pelissier 8365888e6e Add Oplist inheritanc chapter 2023-03-24 20:38:51 +01:00
Patrick Pelissier c3f6e3c5f0 Add trivial script to separate preproc of compilation for debug 2023-03-19 00:29:51 +01:00
Patrick Pelissier 4cafe4dce1 Fix steps to debug 2023-03-19 00:29:06 +01:00
Patrick Pelissier 9f8b97ae46 Rename fields of m_exception_t:
data->context
n->num
2023-03-18 18:11:23 +01:00
Patrick Pelissier 030bea9c11 Add test for M_DEFER & M_LET_IF in exceptions 2023-03-18 17:57:46 +01:00
Patrick Pelissier e33894f1b3 Finish support for M_DEFER / M_LET_IF & exceptions 2023-03-18 17:57:15 +01:00
Patrick Pelissier 66f5e6c67d Support for more than one expression in M_DEFER 2023-03-18 17:56:44 +01:00
Patrick Pelissier 78c6dce068 Update doc 2023-03-18 17:56:11 +01:00
Patrick Pelissier 0798480ad5 Refactoring & implement support for RAII with M_DEFER 2023-03-18 17:39:56 +01:00
Patrick Pelissier e8322215fd Update doc about clang 2023-03-18 17:39:20 +01:00
Patrick Pelissier 42d3042c15 Add NOCLEAR property to M_BASIC_OPLIST and prepare injection for M_DEFER 2023-03-18 17:25:08 +01:00
Patrick Pelissier b7214ad11d Adding test of NOCLEAR property 2023-03-18 17:20:30 +01:00
Patrick Pelissier 08b4bc9052 M_LET_IF reuses clear mechanism provided by M_DEFER 2023-03-18 15:14:31 +01:00
Patrick Pelissier d813171e8a Add new test generation 2023-03-18 09:15:39 +01:00
Patrick Pelissier d1094999f5 Update M_ASSERT to separate requirement for predicate 2023-03-18 09:15:11 +01:00
Patrick Pelissier c8354aa6ed Update doc 2023-03-18 08:08:33 +01:00
Patrick Pelissier ab3aa33fac Add M_SET_THROUGH_INIT_SET 2023-03-18 08:08:23 +01:00
Patrick Pelissier 01f2f376e2 Update doc 2023-03-18 00:21:46 +01:00
Patrick Pelissier 535e00366a Correct reported errors 2023-03-18 00:21:37 +01:00
Patrick Pelissier 42111ec22a Rename field of m_exception_t 2023-03-17 22:13:18 +01:00
Patrick Pelissier ef0e849616 Fix test 2023-03-17 22:04:50 +01:00
Patrick Pelissier 9c516c2055 Update doc 2023-03-17 21:56:27 +01:00
Patrick Pelissier db48b985c3 Update doc 2023-03-17 21:48:56 +01:00
Patrick Pelissier 888796ca06 Update doc 2023-03-17 21:48:07 +01:00
Patrick Pelissier 144ae9c5ed Add ID support for GAIA 2023-03-17 21:47:04 +01:00
Patrick Pelissier 6223c93b53 Update doc 2023-03-17 20:21:19 +01:00
Patrick Pelissier 30f7656822 Update documentation 2023-03-17 20:15:42 +01:00
PpHd 8209a0c32a Merge pull request #107 from jonadem/patch-1
Fix typos
2023-03-17 20:14:38 +01:00
Jona 92e6957320 Fix typos 2023-03-17 14:00:49 +01:00
Patrick Pelissier b3c9f6ee47 Add support of exception for Visual C++ 2023-03-14 20:00:11 +01:00
Patrick Pelissier ab8bbad3f4 Fix syntax 2023-03-13 23:54:52 +01:00
Patrick Pelissier 9047376b7f Add m-try.h in HEADER 2023-03-13 23:53:36 +01:00
Patrick Pelissier dfed8dbc50 Fix format 2023-03-13 23:53:26 +01:00
Patrick Pelissier 2d3c25cd85 TCC doesn't support the __thread attribute,
which is a GCC extension.
Use this extension only for GCC.
2023-03-13 23:45:28 +01:00
Patrick Pelissier bfa948dc7a Add WIP implementation for the exception memory model:
add header m-try that defines the M_TRY / M_CATCH macros
that macros similarly to the C++ try / catch keywords.
Add implementation for C++, GCC, CLANG and pure C compiler.
2023-03-13 23:31:50 +01:00
Patrick Pelissier 94b6d1b9fd Fix computation of HASH_FINAL 2023-03-13 22:17:10 +01:00
Patrick Pelissier 0ddd5ddc6d Add AARCH64 target for CI 2023-03-13 21:04:05 +01:00
Patrick Pelissier cba93d5bb4 Add SC library 2023-03-12 21:12:21 +01:00
Patrick Pelissier d02de75487 Add control that all initialized testobj are properly cleared at the end of the test suite 2023-03-12 20:29:58 +01:00
Patrick Pelissier 2f57766249 Rename NOEXCEPT to NOCLEAR property as NOEXCEPT
doesn't provide enough guarantee to the exception handler.
2023-03-12 20:23:31 +01:00
Patrick Pelissier 3ff01e37eb Update documentation for properties 2023-03-05 19:44:36 +01:00
Patrick Pelissier 5683df0f22 Adding test for M_TEST_NOEXCEPT_P 2023-03-05 19:44:21 +01:00
Patrick Pelissier 11dc7afc06 Add NOEXCEPT property and M_TEST_NOEXCEPT_P macro to test it 2023-03-05 19:44:04 +01:00
Patrick Pelissier 9e2ae3f101 Update example 2023-03-05 18:30:47 +01:00
Patrick Pelissier c35aa9c891 Replace the M_ASSERT(0) by M_ASSUME(0) since they are not reachable (in order to inform the compiler of this fact) 2023-03-05 00:50:40 +01:00
Patrick Pelissier 2fc31d8c12 Factorization find of item in prioqueue 2023-03-03 23:23:06 +01:00
Patrick Pelissier 4f8d0a7156 Split macro 2023-03-03 23:12:40 +01:00
Patrick Pelissier aaf5bbd6a0 Separate IO from core macro 2023-03-03 23:03:24 +01:00
Patrick Pelissier 2f76652f2b Maintenance 2023-03-03 22:50:14 +01:00
Patrick Pelissier 942cf32519 Maintenance: separate macros for type and core functions. 2023-03-03 22:02:07 +01:00
Patrick Pelissier c1c9cb9cd3 Update example 2023-03-03 20:12:50 +01:00
Patrick Pelissier 76bfb48685 Update freebsd CI to be more robust. 2023-03-02 23:41:59 +01:00
Patrick Pelissier afff412f7a Maintenance: continue splitting huge macros into smaller ones. 2023-03-02 00:39:08 +01:00
Patrick Pelissier e48dcdeecc Factorization & assertions 2023-02-27 14:05:59 +01:00
Patrick Pelissier 12fae5c36c Update example 2023-02-26 23:43:57 +01:00
Patrick Pelissier 3f9129c7ed Update comments 2023-02-26 23:43:57 +01:00
Patrick Pelissier b918f61f4f Update example 2023-02-26 23:43:57 +01:00
Patrick Pelissier 93b69d0f8b Fix call of memcpy with size=0 and src=NULL 2023-02-25 12:17:18 +01:00
Patrick Pelissier b3440a2edd Fix position of assertions 2023-02-24 20:35:32 +01:00
Patrick Pelissier 4140df5bfc Improve test suite 2023-02-24 19:56:56 +01:00
Patrick Pelissier fbab093d52 Avoid warnings about variables never read. 2023-02-24 19:56:26 +01:00
Patrick Pelissier f57a0e0bf8 Update README 2023-02-24 18:21:39 +01:00
Patrick Pelissier 925c06beb8 Fix usage of va_copy 2023-02-24 15:07:29 +01:00
Patrick Pelissier 8e2f67b794 Fix building on exe files: some targets don't link with LDFLAGS if it is not in the last argument 2023-02-23 12:42:11 +01:00
Patrick Pelissier f176d01e49 Fix README 2023-02-23 10:53:32 +01:00
Patrick Pelissier 2b99bbe956 Remove bool oplist as it is globally registered 2023-02-22 22:47:31 +01:00
Patrick Pelissier 700bfc5341 Add documentation for RET in API transformation 2023-02-22 22:47:17 +01:00
Patrick Pelissier 4062525821 Add test for RET in API transformation 2023-02-22 22:47:06 +01:00
Patrick Pelissier 800a1e5c36 Add support for RET in API transformation and register global bool oplist 2023-02-22 22:46:46 +01:00
Patrick Pelissier 1838f675a7 Add more comments, another alternative.
Rename some variables to be clearer.
2023-02-18 20:15:17 +01:00
Patrick Pelissier bf6c1341b3 Add comments to explain what we do
Always use the prefixed version of M*LIB
2023-02-18 09:58:30 +01:00
Patrick Pelissier 55b745b916 Use of M_WORKER_SPAWN_DEF2 in example:
it shows how to add paralelization to a code base.
2023-02-18 00:25:30 +01:00
Patrick Pelissier 5cb0d9214b Adding doc for M_WORKER_SPAWN_DEF2. 2023-02-18 00:25:17 +01:00
Patrick Pelissier 8f99b8e617 Adding test for M_WORKER_SPAWN_DEF2 2023-02-18 00:25:06 +01:00
Patrick Pelissier d2ce71a90a Adding M_WORKER_SPAWN_DEF2 for providing specialization
and type-safe variant of m_worker_spawn.
2023-02-18 00:24:20 +01:00
Patrick Pelissier 8562986eea Avoid dereferencing the table in asserts if the lock is done on the tree:
it usually means that the tree is partially accessed by other
threads (at least the derefencing methods which should be
safe).
2023-02-18 00:15:31 +01:00
Patrick Pelissier ee89858bf0 Add renaming of header in compatibility chapter 2023-02-16 00:20:07 +01:00
Patrick Pelissier 085d7157c0 Add compatibility layer with old header m-mutex
as a transition for current programs.
2023-02-16 00:10:55 +01:00
Patrick Pelissier 91f3174a36 Rename m-mutex header into m-thread
as it is not just about mutex but about thread functions
just like the header pthread or thread.h
2023-02-16 00:09:06 +01:00
Patrick Pelissier 56f51c59af Add comments about locale dependent functions. 2023-02-11 23:47:11 +01:00
Patrick Pelissier df0c95ca46 Adding note on locale for JSON outputs 2023-02-11 14:35:36 +01:00
Patrick Pelissier 482ec38e62 Fix wrong use of isprint function. 2023-02-11 14:34:13 +01:00
Patrick Pelissier 82743ca72c Update pipeline for freebsd 2023-02-11 09:28:12 +01:00
Patrick Pelissier 312821454c Avoid running tests in example for freebsd 2023-02-11 00:39:06 +01:00
Patrick Pelissier c953e87660 Link with stdthreads for FreeBSD 2023-02-11 00:11:48 +01:00
Patrick Pelissier 8846707c8b Fix issue on FreeBSD when building in C11 mode:
thrd_sucess is not equal to 0 on this system,
so replace 0 by thrd_success
2023-02-11 00:08:51 +01:00
Patrick Pelissier bf7d4eee55 Avoid using .log suffix for failure checks
some Make program (like FreeBSD one) doesn't handle
priority of a specific rule over a generic rule.
So the generic rule is used for failure checks and it fails the check.
Use another suffix to avoid collision between rules
2023-02-10 23:57:28 +01:00
Patrick Pelissier d4dc85f89a Add FreeBSD target for CI 2023-02-10 21:36:04 +01:00
Patrick Pelissier 130c32e7d4 Include only sysinfoapi.h on Windows machine to reduce dependency
Add fallback to _SC_NPROCESSORS_CONF if _SC_NPROCESSORS_ONLN is not supported (Android)
2023-02-07 23:17:03 +01:00
Patrick Pelissier 2bcaba3bc0 Factorize into smaller macros 2023-02-06 22:17:12 +01:00
Patrick Pelissier 443c805c22 Fix format 2023-02-06 21:28:19 +01:00
Patrick Pelissier 414c87bb69 Rename internal macros 2023-02-05 23:38:29 +01:00
Patrick Pelissier e9ca506d93 Factorization of macros 2023-02-03 20:53:27 +01:00
Patrick Pelissier 8e58f7d637 Factorize into smaller generation macros. Add emplace support for MPMC/SPSC queues 2023-02-01 20:58:28 +01:00
Patrick Pelissier 254beaf3c7 Factorize into smaller generation macros 2023-02-01 20:43:01 +01:00
Patrick Pelissier 27735eb224 Migrate version of action scripts. 2023-01-29 00:19:22 +01:00
Patrick Pelissier 0afc81bd54 Simplify example by using emplace function. 2023-01-28 14:49:17 +01:00
Patrick Pelissier 39e67eebdc EMPLACE: Fix expansion of methods as macro in the oplist
by performing another evaluation step.
2023-01-28 14:49:07 +01:00
Patrick Pelissier 840226c7fd TREE: Add documentation of emplace functions 2023-01-28 14:48:58 +01:00
Patrick Pelissier e421851525 TREE: Add tests for emplace functions 2023-01-28 14:48:50 +01:00
Patrick Pelissier f70b52c9e4 TREE: Add support for emplace functions 2023-01-28 14:48:12 +01:00
Patrick Pelissier 40249ce5bc Separate macros into smaller more functionnal ones 2023-01-28 14:48:01 +01:00
Patrick Pelissier 97ff413f01 Maintenance:
Separate big macros into several smaller ones
2023-01-22 23:33:13 +01:00
Patrick Pelissier 8e4ac99a35 Separate macro into smaller macros (more maintenable) 2023-01-20 23:45:40 +01:00
Patrick Pelissier 4366e8eeab Separate macro into smaller macros
to ease reading and enable easier customization of generation
2023-01-20 23:45:40 +01:00
Patrick Pelissier 4e5e498bb2 Add new library 2023-01-09 23:35:33 +01:00
Patrick Pelissier 870a6f4b57 Update to 0.7.1 2023-01-02 13:06:29 +01:00
Patrick Pelissier a2ae209992 Happy new year 2023-01-02 12:57:41 +01:00
Patrick Pelissier 43fdd10e77 Release 0.7.0 2022-12-27 20:01:44 +01:00
Patrick Pelissier b1183de0f8 Update example to allow more example of promotion. 2022-12-25 23:12:02 +01:00
Patrick Pelissier 3a3ef7454c Fix conflict issue between INIT_WITH_VAI macro and API transformation.
Since both used M_MAP2_C macro, the final expansion was stopped if an
API generic transformation was requested in INIT_WITH_VAI.
Duplicate M_MAP2_C internally for API transformation.
2022-12-24 23:04:42 +01:00
Patrick Pelissier 5f946b728b Update example to include more integration of the different features
(enabling to test more).
2022-12-24 23:03:48 +01:00
Patrick Pelissier 9cc03ff81b Add macro M_INIT_WITH_THROUGH_EMPLACE_TYPE that provides an INIT_WITH
method that scans the different methods provided in EMPLACE_TYPE and
try to search for a matching one.
2022-12-23 11:49:08 +01:00
Patrick Pelissier 89d4db174e Fix format 2022-12-23 11:48:15 +01:00
Patrick Pelissier f5bbc0a7fb Implement multiple kind of workarounds for GCC 12
as it produces more false warnings

Include missing header in C++ mode
2022-12-22 20:42:20 +01:00
Patrick Pelissier 9da0d1d94b Add new internal macro M_TAIL_3 2022-12-22 15:49:10 +01:00
Patrick Pelissier fafaaafdbf Avoid warning for M_RET_ARG if there is the exact number of argument.
Add internal M_TRIPLE_* macros (TBC)
2022-12-22 14:05:46 +01:00
Patrick Pelissier 38f4107b19 Support of keyptr /valueptr iterator 2022-12-04 23:39:42 +01:00
Patrick Pelissier cbefdab4bb Add check of B+TREE map against C++ map 2022-12-04 21:26:20 +01:00
Patrick Pelissier bcd0c46e8b Simplify & factorize the instances of the check against C++ 2022-11-30 23:56:29 +01:00
Patrick Pelissier f25bb73e58 Add comparison to C++ unorder_map 2022-11-30 00:30:45 +01:00
Patrick Pelissier ea3584e048 Rename internal macro to internal namespace 2022-11-29 23:16:55 +01:00
Patrick Pelissier 85473610a4 Update doc 2022-11-22 22:51:40 +01:00
Patrick Pelissier f9f0b307fc Provide even shorter example using EMPLACE_TYPE 2022-11-10 13:50:00 +01:00
Patrick Pelissier d17fa4530b Update comments 2022-11-05 13:36:57 +01:00
Patrick Pelissier 3806495e2d Fix spelling 2022-11-04 10:41:38 +01:00
Patrick Pelissier 15f58d5738 Update example comments. 2022-10-23 21:01:44 +02:00
Patrick Pelissier 4de7da1c05 Adding bench for emhash
https://github.com/ktprime/emhash
2022-10-15 10:24:18 +02:00
Patrick Pelissier 93229c61f2 Update comments 2022-10-12 23:26:33 +02:00
Patrick Pelissier 3f0e8956b8 Add emplace method for buffer. 2022-10-11 22:47:14 +02:00
Patrick Pelissier b82670b643 Add emplace support for concurrent. 2022-10-10 23:08:30 +02:00
Patrick Pelissier 64800dbd3f Use of type from oplist rather than meta name
(more coherent)
2022-10-10 23:06:02 +02:00
Patrick Pelissier 2d9d9fbd9f Remove obsolete macros 2022-10-10 22:54:48 +02:00
Patrick Pelissier f0ba5d17f4 Rework fuzzer support to be fully generic. 2022-10-10 22:47:43 +02:00
Patrick Pelissier e51c988222 Add initial support for fuzzing 2022-10-07 23:39:54 +02:00
Patrick Pelissier 0be3900beb Enable support for external testsuite from stdin
instead of pseudo random values.
This will enable to connect it to a fuzzer.
2022-10-07 23:28:12 +02:00
Patrick Pelissier f60ce0320a Port to new API version of STC. 2022-10-07 22:47:53 +02:00
Patrick Pelissier 77008b8622 Fix leak of memory in non optimized _safe_get
of B+Tree.
2022-10-03 23:07:13 +02:00
Patrick Pelissier a7617002c5 Update documentation for emplace generation. 2022-10-03 22:54:42 +02:00
Patrick Pelissier bc73616bde Add test cases for emplace generation
for dict & B+tree
2022-10-03 22:40:44 +02:00
Patrick Pelissier d6b9b054c2 Fix emplace generation
(incorrect value oplist)
2022-10-03 22:34:13 +02:00
Patrick Pelissier 9eed4be97c Add emplace support for B+Tree 2022-10-03 22:16:50 +02:00
Patrick Pelissier 2519927178 Fix build in case of no MPFR and warnings are treated as errors. 2022-10-02 22:31:50 +02:00
Patrick Pelissier 0fec33b38e * Add emplace generation for dict/hashmap.
(still need more tests).
* Factorize emplace generation for R+TREE/Prioqueue
2022-10-02 22:24:22 +02:00
Patrick Pelissier dc2b6d2b2d Fix detection of GMP / MPFR. 2022-10-02 22:16:45 +02:00
Patrick Pelissier bc63edc595 Fix emplace generation for asso array 2022-10-02 21:41:21 +02:00
Patrick Pelissier 6241a3093c Factor comments. 2022-10-02 21:35:52 +02:00
Patrick Pelissier fb53a464d7 Update comments 2022-10-01 20:41:45 +02:00
Patrick Pelissier aba26b75a2 Fix chapter in documentation 2022-10-01 11:40:23 +02:00
Patrick Pelissier 775ec6f91b Make M_ASSERT_INDEX more robust
in case it is called with a signed integer.
The trick was using x-x to represent 0 so that
the compiler won't complain with the comparaison
x >= 0 when it is called with unsigned number.
2022-10-01 11:38:11 +02:00
Patrick Pelissier 95bc7063a0 Remove some warning with clang:
it complains about using a GNU extension
in GNU mode (gnu11)!
2022-10-01 11:36:14 +02:00
Patrick Pelissier 731d3ecf1a Update error chapter of the documentation 2022-10-01 09:50:38 +02:00
Patrick Pelissier 0d1817e7ca Add tiny example of no stdio support. 2022-10-01 09:50:24 +02:00
Patrick Pelissier 1a5b428bfb Fix proper support of no stdio
and add macro M_RAISE_FATAL to raise a fatal error
with the default is using stdio.
2022-10-01 09:50:09 +02:00
Patrick Pelissier bd49e31f3b Add definition macros for emplace/associative array container. 2022-09-29 23:48:46 +02:00
Patrick Pelissier 2dba83e3c5 Remove M_USE_STDLIB
(It wasn't working at all).
2022-09-28 22:16:04 +02:00
Patrick Pelissier 75e9766da9 Fix wrong generation for emplace / value 2022-09-26 23:43:39 +02:00
Patrick Pelissier d2f8aa1c0d Update documentation. 2022-09-25 22:15:44 +02:00
Patrick Pelissier 4aa4b7693f Add M_C5_EMPTY macro
Add M_CROSS_MAP2 macro
Add emplace generation  for associative array if both key & value are emplace types
Add test cases.
2022-09-25 22:13:51 +02:00
Patrick Pelissier d50b450927 Update documentation. 2022-09-25 00:36:27 +02:00
Patrick Pelissier 5674cdbfc5 Add new macro M_CROSS_MAP
enabling to map a function to each pair
of arguments given two arglists.
2022-09-25 00:30:23 +02:00
Patrick Pelissier 3641829198 M_INC (resp. M_DEC) of M_UNDERFLOW (resp. M_OVERFLOW)
will keep the initial error.
2022-09-16 18:46:13 +02:00
Patrick Pelissier 10a759b09e Add another function for generation 2022-09-15 23:25:42 +02:00
Patrick Pelissier b5a3b36c1b * Add M_C3_EMPTY function.
* Add WIP generator for emplace functions for associative array. What is missing is the hard part (even what is done cannot be said as easy!) Generation of both N x M functions. It probably needs a new MAP function for this.
2022-09-15 23:25:38 +02:00
Patrick Pelissier b0c3839f2b Add serial methods in documentation. 2022-09-15 21:39:17 +02:00
Patrick Pelissier 3aa3e95e4c Remove constraint of calling string_end_p
before string_next or string_get_cref
This generates slighty more code but it is much saner
from user point of view.
2022-09-13 00:18:15 +02:00
Patrick Pelissier 87f1e53e13 Add more basic iteration code generation analysis 2022-09-13 00:03:40 +02:00
Patrick Pelissier d7b45cc220 Fix issue in string_previous 2022-09-11 23:14:52 +02:00
Patrick Pelissier d8142a9764 Add precision on documentation. 2022-09-10 16:38:27 +02:00
Patrick Pelissier 8780f58739 Fix description of string_unocde_t 2022-09-10 16:35:38 +02:00
Patrick Pelissier e352104df8 Update documentation with new function. 2022-09-10 16:30:57 +02:00
Patrick Pelissier cbb2b452bb Add string_previous function
to iterate on the previous UTF8 code point.
2022-09-10 16:30:45 +02:00
Patrick Pelissier 6e947c6262 Add more corner cases. 2022-09-10 16:21:19 +02:00
Patrick Pelissier 18f04da4ec Robustness/fix:
string_next won't advance if the end of string is reached.
2022-09-10 16:19:58 +02:00
Patrick Pelissier 3dad6ef65c Update string API description. 2022-09-10 16:16:42 +02:00
Patrick Pelissier 41c4f5fe5c Add string functions :
* string_it_get_pos to return the position in the steam
* string_it_pos to start iterating from a given position.
2022-09-10 16:16:13 +02:00
Patrick Pelissier cfeedf19f8 Rework to be more compliant (as far as it is possible)
to real cases.
2022-09-10 15:56:36 +02:00
Patrick Pelissier 2ab410bd6a Update comments to reflect that we work
on UTF8 code points and not Unicode characters.
2022-09-10 10:39:04 +02:00
Patrick Pelissier aefbc5b2f5 Factorize the test of the start of an UTF8 code point
in a separate function
2022-09-10 10:34:54 +02:00
Patrick Pelissier abec9c37fa Clarify API
It iterates over UTF-8 code points, not Unicode characters
They can be different (!)
2022-09-10 10:32:34 +02:00
Patrick Pelissier 442b0e7cea Reduce size of struct string_it_t on 64 bits
by storing an offset to the next character
instead of a pointer. An offset can be stored as a
BYTE instead of a PTR since UT-8 can use at most
4 characters per code point.
2022-09-10 09:59:06 +02:00
Patrick Pelissier 0b853c6d52 Fix bug on bitset_resize function in case of increase of size:
the first limb may not be cleared properly in some cases.
(Reported by David M. Lary)
2022-09-04 19:27:38 +02:00
Patrick Pelissier cc7fc66899 Add bitset_ctz function 2022-08-29 19:31:19 +02:00
Patrick Pelissier 6b994c2928 Add m_core_ctz32 & m_core_ctz64 functions
(Count trailing zeros)
2022-08-29 19:30:09 +02:00
Patrick Pelissier e6fe36d3cd Revert "Perform coverage check by continuous integration tests."
as the numbers of lines generated by the generation macros
(which are included in the coverage measure)
through the C preprocessor depend on the exact version
of the C preprocessor.
There is no reliable way to get a measure on it,
except by always targeting the same compiler.
So, this measure of coverage (number of lines)
is not suitable for CIT. Ratio seems also not reliable enough.

This reverts commit f45ededf8b.
2022-08-22 23:53:10 +02:00
Patrick Pelissier f45ededf8b Perform coverage check by continuous integration tests. 2022-08-20 23:33:48 +02:00
Patrick Pelissier ed27bedcb4 Make coverage perfoms a check that the computed coverage is at least
not lower than the reference coverage, ensuring no regression
on the coverage of the tests can occur.

NOTE: some tests (m-i-shared) perform some dynamic test cases
where the exact coverage depend on the exact dynamic behavior
of the test. And this behavior is not always reproducible
(for exact the calls to m_core_backoff_wait may not occur
if the threads are not trying to grab the resource at the
exact same time).
As such, the reference of such tests is taken from the worst
case of execution of the coverage (with the lowest number
of lines covered).
2022-08-20 23:29:02 +02:00
Patrick Pelissier eb1a7a0435 Add more tests for tree 2022-08-19 23:16:42 +02:00
Patrick Pelissier de00fdc5f7 Update documentation 2022-08-13 23:50:51 +02:00
Patrick Pelissier 8febe12c5c Make stdlib an optional header 2022-08-09 00:20:32 +02:00
Patrick Pelissier 1368b201eb Fix warnings in release mode. 2022-08-09 00:19:55 +02:00
Patrick Pelissier 4ca166b0b9 Update examples to remove warnings with assertion disabled. 2022-08-09 00:19:26 +02:00
Patrick Pelissier c13533cf21 Fix naming 2022-08-08 01:22:05 +02:00
Patrick Pelissier 9fdf0f76e7 Add documentation of generic tree. 2022-08-08 01:20:30 +02:00
Patrick Pelissier 308f513edc As the allocated array offers write access to the index -1
remove if conditions to always access the array even for -1
The term tab[-1] will be filled with no pertinent value, but
we don't care about it.
2022-08-02 23:21:39 +02:00
Patrick Pelissier 900bcc3819 The internal array of the tree always allocates one more term,
so that the index -1 in the array exists and can be written.
2022-08-02 23:02:59 +02:00
Patrick Pelissier b6e0994dfc Add test case for _init_set with empty tree. 2022-08-02 23:02:33 +02:00
Patrick Pelissier 121339d948 Add _move_* functions for generic tree. 2022-08-01 22:17:26 +02:00
Patrick Pelissier c5bb84013a Create _raw methods for insertions. 2022-08-01 22:13:41 +02:00
Patrick Pelissier 65b49268d3 Fix allow_realloc for tree 2022-07-30 16:14:03 +02:00
Patrick Pelissier ecebd62f86 Update API compatibility documentation due to the _str to _cstr suffix change.
Note: the old (& still official) naming for the string functions
is still compatible since we have changed only the new namings (with m_ prefix).
See #99
2022-07-30 12:02:58 +02:00
Patrick Pelissier 6a8c9a703d Rename string functions as per latests changes 2022-07-30 12:02:32 +02:00
Patrick Pelissier ad05ae9aa5 Rename the string _suffix for Bounded Strings from _str to _cstr
See #99
2022-07-30 12:01:36 +02:00
Patrick Pelissier abffe201e5 Change the suffix of the functions dealing with C-String to _cstr
instead of _str.
See #99 for details.
2022-07-30 12:00:55 +02:00
Patrick Pelissier ee2bc27bda Fix issue in serial-bin
Note: this is a classic c error, so it may be interresting to discover
why the static analysis tools didn't report this error.
2022-07-30 04:40:09 +02:00
Patrick Pelissier 14b94865b7 Starting document tree. 2022-07-28 23:25:57 +02:00
Patrick Pelissier 6e1ceafcc2 Add more tests for tree. 2022-07-28 23:22:07 +02:00
Patrick Pelissier 58746560e9 Add comment 2022-07-28 23:21:54 +02:00
Patrick Pelissier 082adca3e6 Add test case 2022-07-27 23:48:59 +02:00
Patrick Pelissier ee1dc2a8e8 Fix issue in _graft_child 2022-07-27 23:48:40 +02:00
Patrick Pelissier 92e2d835bd Add more generic random tests 2022-07-26 23:12:41 +02:00
Patrick Pelissier 22aba04b47 Activate optimisation for coverage 2022-07-26 23:12:19 +02:00
Patrick Pelissier 399c615915 Fix issue in unlink 2022-07-26 23:04:15 +02:00
Patrick Pelissier cbdba0941a Adding more test cases 2022-07-26 22:49:07 +02:00
Patrick Pelissier 90c54a48d0 Remove uneeded test 2022-07-26 22:48:47 +02:00
Patrick Pelissier 22b18830f7 Improve test suite by performing no op swap operation randomly 2022-07-24 21:12:59 +02:00
Patrick Pelissier dab085e3a7 Fix other issue 2022-07-24 21:11:08 +02:00
Patrick Pelissier 66fac10a98 Fix corner case 2022-07-24 21:09:35 +02:00
Patrick Pelissier e5fb5ddde1 Fix some issues in insertion 2022-07-24 20:40:31 +02:00
Patrick Pelissier dcf20fbbd6 Add some tests for swap_at 2022-07-24 00:48:18 +02:00
Patrick Pelissier 5d659877fe Fix some bugs in the swap of node in a tree 2022-07-24 00:47:43 +02:00
Patrick Pelissier a30dd69aaa Add more tests for tree 2022-07-18 23:42:25 +02:00
Patrick Pelissier b1f698bb7b Fix tree _prune function 2022-07-18 23:42:13 +02:00
Patrick Pelissier 2323420a87 Add more test cases 2022-07-15 17:23:56 +02:00
Patrick Pelissier 7e120a3615 Add missing assertions 2022-07-15 16:54:51 +02:00
Patrick Pelissier 804db294ca Update test suite 2022-07-15 16:48:54 +02:00
Patrick Pelissier d12aa6c263 Don't expand tree contract for coverage 2022-07-15 00:32:26 +02:00
Patrick Pelissier d59e87d2bf Adding tests for OUT_STR/IN_STR 2022-07-07 22:21:29 +02:00
Patrick Pelissier 8f3c0af548 Add OUT_STR & IN_STR methods for tree 2022-07-07 22:21:14 +02:00
Patrick Pelissier 1f3013c445 Adding more corner cases 2022-07-07 22:10:00 +02:00
Patrick Pelissier f13e99ab1a Add coverage computation for tree 2022-07-07 22:09:51 +02:00
Patrick Pelissier fb8ad84675 Add more tests 2022-07-05 22:46:24 +02:00
Patrick Pelissier 12608afe10 Fix issue in comparing tree 2022-07-05 22:46:13 +02:00
Patrick Pelissier f97e92b4cb Complement basic tests 2022-07-04 20:47:53 +02:00
Patrick Pelissier a74e26e3de Add random generated insertion in a tree 2022-07-04 20:38:51 +02:00
Patrick Pelissier a30b783692 First basic test of tree container 2022-06-28 23:28:45 +02:00
Patrick Pelissier e64a6a22e7 Fix issues in tree 2022-06-28 23:28:09 +02:00
Patrick Pelissier 76892afa13 Fix some warnings. 2022-06-27 23:35:05 +02:00
Patrick Pelissier dcb1eb0d94 First version of IO for the tree container 2022-06-25 17:29:04 +02:00
Patrick Pelissier 950ea224ff Adding untested classic functions for tree (_init_set, _set, _equal, _hash, ...) 2022-06-18 15:26:19 +02:00
Patrick Pelissier b22a844007 update doc 2022-06-17 22:56:37 +02:00
Patrick Pelissier 502756c731 Simplify the control flow to count for utf8 encoded characters 2022-06-16 23:58:23 +02:00
Patrick Pelissier e38dc19ea1 Add current restriction on worker_spawn 2022-06-15 00:55:41 +02:00
Patrick Pelissier 2bebb2b4a1 Update example with new tree functions 2022-06-13 23:21:06 +02:00
Patrick Pelissier 5b7be93c1a Update tree:
* fix swap and add an additional argument to swap or not the child
* add sort functions for the children of a nodes
2022-06-13 23:21:06 +02:00
Patrick Pelissier d04270ae3f Proper use of API transformation for CMP operator in tuples 2022-06-13 23:21:06 +02:00
Patrick Pelissier 1bef7c1977 Fix formatting 2022-06-13 23:21:06 +02:00
Patrick Pelissier ae037ff7af Fix location of library in makefile 2022-06-13 22:12:56 +02:00
Patrick Pelissier a4267d60df Add usage of emplace with tuple 2022-06-04 23:44:22 +02:00
Patrick Pelissier 47e32ab2b3 Add support for EMPLACE_TYPE in TUPLE generations.
As a consequence, the oplist arguments for TUPLE_OPLIST
are much more rigorous. It shall really be the real oplists
of the types used to create the tuple, otherwise a compilation
error may be generated.
2022-06-04 23:41:18 +02:00
Patrick Pelissier 5ac08e42d8 Adding const for the type generation in emplace 2022-06-04 23:40:36 +02:00
Patrick Pelissier 9c59684b61 Fix the OPLIST args of TUPLE_OPLIST so that the given oplists match the types used for the definition of the tuple 2022-06-04 23:34:46 +02:00
Patrick Pelissier f26e1e5a12 Fix issue in case of recursive call of INIT_WITH with conditionnal INIT_WITH 2022-06-04 23:27:13 +02:00
Patrick Pelissier 1cde4633e6 Adding more corner cases 2022-06-04 23:26:03 +02:00
Patrick Pelissier 1393f8e9aa Update comments 2022-06-04 16:03:06 +02:00
Patrick Pelissier bfffa1d245 Update comments & naming 2022-06-04 16:02:58 +02:00
Patrick Pelissier 3a6b568ccc Update example to count the number of lines 2022-06-04 14:55:32 +02:00
Patrick Pelissier 453a920af8 Add methods to scan in post-order a sub-tree 2022-06-04 14:54:51 +02:00
Patrick Pelissier 1fd86ffc2e Update & fix 2022-06-03 22:59:55 +02:00
Patrick Pelissier 96a0639a8a Add more functions for TREE 2022-06-03 21:43:33 +02:00
Patrick Pelissier c12d0a3f23 Update comments 2022-06-03 21:43:15 +02:00
Patrick Pelissier cac8790405 Start working on example with generic tree 2022-06-01 19:52:28 +02:00
Patrick Pelissier ccd9726e01 Fix some warnings / errors 2022-06-01 19:51:50 +02:00
Patrick Pelissier 5516b50b3a Add WIP / untested generic tree datastructure 2022-05-31 23:00:19 +02:00
Patrick Pelissier b5a3e010d8 Add {} for if 2022-05-26 22:13:24 +02:00
Patrick Pelissier 2d7d267252 Update doc 2022-05-26 18:33:43 +02:00
Patrick Pelissier bd5d7aaada Fix wrong prototype in docs 2022-05-24 23:58:20 +02:00
Patrick Pelissier 18b6be8e00 Update doc 2022-05-24 23:56:34 +02:00
Patrick Pelissier 958abfef93 Make INIT_SET operator optional 2022-05-24 23:30:14 +02:00
Patrick Pelissier 198be1062b Update doc 2022-05-24 23:25:37 +02:00
Patrick Pelissier 0cfee02641 Make INIT operator optional 2022-05-24 23:22:36 +02:00
Patrick Pelissier 48dc38508a Factorize the documentation by using the generic interface (WIP) 2022-05-23 23:49:57 +02:00
Patrick Pelissier e763204bf7 Fix example 2022-05-22 22:54:25 +02:00
Patrick Pelissier 370baf56ab Factorize the documentation by using the generic interface (WIP) 2022-05-22 00:22:36 +02:00
Patrick Pelissier 4fd6bcbf99 Factorize the documentation by using the generic interface (WIP) 2022-05-19 22:41:19 +02:00
Patrick Pelissier 59d1e23dea Factorize the documentation by using the generic interface (WIP) 2022-05-19 22:28:53 +02:00
Patrick Pelissier cb173f2f81 Update doc 2022-05-19 21:45:16 +02:00
Patrick Pelissier d047174c2f Update doc 2022-05-19 21:43:42 +02:00
Patrick Pelissier df25159d03 Add generic interface chapter & start factorizing duplicate specification 2022-05-19 00:30:47 +02:00
Patrick Pelissier 99618a687e Update doc 2022-05-19 00:00:36 +02:00
Patrick Pelissier a1b226e185 Update doc 2022-05-16 23:37:04 +02:00
Patrick Pelissier e93df4332a Fix issue for 16 bits architecture 2022-05-14 09:16:41 +02:00
Patrick Pelissier 5a1f768b03 Update comment about lock-free property 2022-05-14 09:16:41 +02:00
Patrick Pelissier e854bc8fc9 Remove warning in C++ mode for using C++ class 2022-05-12 00:00:10 +02:00
Patrick Pelissier 9ab958708d Update doc:
clarify operators
2022-05-11 23:26:36 +02:00
Patrick Pelissier 85ea92d83b Review of m-core.h
* Add control of MSVC preprocessor
* Add comments
* Remove useless evaluation pass
* Rewrite some evaluation pass to be faster.
2022-05-11 21:38:47 +02:00
Patrick Pelissier 22a406ac51 Add new test case (M_MAP + M_SEQ) 2022-05-11 21:38:47 +02:00
Patrick Pelissier 58eed79413 Register the oplist associated to unsigned 2022-05-04 22:25:15 +02:00
Patrick Pelissier e83dea8212 Fix warnings for Visual C++ 2022-05-10 23:49:20 +02:00
Patrick Pelissier c829827f48 Fix warnings for Visual C++ 2022-05-10 23:34:48 +02:00
Patrick Pelissier b47cf05a59 Update doc 2022-05-10 23:14:47 +02:00
Patrick Pelissier 22a93514ff Add EMPLACE test for priority queue 2022-05-10 23:10:58 +02:00
Patrick Pelissier 154865f0f1 Add EMPLACE support for priority queue 2022-05-10 23:10:44 +02:00
Patrick Pelissier 71151770fd Fix wrong type 2022-05-09 22:55:57 +02:00
Patrick Pelissier 72623ce13e Adding test cases for I/O methods 2022-05-09 22:52:28 +02:00
Patrick Pelissier 94f20d56e9 Adding OUT_STR / IN_STR / PARSE_STR / GET_STR / IN_SERIAL / OUT_SERIAL methods 2022-05-09 22:51:46 +02:00
Patrick Pelissier 9e8ad9bfd9 Fix format 2022-05-09 22:48:56 +02:00
Patrick Pelissier e51a5be776 Add check of prioqueue against STL C++ 2022-05-09 22:25:09 +02:00
Patrick Pelissier 7d647340c6 Update 2022-05-09 22:24:48 +02:00
Patrick Pelissier c6ea3c0616 Fix spelling 2022-05-09 20:16:33 +02:00
Patrick Pelissier 9ab90be6d4 Add check of B+Tree / Set 2022-05-09 20:12:55 +02:00
Patrick Pelissier 10440320d1 Remove IT_REF from exported oplist as the items shall appear as not modifiable by algorithms 2022-05-09 20:12:39 +02:00
Patrick Pelissier fc7e93403a Update copyright year 2022-05-09 20:06:05 +02:00
Patrick Pelissier b0c4418584 Fix M_ALGO_EXTRACT: the source oplist wasn't transformed into a global one. 2022-05-09 20:03:26 +02:00
Patrick Pelissier 5f73eb7788 Add test for support C++ class in M*LIB 2022-05-06 23:08:27 +02:00
Patrick Pelissier a554312573 Update doc 2022-05-06 23:07:10 +02:00
Patrick Pelissier 8a1fd391d1 Fix reverse issue 2022-05-06 01:27:34 +02:00
Patrick Pelissier 95b104ee48 Issue in generation of functions:
if the method in the oplist uses API_* transformation,
if this method is a macro itself,
it may delay the expansion too much and
the macro may not be expanded at all in the final code generation.

Fix issue by adding a supplementary evaluation in the macro expansion.
Add test cases
2022-05-06 01:10:31 +02:00
Patrick Pelissier c3df69d011 Add tests for generic API + macros 2022-05-04 22:16:01 +02:00
Patrick Pelissier 73468a3e24 Update doc 2022-05-02 23:15:58 +02:00
Patrick Pelissier f254f98e42 Update doc 2022-05-02 21:40:49 +02:00
Patrick Pelissier d37076dd37 Update comments 2022-05-02 21:11:12 +02:00
Patrick Pelissier 5ef9376148 Improve example (adding ADD/SUB/MUL/DIV operators 2022-04-29 19:55:29 +02:00
Patrick Pelissier d8abda7583 Fix issue (implicit const cast) 2022-04-29 19:55:02 +02:00
Patrick Pelissier 892c755389 Improve example to show emplace support 2022-04-28 23:10:57 +02:00
Patrick Pelissier aba2f90c9d Add test for emplace generation for variant 2022-04-28 23:10:40 +02:00
Patrick Pelissier dc487c7e64 Add support for EMPLACE_TYPE for variant 2022-04-28 23:10:27 +02:00
Patrick Pelissier 18b1bd9518 Fix makefile if MPFR not found 2022-04-28 23:06:41 +02:00
Patrick Pelissier 845ab1fef0 Update comment 2022-04-28 23:03:04 +02:00
Patrick Pelissier 94bfac3f75 Improve example by adding also mpfr 2022-04-28 22:22:05 +02:00
Patrick Pelissier bd5c9ce2a7 Add MPFR detection 2022-04-28 22:10:36 +02:00
Patrick Pelissier f5934a6274 Add emplace type example 2022-04-27 21:57:28 +02:00
Patrick Pelissier c6f71fddc7 Add test for stable_sort 2022-04-26 21:35:51 +02:00
Patrick Pelissier 74764e2d6f Fix issues in stable_sort: wrong assertion & missing init_move 2022-04-26 21:35:51 +02:00
Patrick Pelissier 9b00a8c54e Update documentation 2022-04-25 22:10:19 +02:00
Patrick Pelissier 66735e99c3 Add check sanitize to Continuous Integration 2022-04-23 10:40:39 +02:00
Patrick Pelissier 80acbb4343 Ensure proper order of commands in case of parallelism 2022-04-23 10:37:42 +02:00
Patrick Pelissier 2fb912d43d Should remove warning with Visual C++ 2022-04-23 10:34:54 +02:00
Patrick Pelissier 8c8dc6de7c Add new example 2022-04-23 10:21:46 +02:00
Patrick Pelissier 677acdd14e Use of new M_INIT_EMPLACE_VAI macro 2022-04-23 10:21:33 +02:00
Patrick Pelissier 6caeea98b9 Add M_INIT_EMPLACE_VAI macro for INIT_WITH containers with emplace support 2022-04-23 10:21:17 +02:00
Patrick Pelissier c5d37ce028 Update comments 2022-04-23 10:03:51 +02:00
Patrick Pelissier 112b405df6 Reformat 2022-04-23 10:01:39 +02:00
Patrick Pelissier 47385d58e5 Update documentation with new generated functions 2022-04-23 09:20:11 +02:00
Patrick Pelissier c8275c8f63 Add test cases for generated emplace functions 2022-04-23 09:19:58 +02:00
Patrick Pelissier 0c1e888a78 Add emplace generation for RB Tree 2022-04-23 09:19:42 +02:00
Patrick Pelissier 6a1ff3e080 Add emplace generation for oplist with CMP operator 2022-04-23 09:18:20 +02:00
Patrick Pelissier 6d41eba5ed Update documentation for emplace functions 2022-04-22 22:51:45 +02:00
Patrick Pelissier c0abcc6d60 Add tests for new emplace functions 2022-04-22 22:51:36 +02:00
Patrick Pelissier da71c81195 Add emplace functions for list / deque 2022-04-22 22:51:17 +02:00
Patrick Pelissier 8e0d17e85c Add test for emplace string_t from const char * 2022-04-21 23:11:24 +02:00
Patrick Pelissier 6d98c273c1 Add EMPLACE_TYPE from const char * 2022-04-21 23:11:11 +02:00
Patrick Pelissier 85f6ff34aa Add test cases for generated emplace functions 2022-04-20 22:43:12 +02:00
Patrick Pelissier 759c24be63 Add request for generation for emplace functions 2022-04-20 22:43:12 +02:00
Patrick Pelissier d85955ef60 Add generation of emplace functions 2022-04-20 22:43:12 +02:00
Patrick Pelissier 3a53044198 Add M_EMPLACE macros to enables generic generation of EMPLACE functions 2022-04-20 22:43:12 +02:00
Patrick Pelissier 4d5cd9c635 Code generation shows no difference between && or & for simple & typical OOR values
So let's use the logical comparaison which is clearer.
2022-04-19 22:07:01 +02:00
Patrick Pelissier 57b88160ae Add asm generation for typical OOR_EQUAL_P functions 2022-04-19 20:57:03 +02:00
Patrick Pelissier 33ba602aef Reformat 2022-04-18 22:10:32 +02:00
Patrick Pelissier 3632388315 Reorder macros to group then by logical entity. Remove M_INVERT obsolete macro 2022-04-18 21:22:45 +02:00
Patrick Pelissier 6ee82e885b Update comments 2022-04-18 11:09:12 +02:00
Patrick Pelissier 2f92cee416 Update code for generated asm analysis 2022-04-18 11:08:59 +02:00
Patrick Pelissier 9269473e10 Remove M_APPLY_SIZEOF 2022-04-18 10:04:11 +02:00
Patrick Pelissier c8611ce708 Update comments 2022-04-18 09:44:13 +02:00
Patrick Pelissier d8fd43e9e9 Update comments & avoid using M_ID for internal macros 2022-04-18 09:41:43 +02:00
Patrick Pelissier a2e471620d Add support for '_' meta keyword 2022-04-18 09:24:32 +02:00
Patrick Pelissier ffa3821acf Add tests for M_KEYWORD_TO_VA_ARGS 2022-04-17 19:01:32 +02:00
Patrick Pelissier 5c98d47d8c Add M_KEYWORD_TO_VA_ARGS 2022-04-17 19:01:21 +02:00
Patrick Pelissier 0875eaac03 Add more tests 2022-04-17 18:51:27 +02:00
Patrick Pelissier 60734bdb2b Avoid using M_ID / M_OPFLAT in context where it could be used recursively 2022-04-15 23:44:07 +02:00
Patrick Pelissier e71b19424b Simplify definition of M_EMPTY_P & M_PARENTHESIS_P 2022-04-14 23:50:40 +02:00
Patrick Pelissier daac0169d5 Reformat 2022-04-14 23:47:11 +02:00
Patrick Pelissier baacc0df52 Add test cases for M_AND, M_OR, M_AND3 & M_OR3 2022-04-13 22:49:01 +02:00
Patrick Pelissier c6921536f7 Add M_AND3 & M_OR3 macros 2022-04-13 22:48:40 +02:00
Patrick Pelissier 4abf0ad2b2 Simplify code 2022-04-11 22:34:08 +02:00
Patrick Pelissier 379d555d35 Remove M_IF_DEFAULT1 from documentation 2022-04-10 23:12:32 +02:00
Patrick Pelissier 8c01acb8d2 Remove M_IF_DEFAULT1 (bad interface).
Fix warning in M_DEFAULT_ARGS in some cases.
2022-04-10 23:10:58 +02:00
Patrick Pelissier 2c2c3c21ba Add test for string_search in C11 2022-04-10 23:09:50 +02:00
Patrick Pelissier 50fd27e07b Use of M_DEFAULT_ARGS instead of M_IF_DEFAULT1 2022-04-10 23:09:29 +02:00
Patrick Pelissier 3309035814 Reducing preprocessing time for ALGO_FOR_EACH ALGO_TRANSFORM ALGO_EXTRACT 2022-04-10 11:28:12 +02:00
Patrick Pelissier b691758fa9 Update comments 2022-04-10 11:10:01 +02:00
Patrick Pelissier 7c9afcec8b Update vocabulary 2022-04-09 16:31:57 +02:00
Patrick Pelissier 06ac05526a Update doc 2022-04-09 09:02:26 +02:00
Patrick Pelissier 69cef8249a Update comments and move section 2022-04-09 00:11:51 +02:00
Patrick Pelissier 473df16a5a Update description & assertion of HASH functions 2022-04-08 23:38:33 +02:00
Patrick Pelissier e1abf0528c Rename M_DEFAULT_OPLIST in M_BASIC_OPLIST (cleaner name) 2022-04-08 22:54:29 +02:00
Patrick Pelissier ef0b335f67 Rename M_CHECK_DEFAULT_TYPE in M_CHECK_BASIC_TYPE, and makes it more stricter in C11. Start separating default macros from basic macros (that perform control & check) 2022-04-08 20:57:06 +02:00
Patrick Pelissier 1a866a3dc4 Update README 2022-04-08 20:55:35 +02:00
Patrick Pelissier ed437b9e05 Document SPMC & MPMC snapshots 2022-04-03 19:14:42 +02:00
Patrick Pelissier eea85872fd Simplify code 2022-04-03 19:14:25 +02:00
Patrick Pelissier 9d33e4cd5a Update name of library 2022-04-01 23:47:53 +02:00
Patrick Pelissier 530cc8d2a2 Update comments 2022-03-31 22:16:10 +02:00
Patrick Pelissier 9baca84825 Add operator EMPLACE_TYPE, to be used by future emplace methods 2022-03-30 23:11:07 +02:00
Patrick Pelissier 58538e4822 Fix spelling 2022-03-28 23:27:57 +02:00
Patrick Pelissier e31a8dc407 Update benchmark with new available specialized function 2022-03-26 16:09:25 +01:00
Patrick Pelissier 7875263092 Update documentation 2022-03-26 16:09:02 +01:00
Patrick Pelissier de3b8509bf Add tests for m_string_set_si & m_string_set_ui 2022-03-26 16:08:51 +01:00
Patrick Pelissier a19e1acfff Add function m_string_set_si & m_string_set_ui for converting an integer into a string. 2022-03-26 16:08:28 +01:00
Patrick Pelissier e613b5c624 Proper define of NDEBUG to avoid adding assertions in string benchmarks 2022-03-25 22:45:08 +01:00
Patrick Pelissier ccfddb0685 Update LIBSRT to be the source/build directory 2022-03-25 22:37:23 +01:00
Patrick Pelissier b8cd679679 Move generating macro into the m_ namespace and create a wrapper using historical names for compatibility with existing code 2022-03-24 20:46:49 +01:00
Patrick Pelissier fc26e472ab Move bitset functions to M* namespace 2022-03-23 22:39:18 +01:00
Patrick Pelissier fc8c7349d6 Reformat 2022-03-23 21:35:22 +01:00
Patrick Pelissier a4d9b8df17 Moving internal types to internal namespace 2022-03-22 23:37:35 +01:00
Patrick Pelissier f26da68aa4 Fix regression for C++ / CLANG 2022-03-21 23:27:37 +01:00
Patrick Pelissier 144182b540 Move the worker functions into the m_ namespace and create compatibility layer 2022-03-21 23:15:14 +01:00
Patrick Pelissier a834ca4921 Add missing public function 2022-03-21 23:13:34 +01:00
Patrick Pelissier d1fc216836 Move internal type to internal namespace 2022-03-20 19:02:01 +01:00
Patrick Pelissier 5e57338928 Rename string_ into m_string_ in header files (Test files still test classic API) 2022-03-20 18:30:32 +01:00
Patrick Pelissier f3376b6f0e Move internal functions to internal namespace 2022-03-20 11:50:05 +01:00
Patrick Pelissier 5e001fdd9d Move internal type to correct internal namespace 2022-03-19 17:01:20 +01:00
Patrick Pelissier 9fda06276c Move m_once_t to the public interface 2022-03-19 16:44:40 +01:00
Patrick Pelissier df79c306d9 Move the internal types toye the internal namespace 2022-03-19 16:44:18 +01:00
Patrick Pelissier e4955e6851 Move internal types to the internal namespace 2022-03-19 16:43:55 +01:00
Patrick Pelissier 0fec9e7ac4 Fix format 2022-03-19 11:46:28 +01:00
Patrick Pelissier 5be8bb435b Move WORKER_OPLIST to internal namespace 2022-03-19 11:44:58 +01:00
Patrick Pelissier 35b915ab10 Rename internal functions/types to the internal prefix 2022-03-19 10:47:27 +01:00
Patrick Pelissier 80c57e996d Add pottery string in bench 2022-03-19 08:32:10 +01:00
Patrick Pelissier 511293d580 Provide example of hash function 2022-03-17 23:03:04 +01:00
Patrick Pelissier fe2b816447 Add more example in C11 for showing more possibility 2022-03-17 19:37:12 +01:00
Patrick Pelissier 093b7dc1e8 Update example with new possibility & state of the art 2022-03-17 19:34:18 +01:00
Patrick Pelissier 811fa57cbc Fix generic API: remove the need of superfluous () 2022-03-17 19:33:46 +01:00
Patrick Pelissier 359ad20a6a Update documentation with generic API transformation 2022-03-16 22:44:19 +01:00
Patrick Pelissier ac9989e4ff Add generic API transformation
in the framework responsible of expanding
the call to a method from an operator.

The generic API transformation can
support a wide range of call
(Limited to 9 arguments maximum)
2022-03-16 22:29:57 +01:00
Patrick Pelissier 7268551737 Add micro utilities macros for handling list 2022-03-16 22:29:56 +01:00
Patrick Pelissier 823b1974bb Update comments 2022-03-16 22:29:56 +01:00
Patrick Pelissier 382f636206 Fix build issue of bench 2022-03-16 22:27:37 +01:00
Patrick Pelissier 9a1b4abcf9 Add missing small names 2022-03-15 19:29:18 +01:00
Patrick Pelissier a0fc57687b Fix format 2022-03-15 19:24:53 +01:00
Patrick Pelissier 02897f982f Add m_ prefix for the string API 2022-03-15 19:24:14 +01:00
Patrick Pelissier 07a5d0ed0a Define M_USE_SMALL_NAME user macro 2022-03-15 19:04:45 +01:00
Patrick Pelissier 017995ade6 Update README 2022-03-14 22:13:04 +01:00
Patrick Pelissier 9711b2280c Reorder the list of libraries in alphabetic order 2022-03-14 19:33:36 +01:00
Patrick Pelissier 619331916f Add reference to STR & POTTERY string libraries 2022-03-14 19:32:46 +01:00
Patrick Pelissier d7909f7312 Move internal function / macros with the m_string prefix to the internal m_str1ng prefix 2022-03-14 19:29:33 +01:00
Patrick Pelissier 22674f2b46 Fix format 2022-03-14 19:28:49 +01:00
Patrick Pelissier 845736c489 Fix format 2022-03-14 19:28:23 +01:00
Patrick Pelissier 501f9db465 Add bench of big dict for pottery 2022-03-14 19:08:27 +01:00
Patrick Pelissier 8dd440a582 Add note about the string_t format 2022-03-13 22:48:08 +01:00
Patrick Pelissier dd7f090b4b Add bench for POTTERY 2022-03-13 21:56:49 +01:00
Patrick Pelissier dc14a2677b Reformat & cleanup error messages 2022-03-13 21:10:07 +01:00
Patrick Pelissier 8b1ed7f0ae Fix help usage 2022-03-13 21:09:46 +01:00
Patrick Pelissier 19b01b404d Migrate to 2022 2022-03-12 20:25:45 +01:00
Patrick Pelissier ec780d2d4d Add POTTERY library reference 2022-03-12 20:20:45 +01:00
Patrick Pelissier 07790f6711 Add CPU information for MacOS 2022-03-12 20:09:59 +01:00
Patrick Pelissier f72d2b6c67 Add STC bench 2022-03-12 12:04:49 +01:00
Patrick Pelissier e35d631012 Fix path of MS Visual Studio 2022 2022-03-12 11:59:06 +01:00
Patrick Pelissier 3499a08207 Add support for MS Visual Studio 2022 2022-03-12 11:51:27 +01:00
Patrick Pelissier 0ac23e512e Fix CTL bench 2022-03-12 11:40:38 +01:00
PpHd 1852fabcd2 Merge pull request #98
Fix a few typos
2021-12-23 17:48:04 +01:00
Tim Gates 7b6bfac7cb docs: Fix a few typos
There are small typos in:
- example/ex-algo03.c
- m-algo.h
- m-core.h
- m-dict.h
- m-string.h

Fixes:
- Should read `occurrence` rather than `occurence`.
- Should read `fulfilled` rather than `fullfilled`.
- Should read `dictionaries` rather than `dictionnaries`.
- Should read `environment` rather than `environement`.
- Should read `unordered` rather than `undordered`.
2021-12-23 10:00:44 +11:00
Patrick Pelissier e72aa5fb79 Update doc 2021-12-03 22:59:33 +01:00
Patrick Pelissier f4b02b92cc Update documentation 2021-12-03 22:48:43 +01:00
Patrick Pelissier 39edcc560f Fix name of variable 2021-12-03 22:28:44 +01:00
Patrick Pelissier 50669a320c Add m_ prefix for GENINT module,
as it is purely internal (no need to prevent user space breakage).

It will put more stuff in the global m_ prefix
2021-12-03 22:08:15 +01:00
Patrick Pelissier d22c0b05ef Display CPU information 2021-12-03 21:50:36 +01:00
Patrick Pelissier 689be30803 Update README with an implicit constraint 2021-12-03 21:40:09 +01:00
Patrick Pelissier b393a83d38 Add example of JSON serialization on string 2021-12-03 21:39:41 +01:00
Patrick Pelissier 1a1339da6b Remove deprecated features 2021-11-20 13:05:50 +01:00
Patrick Pelissier 9926b51da0 Revert 829c20ba8 as there is an issue in calling M_KEYWORD_P within M_IF. 2021-11-20 10:15:31 +01:00
Patrick Pelissier 761447dea3 V0.6.1 2021-11-13 19:51:32 +01:00
Patrick Pelissier 829c20ba8a Update M_KEYWORD_P to support () . Add more recognized keywords (type, list, LIST, queue, QUEUE, INIT_WITH) 2021-11-13 19:51:23 +01:00
Patrick Pelissier 9ac734e191 Fix documentation 2021-11-12 20:03:36 +01:00
Patrick Pelissier 5420fc6c51 Fix documentation 2021-11-12 20:02:07 +01:00
Patrick Pelissier 62c8ac3e5d V0.6.0 2021-11-11 19:59:19 +01:00
Patrick Pelissier 1d7e93251c Fix overflow of one element in deque _remove 2021-11-11 19:59:19 +01:00
Patrick Pelissier 92fa4691d1 Add comment about the non presence of _it_remove 2021-11-09 21:20:16 +01:00
Patrick Pelissier a20fdf4713 Update documentation 2021-11-06 23:21:16 +01:00
Patrick Pelissier 570dedf1c3 Factorize _size & _empty_p for both dict 2021-11-06 13:54:17 +01:00
Patrick Pelissier 59e5c873ad Factorize _equal_p for both dict 2021-11-06 13:45:27 +01:00
Patrick Pelissier 8dbcdf9991 Uniformize field name between classic dict & OA dict 2021-11-06 13:38:49 +01:00
Patrick Pelissier cd43b50068 Fix name of method 2021-11-06 13:38:29 +01:00
Patrick Pelissier c0413a26f9 Add more example 2021-11-03 21:21:56 +01:00
Patrick Pelissier b2d3d86e0c Add alternative macro M_TEST_METHOD_ALTER_P 2021-11-03 20:54:03 +01:00
Patrick Pelissier bc7552f4a8 Update container summary 2021-11-03 20:53:31 +01:00
Patrick Pelissier 28ae13092f Workaround for MacOs special make 2021-11-02 18:42:41 +01:00
Patrick Pelissier 1f561da43f Add doc for deque _remove 2021-11-02 18:35:09 +01:00
Patrick Pelissier ef8dcda196 Add tests for deque _remove 2021-11-02 18:32:26 +01:00
Patrick Pelissier cf9eb892cf Update & finish deque _remove algorithm 2021-11-02 18:32:14 +01:00
Patrick Pelissier ffa1e2e59c Add WIP deque_remove method 2021-11-02 08:43:42 +01:00
Patrick Pelissier 9549e82b04 Remove launch of check-stl on MacOS as sanitizer=leak is not supported by clang on this system 2021-10-31 00:29:43 +02:00
Patrick Pelissier 50261e390e Update forgotten rename 2021-10-31 00:14:10 +02:00
Patrick Pelissier 618fc99cda Update Continuous Integration 2021-10-31 00:12:01 +02:00
Patrick Pelissier a9fc7e15f8 Rename GET_SET_KEY operator in SAFE_GET_KEY operator 2021-10-30 23:57:50 +02:00
Patrick Pelissier 6b064870f5 Rename CLEAN operator in RESET operator 2021-10-30 23:26:27 +02:00
Patrick Pelissier d78c50be3b Add new files in Makefile 2021-10-30 00:29:53 +02:00
Patrick Pelissier c96cea5a13 Port the examples to rename _get_at to _safe_get 2021-10-30 00:17:15 +02:00
Patrick Pelissier 51d4e930f5 Rename the suffix _get_at to the _safe_get suffix
(Better & clearer naming of the function)
2021-10-30 00:04:07 +02:00
Patrick Pelissier e650addfe4 Replace _clean into _reset (Fix issues for C11 build) 2021-10-28 18:42:15 +02:00
Patrick Pelissier 30afcb45d8 Replace _clean into _reset 2021-10-28 18:32:53 +02:00
Patrick Pelissier e10c3586a3 Rename BITSET & CONCURRENT _clean in _reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 18:13:00 +02:00
Patrick Pelissier 836d892832 Rename BUFFER, I-LIST, PRIOQUEUE & SHARED _clean in _reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 18:08:07 +02:00
Patrick Pelissier 826d251ffe Rename RBTREE & BPTREE _clean in _reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 17:55:54 +02:00
Patrick Pelissier 510cd062ba Rename DICT, TUPLE & VARIANT _clean in _reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 17:51:17 +02:00
Patrick Pelissier 2695cd6f3e Rename DEQUE _clean in _reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 17:40:56 +02:00
Patrick Pelissier f6e3cbbb65 Rename LIST _clean in _reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 17:38:18 +02:00
Patrick Pelissier f172bbaad2 Rename ARRAY _clean in _reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 17:32:02 +02:00
Patrick Pelissier 9176953a8e Rename string_clean in string_reset to avoid confusing _clean & _clear functions. See #97 2021-10-28 17:27:41 +02:00
Patrick Pelissier ae6b87d646 Optimization in case of small constant strings 2021-10-24 21:48:02 +02:00
Patrick Pelissier f719b2387a Remove file 2021-10-14 21:28:26 +02:00
Patrick Pelissier 5bfa8321d0 Add check dict-set against STL 2021-10-14 21:26:02 +02:00
Patrick Pelissier e99fd23e69 Don't export IT_REF for DICT_SET as they should not be updated directly by algorithm 2021-10-14 21:23:37 +02:00
Patrick Pelissier 5057366fb2 Update documentation for RBTREE _remove 2021-10-10 20:36:02 +02:00
Patrick Pelissier 44801b8b91 Add more tests for _remove (that triggered an issue in _previous) 2021-10-10 20:35:44 +02:00
Patrick Pelissier 9eabc86bdd Fix issue in _next / _previous in some corner cases. Fix issue in _remove (IT was not updated to next item) 2021-10-10 20:35:18 +02:00
Patrick Pelissier fbc8f407eb Add test for method _remove 2021-10-10 10:18:06 +02:00
Patrick Pelissier 09a8b93634 Add method _remove for RBTREE 2021-10-10 10:17:55 +02:00
Patrick Pelissier 2caa7b77e7 Add check of RBTREE 2021-10-10 10:04:48 +02:00
Patrick Pelissier c057247126 Add missing exported method 2021-10-10 10:01:44 +02:00
Patrick Pelissier 0899be21c3 Add support for seed (set/random) for rand 2021-10-10 09:36:35 +02:00
Patrick Pelissier c29c9f9ccd Remove obsolete UPDATE operator 2021-10-09 17:57:49 +02:00
Patrick Pelissier c12f698f32 Restore exe target 2021-10-09 17:27:53 +02:00
Patrick Pelissier d6a8a6d159 Add test for _reserver and _resize 2021-10-09 17:25:43 +02:00
Patrick Pelissier 7bf325f91a Update recent framework to compute dependencies 2021-10-09 17:25:13 +02:00
Patrick Pelissier fdfff0c5c5 Add framework to test containers againts C++ library 2021-10-09 16:55:51 +02:00
Patrick Pelissier 4409f613e0 Add test more complete cases for the last issue 2021-10-09 10:11:27 +02:00
Patrick Pelissier 9de644b0f3 Fix issue in _pop_front & _front method that corrupts the deque in some cases 2021-10-09 10:11:02 +02:00
Patrick Pelissier 3e36363d28 Fix format 2021-10-09 10:08:13 +02:00
Patrick Pelissier 4f1d1a949c Document _get_at method for dict 2021-10-08 20:47:18 +02:00
Patrick Pelissier e52f3b8b30 Add more test cases for deque _next / _previous 2021-10-07 21:47:49 +02:00
Patrick Pelissier 36916e7b3d Fix issue in deque _next and deque _previous methods in some corner cases 2021-10-07 21:47:20 +02:00
Patrick Pelissier ba778e9bd2 Simplify 2021-10-07 21:40:42 +02:00
Patrick Pelissier df7112489a Add tag for identifying C code in documentation 2021-10-05 00:28:31 +02:00
Patrick Pelissier d9c203736f Update examples section 2021-10-04 20:36:39 +02:00
Patrick Pelissier 2b61ffa784 Ignore backup files 2021-10-02 19:15:03 +02:00
Patrick Pelissier ba85640172 Add bench for CTL library 2021-10-02 19:14:01 +02:00
Patrick Pelissier 4d21ad5050 Update 2021-10-02 19:13:10 +02:00
Patrick Pelissier aae14de62b Update documentation 2021-10-02 13:22:12 +02:00
Patrick Pelissier 70fa621745 Add test function for _splice function 2021-10-02 13:09:51 +02:00
Patrick Pelissier e97f4f7f41 Document _splice function for dictionary 2021-10-02 13:09:18 +02:00
Patrick Pelissier 7a08ddce9e Remove UPDATE opertor as there are no default operators that define it (and no one uses it as it is poorly documented). Replace by SET for RB-THREE. Replace by ADD for the splice function of dictionary 2021-10-02 13:06:30 +02:00
Patrick Pelissier e19c9d31a8 Update comments 2021-10-01 07:41:23 +02:00
Patrick Pelissier 51ae5f9f0c Fix spelling 2021-10-01 07:41:11 +02:00
Patrick Pelissier 22e8133f95 Test for corrected issue of IT_INSERT (Wrong behavior if IT==END) 2021-09-29 23:30:20 +02:00
Patrick Pelissier c2e19fed01 Fix issue in IT_INSERT (Wrong behavior if IT==END) 2021-09-29 23:29:57 +02:00
Patrick Pelissier 274afc9978 Fix syntax 2021-09-24 23:26:23 +02:00
Patrick Pelissier 0c337836ca Add CTL library as reference 2021-09-24 23:23:57 +02:00
Patrick Pelissier 1a3e694e20 Add new example of different containers 2021-09-23 23:06:24 +02:00
Patrick Pelissier a0572b63b1 Update documentation for tuple 2021-09-23 23:04:10 +02:00
Patrick Pelissier 1765d8ef06 Update test for testing new possibility of the tuples 2021-09-23 23:04:00 +02:00
Patrick Pelissier 1e00a102e8 TUPLE: Defined HASH/CMP/EQUAL methods if at least ONE methods is defined in the fields. Fields that don't have or have disabled method are supposed to be secondary fields that are not pertinent for comparing the objects. 2021-09-23 23:03:30 +02:00
Patrick Pelissier 61f8dcdbae Add string_set_char function 2021-09-22 23:07:35 +02:00
Patrick Pelissier 39eeb3aec7 Fix buffer overflow in ARRAY _pop_at function (reported by tyrone718) 2021-09-18 09:52:33 +02:00
Patrick Pelissier 2178dcfcab Add LIST_INIT_VALUE & LIST_DUAL_PUSH_INIT_VALUE. 2021-08-15 21:55:09 +02:00
Patrick Pelissier f8b4f44105 Add ARRAY_INIT_VALUE 2021-08-15 21:44:36 +02:00
Patrick Pelissier 9c2468c2b7 Update comments. 2021-08-15 21:27:54 +02:00
Patrick Pelissier 3d5cc55d0a Adding assembly generation for mserial-json
in order to check proper & full inlining.
2021-08-09 10:30:53 +02:00
Patrick Pelissier 5b9cccd2dd Adding more macros not to be expanded in coverage mode 2021-08-09 10:30:04 +02:00
Patrick Pelissier 103b2ab79b Fix C++ 32 bits error on Ubuntu. 2021-08-07 17:15:45 +02:00
Patrick Pelissier 05f1cd784c Add support of GCC Static Analyzer
It seems to report only false positive.
2021-08-07 17:07:38 +02:00
Patrick Pelissier 6e6754f84e Activate tests for C++ 32 bits. 2021-08-07 10:28:19 +02:00
Patrick Pelissier 33ef448a86 Update documentation. 2021-08-07 10:27:56 +02:00
Patrick Pelissier 8ce59c2e9d Maintenance:
* update comments
* simplify code.
2021-08-07 00:34:18 +02:00
Patrick Pelissier 85a363d325 Update definition of returned iterator of _it_from of RB tree
from the greatest element of 'rbtree' lower of equal than 'data'
to the lowest element of the tree 'rbtree' greater or equal than 'data'

It is more logical and natural:
if you have a tree of elements between [2, 4], and you want
to iterate all elements from 0 to 10, the old definition doesn't allow
you to iterate easily over this subset.
2021-07-16 22:46:44 +02:00
Patrick Pelissier 7dc1a9dc0e Update RB Tree:
* Fix issue of the searched element is the root node (See #93)
for _it_from. It now returns a proper iterator.

* Update _it_from to match the last documentation:
if there is no element lower or equal to the searched node,
it returns a null iterator.

* Update _it_while_p so that it returns false if it is null iterator.
2021-07-16 21:47:37 +02:00
Patrick Pelissier 983d90b731 * Complete tests on iterators to be more exhaustive.
* Add tests on _it_from/_it_until_p/_it_while_p.
2021-07-16 21:46:57 +02:00
Patrick Pelissier f307762801 Update document of _it_from, _it_until_p, _it_while_p:
* _it_from: if there is no element that matches the condition,
it returns a null iterator, which is more coherent.
* _it_until_p: clarify condition if the iterator is null.
* _it_while_p: clarify condition if the iterator is null.
2021-07-16 21:42:55 +02:00
Patrick Pelissier 7924798e7a Update names of contract macros as per macro renaming 2021-07-16 21:41:59 +02:00
Patrick Pelissier e46bbaffb9 Avoid GCC warning (-Wstringop-truncation) 2021-07-05 23:14:21 +02:00
Patrick Pelissier 0171c49413 Unlikely some if conditions. 2021-07-05 22:45:57 +02:00
Patrick Pelissier a79cd9da97 Fix issue for RB Tree _it_equal_p method
if both iterators are equal and are associated
to a RB tree without any element.
2021-07-05 22:44:58 +02:00
Patrick Pelissier 408959c927 Be more precise in the bound check. 2021-07-05 22:32:19 +02:00
Patrick Pelissier ac4d93fe29 Clean RB Tree _pop_at to avoid an aliasing issue. 2021-07-05 20:21:26 +02:00
Patrick Pelissier 82d224fa66 Clean up documentation 2021-07-05 20:19:00 +02:00
Patrick Pelissier a5b6d8e391 Rewrite assertion to be more robust. 2021-07-04 00:20:10 +02:00
Patrick Pelissier 7f79abec3f Fix issue with INIT_WITH of array/list/....
combined with tuple:
_push_back_raw was used within an expanded macro
and as a consequence was expanded multiple times,
resulting in adding a new term in the sequence
for each field of the tuple.
2021-07-04 00:01:00 +02:00
Patrick Pelissier ca8d4aa97a Update _back & _front to return a modifiable ptr
(There is no real reasons to return a const pointer).
2021-07-03 23:59:19 +02:00
PpHd 690cef561c Merge pull request #92 from P-p-H-d/let-recur
Recursive INIT_WITH within M_LET
2021-07-01 22:33:34 +02:00
Patrick Pelissier 16ac4c556b Update documentation. 2021-07-01 22:14:17 +02:00
Patrick Pelissier 3c175b9199 Update documentation. 2021-07-01 22:12:15 +02:00
Patrick Pelissier a3827cc384 Add tests for new constructs
allowed in M_LET for tuples
2021-07-01 22:12:15 +02:00
Patrick Pelissier 353daecbd1 Comment new code. 2021-07-01 22:12:15 +02:00
Patrick Pelissier 368392fb8f Add CLEAN operator for default oplist
(same as INIT operator)
2021-07-01 22:12:15 +02:00
Patrick Pelissier 57441b2fc1 Add first draft of recursive
INIT_WITH macro for tuples.
2021-07-01 22:12:15 +02:00
Patrick Pelissier b225600238 Add internal functions for tuple
that are needed for future INIT_WITH support.
2021-07-01 22:12:15 +02:00
Patrick Pelissier 6b361e0d0c Add use of M_PRINT in C11 mode. 2021-07-01 22:12:15 +02:00
Patrick Pelissier 08668aa02b Add a new example of the new M_LET feature. 2021-07-01 22:12:15 +02:00
Patrick Pelissier 3d3eb6f1d2 Update tests to new syntax of M_LET. 2021-07-01 22:12:15 +02:00
Patrick Pelissier 9bd820c652 Force use of INIT_WITH for function object. 2021-07-01 22:12:15 +02:00
Patrick Pelissier 0e960ec23f Force use of INIT_WITH within M_LET. 2021-07-01 22:12:15 +02:00
Patrick Pelissier ca65d81b60 * Fix conflict between M_MAP2 /M_MAP2B
(this arises through M_LET & M_GET_METHOD)

* Rename M_GET_OPPROPERTY into M_GET_PROPERTY

* M_LET can be configured to always use INIT_WITH for special kind of objects.
2021-07-01 22:12:15 +02:00
Patrick Pelissier 23624a1d73 Remove M_EVAL from M_LET as it is not needed anymore. 2021-07-01 22:12:15 +02:00
Patrick Pelissier 3ac08b0395 Add test with a lot of different kind of M_LET with list of strings. 2021-07-01 22:12:15 +02:00
Patrick Pelissier dedb79dbc5 Use of new initializer macro 2021-07-01 22:12:15 +02:00
Patrick Pelissier 154b503bc6 Avoid using the input more than once in macros string_init_* (Avoid issues) 2021-07-01 22:12:15 +02:00
Patrick Pelissier 5c612ce521 Update M_LET to handle both set & init_with depending on the user syntax. Add M_INIT_WITH_VAI to use this new feature. 2021-07-01 22:12:15 +02:00
Patrick Pelissier 80582ac5ce Update as the minimum level of recursion is decreased 2021-07-01 22:12:15 +02:00
Patrick Pelissier 8e6af3bfeb Add note 2021-07-01 22:12:15 +02:00
Patrick Pelissier 61671d1b18 Minor fix 2021-07-01 22:12:15 +02:00
Patrick Pelissier aa3ad973d0 Add another recussive M_LET test 2021-07-01 22:12:15 +02:00
Patrick Pelissier a19a010d1e Add WIP version for a M_LET recursive 2021-07-01 22:12:14 +02:00
Patrick Pelissier 36003b6bb3 * Add support for extented variable for M_[F]PRINT
* Update documentation
* Add test.
2021-07-01 00:13:31 +02:00
Patrick Pelissier 3c83e4088c Add internal macro M_MERGE_ARGLIST 2021-06-20 11:06:19 +02:00
Patrick Pelissier 357feb9532 Update documentation as per lastest changes. 2021-06-19 22:47:13 +02:00
Patrick Pelissier 7e234cba65 Add test of M_FPRINT using string_t. 2021-06-19 22:46:58 +02:00
Patrick Pelissier 0535ceeaeb Add support of string_t by M_PRINT macro. 2021-06-19 22:46:41 +02:00
Patrick Pelissier e688f0b1df Add internal method M_GET_OPPROPERTY to get the subproperty of an oplist
Add test for such macro
Rename operator CLASS into PROPERTIES
2021-06-17 00:20:35 +02:00
Patrick Pelissier a950e15625 Adding method for NAME operator for basic containers 2021-06-12 11:11:30 +02:00
Patrick Pelissier cf8b198dac Fix issue in M_LET: if the INIT/INIT_SET/INIT_WITH uses the macro M_IF, it may be not expanded in some cases (since the M_CALL_* is used itself within an expanded tainted M_IF). Fix this by calling M_CALL_* outside the expanded M_IF. 2021-05-23 00:53:54 +02:00
Patrick Pelissier c75d5da02d Fix: use of M_CALL_INIT / M_CALL_CLEAR instead of M_GET_INIT / M_GET_CLEAR so that API transformation can be applied 2021-05-23 00:42:43 +02:00
Patrick Pelissier cdffb15066 Simplify code 2021-05-23 00:34:08 +02:00
Patrick Pelissier cd0ad0dba9 Factorize code 2021-05-23 00:31:23 +02:00
Patrick Pelissier d3be5dba96 Reduce number of created threads, as sometimes it hits the limits 2021-05-22 18:11:09 +02:00
Patrick Pelissier cb94a26a9f Update documentation 2021-05-22 17:33:46 +02:00
Patrick Pelissier 3c8b238e75 Add operator CLASS and new keywords 2021-05-22 17:33:34 +02:00
Patrick Pelissier 74202d52b3 Adding default value for LIMITS
enabling to avoid defining then for all types.
2021-04-16 23:23:42 +02:00
Patrick Pelissier 603c92cd0e Cleanup uneeded final comma separator 2021-04-10 23:27:49 +02:00
Patrick Pelissier e514d74f43 Update test to be more pertinent 2021-04-04 22:28:32 +02:00
Patrick Pelissier 970161464a Add constraint 2021-04-04 22:28:13 +02:00
Patrick Pelissier 3e7de27c00 Rename M_HASH_SEED into M_USE_HASH_SEED
as it a user overridable macro
(API break).
2021-04-03 23:15:12 +02:00
Patrick Pelissier e28d403216 Undo previous changes until further analysis (it broke CI) 2021-03-28 11:53:18 +02:00
Patrick Pelissier fdeb9f1322 Format 2021-03-28 11:48:59 +02:00
Patrick Pelissier 76fad21103 Update comments and naming 2021-03-28 11:48:59 +02:00
Patrick Pelissier 5d4fa31083 Update doc & comments 2021-03-28 11:48:58 +02:00
Patrick Pelissier c3858f4e63 Update documentation 2021-03-28 11:48:58 +02:00
Patrick Pelissier 2e0fc21878 Fix _push_move of SPSC. It shall take a pointer to the object, not the object itself as argument, just like the other _push_move 2021-03-28 11:48:58 +02:00
Patrick Pelissier 4b71bbec7e Protect key from being changed while iterating. 2021-03-28 11:13:55 +02:00
Patrick Pelissier 052989a5a2 Update m_serial_ll_ct to have more basic types. 2021-03-28 11:09:59 +02:00
Patrick Pelissier 60cfc63c4e Add static assertion. 2021-03-28 09:39:52 +02:00
Patrick Pelissier 60ef4c7f06 Fix documentation 2021-03-28 09:39:41 +02:00
Patrick Pelissier 58fc40d0f1 Update oplist 2021-03-28 09:32:23 +02:00
Patrick Pelissier 3d7e9e7c03 Add _get_at method for B+TREE 2021-03-28 09:29:04 +02:00
Patrick Pelissier 52e745f905 Update documentation of operators 2021-03-27 21:15:03 +01:00
Patrick Pelissier 8433fc178c Fix issue for union with visual & clang-cl 2021-03-20 13:16:10 +01:00
Patrick Pelissier 59807baa18 Fix several minor issues on m-buffer:
1) Fix performance issue if the buffer was not designed
to be thread safe. The internal numbers are in this cases
just plain numbers and not atomic numbers. This is done
through union. Fix #90

2) In case of thread safe buffer, put each item in a
separate cacheline. This ensures proper performance in
case there is several producers. This however
increases the consumption size.

3) Fix a data race issue: after the mutex is locked,
and before the test if the buffer is empty (through the
atomic read of its size). It is solved by performing a
memory acquire when testing if the buffer is empty.

4) Add more comments.
2021-03-20 13:01:51 +01:00
Patrick Pelissier 9b5b15e8cb Update comment 2021-03-16 21:43:09 +01:00
Patrick Pelissier 2c54b63c51 Update dev doc 2021-03-16 21:42:48 +01:00
Patrick Pelissier e4d1167274 Improve test suite to be more representative 2021-03-14 23:42:05 +01:00
Patrick Pelissier 2f10aba390 Workaround issue with address sanitizer 2021-03-14 21:26:04 +01:00
Patrick Pelissier a044fadec8 Fix minor warning in some compiler options 2021-03-14 11:00:05 +01:00
Patrick Pelissier 0edb6165b5 Fix buffer overflow if size=64*N 2021-03-13 23:39:26 +01:00
Patrick Pelissier 7d262f2450 Fix formatting 2021-03-13 23:08:04 +01:00
Patrick Pelissier fa30328572 Reduce allowed range for buffer to unsigned int. It should be more than enough for any scenario. 2021-03-13 22:43:01 +01:00
Patrick Pelissier b0cff7c6ac Remove git checkout HEAD^2 as per recommendation of CodeQL 2021-03-09 22:39:02 +01:00
Patrick Pelissier 50da9e803c Add documentation for m_serial_str_json 2021-03-09 22:12:44 +01:00
Patrick Pelissier 26252fedf5 Add test for JSON serialization over string 2021-03-09 22:12:29 +01:00
Patrick Pelissier 2dcda90c7b Add JSON serial over string 2021-03-09 22:12:16 +01:00
Patrick Pelissier b7d79c0a83 Fix issue for wrong formatted JSON (error not properly reported) 2021-03-09 20:56:13 +01:00
Patrick Pelissier ae285c0a01 Add also const string in serial object 2021-03-09 20:55:46 +01:00
Patrick Pelissier 07db846f3b Rename internal string functions to be compliant with new scheme. Not sure if this scheme will remain however (still searching for a better naming that fits all criteria). 2021-03-01 22:18:32 +01:00
Patrick Pelissier 3b6907b743 Add more test cases. 2021-02-23 16:24:46 +01:00
Patrick Pelissier 82e49c6214 Clarify doc. 2021-02-23 16:03:03 +01:00
Patrick Pelissier 8e9aa9cac4 Fix _min & _max for B+Tree
Make code match the documentation if there is no element in the tree.
2021-02-23 15:59:45 +01:00
Patrick Pelissier 5cd6c1dd36 Update Makefile by controlling when making dist that all files are properly referenced in the Makefile 2021-02-22 18:59:49 +01:00
Patrick Pelissier a98ce5ea91 Remove unused test file 2021-02-22 18:59:49 +01:00
Patrick Pelissier a4bb0fab8f Update documentation for bitset 2021-02-22 12:06:51 +01:00
Patrick Pelissier 7b2e242c94 Add function bitset_popcount 2021-02-22 12:06:46 +01:00
Patrick Pelissier 5fd6352a4e Add more tests for bitset_resize 2021-02-22 11:40:29 +01:00
Patrick Pelissier a82f2ba065 * Fix an issue in _pop_at. * Optimize code by ensuring that the last limbs is always properly masked (simplify algorithm) 2021-02-22 11:31:49 +01:00
Patrick Pelissier 3377acd9e6 Test another bit for _pop_at 2021-02-22 11:30:59 +01:00
Patrick Pelissier 709168652a Reformat and specify clz for bitset size = 0 2021-02-21 21:41:51 +01:00
Patrick Pelissier e25e9ba29b Make the contract of Array & Buffer fail after a clear. 2021-02-21 21:08:35 +01:00
Patrick Pelissier ed5eac6e9d Update doc 2021-02-21 21:08:35 +01:00
Patrick Pelissier 651768f012 Fix name in doc 2021-02-21 21:08:35 +01:00
Patrick Pelissier 88c0a881da Update 2021-02-20 00:22:24 +01:00
Patrick Pelissier 5b9dd504e5 Add chapter "Global User Customization" 2021-02-20 00:20:54 +01:00
Patrick Pelissier 165ec09061 Rename user customizable macros
to be compliant with other
and clearer that they can be customized.
2021-02-20 00:10:26 +01:00
Patrick Pelissier 6cc972bab2 Rename header define to be compliant with others. 2021-02-20 00:08:07 +01:00
Patrick Pelissier 333047fc4c Make assertions more robust.
Fix read out of bound (with test cases).
2021-02-14 00:15:43 +01:00
Patrick Pelissier 3e4a5932c2 Rename internal function / types.
Reformat
2021-02-13 11:45:16 +01:00
Patrick Pelissier e2f6b81a03 Remove M_LOCK from readme as it is obsolete. 2021-02-13 11:45:16 +01:00
Patrick Pelissier 0231aad947 Update coding rules. 2021-02-13 11:45:16 +01:00
Patrick Pelissier 6636800c5b Remove obsolete / deprecated function/macros. 2021-02-13 11:45:16 +01:00
Patrick Pelissier d1f41de0cb Rename internal functions
to use internal prefix.
2021-02-13 11:45:16 +01:00
Patrick Pelissier c4d339cb62 Rename internal interface. 2021-02-13 11:45:16 +01:00
Patrick Pelissier 56b2adc57d Fix internal name. 2021-02-13 11:45:16 +01:00
Patrick Pelissier a73bee2650 Micro-optimization of DICT_OA
by reducing the number of cmp instructions.
2021-02-13 11:45:16 +01:00
Patrick Pelissier 517da1b999 Rename generated internal functions
to avoid "poluting" userspace naming.
2021-02-13 11:45:05 +01:00
Patrick Pelissier 25497bd96f Factorize code so that _DEF macros use _DEF_AS ones 2021-02-07 23:04:59 +01:00
Patrick Pelissier d12b1edc39 Update doc 2021-02-07 23:04:45 +01:00
Patrick Pelissier 0515cfd068 Add macro M_GREATER_THAN_P & M_LESS_OR_EQUAL_P (src, tests, doc) 2021-02-07 09:53:13 +01:00
Patrick Pelissier e84bc9fc0d Fix link 2021-02-07 09:41:10 +01:00
Patrick Pelissier d85df43329 Replace UNERDLOW/OVERFLOW by M_UNDERFLOW/M_OVERFLOW as some systems (Windows/MacOS) perform '#define UNDERFLOW value' in their headers, preventing the detection at preprocessing time. 2021-02-07 09:36:00 +01:00
Patrick Pelissier 16e2e07d41 * Fix M_REVERSE as per the doc (don't add parenthesis on the returned arglist). * Update usage to take this into account. 2021-02-07 00:50:10 +01:00
Patrick Pelissier 57fcb4012b Update doc 2021-02-07 00:42:10 +01:00
Patrick Pelissier 5be981def3 Fix warning 2021-02-07 00:41:59 +01:00
Patrick Pelissier 493e38abfc Fix formatting 2021-02-07 00:31:15 +01:00
Patrick Pelissier 6e006d216b Add macro M_GREATER_OR_EQUAL_P (src, test, doc) 2021-02-07 00:25:47 +01:00
Patrick Pelissier da613ad188 * Add macro M_LESS_THAN_P (src, test, doc). * Robustify M_INC & M_DEC so that overflow & underflow keeps returning overflow & underflow 2021-02-07 00:10:55 +01:00
Patrick Pelissier 3dad326bea Update doc 2021-02-06 23:54:16 +01:00
Patrick Pelissier 480a791f4c Update tests 2021-02-06 23:41:04 +01:00
Patrick Pelissier 753c46ef14 Add OrderPP 2021-02-06 23:40:58 +01:00
Patrick Pelissier f2d5de252b Add M_FILTER and M_FILTER_C macros (src, tests, doc) 2021-02-06 23:24:55 +01:00
Patrick Pelissier 0cb1a8054f Add M_REPLICATE & M_REPLICATE_C (src, test, doc) 2021-02-06 22:32:38 +01:00
Patrick Pelissier 07eb5697ab Remove limitation of M_AS_STR to be called within a M_APPLY 2021-02-06 22:22:50 +01:00
Patrick Pelissier e4dc06a0e2 Update doc 2021-02-06 22:13:06 +01:00
Patrick Pelissier cd2012f33d Update doc 2021-02-06 21:58:52 +01:00
Patrick Pelissier 9eba30648d Rename M_INVERT into M_REVERSE to be more coherent with REVERSE operator 2021-02-06 21:58:45 +01:00
Patrick Pelissier 7e70371197 Format & comment code 2021-02-06 21:28:18 +01:00
Patrick Pelissier 527f6d8d9a Add metalang99 2021-02-06 21:05:26 +01:00
Patrick Pelissier 9ebc12a98f Update to 0.5.1 2021-02-06 21:03:19 +01:00
Patrick Pelissier bb21d9a6ad Update Makefile to control that both versions are the same when making a distribution 2021-02-06 21:00:25 +01:00
Patrick Pelissier ad39cdd393 Add some tests for new function 2021-02-05 00:17:18 +01:00
Patrick Pelissier 0de771036b Add M_REDUCE3
Add M_MAP3_C
Add operator LIMITS.
2021-02-05 00:11:44 +01:00
Patrick Pelissier 6d6afa4cfd Update doc 2021-01-29 20:43:46 +01:00
Patrick Pelissier 7546cbedd2 Update doc 2021-01-20 20:44:48 +01:00
Patrick Pelissier 8d5962eefd Update target html & doc 2021-01-20 20:44:36 +01:00
Patrick Pelissier 8597b0b8c0 Fix warning on clang and old gcc 2021-01-18 18:21:01 +01:00
Patrick Pelissier c625c39883 Add a new implementation of M_CSTR using GNU C extension which provides faster & smaller code 2021-01-18 18:16:45 +01:00
Patrick Pelissier bce86460fe Rewrite test cases to avoid potential warnings 2021-01-18 18:16:05 +01:00
Patrick Pelissier f002eebc83 Update constraint 2021-01-18 18:01:42 +01:00
Patrick Pelissier 139da2e49f Update example 2021-01-16 10:25:55 +01:00
222 changed files with 37842 additions and 27762 deletions

No files matched your search

+139 -16
View File
@@ -10,37 +10,49 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: CPU Information
run: lscpu || sysctl -a|grep cpu || echo "CPU information not available"
- name: make check C99
run: make clean check CC="cc -std=c99 -Wno-unknown-warning-option -Werror"
run: make clean && make check -j 2 CC="cc -std=c99 -Wno-unknown-warning-option -Werror"
- name: make check C11
working-directory: ./tests
run: make clean check CC="cc -std=c11 -Wno-unknown-warning-option -Werror"
run: make clean && make check -j 2 CC="cc -std=c11 -Wno-unknown-warning-option -Werror"
- name: make check C++
working-directory: ./tests
run: make clean check CC="c++ -std=c++11"
run: make clean && make check -j 2 CC="c++ -std=c++11"
build_linux32:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: update package list
run: sudo apt-get update
- name: install multilib
run: sudo apt-get install gcc-multilib
run: sudo apt-get install gcc-multilib g++-multilib
- name: CPU Information
run: lscpu || echo "CPU information not available"
- name: make check C99 (32bits)
working-directory: ./tests
run: make clean check CC="gcc -m32 -std=c99 -Wno-unknown-warning-option -Werror"
run: make clean && make check -j 2 CC="gcc -m32 -std=c99 -Wno-unknown-warning-option -Werror"
- name: make check C11 (32bits)
working-directory: ./tests
run: make clean check CC="gcc -m32 -std=c11 -Wno-unknown-warning-option -Werror"
run: make clean && make check -j 2 CC="gcc -m32 -std=c11 -Wno-unknown-warning-option -Werror"
- name: make check C++ (32 bits)
working-directory: ./tests
run: make clean && make check -j 2 CC="g++ -m32 -std=c++11 -Wno-unknown-warning-option "
- name: make check against C++ STL
working-directory: ./tests
run: make clean && make check-stl -j 2
build_linux_tcc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: CPU Information
run: lscpu || echo "CPU information not available"
- name: Clone TCC
shell: bash
run: git clone https://repo.or.cz/tinycc.git
@@ -52,16 +64,25 @@ jobs:
run: make depend
- name: make check
shell: bash
run: make CC="/tmp/tcc/bin/tcc -std=c99" check
run: make CC="/tmp/tcc/bin/tcc -std=c99" check -j4 || make CC="/tmp/tcc/bin/tcc -std=c99" check -j2 || make CC="/tmp/tcc/bin/tcc -std=c99" check
build_linux_sanitize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: make sanitize
working-directory: ./tests
run: make sanitize -j 2
build_windows_mingw:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: make check
shell: bash
run: mingw32-make CC="gcc -std=c99 -D__USE_MINGW_ANSI_STDIO=1" check
run: mingw32-make -j 2 CC="gcc -std=c99 -D__USE_MINGW_ANSI_STDIO=1" check
build_windows_msys2:
runs-on: windows-latest
@@ -69,20 +90,20 @@ jobs:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: git mingw-w64-x86_64-toolchain make
- name: make check
run: make CC="gcc -std=c99 -D__USE_MINGW_ANSI_STDIO=1" check
run: make -j 2 CC="gcc -std=c99 -D__USE_MINGW_ANSI_STDIO=1" check
build_windows_visual:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: make check
shell: cmd
working-directory: ./tests
@@ -92,9 +113,111 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: make check
shell: cmd
working-directory: ./tests
run: Make-check-cl.bat clang-cl
# The host should always be linux
build_freebsd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test in FreeBSD
id: test
uses: vmactions/freebsd-vm@v1
timeout-minutes: 60
with:
usesh: true
run: |
freebsd-version
cd tests
make check -j 2 CC="cc -std=c99 -Wno-unknown-warning-option -Werror" && make clean && make check -j 2 CC="cc -std=c11 -Wno-unknown-warning-option -Werror" LDFLAGS="-lstdthreads" && make clean
# The host should always be linux
build_aarch64:
runs-on: ubuntu-latest
name: Build on aarch64
steps:
- uses: actions/checkout@v4
- uses: uraimo/run-on-arch-action@v3
name: Run commands on aarch64
id: make
timeout-minutes: 60
with:
arch: aarch64
distro: bullseye
# Not required, but speeds up builds
githubToken: ${{ github.token }}
shell: /bin/sh
run: |
apt-get update -q -y
apt-get install -q -y build-essential git gcc
lscpu
cd tests && make check -j 2 && make clean
# The host should always be linux
build_armv6:
runs-on: ubuntu-latest
name: Build on armv6
steps:
- uses: actions/checkout@v4
- uses: uraimo/run-on-arch-action@v3
name: Run commands on armv6
id: make
timeout-minutes: 60
with:
arch: armv6
distro: alpine_latest
# Not required, but speeds up builds
githubToken: ${{ github.token }}
shell: /bin/sh
run: |
apk update
apk add build-base gcc make
cd tests && make check -j 2 && make clean
# The host should always be linux
build_riscv64:
runs-on: ubuntu-latest
name: Build on riscv64
steps:
- uses: actions/checkout@v4
- uses: uraimo/run-on-arch-action@v3
name: Run commands on riscv64
id: make
timeout-minutes: 60
with:
arch: riscv64
distro: ubuntu22.04
# Not required, but speeds up builds
githubToken: ${{ github.token }}
shell: /bin/sh
run: |
apt-get update -q -y
apt-get install -q -y build-essential git gcc
lscpu
cd tests && make check -j 2 && make clean
# The host should always be linux
build_ppc64le:
runs-on: ubuntu-latest
name: Build on ppc64le
steps:
- uses: actions/checkout@v4
- uses: uraimo/run-on-arch-action@v3
name: Run commands on ppc64le
id: make
timeout-minutes: 60
with:
arch: ppc64le
distro: ubuntu22.04
# Not required, but speeds up builds
githubToken: ${{ github.token }}
shell: /bin/sh
run: |
apt-get update -q -y
apt-get install -q -y build-essential git gcc
lscpu
cd tests && make check -j 2 && make clean
+3 -8
View File
@@ -28,20 +28,15 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -55,4 +50,4 @@ jobs:
run: make exe
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
+6
View File
@@ -38,7 +38,13 @@ depend
other/
a*.dat
config
config.*
*.log
.vscode
.vs
tmp-serial.*
*~
*.gcda
*.gcno
*.gcov
*.synt
+1 -1
View File
@@ -1,6 +1,6 @@
BSD 2-Clause License
Copyright (c) 2017-2021, Patrick Pelissier
Copyright (c) 2017-2025, Patrick Pelissier
All rights reserved.
Redistribution and use in source and binary forms, with or without
+20 -12
View File
@@ -1,4 +1,4 @@
# Copyright (c) 2017-2021, Patrick Pelissier
# Copyright (c) 2017-2025, Patrick Pelissier
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -34,14 +34,14 @@ DESTDIR=
# Package name & version.
PACKAGE=m_lib-$(VERSION)
VERSION=0.5.0
VERSION=0.8.1
# Define the contain of the distribution tarball
HEADER=m-algo.h m-array.h m-atomic.h m-bitset.h m-bptree.h m-buffer.h m-c-mempool.h m-concurrent.h m-core.h m-deque.h m-dict.h m-funcobj.h m-genint.h m-i-list.h m-i-shared.h m-list.h m-mempool.h m-mutex.h m-prioqueue.h m-rbtree.h m-serial-bin.h m-serial-json.h m-shared.h m-snapshot.h m-string.h m-tuple.h m-variant.h m-worker.h
HEADER=m-algo.h m-array.h m-atomic.h m-bitset.h m-bptree.h m-buffer.h m-core.h m-deque.h m-dict.h m-funcobj.h m-generic.h m-genint.h m-i-list.h m-list.h m-thread.h m-prioqueue.h m-rbtree.h m-serial-bin.h m-serial-json.h m-snapshot.h m-string.h m-tree.h m-try.h m-tuple.h m-variant.h m-worker.h m-bstring.h m-shared-ptr.h m-queue.h
DOC1=LICENSE README.md
DOC2=doc/API.txt doc/Container.html doc/Container.ods doc/depend.png doc/DEV.md doc/ISSUES.org doc/oplist.odp doc/oplist.png
EXAMPLE=example/ex11-algo01.c example/ex11-algo02.c example/ex11-json01.c example/ex11-section.c example/ex-algo02.c example/ex-algo03.c example/ex-algo04.c example/ex-array00.c example/ex-array01.c example/ex-array02.c example/ex-array03.c example/ex-array04.c example/ex-array05.c example/ex-bptree01.c example/ex-buffer01.c example/ex-dict01.c example/ex-dict02.c example/ex-dict03.c example/ex-dict04.c example/ex-grep01.c example/ex-list01.c example/ex-mph.c example/ex-multi01.c example/ex-multi02.c example/ex-multi03.c example/ex-multi04.c example/ex-multi05.c example/ex-rbtree01.c example/ex11-algo02.json example/ex11-json01.json example/Makefile
TEST=tests/test-malgo.c tests/test-marray.c tests/test-mbitset.c tests/test-mbptree.c tests/test-mbuffer.c tests/test-mcmempool.c tests/test-mconcurrent.c tests/test-mcore.c tests/test-mdeque.c tests/test-mdict.c tests/test-mfuncobj.c tests/test-mgenint.c tests/test-milist.c tests/test-mlist.c tests/test-mmempool.c tests/test-mmutex.c tests/test-mprioqueue.c tests/test-mrbtree.c tests/test-mserial-bin.c tests/test-mserial-json.c tests/test-mshared.c tests/test-msnapshot.c tests/test-mstring.c tests/test-mtuple.c tests/test-mvariant.c tests/test-mworker.c tests/tgen-bitset.c tests/tgen-marray.c tests/tgen-mdict.c tests/tgen-mlist.c tests/tgen-mstring.c tests/tgen-openmp.c tests/tgen-queue.c tests/tgen-shared.c tests/Makefile tests/coverage.h tests/test-obj.h tests/dict.txt
DOC2=doc/API.txt doc/Container.html doc/Container.ods doc/depend.png doc/DEV.md doc/ISSUES.org doc/oplist.odp doc/oplist.png doc/bench-array-log.png doc/bench-array.png doc/bench-list-log.png doc/bench-list.png doc/bench-oset-log.png doc/bench-oset.png doc/bench-umap-log.png doc/bench-umap.png doc/cc.sh
EXAMPLE=example/ex11-algo01.c example/ex11-algo02.c example/ex11-json01.c example/ex11-section.c example/ex-algo02.c example/ex-algo03.c example/ex-algo04.c example/ex-array00.c example/ex-array01.c example/ex-array02.c example/ex-array03.c example/ex-array04.c example/ex-array05.c example/ex-bptree01.c example/ex-buffer01.c example/ex-dict01.c example/ex-dict02.c example/ex-dict03.c example/ex-dict04.c example/ex-grep01.c example/ex-list01.c example/ex-mph.c example/ex-multi01.c example/ex11-multi02.c example/ex-multi03.c example/ex-multi04.c example/ex-multi05.c example/ex-rbtree01.c example/ex11-algo02.json example/ex11-json01.json example/Makefile example/ex-defer01.c example/ex-string01.c example/ex-string02.c example/ex-astar.c example/ex-string03.c example/ex11-tstc.c example/ex-no-stdio.c example/ex11-count-lines.c example/ex11-json-net.c example/ex11-rbtree02.c example/ex-curl.c example/ex-dict05.c example/ex-dict06.c example/exm-lib.c example/exm-main.c example/exn-lib.c example/exn-main.c example/exm-header.h example/exn-header.h example/ex-alloc1.c example/ex-alloc2.c example/ex-try01.c example/ex11-generic01.c example/ex-bptree02.c example/ex-i-list.c example/ex11-generic02.c example/ex11-small-name.c example/ex11-variant01.c example/ex11-use-pool.c
TEST=tests/test-malgo.c tests/test-marray.c tests/test-mbitset.c tests/test-mbptree.c tests/test-mbuffer.c tests/test-mcore.c tests/test-mdeque.c tests/test-mdict.c tests/test-mfuncobj.c tests/test-mgenint.c tests/test-milist.c tests/test-mlist.c tests/test-mmutex.c tests/test-mprioqueue.c tests/test-mrbtree.c tests/test-mserial-bin.c tests/test-mserial-json.c tests/test-msnapshot.c tests/test-mstring.c tests/test-mtuple.c tests/test-mvariant.c tests/test-mworker.c tests/tgen-bitset.c tests/tgen-marray.c tests/tgen-mdict.c tests/tgen-mlist.c tests/tgen-mstring.c tests/tgen-openmp.c tests/tgen-queue.c tests/tgen-mserial.c tests/Makefile tests/coverage.h tests/test-obj.h tests/dict.txt tests/fail-chain-oplist.c tests/fail-incompatible.c tests/fail-no-oplist.c tests/check-array.cpp tests/check-deque.cpp tests/check-dplist.cpp tests/check-list.cpp tests/check-rbtree.cpp tests/check-uset.cpp tests/check-generic.hpp tests/test-mtree.c tests/check-bptree-map.cpp tests/check-bptree-set.cpp tests/check-prioqueue.cpp tests/check-umap.cpp tests/test-mtry.c tests/tgen-mmap.c tests/tgen-try.c tests/tgen-tuple.c tests/test-mgeneric.c tests/test-mbstring.c tests/except-array.c tests/except-bitset.c tests/except-deque.c tests/except-list.c tests/except-string.c tests/test-mshared-ptr.c tests/test-mshared-ptr.h tests/test-obj-except.h tests/test-mqueue.c
.PHONY: all test check doc clean distclean depend install uninstall dist
@@ -58,17 +58,17 @@ checkall:
cd tests && $(MAKE) checkall
cd example && $(MAKE) all
html: doc
doc: README.md doc/depend.png
html: README.md
markdown < README.md > README.html
doc: html doc/depend.png
clean:
cd tests && $(MAKE) clean
cd example && $(MAKE) clean
cd bench && $(MAKE) clean
$(RM) README.html depend.dot
$(RM) -r 'm*lib-$(VERSION)'
$(RM) 'm*lib-$(VERSION).tar.bz2'
$(RM) -r 'm_lib-$(VERSION)'
$(RM) 'm_lib-$(VERSION).tar.bz2'
distclean: clean
cd tests && $(MAKE) distclean
@@ -81,7 +81,7 @@ doc/depend.png: $(HEADER)
dot -Tpng depend.dot -o doc/depend.png
optipng -o7 doc/depend.png
dist: $(HEADER) $(DOC1) $(DOC2) $(EXAMPLE) $(TEST) Makefile clean
dist: $(HEADER) $(DOC1) $(DOC2) $(EXAMPLE) $(TEST) Makefile clean versioncheck
$(MKDIR) '$(PACKAGE)'
$(MKDIR) '$(PACKAGE)/doc'
$(MKDIR) '$(PACKAGE)/tests'
@@ -96,6 +96,14 @@ dist: $(HEADER) $(DOC1) $(DOC2) $(EXAMPLE) $(TEST) Makefile clean
distcheck: dist
cd '$(PACKAGE)' && make check
versioncheck:
@if test "$(VERSION)." != `grep M_CORE_VERSION m-core.h |awk '{printf "%d.",$$3 } END {printf "\n"}'` ; then echo "ERROR: Version mismatch between Makefile & HEADERS" ; exit 2 ; fi
@for i in *.h ; do echo $(HEADER) | grep -q $$i ; if test $$? -ne 0 ; then echo "ERROR: Missing header $$i in Makefile" ; exit 3 ; fi ; done
@for i in doc/* ; do echo $(DOC2) | grep -q $$i ; if test $$? -ne 0 ; then echo "ERROR: Missing document $$i in Makefile" ; exit 4 ; fi ; done
@for i in tests/*.c tests/*.txt tests/*.h ; do echo $(TEST) | grep -q $$i ; if test $$? -ne 0 ; then echo "ERROR: Missing test $$i in Makefile" ; exit 5 ; fi ; done
@for i in example/*.c example/*.json ; do echo $(EXAMPLE) | grep -q $$i ; if test $$? -ne 0 ; then echo "ERROR: Missing example $$i in Makefile" ; exit 6 ; fi ; done
@for i in tests/*.cpp tests/*.hpp ; do echo $(TEST) | grep -q $$i ; if test $$? -ne 0 ; then echo "ERROR: Missing test $$i in Makefile" ; exit 7 ; fi ; done
install:
$(MKDIR) $(DESTDIR)$(PREFIX)/include/m-lib
$(INSTALL_DATA) $(HEADER) $(DESTDIR)$(PREFIX)/include/m-lib
+7319 -4943
View File
File diff suppressed because it is too large. Load diff
-436
View File
@@ -1,436 +0,0 @@
# Copyright (c) 2017-2021, Patrick Pelissier
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# + Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# + Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
CC=cc -std=c11
CXX=c++ -std=c++11
CFLAGS=-O2 -march=native -Wall
XCFLAGS=
CPPFLAGS=-I..
N=4
BENCH_DEF=
RM=rm -rf
.PHONY: all pgo container queue mempool string plain bench-mlib bench-mlib-mempool bench-stl bench-qt bench-glib bench-klib bench-libdynamic bench-sparsepp bench-collectionc bench-tommyds bench-flathashmap bench-emilib bench-hopscotchmap bench-mlib-thread bench-liblfds bench-concurrentqueue bench-boost bench-mempool bench-string bench-plain bench-rigtorp-mpmc-queue bench-cmc
all: container queue mempool string plain
pgo:
$(MAKE) all XCFLAGS="-fprofile-generate=pgo"
$(MAKE) all XCFLAGS="-fprofile-use=pgo"
#########################################################################
container: bench-mlib bench-mlib-mempool bench-stl bench-qt bench-glib bench-klib bench-libdynamic bench-cmc bench-sparsepp bench-densehashmap bench-collectionc bench-tommyds bench-flathashmap bench-emilib bench-hopscotchmap bench-uthash bench-qlibc bench-libsrt bench-nedtries bench-rigtorp-hashmap
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
queue: bench-mlib-thread bench-liblfds bench-concurrentqueue bench-boost bench-rigtorp-mpmc-queue
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
mempool: bench-mempool
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
string: bench-string
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
plain: bench-plain
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
#########################################################################
bench-mlib:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -pthread bench-mlib.c common.c -o bench-mlib.exe
@./bench-mlib.exe 10
@./bench-mlib.exe 11
@./bench-mlib.exe 20
@./bench-mlib.exe 30
@./bench-mlib.exe 31
@./bench-mlib.exe 40
@./bench-mlib.exe 41
@./bench-mlib.exe 42
@./bench-mlib.exe 46
@./bench-mlib.exe 47
@./bench-mlib.exe 43
@./bench-mlib.exe 50
@./bench-mlib.exe 51
bench-mlib-mempool:
$(CC) $(CFLAGS) $(CPPFLAGS) bench-mlib.c common.c -DUSE_MEMPOOL -pthread -o bench-mlib-mempool.exe
@./bench-mlib-mempool.exe 10
@./bench-mlib-mempool.exe 11
@./bench-mlib-mempool.exe 20
@./bench-mlib-mempool.exe 30
@./bench-mlib-mempool.exe 31
@./bench-mlib-mempool.exe 40
@./bench-mlib-mempool.exe 41
@./bench-mlib-mempool.exe 42
@./bench-mlib-mempool.exe 46
@./bench-mlib-mempool.exe 47
@./bench-mlib-mempool.exe 43
@./bench-mlib-mempool.exe 50
@./bench-mlib-mempool.exe 51
bench-mlib-thread:
$(CC) $(CFLAGS) $(CPPFLAGS) bench-mlib.c common.c -DMULTI_THREAD_MEASURE -pthread -o bench-mlib-thread.exe
@./bench-mlib-thread.exe 60
@./bench-mlib-thread.exe 61
@./bench-mlib-thread.exe 62
@./bench-mlib-thread.exe 63
@./bench-mlib-thread.exe 64
@./bench-mlib-thread.exe 65
@./bench-mlib-thread.exe 66
bench-stl:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) bench-stl.cpp common.c -o bench-stl.exe
@./bench-stl.exe 10
@./bench-stl.exe 20
@./bench-stl.exe 30
@./bench-stl.exe 40
@./bench-stl.exe 41
@./bench-stl.exe 42
@./bench-stl.exe 46
@./bench-stl.exe 43
@./bench-stl.exe 50
@./bench-stl.exe 51
# QT shall point to the the directory containing the file .pc are stored
bench-qt:
@if test -n "$${QT}" ; then $(MAKE) bench-qt0 ; else echo "Nothing to be done for QT." ; fi
bench-qt0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -fPIC `PKG_CONFIG_PATH="$${QT}" pkg-config --libs --cflags Qt5Core` bench-qt.cpp common.c -o bench-qt.exe
@./bench-qt.exe 10
@./bench-qt.exe 20
@./bench-qt.exe 30
@./bench-qt.exe 40
@./bench-qt.exe 41
@./bench-qt.exe 42
@./bench-qt.exe 50
# GLIB shall point to the the directory containing the file .pc are stored
bench-glib:
@if test -n "$${GLIB}" ; then $(MAKE) bench-glib0 ; else echo "Nothing to be done for GLIB." ; fi
bench-glib0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) bench-glib.c common.c -o bench-glib.exe `PKG_CONFIG_PATH="$${GLIB}" pkg-config --libs --cflags glib-2.0`
@./bench-glib.exe 10
@./bench-glib.exe 20
@./bench-glib.exe 30
@./bench-glib.exe 40
@./bench-glib.exe 41
@./bench-glib.exe 50
# KLIB shall point to the directory where the headers are
bench-klib:
@if test -n "$${KLIB}" ; then $(MAKE) bench-klib0 ; else echo "Nothing to be done for KLIB." ; fi
bench-klib0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I $${KLIB} bench-klib.c common.c -o bench-klib.exe
@./bench-klib.exe 10
@./bench-klib.exe 20
@./bench-klib.exe 30
@./bench-klib.exe 40
@./bench-klib.exe 41
@./bench-klib.exe 50
# CMC shall point to the directory where the CMC main header is
bench-cmc:
@if test -n "$${CMC}" ; then $(MAKE) bench-cmc0 ; else echo "Nothing to be done for CMC." ; fi
bench-cmc0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I $${CMC} bench-cmc.c common.c -o bench-cmc.exe
@./bench-cmc.exe 20
@./bench-cmc.exe 30
@./bench-cmc.exe 40
# LIBDYNAMIC shall point to the the directory containing the file libdynamic.pc
bench-libdynamic:
@if test -n "$${LIBDYNAMIC}" ; then $(MAKE) bench-libdynamic0 ; else echo "Nothing to be done for LIBDYNAMIC." ; fi
bench-libdynamic0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) bench-libdynamic.c common.c -o bench-libdynamic.exe `PKG_CONFIG_PATH="$${LIBDYNAMIC}" pkg-config --libs --cflags libdynamic`
@./bench-libdynamic.exe 20
@./bench-libdynamic.exe 40
@./bench-libdynamic.exe 41
# SPARSEPP shall point to the directory where the headers are
bench-sparsepp:
@if test -n "$${SPARSEPP}" ; then $(MAKE) bench-sparsepp0 ; else echo "Nothing to be done for SPARSEPP." ; fi
bench-sparsepp0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${SPARSEPP}" -I "$${SPARSEPP}/.." bench-sparsepp.cpp common.c -o bench-sparsepp.exe
@./bench-sparsepp.exe 41
@./bench-sparsepp.exe 42
@./bench-sparsepp.exe 43
# DENSEHASHMAP shall point to the directory where the src are
bench-densehashmap:
@if test -n "$${DENSEHASHMAP}" ; then $(MAKE) bench-densehashmap0 ; else echo "Nothing to be done Google DENSEHASHMAP." ; fi
bench-densehashmap0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${DENSEHASHMAP}" -I "$${DENSEHASHMAP}/.." bench-densehashmap.cpp common.c -o bench-densehashmap.exe
@./bench-densehashmap.exe 41
@./bench-densehashmap.exe 42
@./bench-densehashmap.exe 43
# COLLECTIONC shall point to the directory where it is installed
bench-collectionc:
@if test -n "$${COLLECTIONC}" ; then $(MAKE) bench-collectionc0 ; else echo "Nothing to be done for COLLECTIONC." ; fi
bench-collectionc0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${COLLECTIONC}/include/collectc" bench-collectionc.c common.c "$${COLLECTIONC}/lib/libcollectc.a" -o bench-collectionc.exe
@./bench-collectionc.exe 10
@./bench-collectionc.exe 20
@./bench-collectionc.exe 30
@./bench-collectionc.exe 40
@./bench-collectionc.exe 41
@./bench-collectionc.exe 50
# TOMMYDS shall point to the source directory.
bench-tommyds:
@if test -n "$${TOMMYDS}" ; then $(MAKE) bench-tommyds0 ; else echo "Nothing to be done for TOMMYDS." ; fi
bench-tommyds0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${TOMMYDS}" bench-tommyds.c $${TOMMYDS}/tommyds/tommyarray.c $${TOMMYDS}/tommyds/tommylist.c $${TOMMYDS}/tommyds/tommytree.c $${TOMMYDS}/tommyds/tommyhashlin.c common.c -o bench-tommyds.exe
@./bench-tommyds.exe 10
@./bench-tommyds.exe 20
@./bench-tommyds.exe 30
@./bench-tommyds.exe 40
@./bench-tommyds.exe 41
# FLATHASHMAP shall point to the directory where the headers are
bench-flathashmap:
@if test -n "$${FLATHASHMAP}" ; then $(MAKE) bench-flathashmap0 ; else echo "Nothing to be done for FLATHASHMAP." ; fi
bench-flathashmap0:
$(CXX) -std=c++14 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${FLATHASHMAP}" bench-flathashmap.cpp common.c -o bench-flathashmap.exe
@./bench-flathashmap.exe 41
@./bench-flathashmap.exe 42
@./bench-flathashmap.exe 46
@./bench-flathashmap.exe 43
# EMILIB shall point to the directory where the headers are
bench-emilib:
@if test -n "$${EMILIB}" ; then $(MAKE) bench-emilib0 ; else echo "Nothing to be done for EMILIB." ; fi
bench-emilib0:
$(CXX) -std=c++14 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${EMILIB}" bench-emilib.cpp common.c -o bench-emilib.exe
@./bench-emilib.exe 41
@./bench-emilib.exe 42
@./bench-emilib.exe 46
@./bench-emilib.exe 43
# HOPSCOTCHMAP shall point to the directory where the source are
bench-hopscotchmap:
@if test -n "$${HOPSCOTCHMAP}" ; then $(MAKE) bench-hopscotchmap0 ; else echo "Nothing to be done for HOPSCOTCHMAP." ; fi
bench-hopscotchmap0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${HOPSCOTCHMAP}/include/tsl" bench-hopscotchmap.cpp common.c -o bench-hopscotchmap.exe
@./bench-hopscotchmap.exe 41
@./bench-hopscotchmap.exe 42
@./bench-hopscotchmap.exe 43
# UTHASH shall point to the directory where the source are
bench-uthash:
@if test -n "$${UTHASH}" ; then $(MAKE) bench-uthash0 ; else echo "Nothing to be done for UTHASH." ; fi
bench-uthash0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${UTHASH}" bench-uthash.c common.c -o bench-uthash.exe
@./bench-uthash.exe 10
@./bench-uthash.exe 20
@./bench-uthash.exe 40
@./bench-uthash.exe 41
@./bench-uthash.exe 50
# QLIBC shall point to the directory where the library is installed.
bench-qlibc:
@if test -n "$${QLIBC}" ; then $(MAKE) bench-qlibc0 ; else echo "Nothing to be done for QLIBC." ; fi
bench-qlibc0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${QLIBC}/include" -L "$${QLIBC}/lib" -lqlibc -pthread bench-qlibc.c common.c -o bench-qlibc.exe
@LD_LIBRARY_PATH="$${QLIBC}/lib:$${LD_LIBRARY_PATH}" ./bench-qlibc.exe 10
@LD_LIBRARY_PATH="$${QLIBC}/lib:$${LD_LIBRARY_PATH}" ./bench-qlibc.exe 20
@LD_LIBRARY_PATH="$${QLIBC}/lib:$${LD_LIBRARY_PATH}" ./bench-qlibc.exe 30
# LIBSRT shall point to the directory where it is installed
bench-libsrt:
@if test -n "$${LIBSRT}" ; then $(MAKE) bench-libsrt0 ; else echo "Nothing to be done for LIBSRT." ; fi
bench-libsrt0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${LIBSRT}/include/libsrt" bench-libsrt.c common.c -o bench-libsrt.exe $${LIBSRT}/lib/libsrt.a
@./bench-libsrt.exe 20
@./bench-libsrt.exe 50
# LIBLFDS shall point to the directory where the bin/build/inc/obj/src directories are
# The library shall be built.
bench-liblfds:
@if test -n "$${LIBLFDS}" ; then $(MAKE) bench-liblfds0 ; else echo "Nothing to be done for LIBLFDS." ; fi
bench-liblfds0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${LIBLFDS}/inc" -Wno-unknown-pragmas bench-liblfds.c common.c -DMULTI_THREAD_MEASURE -o bench-liblfds.exe $${LIBLFDS}/bin/liblfds711.a -lpthread
@LD_LIBRARY_PATH="$${LIBLFDS}/bin:$${LD_LIBRARY_PATH}" ./bench-liblfds.exe 60
# CONCURRENTQUEUE shall point to the directory where the bin/build/inc/obj/src directories are
# The library shall be built.
bench-concurrentqueue:
@if test -n "$${CONCURRENTQUEUE}" ; then $(MAKE) bench-concurrentqueue0 ; else echo "Nothing to be done for CONCURRENTQUEUE." ; fi
bench-concurrentqueue0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${CONCURRENTQUEUE}/" bench-concurrentqueue.cpp common.c -DMULTI_THREAD_MEASURE -o bench-concurrentqueue.exe -lpthread
@./bench-concurrentqueue.exe 60
# XXHASH shall point to the source directory of xxhash
# The library shall be built.
bench-xxhash:
@if test -n "$${XXHASH}" ; then $(MAKE) bench-xxhash0 ; else echo "Nothing to be done for XXHASH." ; fi
bench-xxhash0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${XXHASH}/" bench-xxhash.c common.c "$${XXHASH}/libxxhash.a" -o bench-xxhash.exe
@./bench-xxhash.exe 70
# BOOST shall point to the header location.
bench-boost:
@if test -n "$${BOOST}" ; then $(MAKE) bench-boost0 ; else echo "Nothing to be done for BOOST." ; fi
bench-boost0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${BOOST}" bench-boost.cpp common.c -DMULTI_THREAD_MEASURE -o bench-boost.exe -lpthread
@./bench-boost.exe 60
# NEDTRIES shall point to the header location.
bench-nedtries:
@if test -n "$${NEDTRIES}" ; then $(MAKE) bench-nedtries0 ; else echo "Nothing to be done for NEDTRIES." ; fi
bench-nedtries0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${NEDTRIES}" bench-nedtries.c common.c -o bench-nedtries.exe
@./bench-nedtries.exe 40
@./bench-nedtries.exe 45
# RIGTORP_HASHMAP shall point to the directory where the headers are
bench-rigtorp-hashmap:
@if test -n "$${RIGTORP_HASHMAP}" ; then $(MAKE) bench-rigtorp-hashmap0 ; else echo "Nothing to be done for RIGTORP_HASHMAP." ; fi
bench-rigtorp-hashmap0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${RIGTORP_HASHMAP}/include" bench-rigtorp-hashmap.cpp common.c -o bench-rigtorp-hashmap.exe
@./bench-rigtorp-hashmap.exe 42
@./bench-rigtorp-hashmap.exe 41
@./bench-rigtorp-hashmap.exe 43
# RIGTORP_MPMC_QUEUE shall point to the directory where the headers are
bench-rigtorp-mpmc-queue:
@if test -n "$${RIGTORP_MPMC_QUEUE}" ; then $(MAKE) bench-rigtorp-mpmc-queue0 ; else echo "Nothing to be done for RIGTORP_MPMC_QUEUE." ; fi
bench-rigtorp-mpmc-queue0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${RIGTORP_MPMC_QUEUE}" bench-rigtorp-mpmcqueue.cpp common.c -DMULTI_THREAD_MEASURE -o bench-mpmcqueue.exe -lpthread
@./bench-mpmcqueue.exe 60
############################################################################
bench-mlib-json: bench-mlib
@./bench-mlib.exe 110
@./bench-mlib.exe 111
@./bench-mlib.exe 112
bench-rapidjson:
@if test -n "$${RAPIDJSON}" ; then $(MAKE) bench-rapidjson0 ; else echo "Nothing to be done for RAPIDJSON." ; fi
bench-rapidjson0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${RAPIDJSON}/" bench-rapidjson.cpp common.c -o bench-rapidjson.exe
@./bench-rapidjson.exe 110
@./bench-rapidjson.exe 111
@./bench-rapidjson.exe 112
############################################################################
bench-plain:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) bench-plain-c.c -o bench-plain-c.exe
@./bench-plain-c.exe
############################################################################
bench-mempool:
@if test -n "$${BOOST}" ; then if test -n "$${GLIB}" ; then make bench-mempool0 BENCH_DEF="-DUSE_BOOST -DUSE_GLIB `pkg-config --libs --cflags glib-2.0` -lboost_system" ; else make bench-mempool0 BENCH_DEF="-DUSE_BOOST -lboost_system" ; fi ; else if test -n "$${GLIB}" ; then make bench-mempool0 BENCH_DEF="-DUSE_GLIB `pkg-config --libs --cflags glib-2.0`" ; else make bench-mempool0 ; fi ; fi
bench-mempool0:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) pool.cc $(BENCH_DEF) -o bench-mempool.exe
@./bench-mempool.exe
############################################################################
bench-maxdict:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) max-dict.c -o bench-max-dict.exe
@./bench-max-dict.exe
############################################################################
# BSTRLIB shall point to the BSTRLIB sources
# LIBSRT shall point to the LIBSRT install directory
bench-string:
@if test -n "$${BSTRLIB}" ; then $(MAKE) bench-string-step1 BENCH_DEF="-DBENCH_CAN_USE_BSTRLIB -I ${BSTRLIB} $${BSTRLIB}/obj/bstrlib.o $${BSTRLIB}/obj/bstraux.o $${BSTRLIB}/obj/bstrwrap.o" ; else $(MAKE) bench-string-step1 ; fi
bench-string-step1:
@if test -n "$${LIBSRT}" ; then $(MAKE) bench-string-step2 BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_LIBSRT -I$${LIBSRT}/include/libsrt $${LIBSRT}/lib/libsrt.a" ; else $(MAKE) bench-string-step2 BENCH_DEF="$(BENCH_DEF)"; fi
#NOTE: Need to build by hand sds.o since it is not build by default and sds.c is not compatible with C++
bench-string-step2:
@if test -n "$${SDS}" ; then $(MAKE) bench-string-step4 BENCH_DEF="$(BENCH_DEF) -fpermissive -DBENCH_CAN_USE_SDS -I$${SDS}/ $${SDS}/sds.o" ; else $(MAKE) bench-string-step4 BENCH_DEF="$(BENCH_DEF)"; fi
bench-string-step4:
@if test -n "$${GLIB}" ; then $(MAKE) bench-string-step5 BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_GLIB $$(pkg-config --cflags --libs glib-2.0)" ; else $(MAKE) bench-string-step5 BENCH_DEF="$(BENCH_DEF)"; fi
bench-string-step5:
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -DBENCH_CAN_USE_STL -DBENCH_CAN_USE_MSTARLIB bench-string.cpp common.c $(BENCH_DEF) -o bench-string.exe
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -DBENCH_CAN_USE_STL -DBENCH_CAN_USE_MSTARLIB bench-string-2.cpp common.c $(BENCH_DEF) -o bench-string-2.exe
@./bench-string.exe
@./bench-string-2.exe 2000000 0
@./bench-string-2.exe 2000000 1
@./bench-string-2.exe 2000000 2
@./bench-string-2.exe 2000000 4
bench-string-pgo:
$(MAKE) bench-string XCFLAGS="-fprofile-generate=pgo"
$(MAKE) bench-string XCFLAGS="-fprofile-use=pgo"
############################################################################
bench-find-sort:
g++ bench-find-sort.cpp -O2 -march=native -std=c++11 -I.. -g common.c -o bench-find-sort.exe
./bench-find-sort.exe 10000000
############################################################################
clean:
$(RM) *.o bench-*.exe
$(RM) bench-*.s *~ massif.out.*
$(RM) plot-*.dat
$(RM) pgo
$(RM) tmp-serial.*
cd nucleotide && $(MAKE) clean
############################################################################
massif-do: all
@valgrind --tool=massif ./bench-mlib.exe $(N)
@valgrind --tool=massif ./bench-mlib-mempool.exe $(N)
@valgrind --tool=massif ./bench-stl.exe $(N)
@valgrind --tool=massif ./bench-qt.exe $(N)
@valgrind --tool=massif ./bench-glib.exe $(N)
@test -f ./bench-klib.exe && valgrind --tool=massif ./bench-klib.exe $(N)
@test -f ./bench-libdynamic.exe && valgrind --tool=massif ./bench-libdynamic.exe $(N)
massif-visu:
test -f massif.out.* || $(MAKE) massif-do
for i in massif.out.* ; do ms_print $$i|head -30 ; done
-96
View File
@@ -1,96 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <boost/lockfree/queue.hpp>
#include "common.h"
/********************************************************************************************/
boost::lockfree::queue<unsigned int, boost::lockfree::capacity<4*64>> g_buff;
boost::lockfree::queue<unsigned long long, boost::lockfree::capacity<4*64>> g_final;
static void final(void *arg)
{
size_t *p_n = (size_t*) arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(unsigned int i = 0; i < n;i++) {
while (!g_final.pop(j));
s += j;
}
g_result = s;
}
static void conso(void *arg)
{
unsigned int j;
size_t *p_n = (size_t*)arg;
size_t n = *p_n;
unsigned long long s = 0;
for(unsigned int i = 0; i < n;i++) {
while (!g_buff.pop(j));
s += j;
}
while (!g_final.push(s));
}
static void prod(void *arg)
{
size_t *p_n = (size_t*)arg;
size_t n = *p_n;
size_t r = n;
for(unsigned int i = 0; i < n;i++) {
while (!g_buff.push(r));
r = r * 31421U + 6927U;
}
}
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
const int conso_count = cpu_count - prod_count;
if (cpu_count < 2) {
fprintf(stderr, "WARNING: Can not measure Buffer performance.\n");
return;
}
rand_get();
// Create thread
m_thread_t idx_p[prod_count];
m_thread_t idx_c[conso_count];
m_thread_t idx_final;
for(int i = 0; i < prod_count; i++) {
m_thread_create (idx_p[i], prod, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final, &n2);
// Wait for jobs to be done.
for(int i = 0; i < prod_count; i++) {
m_thread_join(idx_p[i]);
}
for(int i = 0; i < conso_count; i++) {
m_thread_join(idx_c[i]);
}
m_thread_join(idx_final);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
};
int main(int argc, const char *argv[])
{
test("BOOST-LOCKFREE", numberof(table), table, argc, argv);
exit(0);
}
-204
View File
@@ -1,204 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "macro_collections.h"
#include "common.h"
/********************************************************************************************/
// CMC list are dynamic array
#define MY_LIST_PARAMS (list_uint, list_uint_s, , , unsigned int)
C_MACRO_COLLECTIONS_EXTENDED(CMC, LIST, MY_LIST_PARAMS, (STR))
struct list_uint_s_fval list_fval = { .cmp = NULL,
.cpy = NULL,
.str = NULL,
.free = NULL,
.hash = NULL,
.pri = NULL };
static void test_array(size_t n)
{
struct list_uint_s *a1 = list_uint_new(1, &list_fval);
struct list_uint_s *a2 = list_uint_new(1, &list_fval);
for(size_t i = 0; i < n; i++) {
list_uint_push_back(a1, rand_get() );
list_uint_push_back(a2, rand_get() );
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += list_uint_get(a1, i ) * list_uint_get(a2, i );
}
g_result = s;
list_uint_free(a1);
list_uint_free(a2);
}
/********************************************************************************************/
#define my_cmp(a,b) ( (a) < (b) ? -1 : (a) > (b) )
#define MY_TMAP_PARAMS (tree_ulong, tree_ulong_s, , unsigned long, bool)
C_MACRO_COLLECTIONS_EXTENDED(CMC, TREEMAP, MY_TMAP_PARAMS, (STR))
int cmp_ulong(unsigned long a, unsigned long b) { return my_cmp(a,b); }
struct tree_ulong_s_fkey tree_fkey = { .cmp = cmp_ulong,
.cpy = NULL,
.str = NULL,
.free = NULL,
.hash = NULL,
.pri = NULL };
struct tree_ulong_s_fval tree_fval = { .cmp = NULL,
.cpy = NULL,
.str = NULL,
.free = NULL,
.hash = NULL,
.pri = NULL };
static void test_rbtree(size_t n)
{
struct tree_ulong_s *tree;
tree = tree_ulong_new(&tree_fkey, &tree_fval);
for (size_t i = 0; i < n; i++) {
unsigned long j = rand_get();
tree_ulong_insert(tree, j, true);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long j = rand_get();
if (tree_ulong_get_ref(tree, j) != 0)
s+= j;
}
g_result = s;
tree_ulong_free(tree);
}
/********************************************************************************************/
#define hash_func(a) kh_int64_hash_func(a)
size_t hash_ulong(unsigned long a)
{
return ( (a) >> 33 ) ^ (a) ^ ((a) << 11);
}
#define MY_DICT_PARAMS (hmap, hmap_s, , unsigned long, unsigned long)
C_MACRO_COLLECTIONS_EXTENDED(CMC, HASHMAP, MY_DICT_PARAMS, (STR))
struct hmap_s_fkey hmap_fkey = { .cmp = cmp_ulong,
.cpy = NULL,
.str = NULL,
.free = NULL,
.hash = hash_ulong,
.pri = NULL };
struct hmap_s_fval hmap_fval = { .cmp = NULL,
.cpy = NULL,
.str = NULL,
.free = NULL,
.hash = NULL,
.pri = NULL };
static void
test_dict(size_t n)
{
struct hmap_s *dict = hmap_new(16, 0.7, &hmap_fkey, &hmap_fval);
for (size_t i = 0; i < n; i++) {
hmap_insert(dict, rand_get(), rand_get());
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long *val = hmap_get_ref(dict, rand_get());
if (val != 0)
s += *val;
}
g_result = s;
hmap_free(dict);
}
/********************************************************************************************/
#if 0 // Not working issue in using not integer types
typedef struct {
char a[256];
} char_array_t;
static inline int char_cmp (const char_array_t a, const char_array_t b) { return strcmp(a.a,b.a); }
static inline size_t char_hash(const char_array_t a) {
size_t hash = 0;
const char *s = a.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
}
#define MY_DICTB_PARAMS (bhmap, bhmap_s, , char_array_t, char_array_t)
C_MACRO_COLLECTIONS_EXTENDED(CMC, HASHMAP, MY_DICT_PARAMS, (STR))
struct bhmap_s_fkey bhmap_fkey = { .cmp = char_cmp,
.cpy = NULL,
.str = NULL,
.free = NULL,
.hash = char_hash,
.pri = NULL };
struct bhmap_s_fval bhmap_fval = { .cmp = NULL,
.cpy = NULL,
.str = NULL,
.free = NULL,
.hash = NULL,
.pri = NULL };
static void
test_dict_big(size_t n)
{
struct bhmap_s *dict = bhmap_new(16, 0.7, &bhmap_fkey, &bhmap_fval);
for (size_t i = 0; i < n; i++) {
char_array_t s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
bhmap_insert(dict, s1, s2);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_t s1;
sprintf(s1.a, "%u", rand_get() );
char_array_t *val = bhmap_get_ref(dict, s1);
if (val != 0)
s ++;
}
g_result = s;
bhmap_free(dict);
}
#endif
/********************************************************************************************/
const config_func_t table[] = {
{ 20, "Array", 100000000, 0, test_array, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
//{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
};
int main(int argc, const char *argv[])
{
test("CMC", numberof(table), table, argc, argv);
exit(0);
}
-266
View File
@@ -1,266 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "array.h"
#include "slist.h"
#include "treetable.h"
#include "hashtable.h"
#include "common.h"
/********************************************************************************************/
static void test_array(size_t n)
{
Array *a1, *a2;
enum cc_stat stat;
stat = array_new(&a1);
if (stat != CC_OK) abort();
stat = array_new(&a2);
if (stat != CC_OK) abort();
for(size_t i = 0; i < n; i++) {
stat = array_add(a1, (void*) (uintptr_t)rand_get() );
if (stat != CC_OK) abort();
stat = array_add(a2, (void*) (uintptr_t)rand_get() );
if (stat != CC_OK) abort();
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
void *e, *f;
stat = array_get_at(a1, i, &e);
if (stat != CC_OK) abort();
stat = array_get_at(a2, i, &f);
if (stat != CC_OK) abort();
s += ((unsigned int)(uintptr_t) e) * ((unsigned int)(uintptr_t) f);
}
g_result = s;
array_destroy(a1);
array_destroy(a2);
}
/********************************************************************************************/
static void test_list(size_t n)
{
SList *a1, *a2;
enum cc_stat stat;
stat = slist_new(&a1);
if (stat != CC_OK) abort();
stat = slist_new(&a2);
if (stat != CC_OK) abort();
for(size_t i = 0; i < n; i++) {
stat = slist_add(a1, (void*) (uintptr_t)rand_get() );
if (stat != CC_OK) abort();
stat = slist_add(a2, (void*) (uintptr_t)rand_get() );
if (stat != CC_OK) abort();
}
unsigned int s = 0;
SListIter iter1, iter2;
void *e, *f;
slist_iter_init(&iter1, a1);
slist_iter_init(&iter2, a2);
while (slist_iter_next(&iter1, &e) == CC_OK && slist_iter_next(&iter2, &f) == CC_OK) {
s += ((unsigned int)(uintptr_t) e) * ((unsigned int)(uintptr_t) f);
}
g_result = s;
slist_destroy(a1);
slist_destroy(a2);
}
/********************************************************************************************/
static int compare(const void *a, const void *b)
{
const uintptr_t pa = (uintptr_t) a;
const uintptr_t pb = (uintptr_t) b;
return (pa < pb) ? -1 : (pa > pb);
}
static void test_rbtree(size_t n)
{
TreeTable *tree;
enum cc_stat stat;
stat = treetable_new(compare, &tree);
if (stat != CC_OK) abort();
for (size_t i = 0; i < n; i++) {
void *key = (void*)(uintptr_t) rand_get();
stat = treetable_add(tree, key, key);
if (stat != CC_OK) abort();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
void *e;
void *key = (void*) (uintptr_t) rand_get();
stat = treetable_get(tree, key, &e);
if (stat == CC_OK)
s += (uintptr_t)e;
}
g_result = s;
treetable_destroy(tree);
}
/********************************************************************************************/
static size_t hash_func (const void *key, int l, uint32_t seed)
{
const unsigned long pa = (uintptr_t) key;
(void)l;
return pa ^ seed;
}
static int equal_func(const void *key1, const void *key2)
{
const unsigned long pa = (uintptr_t) key1;
const unsigned long pb = (uintptr_t) key2;
return (pa < pb) ? -1 : pa > pb;
}
static void
test_dict(size_t n)
{
HashTable *dict;
enum cc_stat stat;
HashTableConf htc;
hashtable_conf_init(&htc);
htc.hash = hash_func;
htc.key_compare = equal_func;
stat = hashtable_new_conf(&htc, &dict);
if (stat != CC_OK) abort();
for (size_t i = 0; i < n; i++) {
void *value = (void*)(uintptr_t) rand_get();
void *key = (void*)(uintptr_t) rand_get();
stat = hashtable_add(dict, key, value );
if (stat != CC_OK) abort();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
void *key = (void*)(uintptr_t) rand_get();
void *r;
stat = hashtable_get(dict, key, &r);
if (stat == CC_OK)
s += (uintptr_t) r;
}
g_result = s;
hashtable_destroy(dict);
}
/********************************************************************************************/
typedef char char_array_t[256];
static int char_equal (const void* a, const void * b)
{
const char_array_t *pa = (const char_array_t *)a;
const char_array_t *pb = (const char_array_t *)b;
return strcmp(*pa,*pb);
}
static size_t char_hash(const void *a, int l, uint32_t seed)
{
const char_array_t *pa = (const char_array_t *)a;
const char *s = *pa;
(void)l ;
size_t hash = seed;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
}
static void
test_dict_big(size_t n)
{
HashTable *dict;
enum cc_stat stat;
HashTableConf htc;
hashtable_conf_init(&htc);
htc.hash = char_hash;
htc.key_compare = char_equal;
stat = hashtable_new_conf(&htc, &dict);
if (stat != CC_OK) abort();
char_array_t **tab = malloc (sizeof(char_array_t *)*2*n);
if (!tab) abort();
size_t cpt = 0;
for (size_t i = 0; i < n; i++) {
char_array_t *key = malloc (sizeof (char_array_t));
char_array_t *value = malloc (sizeof (char_array_t));
tab[cpt++] = key;
tab[cpt++] = value;
sprintf(*key, "%u", rand_get());
sprintf(*value, "%u", rand_get());
stat = hashtable_add(dict, key, value );
if (stat != CC_OK) abort();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_t s1;
void *r;
sprintf(s1, "%u", rand_get());
stat = hashtable_get(dict, s1, &r);
if (stat == CC_OK)
s ++;
}
g_result = s;
hashtable_destroy(dict);
if (cpt != 2*n) abort();
for(size_t i = 0; i < 2*n;i++)
free(tab[i]);
}
/********************************************************************************************/
static int cmp_float(const void * a, const void *b)
{
const float *const*pa = a, *const*pb = b;
return (**pa < **pb) ? -1 : (**pa > **pb);
}
static void test_sort(size_t n)
{
Array *a1;
enum cc_stat stat;
stat = array_new(&a1);
if (stat != CC_OK) abort();
for(size_t i = 0; i < n; i++) {
float *v = malloc(sizeof(float));
*v = rand_get();
stat = array_add(a1, v );
if (stat != CC_OK) abort();
}
array_sort(a1, cmp_float);
void *e;
stat = array_get_at(a1, 0, &e);
if (stat != CC_OK) abort();
g_result = *(float*)e;
array_destroy(a1);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 50, "Sort",10000000, 0, test_sort, 0},
};
int main(int argc, const char *argv[])
{
test("CollectionC", numberof(table), table, argc, argv);
exit(0);
}
-96
View File
@@ -1,96 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "concurrentqueue.h"
#include "common.h"
/********************************************************************************************/
moodycamel::ConcurrentQueue<unsigned int> g_buff;
moodycamel::ConcurrentQueue<unsigned long long> g_final;
static void final(void *arg)
{
size_t *p_n = (size_t*) arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(unsigned int i = 0; i < n;i++) {
while (!g_final.try_dequeue(j));
s += j;
}
g_result = s;
}
static void conso(void *arg)
{
unsigned int j;
size_t *p_n = (size_t*)arg;
size_t n = *p_n;
unsigned long long s = 0;
for(unsigned int i = 0; i < n;i++) {
while (!g_buff.try_dequeue(j));
s += j;
}
while (!g_final.try_enqueue(s));
}
static void prod(void *arg)
{
size_t *p_n = (size_t*)arg;
size_t n = *p_n;
size_t r = n;
for(unsigned int i = 0; i < n;i++) {
while (!g_buff.try_enqueue(r));
r = r * 31421U + 6927U;
}
}
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
const int conso_count = cpu_count - prod_count;
if (cpu_count < 2) {
fprintf(stderr, "WARNING: Can not measure Buffer performance.\n");
return;
}
rand_get();
// Create thread
m_thread_t idx_p[prod_count];
m_thread_t idx_c[conso_count];
m_thread_t idx_final;
for(int i = 0; i < prod_count; i++) {
m_thread_create (idx_p[i], prod, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final, &n2);
// Wait for jobs to be done.
for(int i = 0; i < prod_count; i++) {
m_thread_join(idx_p[i]);
}
for(int i = 0; i < conso_count; i++) {
m_thread_join(idx_c[i]);
}
m_thread_join(idx_final);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
};
int main(int argc, const char *argv[])
{
test("CONCURRENT-QUEUE", numberof(table), table, argc, argv);
exit(0);
}
-144
View File
@@ -1,144 +0,0 @@
#define NDEBUG
#include <vector>
#include <list>
#include <iterator>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <google/dense_hash_map>
using google::dense_hash_map;
using namespace std;
#include "common.h"
/********************************************************************************************/
static void
test_dict2(size_t n)
{
dense_hash_map<unsigned long, unsigned long> dict;
dict.set_empty_key(-1);
dict.set_deleted_key(-2);
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
dense_hash_map<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
namespace std {
template <> struct hash<char_array_s> {
std::size_t operator()(const char_array_s &k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
namespace tr1 {
template <> struct hash<char_array_s> {
std::size_t operator()(char_array_s k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
}
}
static void
test_dict_big(size_t n)
{
dense_hash_map<char_array_s, char_array_s> dict;
struct char_array_s empty, del;
memset(&empty, 0, sizeof empty); empty.a[1] = 255;
memset(&del, 0, sizeof del); del.a[1] = 255;
dict.set_empty_key(empty);
dict.set_deleted_key(del);
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
dense_hash_map<char_array_s, char_array_s>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict_str(size_t n)
{
dense_hash_map<string, string> dict;
string empty, del;
empty = "";
del = "DEL";
dict.set_empty_key(empty);
dict.set_deleted_key(del);
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s2 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
dense_hash_map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
const config_func_t table[] = {
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict", 1000000, 0, test_dict2, 0},
{ 43, "DictStr", 1000000, 0, test_dict_str, 0}
};
int main(int argc, const char *argv[])
{
test("DENSE-HASPMAP", numberof(table), table, argc, argv);
exit(0);
}
-138
View File
@@ -1,138 +0,0 @@
#define NDEBUG
#include <vector>
#include <list>
#include <iterator>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "emilib/hash_map.hpp"
using namespace emilib;
using namespace std;
#include "common.h"
/********************************************************************************************/
static void
test_dict2(size_t n)
{
HashMap<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
HashMap<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
static void
test_dict2_linear(size_t n)
{
HashMap<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[i] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
HashMap<unsigned long, unsigned long>::iterator it = dict.find(i);
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
namespace std {
template <> struct hash<char_array_s> {
std::size_t operator()(const char_array_s &k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
}
static void
test_dict_big(size_t n)
{
HashMap<char_array_s, char_array_s> dict;
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
HashMap<char_array_s, char_array_s>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict_str(size_t n)
{
HashMap<string, string> dict;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s2 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
HashMap<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
const config_func_t table[] = {
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict", 1000000, 0, test_dict2, 0},
{ 43, "DictStr", 1000000, 0, test_dict_str, 0},
{ 46, "DictLinear", 1000000, 0, test_dict2_linear, 0}
};
int main(int argc, const char *argv[])
{
test("EMILIB", numberof(table), table, argc, argv);
exit(0);
}
-101
View File
@@ -1,101 +0,0 @@
// program to find longest contiguous subsequence
// based on https://www.geeksforgeeks.org/longest-consecutive-subsequence/
#include <iostream>
#include <unordered_set>
using namespace std;
// Returns length of the longest contiguous subsequence
int cpp_find_longest(int arr[], int n)
{
unordered_set<int> S;
int ans = 0;
// Hash all the array elements
for (int i = 0; i < n; i++)
S.insert(arr[i]);
// check each possible sequence from
// the start then update optimal length
for (int i = 0; i < n; i++) {
// if current element is the starting
// element of a sequence
if (S.find(arr[i] - 1) == S.end()) {
// Then check for next elements
// in the sequence
int j = arr[i] + 1;
while (S.find(j) != S.end())
j++;
// update optimal length if
// this length is more
ans = max(ans, j - arr[i]);
}
}
return ans;
}
#include "m-dict.h"
static inline bool oor_equal_p(int a, unsigned char c) { return a == ((c == 0) ? INT_MIN : INT_MAX); }
static inline void oor_set(int *a, unsigned char c) { *a = ((c == 0) ? INT_MIN : INT_MAX); }
DICT_OASET_DEF(dict_int, int, M_OPEXTEND(M_DEFAULT_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)))
// Returns length of the longest contiguous subsequence
int mlib_find_longest(int arr[], int n)
{
dict_int_t S;
int ans = 0;
dict_int_init(S);
// Hash all the array elements
for (int i = 0; i < n; i++)
dict_int_push(S, arr[i]);
// check each possible sequence from
// the start then update optimal length
for (int i = 0; i < n; i++) {
// if current element is the starting
// element of a sequence
int *p = dict_int_get(S, arr[i]-1);
if (p == NULL) {
// Then check for next elements
// in the sequence
int j = arr[i] + 1;
while (dict_int_get(S, j) != NULL)
j++;
// update optimal length if
// this length is more
ans = M_MAX(ans, j - arr[i]);
}
}
dict_int_clear(S);
return ans;
}
#include "common.h"
int main(int argc, const char *argv[])
{
int n = argc == 1 ? 10000 : atoi(argv[1]);
int *arr = (int*) malloc(n * sizeof(int));
for(int i = 0; i < n; i++)
arr[i] = rand_get();
unsigned long long t0 = cputime();
cout << "Length of the Longest contiguous subsequence is "
<< cpp_find_longest(arr, n) << endl;
unsigned long long t1 = cputime();
cout << "Length of the Longest contiguous subsequence is "
<< mlib_find_longest(arr, n) << endl;
unsigned long long t2 = cputime();
cout << "Time C++: " << (t1-t0) << " Time M*LIB: " << (t2-t1) << endl;
return 0;
}
-139
View File
@@ -1,139 +0,0 @@
// Need recent gcc
#define NDEBUG
#include <vector>
#include <list>
#include <iterator>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "flat_hash_map.hpp"
using namespace ska;
using namespace std;
#include "common.h"
/********************************************************************************************/
static void
test_dict2(size_t n)
{
flat_hash_map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
flat_hash_map<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
static void
test_dict2_linear(size_t n)
{
flat_hash_map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[i] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
flat_hash_map<unsigned long, unsigned long>::iterator it = dict.find(i);
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
namespace std {
template <> struct hash<char_array_s> {
std::size_t operator()(const char_array_s &k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
}
static void
test_dict_big(size_t n)
{
flat_hash_map<char_array_s, char_array_s> dict;
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
flat_hash_map<char_array_s, char_array_s>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict_str(size_t n)
{
flat_hash_map<string, string> dict;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s2 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
flat_hash_map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
const config_func_t table[] = {
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict", 1000000, 0, test_dict2, 0},
{ 43, "DictStr", 1000000, 0, test_dict_str, 0},
{ 46, "DictLinear", 1000000, 0, test_dict2_linear, 0}
};
int main(int argc, const char *argv[])
{
test("FLAT-HASPMAP", numberof(table), table, argc, argv);
exit(0);
}
-202
View File
@@ -1,202 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <glib.h>
#include "common.h"
/********************************************************************************************/
static void test_array(size_t n)
{
GArray *a1, *a2;
a1 = g_array_new (FALSE, FALSE, sizeof (unsigned int));
a2 = g_array_new (FALSE, FALSE, sizeof (unsigned int));
for(size_t i = 0; i < n; i++) {
unsigned int v = rand_get();
g_array_append_val(a1, v );
v = rand_get();
g_array_append_val(a2, v );
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += g_array_index(a1, unsigned int, i ) * g_array_index(a2, unsigned int, i );
}
g_result = s;
g_array_free(a1, FALSE);
g_array_free(a2, FALSE);
}
/********************************************************************************************/
static void test_list (size_t n)
{
GSList *a1 = NULL, *a2 = NULL;
for(size_t i = 0; i < n; i++) {
a1 = g_slist_prepend (a1, GINT_TO_POINTER (rand_get() ));
a2 = g_slist_prepend (a2, GINT_TO_POINTER (rand_get() ));
}
unsigned int s = 0;
for(GSList *it1 = a1, *it2 = a2 ; it1 != NULL; it1 = g_slist_next(it1), it2 = g_slist_next(it2) ) {
s += GPOINTER_TO_INT(it1->data) * GPOINTER_TO_INT(it2->data);
n--;
}
g_result = s;
g_slist_free(a1);
g_slist_free(a2);
}
/********************************************************************************************/
static int compare(gconstpointer a, gconstpointer b, gpointer user_data)
{
const unsigned long *pa = a;
const unsigned long *pb = b;
(void) user_data;
return (*pa < *pb) ? -1 : (*pa > *pb);
}
static void test_rbtree(size_t n)
{
GTree *tree = g_tree_new_full(compare, NULL, free, NULL);
for (size_t i = 0; i < n; i++) {
// NOTE: unsigned long are not designed to work with GPOINTER_TO_INT according to documentation.
unsigned long *p = malloc(sizeof(unsigned long));
*p = rand_get();
g_tree_insert(tree, p, p);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long key = rand_get();
unsigned long *p = g_tree_lookup(tree, &key);
if (p)
s += *p;
}
g_result = s;
g_tree_destroy(tree);
}
/********************************************************************************************/
static guint hash_func (gconstpointer a)
{
const unsigned long *pa = a;
return *pa;
}
static gboolean equal_func(gconstpointer a, gconstpointer b)
{
const unsigned long *pa = a;
const unsigned long *pb = b;
return *pa == *pb;
}
static void
test_dict(size_t n)
{
GHashTable *dict = g_hash_table_new_full(hash_func, equal_func, free, free);
for (size_t i = 0; i < n; i++) {
unsigned long *key = malloc(sizeof(unsigned long));
unsigned long *value = malloc(sizeof(unsigned long));
*key = rand_get();
*value = rand_get();
g_hash_table_insert(dict, key, value );
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long key = rand_get();
unsigned long *p = g_hash_table_lookup(dict, &key);
if (p)
s += *p;
}
g_result = s;
g_hash_table_destroy(dict);
}
/********************************************************************************************/
typedef char char_array_t[256];
static gboolean char_equal (gconstpointer a, gconstpointer b)
{
const char_array_t *pa = (const char_array_t *)a;
const char_array_t *pb = (const char_array_t *)b;
return strcmp(*pa,*pb)==0;
}
static guint char_hash(gconstpointer a)
{
const char_array_t *pa = (const char_array_t *)a;
const char *s = *pa;
guint hash = 0;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
}
static void
test_dict_big(size_t n)
{
GHashTable *dict = g_hash_table_new_full(char_hash, char_equal, free, free);
for (size_t i = 0; i < n; i++) {
char_array_t *key = malloc (sizeof (char_array_t));
char_array_t *value = malloc (sizeof (char_array_t));
sprintf(*key, "%u", rand_get());
sprintf(*value, "%u", rand_get());
g_hash_table_insert(dict, key, value );
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_t s1;
sprintf(s1, "%u", rand_get());
char_array_t *p = g_hash_table_lookup(dict, &s1);
if (p)
s ++;
}
g_result = s;
g_hash_table_destroy(dict);
}
/********************************************************************************************/
static gint cmp_float(gconstpointer a,
gconstpointer b)
{
const float *pa = a, *pb = b;
return (*pa < *pb) ? -1 : (*pa > *pb);
}
static void test_sort(size_t n)
{
GArray *a1 = g_array_new (FALSE, FALSE, sizeof (float));
for(size_t i = 0; i < n; i++) {
float v = rand_get();
g_array_append_val(a1, v );
}
g_array_sort(a1, cmp_float);
g_result = g_array_index (a1, float, 0);
g_array_free(a1, FALSE);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 50, "Sort",10000000, 0, test_sort, 0},
};
int main(int argc, const char *argv[])
{
test("GLIB", numberof(table), table, argc, argv);
exit(0);
}
-123
View File
@@ -1,123 +0,0 @@
#define NDEBUG
#include <vector>
#include <list>
#include <iterator>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "hopscotch_map.h"
using namespace tsl;
using namespace std;
#include "common.h"
/********************************************************************************************/
static void
test_dict2(size_t n)
{
tsl::hopscotch_map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
hopscotch_map<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
namespace std {
template <> struct hash<char_array_s> {
std::size_t operator()(const char_array_s &k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
}
static void
test_dict_big(size_t n)
{
hopscotch_map<char_array_s, char_array_s> dict;
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
hopscotch_map<char_array_s, char_array_s>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict_str(size_t n)
{
hopscotch_map<string, string> dict;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s2 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
hopscotch_map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
const config_func_t table[] = {
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict", 1000000, 0, test_dict2, 0},
{ 43, "DictStr", 1000000, 0, test_dict_str, 0}
};
int main(int argc, const char *argv[])
{
test("HOPSCOTCHMAP", numberof(table), table, argc, argv);
exit(0);
}
-202
View File
@@ -1,202 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "kvec.h"
#include "klist.h"
#include "kbtree.h"
#include "khash.h"
#include "ksort.h"
#include "common.h"
/********************************************************************************************/
static void test_array(size_t n)
{
kvec_t(unsigned int) a1, a2;
kv_init(a1);
kv_init(a2);
for(size_t i = 0; i < n; i++) {
kv_push(unsigned int, a1, rand_get() );
kv_push(unsigned int, a2, rand_get() );
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += kv_A(a1, i ) * kv_A(a2, i );
}
g_result = s;
kv_destroy(a1);
kv_destroy(a2);
}
/********************************************************************************************/
#define uint_free(x)
KLIST_INIT(list_uint, unsigned int, uint_free)
static void test_list (size_t n)
{
klist_t(list_uint) *a1, *a2;
a1 = kl_init(list_uint);
a2 = kl_init(list_uint);
for(size_t i = 0; i < n; i++) {
*kl_pushp (list_uint, a1) = rand_get();
*kl_pushp (list_uint, a2) = rand_get();
}
unsigned int s = 0;
kliter_t(list_uint) *it1, *it2;
for(it1 = kl_begin(a1), it2 = kl_begin(a2);
it1 != kl_end(a1);
it1 = kl_next(it1), it2 = kl_next(it2)) {
s += kl_val(it1) * kl_val(it2);
}
g_result = s;
kl_destroy(list_uint, a1);
kl_destroy(list_uint, a2);
}
/********************************************************************************************/
#define my_cmp(a,b) ( (a) < (b) ? -1 : (a) > (b) )
KBTREE_INIT(kTree, unsigned long, my_cmp)
static void test_rbtree(size_t n)
{
kbtree_t(kTree) *tree;
tree = kb_init(kTree, KB_DEFAULT_SIZE/2);
for (size_t i = 0; i < n; i++) {
unsigned long j = rand_get();
kb_putp(kTree, tree, &j);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long j = rand_get();
if (kb_getp(kTree, tree, &j) != 0)
s+= j;
}
g_result = s;
kb_destroy(kTree, tree);
}
/********************************************************************************************/
#define hash_eq(a, b) ((a) == (b))
#define hash_func(a) kh_int64_hash_func(a)
KHASH_INIT(iun, unsigned long, unsigned long, 1, hash_func, hash_eq)
static void
test_dict(size_t n)
{
khash_t(iun) *dict = kh_init(iun);
for (size_t i = 0; i < n; i++) {
int ret;
khiter_t k = kh_put(iun, dict, rand_get(), &ret);
kh_value(dict, k) = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
khiter_t k = kh_get(iun, dict, rand_get());
if (kh_exist(dict, k))
s += kh_value(dict, k);
}
g_result = s;
kh_destroy(iun, dict);
}
/********************************************************************************************/
typedef struct {
char a[256];
} char_array_t;
static inline void char_init (char_array_t *a) { a->a[0] = 0; }
static inline void char_set (char_array_t *a, const char_array_t b) { strcpy(a->a, b.a); }
static inline bool char_equal_p (const char_array_t a, const char_array_t b) { return strcmp(a.a,b.a)==0; }
static inline size_t char_hash(const char_array_t a) {
size_t hash = 0;
const char *s = a.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
}
KHASH_INIT(iub, char_array_t, char_array_t, 1, char_hash, char_equal_p)
static void
test_dict_big(size_t n)
{
khash_t(iub) *dict = kh_init(iub);
for (size_t i = 0; i < n; i++) {
int ret;
char_array_t s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
khiter_t k = kh_put(iub, dict, s1, &ret);
char_set(&kh_value(dict, k), s2);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_t s1;
sprintf(s1.a, "%u", rand_get());
khiter_t k = kh_get(iub, dict, s1);
if (kh_exist(dict, k))
s ++;
}
g_result = s;
kh_destroy(iub, dict);
}
/********************************************************************************************/
// NOTE: Needed for compiling
double drand48(void) { return rand_get(); }
KSORT_INIT_GENERIC(float)
static void test_sort(size_t n)
{
kvec_t(float) a1;
kv_init(a1);
for(size_t i = 0; i < n; i++) {
kv_push(float, a1, rand_get() );
}
// NOTE: Is-it the right way to do? Seems very low level!
ks_introsort_float(n, & kv_A(a1, 0));
g_result = kv_A(a1, 0);
kv_destroy(a1);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 50, "Sort",10000000, 0, test_sort, 0},
};
int main(int argc, const char *argv[])
{
test("KLIB", numberof(table), table, argc, argv);
exit(0);
}
-170
View File
@@ -1,170 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
// Needed due to compilation error in pool.h
#include <pthread.h>
#include "dynamic.h"
#include "common.h"
/********************************************************************************************/
static void test_array(size_t n)
{
vector a1, a2;
vector_construct(&a1, sizeof(unsigned int));
vector_construct(&a2, sizeof(unsigned int));
for(size_t i = 0; i < n; i++) {
unsigned int v = rand_get();
vector_push_back(&a1, &v);
v = rand_get();
vector_push_back(&a2, &v);
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += *(unsigned int*) vector_at(&a1, i) * *(unsigned int*) vector_at(&a2, i);
}
g_result = s;
vector_destruct(&a1, NULL);
vector_destruct(&a2, NULL);
}
/********************************************************************************************/
static size_t hash_func (void *a)
{
return hash_data(a, sizeof (unsigned long));
}
static int equal_func(void *a, void *b)
{
const unsigned long *pa = a;
if (b == NULL) {
return *pa == -1U;
}
const unsigned long *pb = b;
return *pa == *pb;
}
static void set_func(void *a, void *b)
{
unsigned long *pa = a;
if (b == NULL) {
*pa = -1U;
} else {
const unsigned long *pb = b;
*pa = *pb;
}
}
typedef struct map_element map_element;
struct map_element
{
unsigned long key;
unsigned long value;
};
static void
test_dict(size_t n)
{
map dict;
map_construct(&dict, sizeof(map_element), set_func);
for (size_t i = 0; i < n; i++) {
map_insert(&dict, (map_element[]) {{.key = rand_get(), .value = rand_get()}}, hash_func, set_func, equal_func, NULL);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
map_element *p = map_at(&dict, (map_element[]){{.key = rand_get()}}, hash_func, equal_func);
if (p)
s += p->value;
}
g_result = s;
map_destruct(&dict, NULL, NULL);
}
/********************************************************************************************/
typedef char char_array_t[256];
static int char_equal (void *a, void *b)
{
const char_array_t *pa = (const char_array_t *)a;
if (b == NULL)
return strcmp(*pa, "") == 0;
const char_array_t *pb = (const char_array_t *)b;
return strcmp(*pa,*pb)==0;
}
static size_t char_hash(void *a)
{
char_array_t *pa = (char_array_t *)a;
return hash_string(*pa);
}
static void char_set(void *a, void *b)
{
char_array_t *pa = (char_array_t *)a;
if (b == NULL) {
strcpy(*pa, "");
} else {
const char_array_t *pb = (const char_array_t *)b;
strcpy(*pa,*pb);
}
}
typedef struct big_map_element big_map_element;
struct big_map_element
{
char_array_t key;
char_array_t value;
};
static void
test_dict_big(size_t n)
{
map dict;
map_construct(&dict, sizeof(big_map_element), char_set);
for (size_t i = 0; i < n; i++) {
big_map_element el;
sprintf(el.key, "%u", rand_get());
sprintf(el.value, "%u", rand_get());
map_insert(&dict, &el, char_hash, char_set, char_equal, NULL);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
big_map_element el;
sprintf(el.key, "%u", rand_get());
big_map_element *p = map_at(&dict, &el, char_hash, char_equal);
if (p)
s ++;
}
g_result = s;
map_destruct(&dict, NULL, NULL);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 20, "Array", 100000000, 0, test_array, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
};
int main(int argc, const char *argv[])
{
test("LIBDYNAMIC", numberof(table), table, argc, argv);
exit(0);
}
-116
View File
@@ -1,116 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "liblfds711.h"
#include "common.h"
/********************************************************************************************/
struct lfds711_queue_bmm_state g_buff;
struct lfds711_queue_bmm_state g_final;
static void final(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long j, s = 0;
LFDS711_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE;
for(int i = 0; i < n;i++) {
void *p;
while (0 == lfds711_queue_bmm_dequeue(&g_final, &p, NULL)) { m_thread_yield(); }
j = (uintptr_t)p;
s += j;
}
g_result = s;
}
static void conso(void *arg)
{
unsigned int j;
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long s = 0;
LFDS711_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE;
for(int i = 0; i < n;i++) {
void *p;
while (0 == lfds711_queue_bmm_dequeue(&g_buff, &p, NULL)) { m_thread_yield(); }
j = (uintptr_t) p;
s += j;
}
while (0 == lfds711_queue_bmm_enqueue(&g_final, (void*)(uintptr_t)s, NULL)) { m_thread_yield(); }
}
static void prod(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
size_t r = n;
LFDS711_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE;
for(unsigned int i = 0; i < n;i++) {
while (0 == lfds711_queue_bmm_enqueue(&g_buff, (void*)(uintptr_t)r, NULL)) { m_thread_yield(); }
r = r * 31421U + 6927U;
}
}
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
const int conso_count = cpu_count - prod_count;
if (cpu_count < 2) {
fprintf(stderr, "WARNING: Can not measure Buffer performance.\n");
return;
}
rand_get();
// Init
const size_t size = m_core_roundpow2(64*cpu_count);
struct lfds711_queue_bmm_element g_buff_elements[size];
struct lfds711_queue_bmm_element g_final_elements[size];
lfds711_queue_bmm_init_valid_on_current_logical_core(&g_buff, g_buff_elements,
size, NULL);
lfds711_queue_bmm_init_valid_on_current_logical_core(&g_final, g_final_elements,
size, NULL);
// Create thread
m_thread_t idx_p[prod_count];
m_thread_t idx_c[conso_count];
m_thread_t idx_final;
for(int i = 0; i < prod_count; i++) {
m_thread_create (idx_p[i], prod, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final, &n2);
// Wait for jobs to be done.
for(int i = 0; i < prod_count; i++) {
m_thread_join(idx_p[i]);
}
for(int i = 0; i < conso_count; i++) {
m_thread_join(idx_c[i]);
}
m_thread_join(idx_final);
// Clear & quit
lfds711_queue_bmm_cleanup(&g_final, NULL);
lfds711_queue_bmm_cleanup(&g_buff, NULL);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
};
int main(int argc, const char *argv[])
{
test("LIBLFDS", numberof(table), table, argc, argv);
exit(0);
}
-74
View File
@@ -1,74 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "svector.h"
#include "smap.h"
#include "smset.h"
#include "common.h"
/********************************************************************************************/
static void test_array(size_t n)
{
srt_vector *a1 = sv_alloc ( sizeof (unsigned int), 16, NULL);
srt_vector *a2 = sv_alloc ( sizeof (unsigned int), 16, NULL);
for(size_t i = 0; i < n; i++) {
unsigned int value = rand_get();
sv_push(&a1, &value );
value = rand_get();
sv_push(&a2, &value );
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += *(unsigned int*)sv_at(a1, i ) * *(unsigned int *)sv_at(a2, i );
}
g_result = s;
sv_free(&a1);
sv_free(&a2);
}
/********************************************************************************************/
/* There is no 'unsigned long' key in smset */
/********************************************************************************************/
static int cmp_float (const void *a, const void *b)
{
const float *pa=a;
const float *pb = b;
return (*pa < *pb) ? -1 : *pa > *pb;
}
static void test_sort(size_t n)
{
srt_vector *a1 = sv_alloc(sizeof(float), 16, cmp_float);
for(size_t i = 0; i < n; i++) {
unsigned int value = rand_get();
sv_push(&a1, &value );
}
sv_sort(a1);
g_result = *(float*)sv_at(a1, 0);
sv_free(&a1);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 20, "Array", 100000000, 0, test_array, 0},
{ 50, "sort", 10000000, 0, test_sort, 0}
};
int main(int argc, const char *argv[])
{
test("LIBSRT", numberof(table), table, argc, argv);
exit(0);
}
-1090
View File
File diff suppressed because it is too large. Load diff
-99
View File
@@ -1,99 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "nedtrie.h"
#include "common.h"
/********************************************************************************************/
typedef struct foo_s {
NEDTRIE_ENTRY(foo_s) link;
unsigned long key;
unsigned long value;
} foo_t;
typedef struct foo_tree_s foo_tree_t;
NEDTRIE_HEAD(foo_tree_s, foo_s);
static inline size_t fookeyfunct(const foo_t *r)
{
return r->key;
}
NEDTRIE_GENERATE(static, foo_tree_s, foo_s, link, fookeyfunct, NEDTRIE_NOBBLEZEROS(foo_tree_s))
static void
test_dict(size_t n)
{
foo_tree_t footree;
NEDTRIE_INIT(&footree);
for (size_t i = 0; i < n; i++) {
unsigned long key = rand_get();
unsigned long val = rand_get();
foo_t * p = malloc(sizeof(foo_t));
if (p == NULL) abort();
p->key = key;
p->value = val;
NEDTRIE_INSERT(foo_tree_s, &footree, p);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
foo_t key = { .key = rand_get() };
foo_t *p = NEDTRIE_FIND(foo_tree_s, &footree, &key);
if (p)
s += p->value;
}
g_result = s;
foo_t *r, *next;
NEDTRIE_FOREACH_SAFE(r, foo_tree_s, &footree, next) {
// Remove is needed, otherwise it segfault
NEDTRIE_REMOVE(foo_tree_s, &footree, r);
free(r);
}
}
static void
test_dict_noalloc(size_t n)
{
foo_tree_t footree;
NEDTRIE_INIT(&footree);
foo_t *tab = malloc(n*sizeof(foo_t));
if (tab == NULL) abort();
for (size_t i = 0; i < n; i++) {
unsigned long key = rand_get();
unsigned long val = rand_get();
tab[i].key = key;
tab[i].value = val;
NEDTRIE_INSERT(foo_tree_s, &footree, &tab[i]);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
foo_t key = { .key = rand_get() };
foo_t *p = NEDTRIE_FIND(foo_tree_s, &footree, &key);
if (p)
s += p->value;
}
g_result = s;
free(tab);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 45, "dict(noalloc)", 1000000, 0, test_dict_noalloc, 0}
};
int main(int argc, const char *argv[])
{
test("NEDTRIES", numberof(table), table, argc, argv);
exit(0);
}
-90
View File
@@ -1,90 +0,0 @@
// Inspired by: http://stackoverflow.com/questions/3664272/is-stdvector-so-much-slower-than-plain-arrays/3664349#3664349
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/time.h>
#include "m-array.h"
#include "m-list.h"
#include "m-rbtree.h"
#include "m-dict.h"
#include "m-algo.h"
#include "m-mempool.h"
#include "m-string.h"
unsigned long g_result;
static unsigned long long
cputime (void)
{
struct rusage rus;
getrusage (0, &rus);
return rus.ru_utime.tv_sec * 1000000ULL + rus.ru_utime.tv_usec;
}
struct Pixel
{
unsigned char r, g, b;
};
ARRAY_DEF(array_pixel, struct Pixel, (INIT(M_NOTHING_DEFAULT)) )
void UseMlib(void)
{
unsigned long long t1 = cputime();
for(int i = 0; i < 1000; ++i)
{
int dimension = 999;
array_pixel_t pixels;
array_pixel_init(pixels);
array_pixel_reserve(pixels, dimension * dimension);
for(int i = 0; i < dimension * dimension; ++i)
{
const struct Pixel p = { 255, 0, 0};
array_pixel_push_back (pixels, p);
}
array_pixel_clear(pixels);
}
unsigned long long t2 = cputime();
printf ("M*Lib Array: %Lu us\n", (t2-t1)/1000);
}
void UseNative(void)
{
unsigned long long t1 = cputime();
for(int i = 0; i < 1000; ++i)
{
int dimension = 999;
struct Pixel * pixels = malloc(sizeof(struct Pixel) * dimension * dimension);
for(int i = 0 ; i < dimension * dimension; ++i)
{
pixels[i].r = 255;
pixels[i].g = 0;
pixels[i].b = 0;
}
free(pixels);
}
unsigned long long t2 = cputime();
printf ("Native Array: %Lu us\n", (t2-t1)/1000);
}
int main(void)
{
UseNative();
UseMlib();
return 0;
}
-113
View File
@@ -1,113 +0,0 @@
#define NDEBUG
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include "qlibc/qlibc.h"
#include "common.h"
/********************************************************************************************/
static void test_array(size_t n)
{
qvector_t *a1 = qvector(16, sizeof(unsigned int), QVECTOR_RESIZE_DOUBLE);
if (!a1) abort();
qvector_t *a2 = qvector(16, sizeof(unsigned int), QVECTOR_RESIZE_DOUBLE);
if (!a2) abort();
for(size_t i = 0; i < n; i++) {
unsigned int v = rand_get();
bool success = a1->addlast(a1, &v);
if (!success) abort();
v = rand_get();
success = a2->addlast(a2, &v);
if (!success) abort();
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += *(unsigned int*)a1->getat(a1, i, false) * *(unsigned int *) a2->getat(a2, i, false);
}
g_result = s;
a1->free(a1);
a2->free(a2);
}
/********************************************************************************************/
static void test_list (size_t n)
{
qlist_t *a1 = qlist(0);
qlist_t *a2 = qlist(0);
for(size_t i = 0; i < n; i++) {
unsigned int u = rand_get(), v = rand_get();
a1->addlast(a1, &u, sizeof(unsigned int));
a2->addlast(a2, &v, sizeof(unsigned int));
}
unsigned int s = 0;
qlist_obj_t it1, it2;
memset(&it1, 0, sizeof (it1));
memset(&it2, 0, sizeof (it2));
while (a1->getnext(a1, &it1, false) == true
&& a2->getnext(a2, &it2, false) == true) {
s += *(unsigned int*)it1.data * *(unsigned int*)it2.data;
}
g_result = s;
a1->free(a1);
a2->free(a2);
}
/********************************************************************************************/
static int compare(const void *key1, size_t size1,
const void *key2, size_t size2)
{
assert(size1 == sizeof(unsigned long));
assert(size2 == sizeof(unsigned long));
const unsigned long *pa = key1;
const unsigned long *pb = key2;
return (*pa < *pb) ? -1 : (*pa > *pb);
}
static void test_rbtree(size_t n)
{
qtreetbl_t *tree = qtreetbl(0);
tree->set_compare(tree, compare);
for (size_t i = 0; i < n; i++) {
unsigned long v = rand_get();
tree->put_by_obj(tree,
&v, sizeof(unsigned long), /* key */
&v, sizeof(unsigned long) /* value */ );
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long v = rand_get();
void *obj = tree->get_by_obj(tree, (const char*)&v, sizeof(unsigned long), NULL, 0);
if (obj)
s += *(unsigned long*)obj;
}
g_result = s;
tree->free(tree);
}
/* qlibc hash functions only accept a string as the key */
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0}
};
int main(int argc, const char *argv[])
{
test("QLIBC", numberof(table), table, argc, argv);
exit(0);
}
-179
View File
@@ -1,179 +0,0 @@
#define NDEBUG
#include <QLinkedList>
#include <QVector>
#include <QSet>
#include <QMap>
#include <QHash>
#include <QtAlgorithms>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
using namespace std;
#include "common.h"
/********************************************************************************************/
static void test_list(size_t n)
{
QLinkedList<unsigned int> a1, a2;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
a2.push_back(rand_get() );
}
unsigned int s = 0;
for (QLinkedList<unsigned int>::const_iterator ci1 = a1.begin(), ci2 = a2.begin (); ci1 != a1.end(); ++ci1, ++ci2) {
s += *ci1 * *ci2;
}
g_result = s;
}
/********************************************************************************************/
static void test_array(size_t n)
{
QVector<unsigned int> a1, a2;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
a2.push_back(rand_get() );
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += a1[i] * a2[i];
}
g_result = s;
}
/********************************************************************************************/
/* NOTE: QSet doesn't perform full ordering. I can't find any container
which is a set with total ordering within Qt. So we have to fake it. */
static void test_rbtree(size_t n)
{
QMap<unsigned long, QHashDummyValue> tree;
for (size_t i = 0; i < n; i++) {
tree[rand_get()] = QHashDummyValue();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
QMap<unsigned long, QHashDummyValue>::iterator it = tree.find(rand_get());
if (it != tree.end())
s += it.key();
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict1(size_t n)
{
QMap<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
QMap<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it.value();
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict2(size_t n)
{
QHash<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
QHash<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it.value();
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
uint qHash(const char_array_s &k)
{
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
static void
test_dict_big(size_t n)
{
QHash<char_array_s, char_array_s> dict;
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
QHash<char_array_s, char_array_s>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void test_sort(size_t n)
{
QVector<float> a1;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
}
qSort(a1.begin(), a1.end());
g_result = a1[0];
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 40, "dict(m)", 1000000, 0, test_dict1, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict(u)", 1000000, 0, test_dict2, 0},
{ 50, "Sort",10000000, 0, test_sort, 0}
};
int main(int argc, const char *argv[])
{
test("QT", numberof(table), table, argc, argv);
exit(0);
}
-185
View File
@@ -1,185 +0,0 @@
#define NDEBUG
#define RAPIDJSON_HAS_STDSTRING 1
#include "rapidjson/reader.h"
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/encodedstream.h"
#include "rapidjson/error/en.h"
#include <stdio.h>
#include <string>
#include <vector>
#include "common.h"
using namespace std;
/********************************************************************************************/
vector<string> vstring;
vector<string> vstring2;
static void
bench_vector_string_init(size_t n)
{
for(size_t i = 0; i < n; i++)
{
char buff[100];
snprintf(buff, sizeof(buff), "%zu", i);
std::string s(buff);
vstring.push_back(s);
}
}
static void
bench_vector_string_init_big(size_t n)
{
for(size_t i = 0; i < n; i++)
{
char buff[100];
snprintf(buff, sizeof(buff), "%zu%zu%zu%zu%zu%zu", i, i, i, i, i, i);
std::string s(buff);
vstring.push_back(s);
}
}
static void
bench_vector_string_json_run(size_t n)
{
if (vstring.size() != n) {
printf("Size are different!\n");
abort();
}
FILE *f = fopen("tmp-serial.json", "wt");
if (!f) abort();
{
// Prepare writer and output stream.
char writeBuffer[65536];
typedef rapidjson::AutoUTFOutputStream<unsigned, rapidjson::FileWriteStream> OutputStream;
rapidjson::FileWriteStream os(f, writeBuffer, sizeof(writeBuffer));
OutputStream eos(os, rapidjson::kUTF8, false);
rapidjson::PrettyWriter<OutputStream, rapidjson::UTF8<>, rapidjson::AutoUTF<unsigned> > writer(eos);
writer.StartArray();
for(size_t i = 0; i < n; i++){
writer.String(vstring[i]);
}
writer.EndArray();
}
fclose(f);
f = fopen("tmp-serial.json", "rt");
if (!f) abort();
{
char readBuffer[65536];
rapidjson::FileReadStream is(f, readBuffer, sizeof(readBuffer));
rapidjson::Document d;
d.ParseStream(is);
for(size_t i = 0; i < d.Size(); i++) {
rapidjson::Value& s = d[i];
vstring2.push_back(s.GetString());
}
}
fclose(f);
if (vstring2.size() != n) {
printf("Size are different!\n");
abort();
}
}
static void
bench_vector_string_clear(void)
{
if (vstring != vstring2) {
printf("Array are different!\n");
abort();
}
}
/********************************************************************************************/
vector<unsigned long> vulong;
vector<unsigned long> vulong2;
static void
bench_vector_ulong_init(size_t n)
{
for(size_t i = 0; i < n; i++)
{
vulong.push_back(i*i);
}
}
static void
bench_vector_ulong_json_run(size_t n)
{
if (vulong.size() != n) {
printf("Size are different!\n");
abort();
}
FILE *f = fopen("tmp-serial.json", "wt");
if (!f) abort();
{
// Prepare writer and output stream.
char writeBuffer[65536];
typedef rapidjson::AutoUTFOutputStream<unsigned, rapidjson::FileWriteStream> OutputStream;
rapidjson::FileWriteStream os(f, writeBuffer, sizeof(writeBuffer));
OutputStream eos(os, rapidjson::kUTF8, false);
rapidjson::PrettyWriter<OutputStream, rapidjson::UTF8<>, rapidjson::AutoUTF<unsigned> > writer(eos);
writer.StartArray();
for(size_t i = 0; i < n; i++){
writer.Int64(vulong[i]);
}
writer.EndArray();
}
fclose(f);
f = fopen("tmp-serial.json", "rt");
if (!f) abort();
{
char readBuffer[65536];
rapidjson::FileReadStream is(f, readBuffer, sizeof(readBuffer));
rapidjson::Document d;
d.ParseStream(is);
for(size_t i = 0; i < d.Size(); i++) {
rapidjson::Value& s = d[i];
vulong2.push_back(s.GetInt64());
}
}
fclose(f);
if (vulong2.size() != n) {
printf("Size are different!\n");
abort();
}
}
static void
bench_vector_ulong_clear(void)
{
if (vulong != vulong2) {
printf("Array are different!\n");
abort();
}
}
/********************************************************************************************/
const config_func_t table[] = {
{110, "serial-json STR", 10000000, bench_vector_string_init, bench_vector_string_json_run, bench_vector_string_clear},
{111, "serial-json STR.big", 10000000, bench_vector_string_init_big, bench_vector_string_json_run, bench_vector_string_clear},
{112, "serial-json INT", 10000000, bench_vector_ulong_init, bench_vector_ulong_json_run, bench_vector_ulong_clear}
};
int main(int argc, const char *argv[])
{
test("RAPIDJSON", numberof(table), table, argc, argv);
exit(0);
}
-159
View File
@@ -1,159 +0,0 @@
#define NDEBUG
#include <vector>
#include <list>
#include <iterator>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "rigtorp/HashMap.h"
using namespace rigtorp;
using namespace std;
#include "common.h"
/********************************************************************************************/
// Hash for using unsigned long as lookup key
struct UL_Hash {
size_t operator()(const unsigned long v) { return v * 7; }
};
// Equal comparison for using unsigned long as lookup key
struct UL_Equal {
bool operator()(const unsigned long lhs, const unsigned long rhs) {
return lhs == rhs;
}
};
static void
test_dict2(size_t n)
{
HashMap<unsigned long, unsigned long, UL_Hash, UL_Equal> dict(16, -1UL);
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
HashMap<unsigned long, unsigned long, UL_Hash, UL_Equal>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
namespace std {
template <> struct hash<char_array_s> {
std::size_t operator()(const char_array_s &k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
}
struct BIG_Hash {
size_t operator()(const char_array_s v) { return hash<char_array_s>()(v); }
};
struct BIG_Equal {
bool operator()(const char_array_s lhs, const char_array_s rhs) {
return lhs == rhs;
}
};
static void
test_dict_big(size_t n)
{
char_array_s empty;
HashMap<char_array_s, char_array_s, BIG_Hash, BIG_Equal> dict(16, empty);
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
HashMap<char_array_s, char_array_s, BIG_Hash, BIG_Equal>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
struct STR_Hash {
size_t operator()(const string v) { return hash<string>()(v); }
};
struct STR_Equal {
bool operator()(const string lhs, const string rhs) {
return lhs == rhs;
}
};
static void
test_dict_str(size_t n)
{
string empty;
HashMap<string, string, STR_Hash, STR_Equal> dict(16, empty);
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s2 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
HashMap<string, string, STR_Hash, STR_Equal>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
const config_func_t table[] = {
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict", 1000000, 0, test_dict2, 0},
{ 43, "DictStr", 1000000, 0, test_dict_str, 0}
};
int main(int argc, const char *argv[])
{
test("RIGTORP-HASHMAP", numberof(table), table, argc, argv);
exit(0);
}
-96
View File
@@ -1,96 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <rigtorp/MPMCQueue.h>
#include "common.h"
/********************************************************************************************/
rigtorp::MPMCQueue<unsigned int> g_buff(4*64);
rigtorp::MPMCQueue<unsigned long long> g_final(4*64);
static void final(void *arg)
{
size_t *p_n = (size_t*) arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(unsigned int i = 0; i < n;i++) {
g_final.pop(j);
s += j;
}
g_result = s;
}
static void conso(void *arg)
{
unsigned int j;
size_t *p_n = (size_t*)arg;
size_t n = *p_n;
unsigned long long s = 0;
for(unsigned int i = 0; i < n;i++) {
g_buff.pop(j);
s += j;
}
g_final.push(s);
}
static void prod(void *arg)
{
size_t *p_n = (size_t*)arg;
size_t n = *p_n;
size_t r = n;
for(unsigned int i = 0; i < n;i++) {
g_buff.push(r);
r = r * 31421U + 6927U;
}
}
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
const int conso_count = cpu_count - prod_count;
if (cpu_count < 2) {
fprintf(stderr, "WARNING: Can not measure Buffer performance.\n");
return;
}
rand_get();
// Create thread
m_thread_t idx_p[prod_count];
m_thread_t idx_c[conso_count];
m_thread_t idx_final;
for(int i = 0; i < prod_count; i++) {
m_thread_create (idx_p[i], prod, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final, &n2);
// Wait for jobs to be done.
for(int i = 0; i < prod_count; i++) {
m_thread_join(idx_p[i]);
}
for(int i = 0; i < conso_count; i++) {
m_thread_join(idx_c[i]);
}
m_thread_join(idx_final);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
};
int main(int argc, const char *argv[])
{
test("RIGTORP-MPMC-QUEUE", numberof(table), table, argc, argv);
exit(0);
}
-122
View File
@@ -1,122 +0,0 @@
#define NDEBUG
#include <vector>
#include <list>
#include <iterator>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sparsepp/spp.h>
using spp::sparse_hash_map;
using namespace std;
#include "common.h"
/********************************************************************************************/
static void
test_dict2(size_t n)
{
sparse_hash_map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
sparse_hash_map<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
namespace std {
template <> struct hash<char_array_s> {
std::size_t operator()(const char_array_s &k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
}
static void
test_dict_big(size_t n)
{
sparse_hash_map<char_array_s, char_array_s> dict;
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
sparse_hash_map<char_array_s, char_array_s>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict_str(size_t n)
{
sparse_hash_map<string, string> dict;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s2 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
sparse_hash_map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
const config_func_t table[] = {
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict", 1000000, 0, test_dict2, 0},
{ 43, "DictStr", 1000000, 0, test_dict_str, 0}
};
int main(int argc, const char *argv[])
{
test("SPARSEPP", numberof(table), table, argc, argv);
exit(0);
}
-278
View File
@@ -1,278 +0,0 @@
#define NDEBUG
#include <vector>
#include <deque>
#include <list>
#include <iterator>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
using namespace std;
#include "common.h"
/********************************************************************************************/
static void test_list(size_t n)
{
list<unsigned int> a1, a2;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
a2.push_back(rand_get() );
}
unsigned int s = 0;
for (list<unsigned int>::const_iterator ci1 = a1.begin(), ci2 = a2.begin (); ci1 != a1.end(); ++ci1, ++ci2) {
s += *ci1 * *ci2;
}
g_result = s;
}
/********************************************************************************************/
static void test_array(size_t n)
{
vector<unsigned int> a1, a2;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
a2.push_back(rand_get() );
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += a1[i] * a2[i];
}
g_result = s;
}
/********************************************************************************************/
static void test_deque(size_t n)
{
deque<unsigned int> a1, a2;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
a2.push_back(rand_get() );
}
unsigned int s = 0;
for(auto it1 = a1.cbegin(), it2 = a2.cbegin();
it1 != a1.cend() ;it1++, it2++) {
s += *it1 * *it2;
}
g_result = s;
}
/********************************************************************************************/
static void test_rbtree(size_t n)
{
set<unsigned long> tree;
for (size_t i = 0; i < n; i++) {
tree.insert(rand_get());
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
set<unsigned long>::iterator it = tree.find(rand_get());
if (it != tree.end())
s += *it;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict1(size_t n)
{
map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
map<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict2(size_t n)
{
unordered_map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[rand_get()] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unordered_map<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
if (it != dict.end())
s += it->second;
}
g_result = s;
}
static void
test_dict2_linear(size_t n)
{
unordered_map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
dict[i] = rand_get();
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unordered_map<unsigned long, unsigned long>::iterator it = dict.find(i);
if (it != dict.end())
s += it->second;
}
g_result = s;
}
/********************************************************************************************/
struct char_array_s {
char a[256];
char_array_s () { a[0] = 0 ; }
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
};
namespace std {
template <> struct hash<char_array_s> {
std::size_t operator()(const char_array_s &k) const {
size_t hash = 0;
const char *s = k.a;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
};
};
}
static void
test_dict_big(size_t n)
{
unordered_map<char_array_s, char_array_s> dict;
for (size_t i = 0; i < n; i++) {
char_array_s s1, s2;
sprintf(s1.a, "%u", rand_get());
sprintf(s2.a, "%u", rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_s s1;
sprintf(s1.a, "%u", rand_get());
unordered_map<char_array_s, char_array_s>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void
test_dict_str(size_t n)
{
unordered_map<string, string> dict;
for (size_t i = 0; i < n; i++) {
string s1 = to_string(rand_get());
string s2 = to_string(rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = to_string (rand_get());
unordered_map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
static void
test_dict_str2(size_t n)
{
map<string, string> dict;
for (size_t i = 0; i < n; i++) {
string s1 = to_string(rand_get());
string s2 = to_string(rand_get());
dict[s1] = s2;
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
string s1 = to_string(rand_get());
map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
}
g_result = s;
}
/********************************************************************************************/
static void test_sort(size_t n)
{
vector<float> a1;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
}
sort(a1.begin(), a1.end());
g_result = a1[0];
}
static void test_stable_sort(size_t n)
{
vector<float> a1;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
}
stable_sort(a1.begin(), a1.end());
g_result = a1[0];
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 21, "Deque", 100000000, 0, test_deque, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 40, "dict(m)", 1000000, 0, test_dict1, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict(u)", 1000000, 0, test_dict2, 0},
{ 43,"DictStr(u)", 1000000, 0, test_dict_str, 0},
{ 44,"DictStr(m)", 1000000, 0, test_dict_str2, 0},
{ 46, "dictLinear(u)", 1000000, 0, test_dict2_linear, 0},
{ 50, "Sort",10000000, 0, test_sort, 0},
{ 51, "Stable Sort",10000000, 0, test_stable_sort, 0}
};
int main(int argc, const char *argv[])
{
test("STL", numberof(table), table, argc, argv);
exit(0);
}
-258
View File
@@ -1,258 +0,0 @@
/*
* M*LIB - String Bench
*
* Copyright (c) 2017-2021, Patrick Pelissier
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string>
#include <sstream>
#include <string>
#include <vector>
#include "common.h"
#include "m-string.h"
#ifdef BENCH_CAN_USE_SDS
extern "C" {
#include "sds.h"
};
#endif
#ifdef BENCH_CAN_USE_BSTRLIB
#include "bstrlib.h"
#include "bstrwrap.h"
#include "bstraux.h"
#endif
/*
* BENCH
* 2000000
* 1. Generate N strings of random numbers 32 bits.
* 2. Concat all strings in a string usigned a random permutation of N.
* 3. Replace "1234" in the string into "WELL" until nothing remains.
* 4. Replace "56789" in the string into "DONE" until nothing remains.
* Return the final string length.
*/
unsigned *permutation_tab = NULL;
void random_permutation(unsigned n)
{
if (permutation_tab) free(permutation_tab);
permutation_tab = (unsigned *) malloc(n * sizeof(unsigned));
if (permutation_tab == NULL) abort();
for(unsigned i = 0; i < n; i++)
permutation_tab[i] = i;
for(unsigned i = 0; i < n; i++) {
unsigned j = rand_get() % n;
unsigned k = rand_get() % n;
unsigned l = permutation_tab[j];
permutation_tab[j] = permutation_tab[k];
permutation_tab[k] = l;
}
}
using namespace std;
static void replace_all_stl(string &str, const char pattern[], const char replace[])
{
size_t pos = 0;
do {
pos = str.find(pattern, pos);
if (pos != string::npos) {
str.replace (pos, strlen(pattern), replace);
}
} while (pos != string::npos);
}
size_t bench_stl(unsigned n)
{
vector<string> tab;
tab.resize(n);
for(unsigned i = 0; i < n; i++)
tab[i] = to_string(rand_get());
string str;
for(unsigned i = 0; i < n; i++) {
str += tab[permutation_tab[i]];
}
replace_all_stl(str, "1234", "WELL");
replace_all_stl(str, "56789", "DONE");
return str.length();
}
size_t bench_mlib(unsigned n)
{
string_t *tab = (string_t*) malloc (n * sizeof (string_t));
assert (tab != 0);
// P1
for(unsigned i = 0; i < n; i++) {
string_init(tab[i]);
string_printf(tab[i], "%u", rand_get());
}
// P2
string_t str;
string_init(str);
for(unsigned i = 0; i < n; i++) {
string_cat(str, tab[permutation_tab[i]]);
}
// P3
string_replace_all_str(str, "1234", "WELL");
string_replace_all_str(str, "56789", "DONE");
size_t length = string_size(str);
// Clean
string_clear(str);
for(unsigned i = 0; i < n; i++) {
string_clear(tab[i]);
}
free(tab);
return length;
}
#ifdef BENCH_CAN_USE_BSTRLIB
static void replace_all_bstrlib(CBString &str, const char pattern[], const char replace[])
{
size_t pos = 0;
do {
pos = str.find(pattern, pos);
if (pos != string::npos) {
str.replace (pos, strlen(pattern), replace);
}
} while (pos != string::npos);
}
size_t bench_bstrlib(unsigned n)
{
vector<CBString> tab;
tab.resize(n);
for(unsigned i = 0; i < n; i++) {
char tmp[10];
sprintf(tmp, "%u", rand_get());
tab[i] = tmp;
}
CBString str;
for(unsigned i = 0; i < n; i++) {
str += tab[permutation_tab[i]];
}
replace_all_bstrlib(str, "1234", "WELL");
replace_all_bstrlib(str, "56789", "DONE");
return str.length();
}
#endif
#ifdef BENCH_CAN_USE_SDS
sds SDS_replace_at(sds str, size_t pos, size_t len, const char str2[])
{
// simple implementation as replace is not available
sds a = sdsnewlen((const void*) str, pos);
a = sdscat(a, str2);
a = sdscat(a, &str[pos+len]);
sdsfree(str);
return a;
}
sds replace_all_sds(sds str, const char pattern[], const char replace[])
{
size_t pos = 0;
do {
char *p = strstr(&str[pos], pattern);
pos = p == NULL ? -1U : (p - str);
if (pos != -1U) {
str = SDS_replace_at(str, pos, strlen(pattern), replace);
}
} while (pos != -1U);
return str;
}
size_t bench_sds(unsigned n)
{
sds *tab = (sds*) malloc (n * sizeof (sds));
assert (tab != 0);
// P1
for(unsigned i = 0; i < n; i++) {
tab[i] = sdsfromlonglong(rand_get());
}
// P2
sds str = sdsempty();
for(unsigned i = 0; i < n; i++) {
str = sdscat(str, tab[permutation_tab[i]]);
}
// P3
str = replace_all_sds(str, "1234", "WELL");
str = replace_all_sds(str, "56789", "DONE");
// Clean
size_t length = sdslen(str);
sdsfree(str);
for(unsigned i = 0; i < n; i++) {
sdsfree(tab[i]);
}
free(tab);
return length;
}
#endif
int main(int argc, const char *argv[])
{
unsigned length, n = atoi(argv[1]);
unsigned select = atoi(argv[2]);
const char *name;
random_permutation(n);
rand_init();
unsigned long long t0 = cputime();
switch (select) {
case 0:
length = bench_mlib(n);
name = "MLIB";
break;
case 1:
length = bench_stl(n);
name = "STL";
break;
#ifdef BENCH_CAN_USE_SDS
case 2:
length = bench_sds(n);
name = "SDS";
break;
#endif
#ifdef BENCH_CAN_USE_BSTRLIB
case 4:
length = bench_bstrlib(n);
name = "BSTRLIB";
break;
#endif
default:
exit(0);
}
unsigned long long t1 = cputime();
printf("%5.5s LENGTH=%u T= %f s\n", name, length, (t1-t0) / 1000000.0 );
return 0;
}
File diff suppressed because it is too large. Load diff
-221
View File
@@ -1,221 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "tommyds/tommy.h"
#include "common.h"
/********************************************************************************************/
static void test_array(size_t n)
{
tommy_array a1, a2;
tommy_array_init(&a1);
tommy_array_init(&a2);
for(size_t i = 0; i < n; i++) {
unsigned int v = rand_get();
tommy_array_insert(&a1, (void*)(uintptr_t) v);
v = rand_get();
tommy_array_insert(&a2, (void*)(uintptr_t) v);
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += (uintptr_t) *tommy_array_ref(&a1, i) * (uintptr_t) *tommy_array_ref(&a2, i );
}
g_result = s;
tommy_array_done(&a1);
tommy_array_done(&a2);
}
/********************************************************************************************/
struct list_node_s {
unsigned int value;
tommy_node node;
};
static void test_list (size_t n)
{
tommy_list a1, a2;
tommy_list_init(&a1);
tommy_list_init(&a2);
for(size_t i = 0; i < n; i++) {
struct list_node_s *obj;
obj = malloc(sizeof(struct list_node_s));
if (obj == NULL) abort();
obj->value = rand_get();
tommy_list_insert_tail(&a1, &obj->node, obj);
obj = malloc(sizeof(struct list_node_s));
if (obj == NULL) abort();
obj->value = rand_get();
tommy_list_insert_tail(&a2, &obj->node, obj);
}
unsigned int s = 0;
for(tommy_node *it1 = tommy_list_head(&a1), *it2 = tommy_list_head(&a2)
; it1 != NULL; it1 = it1->next, it2 = it2->next ) {
struct list_node_s *obj1 = it1->data, *obj2 = it2->data;
s += obj1->value * obj2->value;
}
g_result = s;
tommy_list_foreach(&a1, free);
tommy_list_foreach(&a2, free);
}
/********************************************************************************************/
struct tree_node_s {
unsigned long value;
tommy_tree_node node;
} ;
static int compare(const void *a, const void *b)
{
const struct tree_node_s *pa = a;
const struct tree_node_s *pb = b;
return (pa->value < pb->value) ? -1 : (pa->value > pb->value);
}
static void test_rbtree(size_t n)
{
tommy_tree tree;
tommy_tree_init(&tree, compare);
for (size_t i = 0; i < n; i++) {
struct tree_node_s *obj = malloc(sizeof(struct tree_node_s));
if (obj == NULL) abort();
obj->value = rand_get();
tommy_tree_insert(&tree, &obj->node, obj);
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
struct tree_node_s key = { .value = rand_get() };
struct tree_node_s *obj = tommy_tree_search (&tree, &key);
if (obj)
s += obj->value;
}
g_result = s;
tommy_tree_foreach(&tree, free);
}
/********************************************************************************************/
struct hash_i_node_s {
unsigned long key;
unsigned long value;
tommy_node node;
};
static inline size_t hash_func (const unsigned long key)
{
return key;
}
static int equal_func(const void* arg, const void *obj_p)
{
const struct hash_i_node_s *obj = obj_p;
const unsigned long *key = arg;
return *key != obj->key;
}
static void
test_dict(size_t n)
{
tommy_hashlin dict;
tommy_hashlin_init(&dict);
for (size_t i = 0; i < n; i++) {
struct hash_i_node_s *obj = malloc(sizeof (struct hash_i_node_s));
if(!obj) abort();
obj->key = rand_get();
obj->value = rand_get();
tommy_hashlin_insert(&dict, &obj->node, obj, hash_func(obj->key));
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long key = rand_get();
struct hash_i_node_s *obj = tommy_hashlin_search(&dict, &equal_func,
&key,
hash_func(key));
if (obj)
s += obj->value;
}
g_result = s;
tommy_hashlin_done(&dict);
}
/********************************************************************************************/
typedef char char_array_t[256];
struct hash_b_node_s {
char_array_t key;
char_array_t value;
tommy_node node;
};
static int char_equal (const void *arg, const void *obj_p)
{
const struct hash_b_node_s *obj = obj_p;
const char_array_t *key = (const char_array_t *)arg;
return strcmp(*key, (obj->key));
}
static size_t char_hash(const char *s)
{
size_t hash = 0;
while (*s) hash = hash * 31421 + (*s++) + 6927;
return hash;
}
static void
test_dict_big(size_t n)
{
tommy_hashlin dict;
tommy_hashlin_init(&dict);
for (size_t i = 0; i < n; i++) {
struct hash_b_node_s *obj = malloc(sizeof (struct hash_b_node_s));
if(!obj) abort();
sprintf(obj->key, "%u", rand_get());
sprintf(obj->value, "%u", rand_get());
/* NOTE: this is not an insert_or_replace func...
It will always insert a new node, even if the key already exists...
Maybe searching then inserting will be a better representative?
*/
tommy_hashlin_insert(&dict, &obj->node, obj, char_hash(obj->key));
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_t s1;
sprintf(s1, "%u", rand_get());
struct hash_b_node_s *obj = tommy_hashlin_search(&dict, &char_equal,
&s1,
char_hash(s1));
if (obj)
s ++;
}
g_result = s;
tommy_hashlin_done(&dict);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0}
};
int main(int argc, const char *argv[])
{
test("TommyDS", numberof(table), table, argc, argv);
exit(0);
}
-215
View File
@@ -1,215 +0,0 @@
#define NDEBUG
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "include/uthash.h"
#include "include/utarray.h"
#include "include/utlist.h"
#include "common.h"
/********************************************************************************************/
static const UT_icd int_icd = {
.sz = sizeof (unsigned int),
.init = NULL,
.dtor = NULL,
.copy = NULL
};
static void test_array(size_t n)
{
UT_array a1, a2;
utarray_init(&a1, &int_icd);
utarray_init(&a2, &int_icd);
for(size_t i = 0; i < n; i++) {
unsigned int v1 = rand_get(), v2 = rand_get();
utarray_push_back(&a1, &v1);
utarray_push_back(&a2, &v2);
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += *(unsigned long *) utarray_eltptr(&a1, i ) * *(unsigned long *)utarray_eltptr(&a2, i );
}
g_result = s;
utarray_done(&a1);
utarray_done(&a2);
}
/********************************************************************************************/
struct list_node_s {
unsigned int value;
struct list_node_s *next;
};
static void test_list (size_t n)
{
struct list_node_s *a1 = NULL, *a2 = NULL;
for(size_t i = 0; i < n; i++) {
struct list_node_s *p = malloc(sizeof(struct list_node_s));
if (!p) abort();
p->value = rand_get();
LL_PREPEND(a1, p);
p = malloc(sizeof(struct list_node_s));
if (!p) abort();
p->value = rand_get();
LL_PREPEND(a2, p);
}
unsigned int s = 0;
for(struct list_node_s *it1 = a1, *it2 = a2
; it1 != NULL
; it1 = it1->next, it2 = it2->next) {
s += it1->value * it2->value;
}
g_result = s;
struct list_node_s *el;
LL_FOREACH(a1, el) free(el);
LL_FOREACH(a2, el) free(el);
}
/********************************************************************************************/
struct hash_i_node_s {
unsigned long key;
unsigned long value;
UT_hash_handle hh;
};
static void
test_dict(size_t n)
{
struct hash_i_node_s *dict = NULL;
for (size_t i = 0; i < n; i++) {
unsigned long k = rand_get();
struct hash_i_node_s *s;
HASH_FIND(hh, dict, &k, sizeof (unsigned long), s);
if (s == NULL) {
s = malloc(sizeof(struct hash_i_node_s));
if (!s) abort();
s->key = k;
s->value = rand_get();
HASH_ADD(hh, dict, key, sizeof(unsigned long), s);
}
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long k = rand_get();
struct hash_i_node_s *sp;
HASH_FIND(hh, dict, &k, sizeof (unsigned long), sp);
if (sp != NULL)
s += sp->value;
}
g_result = s;
struct hash_i_node_s *current, *tmp;
HASH_ITER(hh, dict, current, tmp) {
HASH_DEL(dict,current); /* delete it (users advances to next) */
free(current); /* free it */
}
}
/********************************************************************************************/
typedef struct {
char a[256];
} char_array_t;
struct hash_b_node_s {
char_array_t key;
char_array_t value;
UT_hash_handle hh;
};
static void
test_dict_big(size_t n)
{
struct hash_b_node_s *dict = NULL;
for (size_t i = 0; i < n; i++) {
char_array_t k;
sprintf(k.a, "%u", rand_get());
struct hash_b_node_s *s;
HASH_FIND(hh, dict, &k, sizeof (char_array_t), s);
if (s == NULL) {
s = malloc(sizeof(struct hash_b_node_s));
if (!s) abort();
memcpy(s->key.a, k.a, sizeof(s->key));
sprintf(s->value.a, "%u", rand_get());
HASH_ADD(hh, dict, key, sizeof(char_array_t), s);
}
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
char_array_t k;
sprintf(k.a, "%u", rand_get());
struct hash_b_node_s *sp;
HASH_FIND(hh, dict, &k, sizeof (char_array_t), sp);
if (sp != NULL)
s ++;
}
g_result = s;
struct hash_b_node_s *current, *tmp;
HASH_ITER(hh, dict, current, tmp) {
HASH_DEL(dict,current); /* delete it (users advances to next) */
free(current); /* free it */
}
}
/********************************************************************************************/
static const UT_icd float_icd = {
.sz = sizeof (float),
.init = NULL,
.dtor = NULL,
.copy = NULL
};
static int cmp(const void *a1, const void *a2)
{
const float *f1 = a1;
const float *f2 = a2;
return (*f1 < *f2) ? -1 : (*f1 > *f2);
}
static void test_sort(size_t n)
{
UT_array a1;
utarray_init(&a1, &float_icd);
for(size_t i = 0; i < n; i++) {
float v1 = rand_get();
utarray_push_back(&a1, &v1);
}
utarray_sort(&a1, cmp);
g_result = *(float *)utarray_eltptr(&a1, 0);
utarray_done(&a1);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 50, "sort", 10000000, 0, test_sort, 0}
};
int main(int argc, const char *argv[])
{
test("UT-HASH", numberof(table), table, argc, argv);
exit(0);
}
-42
View File
@@ -1,42 +0,0 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "xxhash.h"
#include "common.h"
static unsigned long *g_p;
static void test_hash_prepare(size_t n)
{
g_p = malloc (n * sizeof(unsigned long));
if (g_p == NULL) abort();
for(size_t i = 0; i < n ; i++)
g_p[i] = ((rand_get()*RAND_MAX + rand_get())*RAND_MAX+rand_get())*RAND_MAX + rand_get();
}
static void test_hash_final(void)
{
free(g_p);
}
static void test_hash(size_t n)
{
g_result = XXH64(g_p, sizeof(unsigned long)*n, 0);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 70,"XXHASH64", 100000000, test_hash_prepare, test_hash, test_hash_final}
};
int main(int argc, const char *argv[])
{
test("XXHASH", numberof(table), table, argc, argv);
exit(0);
}
-304
View File
@@ -1,304 +0,0 @@
/*
* M*LIB - common functions for bench module
*
* Copyright (c) 2017-2021, Patrick Pelissier
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "common.h"
// Maximum supported value for repeat argument
#define MAX_REPEAT 10000
// The global result
unsigned long g_result;
// The rand value
#if defined(MULTI_THREAD_MEASURE)
M_THREAD_ATTR
#endif
unsigned int randValue = 0;
void compiler_barrier(void *p)
{
// Do nothing, but let the compiler thinks that we did.
(void) p;
// Can be used for FLTO building
// asm volatile("": "+r" (p) : :"memory");
}
struct parse_opt_s {
int test_function;
double from, to, step, grow;
double within;
unsigned repeat;
bool graph, best, best_within, average, quiet;
};
static void
parse_config(struct parse_opt_s *opt, int argc, const char *argv[])
{
char *end;
opt->test_function = 0;
opt->from = 0.0;
opt->to = 0.0;
opt->step = 0.0;
opt->grow = 1.1;
opt->graph = false;
opt->best = false;
opt->best_within = false;
opt->average = false;
opt->quiet = false;
opt->repeat = 1;
opt->within = .05;
for(int i = 1; i < argc ; i++)
{
if (argv[i][0] == '-') {
if (strcmp(argv[i], "--from") == 0){
i++;
opt->from = strtod(argv[i], &end);
opt->to = opt->from;
} else if (strcmp(argv[i], "--to") == 0) {
i++;
opt->to = strtod(argv[i], &end);
opt->grow = 1.1;
} else if (strcmp(argv[i], "--step") == 0) {
i++;
opt->step = strtod(argv[i], &end);
opt->grow = 0;
} else if (strcmp(argv[i], "--grow") == 0) {
i++;
opt->grow = strtod(argv[i], &end);
opt->step = 0;
} else if (strcmp(argv[i], "--repeat") == 0) {
i++;
opt->repeat = strtol(argv[i], &end, 10);
opt->repeat = (opt->repeat > MAX_REPEAT) ? MAX_REPEAT : opt->repeat;
} else if (strcmp(argv[i], "--graph") == 0) {
opt->graph = true;
} else if (strcmp(argv[i], "--best") == 0) {
opt->best = true;
opt->average = false;
opt->best_within = false;
} else if (strcmp(argv[i], "--best-within") == 0) {
opt->best_within = true;
opt->best = false;
opt->average = false;
i++;
opt->within = strtod(argv[i], &end) / 100.0;
} else if (strcmp(argv[i], "--average") == 0) {
opt->average = true;
opt->best = false;
opt->best_within = false;
} else if (strcmp(argv[i], "--quiet") == 0) {
opt->quiet = true;
} else {
fprintf(stderr, "ERROR: Option unkown: %s.\n",
argv[i]);
exit(-1);
}
if (*end != 0) {
fprintf(stderr, "ERROR: Cannot parse %s. Expected float\n",
argv[i]);
exit(-1);
}
} else {
opt->test_function = strtol (argv[i], &end, 10);
if (*end != 0) {
fprintf(stderr, "ERROR: Cannot parse %s. Expected function number\n",
argv[i]);
exit(-1);
}
}
}
}
static int
select_config(int func, size_t n, const config_func_t functions[])
{
for(size_t i = 0; i < n;i++) {
if (functions[i].num == func)
return i;
}
fprintf(stderr, "ERROR: Function number %d not found. Available functions are:\n", func);
for(size_t i = 0; i < n;i++) {
fprintf(stderr, " %d: %s\n", functions[i].num, functions[i].funcname);
}
fprintf(stderr,
"USAGE: FUNC_NUMBER [--from number --to number (--grow number | --step number)] [--grapĥ]\n"
"[--repeat number] [--best|--average|--best-within] [--quiet]\n");
exit(-1);
}
// Utility function for qsort
static int cmp_double(const void *pa, const void *pb)
{
const double *a = (const double *) pa, *b = (const double *)pb;
return (*a < *b) ? -1 : *a > *b;
}
/* Get the longest sequence of values within 'f'% */
static int
get_sequence(int i, int n, double tab[], double f)
{
int j;
for(j = i + 1; j < n; j++) {
if (tab[j] > f * tab[i])
break;
}
return j-i;
}
/* Return the minimum of the longest sequence of values with 'f'% */
static double
get_best_within(int n, double tab[], double f)
{
qsort(tab, n, sizeof(double), cmp_double);
int best_i = 0;
int best_seq = get_sequence(0, n, tab, f);
for(int i = 1; i < n && (n-i) > best_seq ; i++) {
int seq = get_sequence(i, n, tab, f);
if (seq > best_seq) {
best_i = i;
best_seq = seq;
}
}
return tab[best_i];
}
// Integer sqrt function (to avoid depending on libm)
static unsigned integer_sqrt(unsigned n)
{
// Find greatest shift.
int shift = 2;
unsigned nShifted = n >> shift;
// We check for nShifted being n, since some implementations
// perform shift operations modulo the word size.
while (nShifted != 0 && nShifted != n){
shift += 2;
nShifted = n >> shift;
}
shift -= 2;
// Find digits of result.
unsigned result = 0;
while (shift >= 0) {
result = result << 1;
unsigned candidateResult = result + 1;
if (candidateResult*candidateResult <= n >> shift) {
result = candidateResult;
}
shift -= 2;
}
return result;
}
void
test(const char library[], size_t n, const config_func_t functions[], int argc, const char *argv[])
{
// Init & parse arguments
// NUMBER
// --from NUMBER --to NUMBER --step NUMBER --grow NUMBER
// --graph --best --average --quiet
// --repeat N
struct parse_opt_s arg;
parse_config(&arg, argc, argv);
int i = select_config(arg.test_function, n, functions);
double from = (arg.from == 0) ? functions[i].default_n : arg.from;
double to = (arg.to == 0) ? functions[i].default_n : arg.to;
// Open plot file if needed
FILE *graph_file = NULL;
if (arg.graph) {
char filename[100];
sprintf(filename, "plot-%s-%d.dat", library, arg.test_function);
graph_file = fopen(filename, "wt");
if (!graph_file) {
fprintf(stderr, "ERROR: Cannot create plot.dat\n");
exit(-2);
}
fprintf(graph_file, "# plotting %s-%d : %s\n# N T", library, arg.test_function, functions[i].funcname);
}
// Do the bench
for(double n = from; n <= to ; n = ((arg.grow == 0) ? n + arg.step : n * arg.grow))
{
double best = (1.0/0.0);
double avg = 0.0;
double variance = 0.0;
static double measure[MAX_REPEAT];
double ba = 0.0;
if (functions[i].init != NULL)
functions[i].init(n);
// Measure the time of the test_function
for(unsigned r = 0; r < arg.repeat; r++) {
double t0 = test_function( (arg.graph|arg.best|arg.average|arg.quiet) ? NULL : functions[i].funcname, (size_t) n, functions[i].func);
best = (t0 < best) ? t0 : best;
avg += t0;
variance += t0 * t0;
measure[r] = t0;
}
// Closure of the tests
if (functions[i].clear != NULL)
functions[i].clear();
// Finish computing the different times
if (arg.repeat > 1) {
avg /= arg.repeat;
variance = (variance - arg.repeat * avg * avg) / (arg.repeat - 1);
ba = get_best_within(arg.repeat, measure, 1. + arg.within);
}
// The average value shall be around best_within (and greater)
// otherwise the result doesn't seem reliable.
bool reliable = (ba <= avg && ba * (1.0+arg.within/2) + 0.5 > avg);
// Print the result
if (arg.graph) {
fprintf(graph_file, "%f %f\n", n, arg.average ? avg : arg.best ? best : ba);
} else if (arg.quiet) {
printf("%ld\n", (long)(arg.average ? avg : arg.best ? best : reliable ? ba : -1));
} else if (arg.repeat > 1) {
if (arg.average == false && arg.best_within == false)
printf ("%20.20s time %lu ms for n = %lu *** BEST ***\n", functions[i].funcname, (unsigned long) best, (unsigned long) n);
if (arg.best == false && arg.best_within == false)
printf ("%20.20s time %lu ms +/- %u ms for n = %lu *** AVERAGE ***\n", functions[i].funcname, (unsigned long) avg, 2*integer_sqrt(variance), (unsigned long) n);
if (arg.best == false && arg.average == false)
printf ("%20.20s time %lu ms for n = %lu *** BEST within %d%% *** %s\n", functions[i].funcname, (unsigned long) ba, (unsigned long) n, (int)(100*arg.within), reliable ? "" : "(unreliable result)");
}
}
// Close the FILE if needed
if (arg.graph) {
fclose(graph_file);
printf("File plot-%s-%d.dat generated.\n"
"Run in gnuplot the following command:\n"
"\tplot 'plot-%s-%d.dat' with linespoints linestyle 1\n",
library, arg.test_function, library, arg.test_function);
}
return;
}
-172
View File
@@ -1,172 +0,0 @@
/*
* M*LIB - common functions for bench module
*
* Copyright (c) 2017-2021, Patrick Pelissier
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __COMMON_BENCH__H
#define __COMMON_BENCH__H
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Needed for M_THREAD_ATTR
#if defined(MULTI_THREAD_MEASURE)
#include "m-mutex.h"
#endif
#if defined(_WIN32)
# include <windows.h>
#elif (defined(__APPLE__) && defined(__MACH__)) \
|| defined(__DragonFly__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__)
# include <sys/types.h>
# include <sys/resource.h>
# include <sys/time.h>
# include <sys/param.h>
# include <sys/sysctl.h>
# define USE_SYSCTL
#else
# include <sys/types.h>
# include <sys/resource.h>
# include <sys/time.h>
# include <unistd.h>
#endif
// Number of elements of a table
#define numberof(x) (sizeof(x)/sizeof(x[0]))
/* Get the current CPU time. */
#if defined(_WIN32)
/* WINDOWS variant */
static inline unsigned long long
cputime (void)
{
LARGE_INTEGER freq, val;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&val);
return (unsigned long long) (1000000. * (double) val.QuadPart / (double) freq.QuadPart);
}
#else
/* UNIX variant */
static inline unsigned long long
cputime (void)
{
#if defined(MULTI_THREAD_MEASURE)
// Multi thread: Uses real time
struct timeval tv;
gettimeofday (&tv, NULL);
return tv.tv_sec * 1000000ULL + tv.tv_usec;
#else
// Single thread: Uses process usage time
struct rusage rus;
getrusage (0, &rus);
return rus.ru_utime.tv_sec * 1000000ULL + rus.ru_utime.tv_usec;
#endif
}
#endif
// The result of the bench
extern unsigned long g_result;
// The rand value
extern
#if defined(MULTI_THREAD_MEASURE)
M_THREAD_ATTR
#endif
unsigned int randValue;
// Pseudo rand value generator.
// Not very random but sufficient and fast enough for the bench
static inline void rand_init(void)
{
randValue = 0;
}
static inline unsigned int rand_get(void)
{
randValue = randValue * 31421U + 6927U;
return randValue;
}
// The function that performs the bench
static inline double
test_function(const char *str, size_t n, void (*func)(size_t))
{
double result;
unsigned long long start, end;
rand_init();
start = cputime();
(*func)(n);
end = cputime();
result = (double)(end-start) / 1000.0;
end = (end - start) / 1000U;
if (str != NULL) {
printf ("%20.20s time %lu ms for n = %lu [r=%lu]\n", str, (unsigned long) end, (unsigned long) n, g_result);
}
return result;
}
// Configuration table
typedef struct {
int num;
const char *funcname;
size_t default_n;
void (*init)(size_t);
void (*func)(size_t);
void (*clear)(void);
} config_func_t;
// Perform a parsing of the given arguments and do the bench according to the table
#ifdef __cplusplus
extern "C"
#endif
void test(const char library[], size_t n, const config_func_t functions[], int argc, const char *argv[]);
/* Return the number of CPU of the system */
static inline int get_cpu_count(void)
{
#if defined(_WIN32)
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#elif defined(USE_SYSCTL)
int nm[2];
int count = 0;
size_t len = sizeof (count);
nm[0] = CTL_HW;
nm[1] = HW_NCPU;
sysctl(nm, 2, &count, &len, NULL, 0);
return MAX(1, count);
#elif defined (_SC_NPROCESSORS_ONLN)
return sysconf(_SC_NPROCESSORS_ONLN);
#else
return 1;
#endif
}
#ifdef __cplusplus
extern "C"
#endif
void compiler_barrier(void *p);
#endif
-22
View File
@@ -1,22 +0,0 @@
CC=cc -std=c11
CXX=c++ -std=c++11
CFLAGS=-O2 -march=native -Wall
CPPFLAGS=-I../..
all: k-nucleotide
k-nucleotide: k-nucleotide.exe data.txt
./k-nucleotide.exe < data.txt
k-nucleotide.exe: nucleotide.c
$(CC) $(CFLAGS) $(CPPFLAGS) nucleotide.c -o k-nucleotide.exe -lpthread
data.txt: fasta.exe
./fasta.exe 25000000 > data.txt
fasta.exe: fasta.c
$(CC) $(CFLAGS) $(CPPFLAGS) -fopenmp fasta.c -o fasta.exe
clean:
rm -f *.exe *~ *.o data.txt
-344
View File
@@ -1,344 +0,0 @@
// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// contributed by Jeremy Zerfas
// rewritten by Аноним Легионов, inspired by fasta Rust #2 program
// use two OpenMP locks instead of one critical section
// decouples IO activity from random number generation
//
// modified by Josh Goldfoot, adding use of a buffer for fasta_repeat
// This controls the width of lines that are output by this program.
#define MAXIMUM_LINE_WIDTH 60
// This program will generate the random nucleotide sequences in parallel which
// are worked on in blocks of lines. The number of lines in those blocks is
// controlled by this setting.
#define LINES_PER_BLOCK 1024
#define CHARACTERS_PER_BLOCK (MAXIMUM_LINE_WIDTH*LINES_PER_BLOCK)
#define THREADS_TO_USE 4
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _OPENMP
#include <omp.h>
#endif
// intptr_t should be the native integer type on most sane systems.
typedef intptr_t intnative_t;
typedef struct
{
char letter;
float probability;
} nucleotide_info;
// Repeatedly print string_To_Repeat until it has printed
// number_Of_Characters_To_Create. The output is also wrapped to
// MAXIMUM_LINE_WIDTH columns.
static char* make_Sequence_Buffer(const char string_To_Repeat[])
{
const intnative_t string_To_Repeat_Length = strlen(string_To_Repeat);
// JG: Changed to that this writes a sequence to a buffer, which is used
intnative_t number_Of_Characters_To_Create = string_To_Repeat_Length * MAXIMUM_LINE_WIDTH;
char* buffer = (char*) malloc(number_Of_Characters_To_Create +
number_Of_Characters_To_Create / MAXIMUM_LINE_WIDTH + 1);
if (buffer == NULL)
exit(-1);
char* bufferOffset = buffer;
// Create an extended_String_To_Repeat which is a copy of string_To_Repeat
// but extended with another copy of the first MAXIMUM_LINE_WIDTH characters
// of string_To_Repeat appended to the end. Later on this allows us to
// generate a line of output just by doing simple memory copies using an
// appropriate offset into extended_String_To_Repeat.
char extended_String_To_Repeat[string_To_Repeat_Length + MAXIMUM_LINE_WIDTH];
for (intnative_t column = 0; column<string_To_Repeat_Length + MAXIMUM_LINE_WIDTH;
column++)
extended_String_To_Repeat[column] =
string_To_Repeat[column%string_To_Repeat_Length];
intnative_t offset = 0;
char line[MAXIMUM_LINE_WIDTH + 1];
line[MAXIMUM_LINE_WIDTH] = '\n';
for (intnative_t current_Number_Of_Characters_To_Create =
number_Of_Characters_To_Create;
current_Number_Of_Characters_To_Create>0;)
{
// Figure out the length of the line we need to write. If it's less than
// MAXIMUM_LINE_WIDTH then we also need to add a line feed in the right
// spot too.
intnative_t line_Length = MAXIMUM_LINE_WIDTH;
if (current_Number_Of_Characters_To_Create<MAXIMUM_LINE_WIDTH)
{
line_Length = current_Number_Of_Characters_To_Create;
line[line_Length] = '\n';
}
memcpy(line, extended_String_To_Repeat + offset, line_Length);
// Update the offset, reducing it by string_To_Repeat_Length if
// necessary.
offset += line_Length;
if (offset>string_To_Repeat_Length)
offset -= string_To_Repeat_Length;
// "Output" that line to our buffer and update the
// current_Number_Of_Characters_To_Create.
memcpy(bufferOffset, line, line_Length + 1); // JG: used to be fwrite(line, line_Length + 1, 1, stdout);
bufferOffset += line_Length + 1;
current_Number_Of_Characters_To_Create -= line_Length;
}
*bufferOffset = 0;
return buffer;
}
void repeat_And_Wrap_String(const char string_To_Repeat[], intnative_t number_Of_Characters_To_Create)
{
/* JG: fasta_repeat repeats every len(alu) * line-length = 287 * 61 = 17507 characters.
So, calculate this once, then just print that buffer over and over. */
char* sequence = make_Sequence_Buffer(string_To_Repeat);
intnative_t sequenceLen = (intnative_t) strlen(sequence);
intnative_t outputBytes = number_Of_Characters_To_Create + number_Of_Characters_To_Create / 60;
while (outputBytes >= sequenceLen) {
fwrite(sequence, sequenceLen, 1, stdout);
outputBytes -= sequenceLen;
}
if (outputBytes > 0) {
fwrite(sequence, outputBytes, 1, stdout);
printf("\n");
}
free(sequence);
}
// Generate a pseudorandom number from 0 to max using a linear
// congruential generator.
#define IM 139968
#define IA 3877
#define IC 29573
uint32_t seed = 42;
int rng_tid; //Thread ID
int rng_tnum = 1; //Thread number
intnative_t rng_cnt = 0;
#ifdef _OPENMP
omp_lock_t rng_lock;
#define RNG_LOCK_INIT() omp_init_lock(&rng_lock)
#define RNG_LOCK() omp_set_lock(&rng_lock)
#define RNG_FREE() omp_unset_lock(&rng_lock)
#else
#define RNG_LOCK_INIT() do{}while(0)
#define RNG_LOCK() do{}while(0)
#define RNG_FREE() do{}while(0)
#endif
static void rng_init(void)
{
RNG_LOCK_INIT();
rng_tid = 0;
}
static intnative_t rng_gen_blk(uint32_t * buf, intnative_t len, int curr_tid)
{
intnative_t gen_cnt = -1;//Error by default
RNG_LOCK();
if (rng_tid == curr_tid)
{
if (++rng_tid >= rng_tnum)
{
rng_tid = 0;
}
gen_cnt = (len<rng_cnt) ? len : rng_cnt;
rng_cnt -= gen_cnt;
len = gen_cnt;
while (0 != len--)
{
seed = (seed*IA + IC) % IM;
*(buf++) = seed;//This is stupid actually!
}
}
RNG_FREE();
return gen_cnt;
}
int out_tid; //Thread ID
int out_tnum = 1; //Thread number
#ifdef _OPENMP
omp_lock_t out_lock;
#define OUT_LOCK_INIT() omp_init_lock(&out_lock)
#define OUT_LOCK() omp_set_lock(&out_lock)
#define OUT_FREE() omp_unset_lock(&out_lock)
#else
#define OUT_LOCK_INIT() do{}while(0)
#define OUT_LOCK() do{}while(0)
#define OUT_FREE() do{}while(0)
#endif
static void out_init(void)
{
OUT_LOCK_INIT();
rng_tid = 0;
}
static intnative_t out_write(char * buf, intnative_t len, int curr_tid)
{
intnative_t wr_cnt = -1;//Error by default
OUT_LOCK();
if (out_tid == curr_tid)
{
if (++out_tid >= out_tnum)
{
out_tid = 0;
}
wr_cnt = fwrite(buf, len, 1, stdout);
}
OUT_FREE();
return wr_cnt; //-1 - thread error, 0 - IO error, 1 - ОК
}
static void generate_And_Wrap_Pseudorandom_DNA_Sequence(
const nucleotide_info nucl_info[],
const intnative_t nucl_num,
const intnative_t char_num)
{
uint32_t cumul_p[nucl_num];
float cumul_acc = 0.0;
for (intnative_t i = 0; i<nucl_num; i++)
{
cumul_acc += nucl_info[i].probability;
cumul_p[i] = 1ul + (uint32_t)(cumul_acc*(float)IM); //Compensate rounding errors on test file
}
#ifdef _OPENMP
intnative_t tnum = omp_get_num_procs();
if (tnum>THREADS_TO_USE) tnum = THREADS_TO_USE;
omp_set_num_threads(tnum);
rng_tnum = tnum;
out_tnum = tnum;
#endif
rng_tid = 0;
out_tid = 0;
rng_cnt = char_num;
#pragma omp parallel
{
char block[CHARACTERS_PER_BLOCK + LINES_PER_BLOCK];
char * line;
uint32_t rnd[CHARACTERS_PER_BLOCK], r;
intnative_t cnt, col, prid, nid, ncnt;
int cur_tid;
#ifdef _OPENMP
cur_tid = omp_get_thread_num();
#else
cur_tid = 0;
#endif
while (1)
{
do
{
cnt = rng_gen_blk(rnd, CHARACTERS_PER_BLOCK, cur_tid);
} while (-1 == cnt);
if (0 == cnt)
{
break;//Work finished!
}
line = block;
for (col = 0, prid = 0; prid < cnt; prid++)
{
r = rnd[prid];
ncnt = 0;
for (nid = 0; nid < nucl_num; nid++)
{
if (cumul_p[nid] <= r)
{
ncnt++;
}
}
*line++ = nucl_info[ncnt].letter;
if (++col >= MAXIMUM_LINE_WIDTH)
{
col = 0;
*line++ = '\n';
}
}
//Check if we need to end the line
if (0 != col)
{
//Last iteration didn't end the line, so finish the job.
*line++ = '\n';
}
//Print results
do
{
cnt = out_write(block, line - block, cur_tid);
} while (-1 == cnt);
//Check fot IO error
if (0 == cnt)
{
exit(1);
}
}
}
}
int main(int argc, char ** argv)
{
const intnative_t n = atoi(argv[1]);
fputs(">ONE Homo sapiens alu\n", stdout);
const char homo_Sapiens_Alu[] =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTC"
"AGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAATTAGCCGGGCG"
"TGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGG"
"AGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
repeat_And_Wrap_String(homo_Sapiens_Alu, 2 * n);
rng_init();
out_init();
fputs(">TWO IUB ambiguity codes\n", stdout);
nucleotide_info iub_Nucleotides_Information[] =
{
{ 'a', 0.27 },{ 'c', 0.12 },{ 'g', 0.12 },{ 't', 0.27 },{ 'B', 0.02 },
{ 'D', 0.02 },{ 'H', 0.02 },{ 'K', 0.02 },{ 'M', 0.02 },{ 'N', 0.02 },
{ 'R', 0.02 },{ 'S', 0.02 },{ 'V', 0.02 },{ 'W', 0.02 },{ 'Y', 0.02 }
};
generate_And_Wrap_Pseudorandom_DNA_Sequence(iub_Nucleotides_Information,
sizeof(iub_Nucleotides_Information) / sizeof(nucleotide_info), 3 * n);
fputs(">THREE Homo sapiens frequency\n", stdout);
nucleotide_info homo_Sapien_Nucleotides_Information[] =
{
{ 'a', 0.3029549426680 },{ 'c', 0.1979883004921 },
{ 'g', 0.1975473066391 },{ 't', 0.3015094502008 }
};
generate_And_Wrap_Pseudorandom_DNA_Sequence(homo_Sapien_Nucleotides_Information,
sizeof(homo_Sapien_Nucleotides_Information) / sizeof(nucleotide_info), 5 * n);
return 0;
}
-267
View File
@@ -1,267 +0,0 @@
// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// Original version Contributed by Jeremy Zerfas
// M*LIB port contributed by Patrick Pélissier
#define NDEBUG
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "m-worker.h"
#include "m-dict.h"
#include "m-bptree.h"
// This controls the maximum length for each set of oligonucleotide frequencies
// and each oligonucleotide count output by this program.
#define MAXIMUM_OUTPUT_LENGTH 4096
// Number of outputs to display
#define MAXMUM_NUMBER_OUTPUT 7
/* Define the needed containers */
/* Define Open Addressing dictionary of uint64_t --> uint32_t. Need to define how to handle out of bound data. */
static inline bool my_oor_equal_p(uint64_t k, unsigned char n)
{
return k == ~(uint64_t) n;
}
static inline void my_oor_set(uint64_t *k, unsigned char n)
{
*k = ~(uint64_t)n;
}
static inline size_t my_hash(uint64_t key)
{
return ((key) ^ (key)>>7);
}
static inline void update_val(uint32_t *p, uint32_t v) { *p += v;}
DICT_OA_DEF2(dict_oligonucleotide,
uint64_t, M_OPEXTEND(M_DEFAULT_OPLIST, HASH(my_hash), OOR_EQUAL(my_oor_equal_p), OOR_SET(my_oor_set M_IPTR)),
uint32_t, M_OPEXTEND(M_DEFAULT_OPLIST, UPDATE(update_val M_IPTR)))
#define M_OPL_dict_oligonucleotide_t() DICT_OPLIST(dict_oligonucleotide, M_OPEXTEND(M_DEFAULT_OPLIST, HASH(my_hash), OOR_EQUAL(my_oor_equal_p), OOR_SET(my_oor_set M_IPTR)), M_DEFAULT_OPLIST)
// Define a B*TREE-21 of uint32_t --> uint64_t and register its oplist
#define TREE_CMP(a,b) ((a) > (b) ? -1 : (a) < (b)) /* reverse natural order */
BPTREE_DEF2(tree_dict_oligonucleotide, 21, uint32_t, M_OPEXTEND(M_DEFAULT_OPLIST, CMP(TREE_CMP)), uint64_t, M_DEFAULT_OPLIST)
#define M_OPL_tree_dict_oligonucleotide_t() BPTREE_OPLIST2(tree_dict_oligonucleotide, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
/* Define the data to analyse (a plain array) */
ARRAY_DEF(polynucleotide, unsigned char)
// Macro to convert a nucleotide character to a code. Note that upper and lower
// case ASCII letters only differ in the fifth bit from the right and we only
// need the three least significant bits to differentiate the letters 'A', 'C',
// 'G', and 'T'. Spaces in this array/string will never be used as long as
// characters other than 'A', 'C', 'G', and 'T' aren't used.
#define CODE_FOR_NUCLEOTIDE(nucleotide) (" \0 \1\3 \2"[nucleotide & 0x7])
// And one more macro to convert the codes back to nucleotide characters.
#define NUCLEOTIDE_FOR_CODE(code) ("ACGT"[code & 0x3])
static worker_t worker;
// Read from the given stream the data and fill in the array with the converted one.
static void polynucleotide_init_stream(polynucleotide_t p, FILE *stream)
{
char buffer[MAXIMUM_OUTPUT_LENGTH], c;
polynucleotide_init(p);
polynucleotide_reserve(p, MAXIMUM_OUTPUT_LENGTH);
// Find the start of the third polynucleotide.
while(fgets(buffer, sizeof(buffer), stream) && memcmp(">THREE", buffer, 6));
// Start reading and encoding the third polynucleotide.
while(fgets(buffer, sizeof(buffer), stream) && buffer[0]!='>'){
for(size_t i = 0; (c = buffer[i]) !='\0'; i++) {
if (c != '\n') {
polynucleotide_push_back(p, CODE_FOR_NUCLEOTIDE(c));
}
}
}
}
// This is the function which does 95% of the work.
/* NOTE: paralelisation is not done by cutting the input set in two.
This is not efficient as the size of the output table will be the same
as for the whole table. */
static void init_hash(dict_oligonucleotide_t hash_Table, const size_t size, const unsigned char tab[size], const size_t desiredLength, const size_t offset, const size_t skip)
{
uint64_t key = 0;
const uint64_t mask = (1ULL<<(2*desiredLength))-1;
assert (2*desiredLength < 64 && desiredLength < size);
assert ((1 == skip || 4 == skip) && offset < size);
// For the first several nucleotides we only need to append them to key in
// preparation for the insertion of complete oligonucleotides to hash.
for(size_t i = 0; i < desiredLength - 1 + offset; i++)
key = (key<<2) | tab[i];
key &= mask;
dict_oligonucleotide_t hash;
dict_oligonucleotide_init(hash);
// Add all the complete oligonucleotides of
// desiredLength to hash, updating their count
if (skip == 1) {
for(size_t i = desiredLength-1+offset ; i < size; i++) {
key = (key<<2) | tab[i+0];
key &= mask;
uint32_t *p = dict_oligonucleotide_get(hash, key);
if (p != NULL) {
(*p) ++;
} else {
dict_oligonucleotide_set_at(hash, key, 1);
}
}
} else { // skip = 4
for(size_t i = desiredLength-1+offset ; i < size; i+=4) {
for (size_t j = 0; j < 4; j++)
key = (key<<2) | tab[i+j];
key &= mask;
uint32_t *p = dict_oligonucleotide_get(hash, key);
if (p != NULL) {
(*p) ++;
} else {
dict_oligonucleotide_set_at(hash, key, 1);
}
}
}
dict_oligonucleotide_init_move(hash_Table, hash);
}
static void compute_hash(dict_oligonucleotide_t hash_Table, const polynucleotide_t p, const size_t desiredLength)
{
size_t size = polynucleotide_size(p);
unsigned char *tab = polynucleotide_get(p, 0);
if (desiredLength < 8) {
init_hash(hash_Table, size, tab, desiredLength, 0, 1);
return;
}
worker_sync_t block; // Define a synchronization block
worker_start(block, worker);
dict_oligonucleotide_t hash_Table3, *p_hash_Table3 = &hash_Table3;
dict_oligonucleotide_t hash_Table2, *p_hash_Table2 = &hash_Table2;
dict_oligonucleotide_t hash_Table1, *p_hash_Table1 = &hash_Table1;
WORKER_SPAWN(block, (p_hash_Table1, size, tab, desiredLength), {
init_hash(*p_hash_Table1, size, tab, desiredLength, 3, 4);
}, (/*no output*/));
WORKER_SPAWN(block, (p_hash_Table2, size, tab, desiredLength), {
init_hash(*p_hash_Table2, size, tab, desiredLength, 2, 4);
}, (/*no output*/));
WORKER_SPAWN(block, (p_hash_Table3, size, tab, desiredLength), {
init_hash(*p_hash_Table3, size, tab, desiredLength, 1, 4);
}, (/*no output*/));
init_hash(hash_Table, size, tab, desiredLength, 0, 4);
worker_sync(block);
// Merge all hashtables
dict_oligonucleotide_splice(hash_Table, hash_Table1);
dict_oligonucleotide_splice(hash_Table, hash_Table2);
dict_oligonucleotide_splice(hash_Table, hash_Table3);
// Clear extra hashtables
dict_oligonucleotide_clear(hash_Table3);
dict_oligonucleotide_clear(hash_Table2);
dict_oligonucleotide_clear(hash_Table1);
}
// Generate frequencies for all oligonucleotides in polynucleotide that are of
// desiredLength and then save it to output.
static void compute_freq(const polynucleotide_t p, const size_t desiredLength, char output[])
{
dict_oligonucleotide_t hash_Table;
compute_hash(hash_Table, p, desiredLength);
// Order key is the count frequency (inverse value & key)
tree_dict_oligonucleotide_t tree;
tree_dict_oligonucleotide_init(tree);
for M_EACH(item, hash_Table, dict_oligonucleotide_t) {
tree_dict_oligonucleotide_set_at (tree, item->value, item->key);
}
// Create Output
char oligonucleotide[64];
const double invSum = 100.0 / (double) (polynucleotide_size(p) - desiredLength + 1);
int output_Position = 0;
for M_EACH(item, tree, tree_dict_oligonucleotide_t) {
// Convert the key for the oligonucleotide to a string.
uint64_t freq = *item->value_ptr;
uint32_t count = *item->key_ptr;
for(size_t j = desiredLength-1; j < desiredLength; j--){
oligonucleotide[j]=NUCLEOTIDE_FOR_CODE(freq);
freq>>=2;
}
oligonucleotide[desiredLength]='\0';
// Output the frequency for oligonucleotide to output.
output_Position+=snprintf(output+output_Position, MAXIMUM_OUTPUT_LENGTH-output_Position,
"%s %.3f\n", oligonucleotide, invSum * count);
}
dict_oligonucleotide_clear(hash_Table);
tree_dict_oligonucleotide_clear(tree);
}
// Generate a count for the number of times oligonucleotide appears in
// polynucleotide and then save it to output.
static void compute_count(polynucleotide_t p, const char oligonucleotide[], char output[])
{
const size_t oligonucleotide_Length = strlen(oligonucleotide);
dict_oligonucleotide_t hash_Table;
compute_hash(hash_Table, p, oligonucleotide_Length);
// Generate the key for oligonucleotide.
uint64_t key=0;
for(size_t i=0; i<oligonucleotide_Length; i++)
key = (key<<2) | CODE_FOR_NUCLEOTIDE(oligonucleotide[i]);
// Output the count for oligonucleotide to output.
uint32_t *val = dict_oligonucleotide_get(hash_Table, key);
uintmax_t count= val== NULL ? 0 : *val;
snprintf(output, MAXIMUM_OUTPUT_LENGTH, "%ju\t%s", count, oligonucleotide);
dict_oligonucleotide_clear(hash_Table);
}
int main()
{
// Initialize the different worker threads by auto-detecting the number of cores of the system
worker_init(worker, -1, 0, NULL);
// Read the input
polynucleotide_t p, *ptr = &p;
polynucleotide_init_stream(p, stdin);
// Prepare outputs
char outputBuffer[MAXMUM_NUMBER_OUTPUT][MAXIMUM_OUTPUT_LENGTH];
char (*output)[MAXIMUM_OUTPUT_LENGTH] = outputBuffer;
// Do the following functions in parallel.
worker_sync_t block; // Define a synchronization block
worker_start(block, worker);
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTATTTTAATTTATAGT", output[6]);
}, (/*no output*/));
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTATTTTAATT", output[5]);
}, (/*no output*/));
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTATT", output[4]);
}, (/*no output*/));
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTA", output[3]);
}, (/*no output*/));
compute_count(*ptr, "GGT", output[2]);
compute_freq(*ptr, 2, output[1]);
compute_freq(p, 1, output[0]);
worker_sync(block);
// Output the results to stdout.
for(int i=0; i<MAXMUM_NUMBER_OUTPUT; i++)
printf("%s\n", outputBuffer[i]);
polynucleotide_clear(p);
worker_clear(worker);
return 0;
}
-940
View File
@@ -1,940 +0,0 @@
/**
* Memory pool benchmark.
*
* Results (the better values for each measure from at least 3 runs)for
* Intel Core i7-4650U CPU 1.70GHz, 8GB RAM:
*
* small object size: 24
* big object size: 240
* huge object size: 8305
*
* boost::pool (Small): 258ms
* boost::pool w/ free (Small): 165ms
* boost::pool (Big): 174ms
* boost::pool w/ free (Big): 154ms
* boost::pool cr. & destr.: 133ms
*
* ngx_pool (Small): 305ms
* ngx_pool (Big): 132ms
* ngx_pool w/ free (Mix): 542ms
* ngx_pool cr. & destr.: 98ms
*
* tfw_pool (Small): 279ms
* tfw_pool w/ free (Small): 101ms
* tfw_pool (Big): 106ms
* tfw_pool w/ free (Big): 50ms
* tfw_pool w/ free (Mix): 107ms
* tfw_pool cr. & destr.: 53ms
*
* Copyright (C) 2015 Alexander Krizhanovsky (ak@natsys-lab.com).
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* See http://www.gnu.org/licenses/lgpl.html .
*
* From https://github.com/natsys/blog/tree/master/mempool
*/
#define NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <string>
#ifdef USE_BOOST
#include <boost/pool/object_pool.hpp>
#endif
#ifdef USE_GLIB
#include <glib.h>
#endif
static const size_t PAGE_SIZE = 4096;
// sizeof(TfwStr)
struct Small {
long l[3];
std::string
operator+(const char *str)
{ return std::string(str) + " (Small)"; }
};
// size of common HTTP headers table
struct Big {
Small s[10];
std::string
operator+(const char *str)
{ return std::string(str) + " (Big)"; }
};
// very big allocation
struct Huge {
char c[PAGE_SIZE * 2 + 113];
std::string
operator+(const char *str)
{ return std::string(str) + " (Huge)"; }
};
static const size_t N = 20 * 1000 * 1000;
void
benchmark(std::string &&desc, std::function<void ()> cb)
{
using namespace std::chrono;
// steady_clock has the same resolution as high_resolution_clock
auto t(steady_clock::now());
cb();
auto dt = steady_clock::now() - t;
std::cout << std::setw(30) << std::right << desc << ": "
<< duration_cast<milliseconds>(dt).count()
<< "ms" << std::endl;
}
#define touch_obj(o) \
if (__builtin_expect(!o, 0)) { \
std::cerr << "failed alloc" << std::endl; \
break; \
} else { \
*(long *)o = 1; \
}
/*
* ------------------------------------------------------------------------
* Boost::pool
* ------------------------------------------------------------------------
*/
#ifdef USE_BOOST
template<class T>
void
benchmark_boost_pool()
{
boost::object_pool<T> p;
benchmark(std::move(T() + "boost::pool"), [&]() {
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = p.malloc();
touch_obj(o);
}
});
}
template<class T>
void
benchmark_boost_pool_free()
{
boost::object_pool<T> p;
benchmark(std::move(T() + "boost::pool w/ free"), [&]() {
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = p.malloc();
touch_obj(o);
if (__builtin_expect(!(i & 3), 0))
p.free(o);
}
});
}
void
benchmark_boost_pool_create_and_destroy()
{
benchmark(std::move(std::string("boost::pool cr. & destr.")), []() {
for (size_t i = 0; i < N / 100; ++i) {
if (__builtin_expect(!(i & 3), 0)) {
boost::object_pool<Big> p;
for (size_t j = 0; j < 100; ++j) {
Big *o = p.malloc();
touch_obj(o);
}
} else {
boost::object_pool<Small> p;
for (size_t j = 0; j < 100; ++j) {
Small *o = p.malloc();
touch_obj(o);
}
}
}
});
}
#endif
/*
* ------------------------------------------------------------------------
* malloc/free
* ------------------------------------------------------------------------
*/
template<class T>
void
benchmark_mallocfree()
{
benchmark(std::move(T() + "mallocfree"), [&]() {
static __thread T *ptrs[N * sizeof(Small) / sizeof(T)];
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = (T*)malloc(sizeof(T));
ptrs[i] = o;
touch_obj(o);
}
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
free(ptrs[i]);
}
});
}
template<class T>
void
benchmark_mallocfree_free()
{
benchmark(std::move(T() + "mallocfree w/ free"), [&]() {
static __thread T *ptrs[N * sizeof(Small) / sizeof(T)];
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = (T*)malloc(sizeof(T));
ptrs[i] = o;
touch_obj(o);
if (__builtin_expect(!(i & 3), 0)) {
free(o);
ptrs[i] = NULL;
}
}
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
free(ptrs[i]);
}
});
}
/*
* ------------------------------------------------------------------------
* GLib slices
* ------------------------------------------------------------------------
*/
#ifdef USE_GLIB
template<class T>
void
benchmark_glib_slices()
{
benchmark(std::move(T() + "GLib slices"), [&]() {
static __thread T *ptrs[N * sizeof(Small) / sizeof(T)];
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = (T*)g_slice_alloc(sizeof(T));
ptrs[i] = o;
touch_obj(o);
}
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
g_slice_free1(sizeof(T), ptrs[i]);
}
});
}
template<class T>
void
benchmark_glib_slices_free()
{
benchmark(std::move(T() + "GLib slices w/ free"), [&]() {
static __thread T *ptrs[N * sizeof(Small) / sizeof(T)];
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = (T*)g_slice_alloc(sizeof(T));
ptrs[i] = o;
touch_obj(o);
if (__builtin_expect(!(i & 3), 0)) {
g_slice_free1(sizeof(T), o);
ptrs[i] = NULL;
}
}
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
g_slice_free1(sizeof(T), ptrs[i]);
}
});
}
#endif
/*
* ------------------------------------------------------------------------
* Nginx pool
* Simplified version of src/core/ngx_palloc.c from nginx-1.9.5 with
* some code adjustments to be built in this benchmark.
* ------------------------------------------------------------------------
*/
struct ngx_pool_t;
typedef uintptr_t ngx_uint_t;
#define NGX_POOL_ALIGNMENT 16
#define NGX_ALIGNMENT sizeof(unsigned long)
#define ngx_align_ptr(p, a) \
(u_char *)(((uintptr_t)(p) + ((uintptr_t)a - 1)) & ~((uintptr_t)a - 1))
#define NGX_MAX_ALLOC_FROM_POOL ((size_t)PAGE_SIZE - 1)
struct ngx_pool_data_t {
unsigned char *last;
unsigned char *end;
ngx_pool_t *next;
unsigned int failed;
};
struct ngx_pool_large_t {
ngx_pool_large_t *next;
void *alloc;
};
struct ngx_pool_t {
ngx_pool_data_t d;
size_t max;
ngx_pool_t *current;
ngx_pool_large_t *large;
};
ngx_pool_t *
ngx_create_pool(size_t size)
{
ngx_pool_t *p;
if (posix_memalign((void **)&p, NGX_POOL_ALIGNMENT, size))
return NULL;
p->d.last = (unsigned char *)p + sizeof(ngx_pool_t);
p->d.end = (unsigned char *)p + size;
p->d.next = NULL;
p->d.failed = 0;
size = size - sizeof(ngx_pool_t);
p->max = (size < NGX_MAX_ALLOC_FROM_POOL)
? size : NGX_MAX_ALLOC_FROM_POOL;
p->current = p;
p->large = NULL;
return p;
}
void
ngx_destroy_pool(ngx_pool_t *pool)
{
ngx_pool_t *p, *n;
ngx_pool_large_t *l;
for (l = pool->large; l; l = l->next) {
if (l->alloc)
free(l->alloc);
}
for (p = pool, n = pool->d.next; ; p = n, n = n->d.next) {
free(p);
if (n == NULL)
break;
}
}
static void *
ngx_palloc_block(ngx_pool_t *pool, size_t size)
{
unsigned char *m;
size_t psize = (size_t)(pool->d.end - (unsigned char *)pool);
ngx_pool_t *p, *p_new;
if (posix_memalign((void **)&m, NGX_POOL_ALIGNMENT, psize))
return NULL;
p_new = (ngx_pool_t *)m;
p_new->d.end = m + psize;
p_new->d.next = NULL;
p_new->d.failed = 0;
m += sizeof(ngx_pool_data_t);
m = ngx_align_ptr(m, NGX_ALIGNMENT);
p_new->d.last = m + size;
for (p = pool->current; p->d.next; p = p->d.next) {
if (p->d.failed++ > 4)
pool->current = p->d.next;
}
p->d.next = p_new;
return m;
}
void *ngx_palloc(ngx_pool_t *pool, size_t size);
static void *
ngx_palloc_large(ngx_pool_t *pool, size_t size)
{
void *p;
unsigned int n = 0;
ngx_pool_large_t *large;
p = malloc(size);
if (p == NULL)
return NULL;
for (large = pool->large; large; large = large->next) {
if (large->alloc == NULL) {
large->alloc = p;
return p;
}
if (n++ > 3)
break;
}
large = (ngx_pool_large_t *)ngx_palloc(pool, sizeof(ngx_pool_large_t));
if (large == NULL) {
free(p);
return NULL;
}
large->alloc = p;
large->next = pool->large;
pool->large = large;
return p;
}
void *
ngx_palloc(ngx_pool_t *pool, size_t size)
{
unsigned char *m;
ngx_pool_t *p;
if (size <= pool->max) {
p = pool->current;
do {
m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT);
if ((size_t)(p->d.end - m) >= size) {
p->d.last = m + size;
return m;
}
p = p->d.next;
} while (p);
return ngx_palloc_block(pool, size);
}
return ngx_palloc_large(pool, size);
}
void
ngx_pfree(ngx_pool_t *pool, void *p)
{
ngx_pool_large_t *l;
for (l = pool->large; l; l = l->next) {
if (p == l->alloc) {
free(l->alloc);
l->alloc = NULL;
return;
}
}
}
template<class T>
void
benchmark_ngx_pool()
{
ngx_pool_t *p = ngx_create_pool(PAGE_SIZE);
assert(p);
benchmark(std::move(T() + "ngx_pool"), [=]() {
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = (T *)ngx_palloc(p, sizeof(T));
touch_obj(o);
}
});
ngx_destroy_pool(p);
}
void
benchmark_ngx_pool_mix_free()
{
ngx_pool_t *p = ngx_create_pool(PAGE_SIZE);
assert(p);
benchmark(std::move(std::string("ngx_pool w/ free (Mix)")), [=]() {
for (size_t i = 0; i < N; ++i) {
if (__builtin_expect(!(i & 0xfff), 0)) {
Huge *o;
o = (Huge *)ngx_palloc(p, sizeof(*o));
touch_obj(o);
if (!(i & 1))
ngx_pfree(p, o);
}
else if (__builtin_expect(!(i & 3), 0)) {
Big *o = (Big *)ngx_palloc(p, sizeof(*o));
touch_obj(o);
if (!(i & 1))
ngx_pfree(p, o);
}
else {
Small *o = (Small *)ngx_palloc(p, sizeof(*o));
touch_obj(o);
if (!(i & 1))
ngx_pfree(p, o);
}
}
});
ngx_destroy_pool(p);
}
void
benchmark_ngx_pool_create_and_destroy()
{
benchmark(std::move(std::string("ngx_pool cr. & destr.")), []() {
for (size_t i = 0; i < N / 100; ++i) {
ngx_pool_t *p = ngx_create_pool(PAGE_SIZE);
for (size_t j = 0; j < 100; ++j) {
if (__builtin_expect(!(i & 3), 0)) {
Big *o;
o = (Big *)ngx_palloc(p, sizeof(*o));
touch_obj(o);
} else {
Small *o;
o = (Small *)ngx_palloc(p, sizeof(*o));
touch_obj(o);
}
}
ngx_destroy_pool(p);
}
});
}
/*
* ------------------------------------------------------------------------
* Tempesta FW pool
* Simplified and ported to user-space from
* https://github.com/natsys/tempesta/blob/master/tempesta_fw/pool.c
* ------------------------------------------------------------------------
*/
/**
* Emulation of Linux buddy allocator.
*/
#define GFP_ATOMIC 0
#define PAGE_MASK (~(PAGE_SIZE - 1))
#define likely(x) __builtin_expect(x, 1)
#define unlikely(x) __builtin_expect(x, 0)
#define free_pages(p, o) free((void *)(p))
#define get_order(n) (assert((n) < PAGE_SIZE * 128), \
(n) < PAGE_SIZE ? 0 \
: (n) < PAGE_SIZE * 2 ? 1 \
: (n) < PAGE_SIZE * 4 ? 2 \
: (n) < PAGE_SIZE * 8 ? 3 \
: (n) < PAGE_SIZE * 16 ? 4 \
: (n) < PAGE_SIZE * 32 ? 5 \
: (n) < PAGE_SIZE * 64 ? 6 \
: 7)
static inline unsigned long
__get_free_pages(int flags __attribute__((unused)), int order)
{
void *p;
if (posix_memalign((void **)&p, PAGE_SIZE, PAGE_SIZE << order))
return 0;
return (unsigned long)p;
}
/**
* Memory pool chunk descriptor.
*
* @next - pointer to next memory chunk;
* @order - order of number of pages in the chunk;
* @off - current chunk offset;
*/
struct TfwPoolChunk {
TfwPoolChunk *next;
unsigned int order;
unsigned int off;
};
/**
* Memory pool descriptor.
*
* @curr - current chunk to allocate memory from;
* @order,@off - cached members of @curr;
*/
typedef struct {
TfwPoolChunk *curr;
unsigned int order;
unsigned int off;
} TfwPool;
#define TFW_POOL_CHUNK_SZ(p) (PAGE_SIZE << (p)->order)
#define TFW_POOL_CHUNK_BASE(c) ((unsigned long)(c) & PAGE_MASK)
#define TFW_POOL_CHUNK_END(p) (TFW_POOL_CHUNK_BASE((p)->curr) + (p)->off)
#define TFW_POOL_ALIGN_SZ(n) (((n) + 7) & ~7UL)
#define TFW_POOL_HEAD_OFF (TFW_POOL_ALIGN_SZ(sizeof(TfwPool)) \
+ TFW_POOL_ALIGN_SZ(sizeof(TfwPoolChunk)))
#define TFW_POOL_PGCACHE_SZ 256
static unsigned int pg_next;
static unsigned long pg_cache[TFW_POOL_PGCACHE_SZ];
static unsigned long
tfw_pool_alloc_pages(unsigned int order)
{
if (likely(pg_next && !order))
return pg_cache[--pg_next];
return __get_free_pages(GFP_ATOMIC, order);
}
static void
tfw_pool_free_pages(unsigned long addr, unsigned int order)
{
if (likely(pg_next < TFW_POOL_PGCACHE_SZ && !order)) {
pg_cache[pg_next++] = addr;
} else {
free_pages(addr, order);
}
}
TfwPool *
__tfw_pool_new(size_t n)
{
TfwPool *p;
TfwPoolChunk *c;
unsigned int order;
order = get_order(TFW_POOL_ALIGN_SZ(n) + TFW_POOL_HEAD_OFF);
c = (TfwPoolChunk *)tfw_pool_alloc_pages(order);
if (unlikely(!c))
return NULL;
p = (TfwPool *)((char *)c + TFW_POOL_ALIGN_SZ(sizeof(*c)));
c->next = NULL;
p->order = order;
p->off = TFW_POOL_HEAD_OFF;
p->curr = c;
return p;
}
void *
tfw_pool_alloc(TfwPool *p, size_t n)
{
void *a;
n = TFW_POOL_ALIGN_SZ(n);
if (unlikely(p->off + n > TFW_POOL_CHUNK_SZ(p))) {
TfwPoolChunk *c, *curr = p->curr;
unsigned int off = TFW_POOL_ALIGN_SZ(sizeof(TfwPoolChunk)) + n;
unsigned int order = get_order(off);
c = (TfwPoolChunk *)tfw_pool_alloc_pages(order);
if (!c)
return NULL;
c->next = curr;
curr->order = p->order;
curr->off = p->off;
p->order = order;
p->off = off;
p->curr = c;
return (void *)TFW_POOL_ALIGN_SZ((unsigned long)(c + 1));
}
a = (char *)TFW_POOL_CHUNK_END(p);
p->off += n;
return a;
}
void
tfw_pool_free(TfwPool *p, void *ptr, size_t n)
{
n = TFW_POOL_ALIGN_SZ(n);
/* Stack-like usage is expected. */
if (unlikely((char *)ptr + n != (char *)TFW_POOL_CHUNK_END(p)))
return;
p->off -= n;
/* Free empty chunk which doesn't contain the pool header. */
if (unlikely(p->off == TFW_POOL_ALIGN_SZ(sizeof(TfwPoolChunk)))) {
TfwPoolChunk *next = p->curr->next;
tfw_pool_free_pages(TFW_POOL_CHUNK_BASE(p->curr), p->order);
p->curr = next;
p->order = next->order;
p->off = next->off;
}
}
void
tfw_pool_destroy(TfwPool *p)
{
TfwPoolChunk *c, *next;
for (c = p->curr; c; c = next) {
next = c->next;
tfw_pool_free_pages(TFW_POOL_CHUNK_BASE(c), c->order);
}
}
template<class T>
void
benchmark_tfw_pool()
{
TfwPool *p = __tfw_pool_new(0);
assert(p);
benchmark(std::move(T() + "tfw_pool"), [=]() {
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = (T *)tfw_pool_alloc(p, sizeof(T));
touch_obj(o);
}
});
tfw_pool_destroy(p);
}
template<class T>
void
benchmark_tfw_pool_free()
{
TfwPool *p = __tfw_pool_new(0);
assert(p);
benchmark(std::move(T() + "tfw_pool w/ free"), [&]() {
for (size_t i = 0; i < N * sizeof(Small) / sizeof(T); ++i) {
T *o = (T *)tfw_pool_alloc(p, sizeof(T));
touch_obj(o);
if (__builtin_expect(!(i & 3), 0))
tfw_pool_free(p, o, sizeof(T));
}
});
tfw_pool_destroy(p);
}
void
benchmark_tfw_pool_mix_free()
{
TfwPool *p = __tfw_pool_new(0);
assert(p);
benchmark(std::move(std::string("tfw_pool w/ free (Mix)")), [=]() {
for (size_t i = 0; i < N; ++i) {
if (__builtin_expect(!(i & 0xfff), 0)) {
Huge *o;
o = (Huge *)tfw_pool_alloc(p, sizeof(*o));
touch_obj(o);
if (!(i & 1))
tfw_pool_free(p, o, sizeof(*o));
}
else if (__builtin_expect(!(i & 3), 0)) {
Big *o = (Big *)tfw_pool_alloc(p, sizeof(*o));
touch_obj(o);
if (!(i & 1))
tfw_pool_free(p, o, sizeof(*o));
}
else {
Small *o;
o = (Small *)tfw_pool_alloc(p, sizeof(*o));
touch_obj(o);
}
}
});
tfw_pool_destroy(p);
}
void
benchmark_tfw_pool_create_and_destroy()
{
benchmark(std::move(std::string("tfw_pool cr. & destr.")), []() {
for (size_t i = 0; i < N / 100; ++i) {
TfwPool *p = __tfw_pool_new(0);
for (size_t j = 0; j < 100; ++j) {
if (__builtin_expect(!(i & 3), 0)) {
Big *o;
o = (Big *)tfw_pool_alloc(p,
sizeof(*o));
touch_obj(o);
} else {
Small *o;
o = (Small *)tfw_pool_alloc(p,
sizeof(*o));
touch_obj(o);
}
}
tfw_pool_destroy(p);
}
});
}
/**************************************************************************/
/* Adding M*LIB mempool */
/**************************************************************************/
#include "m-mempool.h"
MEMPOOL_DEF(mempool_small, Small)
MEMPOOL_DEF(mempool_big, Big)
MEMPOOL_DEF(mempool_huge, Huge)
void
benchmark_mempool_small()
{
mempool_small_t p;
mempool_small_init (p);
mempool_small_t *ptr = &p; // C++ lambda !
benchmark(std::move(Small() + "M*LIB mempool"), [=]() {
for (size_t i = 0; i < N * sizeof(Small) / sizeof(Small); ++i) {
Small *o = mempool_small_alloc(*ptr);
touch_obj(o);
}
});
mempool_small_clear(p);
}
void
benchmark_mempool_big()
{
mempool_big_t p;
mempool_big_init (p);
mempool_big_t *ptr = &p; // C++ lambda !
benchmark(std::move(Big() + "M*LIB mempool"), [=]() {
for (size_t i = 0; i < N * sizeof(Small) / sizeof(Big); ++i) {
Big *o = mempool_big_alloc(*ptr);
touch_obj(o);
}
});
mempool_big_clear(p);
}
void
benchmark_mempool_mix_free()
{
mempool_small_t s, *ptr_s = &s;
mempool_big_t b, *ptr_b = &b;
mempool_huge_t h, *ptr_h = &h;
mempool_small_init (s);
mempool_big_init (b);
mempool_huge_init (h);
benchmark(std::move(std::string("M*LIB mempool w/ free (Mix)")), [=]() {
for (size_t i = 0; i < N; ++i) {
if (__builtin_expect(!(i & 0xfff), 0)) {
Huge *o = mempool_huge_alloc (*ptr_h);
touch_obj(o);
if (!(i & 1))
mempool_huge_free (*ptr_h, o);
}
else if (__builtin_expect(!(i & 3), 0)) {
Big *o = mempool_big_alloc(*ptr_b);
touch_obj(o);
if (!(i & 1))
mempool_big_free (*ptr_b, o);
}
else {
Small *o = mempool_small_alloc (*ptr_s);
touch_obj(o);
if (!(i & 1))
mempool_small_free (*ptr_s, o);
}
}
});
mempool_small_clear (s);
mempool_big_clear (b);
mempool_huge_clear (h);
}
/*
* ------------------------------------------------------------------------
* Main part of the benchmark
* ------------------------------------------------------------------------
*/
int
main()
{
std::cout << std::setw(35) << std::right << "small object size: "
<< sizeof(Small) << std::endl;
std::cout << std::setw(35) << std::right << "big object size: "
<< sizeof(Big) << std::endl;
std::cout << std::setw(35) << std::right << "huge object size: "
<< sizeof(Huge) << "\n" << std::endl;
// Warm up malloc().
static const size_t n = N * sizeof(Big);
void *p = malloc(n);
assert(p);
memset(p, 0, n);
free(p);
benchmark_mallocfree<Small>();
benchmark_mallocfree_free<Small>();
benchmark_mallocfree<Big>();
benchmark_mallocfree_free<Big>();
std::cout << std::endl;
#ifdef USE_GLIB
benchmark_glib_slices<Small>();
benchmark_glib_slices_free<Small>();
benchmark_glib_slices<Big>();
benchmark_glib_slices_free<Big>();
std::cout << std::endl;
#endif
#ifdef USE_BOOST
benchmark_boost_pool<Small>();
benchmark_boost_pool_free<Small>();
benchmark_boost_pool<Big>();
benchmark_boost_pool_free<Big>();
benchmark_boost_pool_create_and_destroy();
std::cout << std::endl;
#endif
benchmark_ngx_pool<Small>();
benchmark_ngx_pool<Big>();
benchmark_ngx_pool_mix_free();
benchmark_ngx_pool_create_and_destroy();
std::cout << std::endl;
benchmark_mempool_small();
benchmark_mempool_big();
benchmark_mempool_mix_free();
std::cout << std::endl;
benchmark_tfw_pool<Small>();
benchmark_tfw_pool_free<Small>();
benchmark_tfw_pool<Big>();
benchmark_tfw_pool_free<Big>();
benchmark_tfw_pool_mix_free();
benchmark_tfw_pool_create_and_destroy();
return 0;
}
-53
View File
@@ -1,53 +0,0 @@
CC= gcc
CXX= g++
CFLAGS= -g -Wall -O2 -fomit-frame-pointer -march=native -lm -include stddef.h
CXXFLAGS= $(CFLAGS)
LDFLAGS=
OBJS=
LIBS= -lm
all: run
benchmarks:
git clone https://github.com/attractivechaos/benchmarks.git
build: benchmarks
mkdir -p benchmarks/udb/mlib
cp test-mlib.c benchmarks/udb/mlib/test.c
cp Makefile-mlib benchmarks/udb/mlib/Makefile
mkdir -p benchmarks/udb/mlib-oa
cp test-mlib-oa.c benchmarks/udb/mlib-oa/test.c
cp Makefile-mlib benchmarks/udb/mlib-oa/Makefile
touch build
all-recur: build
cd benchmarks/udb; \
wdir=`pwd`; \
list_c=`find . -name 'test.c'`; \
list_cc=`find . -name 'test.cc'`; \
for t in $$list_c $$list_cc ; do \
subdir=`dirname $$t`; \
cd $$subdir; \
$(MAKE) CC="$(CC)" CXX="$(CXX)" DFLAGS="$(DFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" || exit 1; \
cd $$wdir; \
done;
run: all-recur
@cd benchmarks/udb; \
echo ; echo "LIBRARY | INT TIME | STR TIME" ; \
for i in `find . -name 'test'` ; do \
printf "%s|" `dirname $$i|sed -e 's+./++g'`; \
$$i -is | awk ' \
/\[int data\] # element/ { nbInt= $$5 } \
/\[int data\] CPU time/ {timeInt= $$5 } \
/\[str data\] # element/ { nbStr= $$5 } \
/\[str data\] CPU time/ {timeStr= $$5 } \
END { \
if (nbInt != 624444) timeInt="BRK" ; \
if (nbStr != 624444) timeStr="BRK" ; \
print timeInt,"|" ,timeStr \
}' ; \
done
clean:
rm -rf benchmarks build
-22
View File
@@ -1,22 +0,0 @@
CC= gcc
CFLAGS= -g -Wall -O2 -march=native
OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o
DFLAGS=
INCLUDES= -I../benchmark -I../runit -I../../../../..
LIBS=
.SUFFIXES:.c .o
.c.o:
$(CC) -std=gnu11 -DNDEBUG -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@
all:test
test:$(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
cleanlocal:
rm -f *.o a.out *~ test
clean:cleanlocal
-73
View File
@@ -1,73 +0,0 @@
#include <string.h>
#include "benchmark.h"
#include "m-dict.h"
#include "m-mempool.h"
static inline bool oor_equal_p(int k, unsigned char n)
{
return k == (int)-n - 1;
}
static inline void oor_set(int *k, unsigned char n)
{
*k = (int)-n - 1;
}
DICT_OA_DEF2(dict_int,
int, M_OPEXTEND(M_DEFAULT_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)),
int, M_DEFAULT_OPLIST)
static const char *const oor[2] = { "EMPTY", "DELETED" };
static inline bool str_oor_equal_p(const char *k, unsigned char n)
{
return k == oor[n];
}
static inline void str_oor_set(const char * *k, unsigned char n)
{
*k = oor[n];
}
DICT_OA_DEF2(dict_str, const char *,
M_OPEXTEND (M_CSTR_OPLIST, OOR_EQUAL(str_oor_equal_p), OOR_SET(str_oor_set M_IPTR)),
int, M_DEFAULT_OPLIST)
int test_int(int N, const unsigned *data)
{
int ret;
M_LET(h, DICT_OPLIST(dict_int)) {
for (int i = 0; i < N; ++i) {
if (dict_int_get (h, data[i]) == NULL) {
dict_int_set_at (h, data[i], i);
} else {
dict_int_erase(h, data[i]);
}
}
ret = (int)dict_int_size(h);
}
return ret;
}
int test_str(int N, char * const *data)
{
int ret;
M_LET(h, DICT_OPLIST(dict_str)) {
for (int i = 0; i < N; ++i) {
if (dict_str_get (h, data[i]) == NULL) {
dict_str_set_at (h, data[i], i);
} else {
dict_str_erase(h, data[i]);
}
}
ret = (int)dict_str_size(h);
}
return ret;
}
int main(int argc, char *argv[])
{
return udb_benchmark(argc, argv, test_int, test_str);
}
-53
View File
@@ -1,53 +0,0 @@
#include <string.h>
#include "benchmark.h"
#include "m-dict.h"
#include "m-mempool.h"
DICT_STOREHASH_DEF2(dict_int,
int, M_OPEXTEND(M_DEFAULT_OPLIST, MEMPOOL(mpool_int), MEMPOOL_LINKAGE(static)),
int, M_DEFAULT_OPLIST)
DICT_STOREHASH_DEF2(dict_str,
const char *, M_OPEXTEND (M_CSTR_OPLIST, MEMPOOL(mpool_str), MEMPOOL_LINKAGE(static)),
int, M_DEFAULT_OPLIST)
int test_int(int N, const unsigned *data)
{
int ret;
dict_int_list_pair_mempool_init(mpool_int);
M_LET(h, DICT_OPLIST(dict_int)) {
for (int i = 0; i < N; ++i) {
if (dict_int_get (h, data[i]) == NULL) {
dict_int_set_at (h, data[i], i);
} else {
dict_int_erase(h, data[i]);
}
}
ret = (int)dict_int_size(h);
}
dict_int_list_pair_mempool_clear(mpool_int);
return ret;
}
int test_str(int N, char * const *data)
{
int ret;
dict_str_list_pair_mempool_init(mpool_str);
M_LET(h, DICT_OPLIST(dict_str)) {
for (int i = 0; i < N; ++i) {
if (dict_str_get (h, data[i]) == NULL) {
dict_str_set_at (h, data[i], i);
} else {
dict_str_erase(h, data[i]);
}
}
ret = (int)dict_str_size(h);
}
dict_str_list_pair_mempool_clear(mpool_str);
return ret;
}
int main(int argc, char *argv[])
{
return udb_benchmark(argc, argv, test_int, test_str);
}
-33
View File
@@ -1,33 +0,0 @@
CC= gcc
CXX= g++
CFLAGS= -g -Wall -O2 -fomit-frame-pointer -march=native -lm -include stddef.h
CXXFLAGS= $(CFLAGS)
LDFLAGS=
OBJS=
LIBS=
all: run
udb2:
git clone https://github.com/attractivechaos/udb2.git
build: udb2
mkdir -p udb2/mlib
cp test-mlib.c udb2/mlib/test.c
cp Makefile-mlib udb2/mlib/Makefile
touch build
all-recur: build
cd udb2/stb && make CC="gcc -lm"
cd udb2 && for dir in `ls | egrep -v '^(Makefile|common.c|_)'`; do cd $$dir && make && cd -; done
run: all-recur
@cd udb2; \
echo ; echo RUNNING BENCH ; echo ; \
for i in `find . -name 'run-test'` ; do \
echo ; echo `dirname $$i|sed -e 's+./++g'`; \
$$i ; \
done
clean:
rm -rf udb2 build *~
-8
View File
@@ -1,8 +0,0 @@
all:run-test
run-test:test.c ../common.c
$(CC) -std=gnu99 -O2 -Wall -I../../../.. $< -o $@
clean:
rm -f run-test* *~
rm -rf mlib
-34
View File
@@ -1,34 +0,0 @@
#include "../common.c"
#define DICTI_OA_PROBING(s) 1
#include "m-dict.h"
static inline bool oor_equal_p(unsigned int k, unsigned char n)
{
return k == (unsigned int)n;
}
static inline void oor_set(unsigned int *k, unsigned char n)
{
*k = (unsigned int)n;
}
DICT_OA_DEF2(dict_oa_uint,
unsigned int, M_OPEXTEND(M_DEFAULT_OPLIST, HASH(hash_fn), OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)),
unsigned int, M_DEFAULT_OPLIST)
uint32_t test_int(uint32_t n, uint32_t x0)
{
uint32_t i, x, z = 0;
dict_oa_uint_t h;
dict_oa_uint_init(h);
for (i = 0, x = x0; i < n; ++i) {
x = hash32(x);
unsigned int key = get_key(n, x);
unsigned int *ptr = dict_oa_uint_get_at(h, key);
(*ptr)++;
z += *ptr;
}
fprintf(stderr, "# unique keys: %d; checksum: %u\n", (int) dict_oa_uint_size(h), z);
z = dict_oa_uint_size(h);
dict_oa_uint_clear(h);
return z;
}
+55
View File
@@ -57,3 +57,58 @@ V0.4.*: * The order of a list initialized using M_LET is reversed
* Rename TUPLE _init_set2 in _init_emplace & _set2 in _emplace.
* Rename Priority Queue method _update_further in _update.
V0.5.*: * M_INVERT is renamed into M_REVERSE to be more coherent with the REVERSE operator.
M_INVERT is marked as obsolete.
* Remove _it_to_p method of B+TREE / RB-TREE as it has been deprecated.
* Remove ALGO_INIT_VA & M_ALG0_LET_INIT_VAI of m-algo as it has been deprecated (Use of M_LET instead).
* Some Internal name of user modifiable macros have been renamed to be properly
customizable by the user.
* Rename M_HASH_SEED into M_USE_HASH_SEED (as it is a user macro).
* M_LET: for initialization of variable with arguments, if there is only one argument,
it will default to use INIT_SET instead of INIT_WITH.
==> Encapsulate the argument between () to force use of INIT_WITH.
* Remove of UPDATE operator. Use of SET for RBTREE or ADD for DICT instead.
* Make the _clean suffix for reseting the container to empty deprecated. Use new _reset suffix instead.
* Make the _get_at suffix for always getting a value deprecated. Use new _safe_get suffix instead.
* Rename CLEAN operator in RESET operator.
* Rename GET_SET_KEY operator in SAFE_GET_KEY operator.
V0.6.*: * Rename M_DEFAULT_OPLIST in M_BASIC_OPLIST
* Remove experimental macro M_IF_DEFAULT1.
* Remove M_INVERT
* String functions with _str suffix for C strings have been renamed with _cstr suffix (like string_cat_str ==> m_string_cat_cstr)
Note: the compatible layer still keeps the old naming,
so except if you are using the prefixed version of the strings
or the bounded strings API, you won't need to upgrade your code.
V0.7.2: * Rename m-mutex.h header in m-thread.h
V0.7.3 : * DICT_STOREHASH_DEF2 / DICT_STOREHASH_DEF2_AS are deprecated.
Use DICT_DEF2 / DICT_DEF2_AS
V0.8.0 : * Memory interface massive compatibility break to allow more efficient integration of custom allocators.
The prototypes of NEW / DEL REALLOC / FREE operators are incompatible:
* Add the old number of elements of the array as argument of REALLOC
* Add the number of elements of the array and its base type as arguments of FREE.
* Add the context argument (which shall be ignored in not specific build)
(You can ignore the new arguments which are only hints provided to memory functions).
Also impact M_MEMORY_NEW / M_MEMORY_DEL / M_MEMORY_REALLOC & M_MEMORY_FREE
M_MEMORY_FULL: replace the failed size allocation size argument into the base type and the number of elements that failed to be allocated.
* m-buffer:
* non-thread safe queue & stack are moved into their dedicated header (m-queue)
* BUFFER_THREAD_UNSAFE policy is no longer supported.
* Disabling BUFFER_BLOCKING policy is no longer supported (default policy is now forced).
* _push / _pop now returns now void like other containers instead of a bool (it was undocumented)
* Remove MEMPOOL support from list & R/B tree
* m-mempool: Header is obsolete (and no longer useful at all as lists & RB Tree no longer can use it. To remove). Use new M_USE_CONTEXT interface to pass local pool context.
* M*LIB becomes stricter for the INIT_MOVE operator:
The Emulation layer using CLEAR+INIT_SET methods, when there is no INIT_MOVE operator, has been removed:
either default INIT_MOVE operator (operator '=') is working, or a method is provided for INIT_MOVE or it is disabled.
If it is an array of size 1, you can use M_COPY_A1_DEFAULT as a default method.
(It's because supporting emulation layer with new memory context parameter was complicated)
* Remove obsole headers: m-c-mempool, m-mempool, m-shared, m-i-shared, -mconcurrent
V0.8.1 : * m-algo: Update interface of _transform to be more flexible: adding user context pointer, and filtering of the input elements.
* m-algo: Update interface of _reduce to be more user friendly: return value indicates if the reduction is empty or not.
* m-algo: Rename _map_reduce into _transform_reduce and update its interface to be more flexible: adding user context pointer, and filtering of the input elements and return value indicates if the reduction is empty or not.
* Rename _push_raw method by _push_back_raw for all containers (clearer on the semantic)
BIN
View File
Binary file not shown.
+61 -16
View File
@@ -17,23 +17,31 @@ How to make a release?
In case of problem, open a problem report.
List of tested systems
=======================
List of automatically tested systems
====================================
* gcc 4.9, 7 & 8 on linux/x86-64
* clang 3.5, 4 & 6 on linux/x86-64
* g++ 7 & 8 on linux/x86-64
* gcc on linux/x86-64 (32 bits and 64 bits)
* g++ on linux/x86-64 (32 bits and 64 bits)
* clang on macos/x86-64
* clang++ on macos/x86-64
* tcc on linux/x86-64
* gcc 7 on windows/x86-64
* gcc 4.9 on linux/powerpc
* gcc 6 on linux/armv7l
* clang 3.8 on linux/armv7l
* gcc on windows/x86-64 (mingw)
* msvc on windows/x86-64
* clang on windows/x86-64
List of manually tested systems
===============================
* clang on linux/x86-64
* clang on linux/armv7l
* gcc on linux/powerpc
* gcc on linux/armv7l
Atomic library
==============
For target, armel m68k mips mipsel powerpc powerpcspe sh4, you may need to run the test suite:
For the targets armel, m68k, mips, mipsel, powerpc, powerpcspe or sh4,
you may need to run the test suite by adding the atomic library:
make check LDFLAGS="-pthread -latomic"
@@ -45,7 +53,7 @@ Cross compilation
There is no need to cross compile the library as it is a header only library.
However if you want to run the test with a cross-compiler, do like the following
However if you want to run the tests with a cross-compiler, do like the following
command. It performs a cross-compilation of the test suite from linux to windows
and run the test suite with wine:
@@ -57,9 +65,8 @@ Handling issues
Issues are opened in the bug tracker of the project (typically https://github.com/P-p-H-d/mlib/issues )
If the issue cannot be closed and taken into account in less than (typically) one month,
or before a release,
it shall be moved into the long term issues included in the repository:
If the issue cannot be taken into account quickly and are long term,
it should be moved into the long term issues included in the repository:
https://github.com/P-p-H-d/mlib/blob/master/doc/ISSUES.org
This is a file in ORG mode: the issues are created with the proper tags.
@@ -75,7 +82,7 @@ its state shall be changed to DONE (the issue shall not be removed).
Debugging
===============
=========
Debugging the library can be quite difficult
as it performs heavy preprocessing expansion
@@ -86,7 +93,7 @@ Different strategy for debugging the library itself are still possible:
Add printf of interresting values in the debugged function.
2) Preprocess the library and then compile the preprocessed file:
2) Preprocess the library and then compile the preprocessed file like this:
cc -std=c99 -E test-file.c > test-file.i
perl -pi -e 's/;/;\n/g' test-file.i
@@ -109,3 +116,41 @@ Run the wave driver:
./wave ex-array01.c -I .. --c99 -t test.trace
The different expansion performed by the library are described in test.trace
Coding rules
============
* Use of non standard C shall be protected under a specific compiler test,
so that the library remains compatible with a strict C99 compiler.
* C11 features shall be optional.
* Use 'make format' to format the header files properly.
* External types shall be suffixed by _t and in lower case
but shall be optional if the user doesn't want then.
* Internal types shall be suffixed by _ct and in lower case
(as confidential types)
* External / Internal functions shall be in lower case.
* External / Internal macros shall be in upper case.
* Internal macros / functions shall be prefixed by m_<container>
with container is the name of the container with one letter transformed:
o --> 0
e --> 3
i --> 1
y --> 4
This prevents the automatic completion to work when the user starts writing its function.
* Test functions shall be predicated and be suffixed by '_p'
Misc
====
To put a breakpoint for the thread sanitizer in case of error, in gdb add:
$ set env TSAN_OPTIONS=halt_on_error=1,abort_on_error=1
+459 -80
View File
@@ -1,34 +1,391 @@
*Long term issues*
------------------
==========================================================
* TODO #26 : Hash-Map for huge objects :ENHANCEMENT:
* DONE #34 : Pass old size arguments to memory allocator :ENHANCEMENT:
** State
Some custom allocators don't store the old size of an object to maximize memory usage
used by the allocated objects. On realloc, they need the old size argument.
This is inline with the GMP allocator which provides the old size argument.
There is no difficulty in the data structure to compute the old size of the object
(it is quite easily available).
It is needed for REALLOC operator (and FREE)
** Solution #1
Add the oldsize argument to the REALLOC and FREE operators.
** Solution #2
Create a local variable m_local_old_size before calling the REALLOC or FREE operators
Modify GAIA interface to link OLDSIZE patttern to m_local_old_size
Need to handle the warnings correctly.
** Tradeof analysis
Solution #1 is simpler but breaks API. However custom allocators are not common.
Solution #2 keeps API as it is but increases code complexity by adding more hacks into the codebase.
* TODO #33 : Handling of partially constructed object :ANOMALY:
** State
Support of partially constructed object needs special code to handle it
correctly (register a correct cleanup function in case of exception).
Current containers don't support such features.
> NOTE:
An exception for init_set supposes that the object is *not* initialized.
An exception for set supposes that the object *remains* initialized.
Some containers perform an init_set using init+set
others perform a set using a clear+init_set
The property of init_set (resp. set) is broken if an exception is raised in the set (resp. init_set):
the object is not let in the expected uninitialized (resp. initialized) state.
** Actions
Add such support in M*LIB containers.
Need to analyse each function for execption safety.
It can be difficult. For example, for array _init_set
function due to the copy of the object one per one. Each copied sub object
may throw an exception, so we always need to have the container in a correct
state so that it can be cleanup.
* DONE #32 : User specialization fields in the container :ENHANCEMENT:
** State
Some methods of a contained object may need to have some options that
are neither constant nor global, but are specialized in function of the container.
For example, a memory handler may need a parameter which is needed to identify
which pool of memory has to be used.
** Plan:
Add a new operator "CONTEXT" which is a type to be added in the
defined container. Then it can be accessed by the operator through an extension
of the GAIA by adding support for identification of specialization like this:
( CONTEXT( memory_pool_ref ),
NEW( API(NONE, memory_pool_alloc, CONTEXT, ARG1)),
DEL( API(NONE, memory_pool_free, CONTEXT, ARG1)) )
** Open points:
- How to get access to the specialization field of the container?
==> Define the "self" name as the name of the container for all methods?
- What to do when there are several containers for a method?
==> self shall be the destination?
- How to initialize the specialization field of the container? provide custom initialization functions? It seems to be the hard point.
Use GAIA interface and a local variable with force naming : m_local_context for example.
** Proposed Solution:
New operator USER_CONTEXT created. If operator USER_CONTEXT exist:
+ add a USER_CONTEXT user_data in the data structure.
+ for INIT & INIT_WITH, add a new parameter to the function to pass the context to initialize
+ for INIT_SET & INIT_MOVE & MOVE, initialize it with the source object (FIXME: This may not be what we want for INIT_SET if we want to copy an object from an allocator to another)
+ for each functions that use an operator that may use the USER_CONTEXT, add a local variable m_local_context and initialize to the user context
==> Limit user context to pointer or integer (Good enough)
+ Expand GAIA interface to handle specially the term USER_CONTEXT: if it exists, expands it to m_local_context. The user will therefore be able to expand its operator with the user provided local context.
+ Update OPLIST of data structure to change the call to INIT & INIT_WITH to use GAIA/USER_CONTEXT if the basic type has a USER_CONTEXT
+ To be checked: EMPLACE_TYPE ?
+ Create M_USING_CONTEXT to initialize a local variable m_local_context and initalize it with the user context to be used y the M_LET macro:
M_USING_CONTEXT(int *, &y)
M_LET(x, object_t) {
}
Done in branch feature/user-data-v2 with a full working implementation for array
** Solution limitation:
INIT & INIT_WITH interface change for the user. This however is an acceptable limitation.
Adding a user context to each data structure will increase a lot the size of the data structure in case of recursive data structures: For example, an array of string_t. Each string_t will need a user data context for it to work properly, so we'll need N*sizeof(user data context) memory just to make it work. This becomes even more problematic if we chain more data structures.
And in general, we use custom allocators to be faster and use less memory: this will defeat the purpose of custom allocators a lot.
Another limitation is that string_t / bitset_t are not supported correctly. We can make this change globally but it will prevent mixing different codebase that uses the string_t together (one expects a user context, the other not).
** Alternative #1
Passing user context arguments to each function call seems to be a little bit better.
It might however reduces code optimization as one more register will be user everywhere in the calling chain, which may huge.
** Alternative #2
The custom allocator could have a thread default allocator as a global variable (thread attribute). It seems to be a better solution, more scalable.
The custom allocator will need to be able to switch quickly between scrach arena and permanent arena. This seems to be easy.
However switching allocators puts a burden to the user:
the user needs to properly be sure to call the destructor with the custom allocator set to be the same as when it was created.
This might not even be possible in case of exceptions.
* TODO #31 : Uniformize parametrization options of containers :ENHANCEMENT:
** State
Currently in order to pass some parametrization of the containers,
the parameters are passed to the generation macros through:
- extra parameters of the macros,
- special operators of the contained object oplist.
The extra parameters of some generation macros break the uniformity
of the interface.
It is conceptually wrong to put some special operators of the contained object
that have only meanings for the container object.
In case of adding new options, it break the existing interface or put another
operator in the contained object oplist.
The following parameters are used:
- Fixed size of a queue (buffer / B+Tree),
- Policy of a queue (buffer),
- Type of the container, IT type of the container, Ref type of the iterator
The following operators are used:
- NEW / DEL / REALLOC / FREE
- MEMPOOL / MEMPOOL_LINKAGE
The following new options is planned:
- Interface (See #28)
- Extra parameter for memory allocation function
** Plan
The M\_*\_DEF\_AS macros shall be changed like this:
M_*_DEF_AS(name, cont_oplist, type[, type_oplist])
with cont\_oplist being the container oplist that gives parametrization to the container definition.
The following operators are planned:
- TYPE: to define the type of the container,
- IT\_TYPE: to define the IT type of the container,
- SUBTYPE: to define the type pointed by the iterator,
- FIXED\_SIZE: to define the fixed size of a container,
- POLICY: to define the policy of a container,
- NEW / DEL / REALLOC / FREE: to define the memory interface,
- MEMPOOL / MEMPOOL_LINKAGE: to request a definition of a specialized memory interface,
- INTERFACE: to request a pure header definition, an implementation or both (see #28),
- CONTEXT: to request an extra context parameter to add in the container.
All operators should be optional.
The NEW / DEL / REALLOC / FREE / MEMPOOL / MEMPOOL_LINKAGE won't have any effects anymore if defined in the contained object oplist.
** Pro:
- Uniformize interface
** Con:
- API breakage. It can be mitigated by providing an adaptating layer by prividing the new interface for M\_*\_DEF\_AS only
and *\_DEF\_AS will provide a translation layer.
* TODO #30 : Serialization rework :ENHANCEMENT:
** State
Currently, each container supports 3 serialization methods:
- old format to FILE
- old format to string
- generic serialization
Generic serialiation connect the container format to the serialization object constraints.
It is done through a vtable. As such there is a performance penality and it avoids proper inlining.
It is however quite flexible and decouple the data structure from the serialization format.
** Evolution
Old format should be deprecated and the functions implemented it shall use the generic serialization interface.
Serialization object shall provide a special OPLIST of serialization.
For example M-CORE will provide OLD Format oplist and M-SERIAL-JSON will provide JSON format oplist.
Each oplist will provide the suffix needed for the serialization, and the interface
(see already existing interface).
Then a container will generate specialized serialization methods for each provided oplist.
** Pros:
- Faster
- In the M*LIB philosphy: much like other oplist usage.
** Cons:
- compatibility breakage.
- increase code complexity.
** Open point:
- how can a user add a new serialization object? ==> See solution implemented by M-GENERIC.
- Can we make a generic serialization object to support migration path? Seems possible.
** Example
serial-json provides
#define M_SERIAL_1() (NAME(_json), READ_INT(...), WRITE_INT(...) )
containers provides
For i in 1 100 ; do
if do exist M_SERIAL_ ## i ()
expand(SERIAL_METHOD with M_SERIAL_1())
SERIAL_METHOD(name, ....)
static inline m_serial_return_code_t \
M_C(M_F(name, _out_serial),M_GET_NAME(serial_op) )(M_GET_TYPE(serial_op) f, const list_t list) \
* DONE #29 : Support of partial initialized object :ANOMALY:
** State
In case of exception during the construction of an object,
if the object is partially constructed, there is no destructor to call.
Therefore if there is some partially constructed object
(with some fields already fully constructed), there will be some links.
This is the same problem with C++
** Proposition
Provide new macros to perform the partial initialization before doing the remaining taf.
Something like:
M_CHAIN_INIT( init_code, clear_code)
or
x is { string_t s; string_t d; int num; }
void struct_init_set(struct_t x, const struct_t y)
{
// First thing is Chained Initialization
M_CHAIN_INIT( string_init_set(x->s, y->s), string_clear(x->s) );
M_CHAIN_INIT( string_init_set(x->d, y->d), string_clear(x->d) );
// End of chain init
x->num = y->num;
}
M_CHAIN_INIT will push the clean code pretty much like M_LET.
Everything else is done in M_LET: when the constructor fully returns,
the index of the clean code to call is reset to its value before calling
the constructor. It means that the partially initialized code will be removed
from this stack before the clean method of the structure itself is pushed.
If an exception is raised after a M_CHAIN_INIT, only the clean methods
of the M_CHAIN_INIT are called.
* TODO #28 : Separate generation of interface to implementation :ENHANCEMENT:
** State
Enable support for generating an interface only for the headers
and an implementation only for the source code.
** Analysis
Try to keep API compatibility
==> Only modify renamed macro with M_ prefix by giving a new mandatory
argument for such generation.
This argument is a generation parametric argument.
oplist is a parameter that define the property of the contained type.
It could be used to pass this information but it will be an abuse of interface.
Another argument is needed.
Used arguments to parameter generation not related to the contained type:
- memory interface (NEW / DEL / ...)
- queue policy
- fixed size for queue
- fixed node size for B+Tree
- generate static inline, public (extern) or private (define) functions.
- name of the type.
- name of the iterator
- name of the iterated element.
- ...
Use another oplist as argument for M_.._DEF_AS (See #31)
M_BUFFER_DEF_AS(name, (TYPE(toto), FIXED_SIZE(10), POLICY(STACK), INTERFACE(header)), int, M_BASIC_OPLIST)
* TODO #27 : Uniformization of m-buffer interface :ENHANCEMENT:
** State
The m-buffer interface requires special argument to work:
- size & policy for BUFFER,
- policy only for the others.
This is not uniform with the others generation macros and not uniform with each other.
Moreover the others are the only one which can be used in a shared memory, so
a fixed size will be good to have too for such interface.
** Plan
- Uniformization of the interface (See #31)
- Provide static size for all QUEUE.
* DONE #26 : Hash-Map for huge objects :ENHANCEMENT:
Specialize Hashmap for huge objects on supported hardware:
based on OA hash map with taggued pointer (needs space for tagging):
low bits = low bits of hash
Based on OA hash map with taggued pointer (needs space for tagging):
low bits = high bits of hash
pointer to object { key, hash, value }
Can detect collision without dereferencing object with 1/2^lowbits chances.
Can solve collision without dereferencing object with 1/2^lowbits chances.
NB: hash may be uneeded due to the small chances of collision.
Reduce cache usage ==> Should be faster.
Increase cache usage for very small object (integer).
Use of pointer to avoid moving object on GC.
On AMD64, only 48 bits of 64 bits are really used for addressing data.
==> lowbits= 16
Empty representation= 0 (hash can be 0. pointer cannot be it).
Deleted representation = 1 (pointer cannot be zero)
<---- PTR ----><-HASH->
* TODO #25 : Support of error code model for error handling. :ENHANCEMENT:
#+BEGIN_SRC C
#define LOW_BITS 16
#define ALIGNED_BITS 2
void *get_ptr(int64_t x) {
return (void*) ((x >> LOW_BITS) << ALIGNED_BITS);
}
unsigned get_small_hash(int64_t x) {
return x & ((1<<LOW_BITS)-1);
}
#+END_SRC
Can also (should?) use SIMD to test for several hash entries at the same times
In which case a complete new implementation will be needed
Note: SIMD doesn't seem to be a win if not handled properly.
Since the first guess of a good hashtable shall give the right entry > 90% of the time.
So 90% of the times SIMD will pay the cost of reading not needed memory.
It might still be a win, but proper tuning needs to be done.
* TODO #25 : Support of error return model for error handling. :ENHANCEMENT:
** State
Find a way to support error return code for the API in case of allocation
failure.
Any service that returns void shall return a "int".
** Analysis
Any service that returns void shall return a "int" (or another type).
In case of allocation failure, it shall return an error.
M_CALL macro shall stop its execution if the service returns an error code
and the error code represents an error (avoid rewritting everything)
and throw back the error code (stopping the execution flow).
Services returning already something shall not be modified.
Services returning already something shall not be modified but returns the error code embedded (like a NULL pointer).
This model should be applied at the container level only and not globally.
Different containers may need different levels of error handling.
@@ -80,26 +437,30 @@ RETCODE/RETCODE
If really needed, the macro can be avoided and code can be hand written.
Open points:
** Open points:
- How to handle warnings on unused labels?
- What about M_LET/ M_EACH?
- What about M_LET / M_EACH? Maybe only supports those.
* TODO #24 : New MIN-MAX-HEAP container :ENHANCEMENT:
* TODO #24 : Add MIN-MAX-HEAP container :ENHANCEMENT:
** State
See https://en.wikipedia.org/wiki/Min-max_heap
as DPRIORITY_QUEUE_DEF ?
** Analysis
NOTE: Needs for such container?
On hold until a user needs it.
* DONE #23 : Strict MOVE semantic to clarify :ENHANCEMENT:
* TODO #23: Force MOVE semantic :ENHANCEMENT:
** State
Some type may need to have a force MOVE semantic (for example, they can store
pointer to themselves). Currently the INIT_MOVE & MOVE operators are more
a help for performance than a strict semantic usage.
** ARRAY container
** ARRAY container constraint
The ARRAY container doesn't support strict MOVE semantic for example.
It is not a simple matter as it performs a realloc of the table, thus
@@ -108,7 +469,7 @@ moving the data before they can be moved using MOVE. Two solutions:
- New operator MOVE_SELF to fix a type after it has been moved.
- If MOVE defined, force another table and then copy by hand the type. This will be slower and consumme more memory.
** MOVE in OPLIST :ENHANCEMENT:
** MOVE in OPLIST
Proposal: do not export INIT_MOVE / MOVE operator in OPLIST if the MOVE operator is
compatible with a pure COPY semantic. An exported MOVE operator will tell
@@ -122,14 +483,29 @@ For example for tuple, it shall
** DO_INIT_MOVE operator
DO_INIT_MOVE macro is not also fully working for structure
DO_INIT_MOVE macro is also fully working for structure
defined with [1] tricks but without an explicit INIT_MOVE / MOVE
operators as it uses MOVE_DEFAULT which is not (fully compatible).
operators as it uses MOVE_DEFAULT which is not compatible.
==> Analyse limitation and possible constraint usages.
Being able to define a correct default for INIT_MOVE will be really good
(compatible with trivial move copy).
In such case, all INIT_MOVE & MOVE operators can be removed from oplist
to only use the default, and theses operators can be disabled or defined
only when really needed in the oplist.
However creating a default INIT_MOVE macro seems problematic.
If the type is typedef T t[1] then passing such an argument to a function,
will transform the argument to T*, and the type of the argument doesn't match
what is expecting resulting in a move of the pointers, not a move of the design data.
* TODO #20: Bucket priority queue :ENHANCEMENT:
Defining this type seems possible with C11 _Generic and a TYPE in the oplist,
but without C11 _Generic I don't see any way to define such macro
and we still need to target C99 for such basic feature.
Without a way to write such a macro, the ticket seems pretty much a dead end.
* TODO #20 : New: Bucket priority queue :ENHANCEMENT:
** State
Add a new kind of priority queue.
See https://en.wikipedia.org/wiki/Bucket_queue
@@ -144,23 +520,34 @@ except that we can scan 64 entries at a time).
Check if we can use BITSET, or introduce fixed size BITSET or use ad-hock
implementation.
** Analysis
NOTE: Needs for such container?
On hold until a user needs it.
* TODO #19: Intrusive Red Black Tree :ENHANCEMENT:
* CANC #19 : New: Intrusive Red Black Tree :ENHANCEMENT:
** State
Add intrusive red black tree.
Look also for AVL tree (NOTE: Is there a performance difference between the two?)
** Analysis
Only needed for unmovable objects for which B+Tree cannot do the job.
But standard Read/Black Tree will do the job just fine.
There is really no need for it.
==> Cancelled
* TODO #18: Missing methods :ENHANCEMENT:
* TODO #18 : Missing methods :ENHANCEMENT:
** State
Some containers don't have all the methods they should.
See the cells in yellow here:
http://htmlpreview.github.io/?https://github.com/P-p-H-d/mlib/blob/master/doc/Container.html
** Analysis
Analyzed each missing methods and fill in the gap
* TODO #17: Ressource handler :ENHANCEMENT:
* TODO #17 : New: Ressource handler :ENHANCEMENT:
A ressouce handler which shall associated a unique handle to a ressource.
** State
A global 'ressouce handler' which shall associated a unique handle to a ressource.
The handle shall be unique for the ressource and shall not be reused.
It is typically a 64 bits integers always incremented (even if the program
creates one billion ressources per second, the counter won't overflow
@@ -185,11 +572,11 @@ http://htmlpreview.github.io/?https://github.com/P-p-H-d/mlib/blob/master/doc/Co
How to handle multiple resource ?
* variant: works fine. Memory usage can be (much) higher than needed if there is a lot of dissimilarity between the size of the objects.
* embedded the type in the ressource handler: more work, API more complex. Memory usage seems better.
** Analysis
- use of variant: Pro : easy. Con: Memory usage can be (much) higher than needed if there is a lot of dissimilarity between the size of the objects.
- embedded the type in the ressource handler: Con: more work, API more complex. Pro: Memory usage seems better.
* TODO #16: Lock Free List :ENHANCEMENT:
* TODO #16 : New: Lock Free List :ENHANCEMENT:
Implement a lock free list. Most of the difficulty is the memory reclamation part.
Typically this lock free list shall be compatible with RCU method.
@@ -212,31 +599,9 @@ http://htmlpreview.github.io/?https://github.com/P-p-H-d/mlib/blob/master/doc/Co
- needs to be logically deleted : needs a previous field
(NULL if not logically deleted) ? TBC
NOTE: m-c-mempool doesn't seem to be fully robust. random failure of the test cases appear (more notably with Visual C++, but it is still quite rare).
* TODO #15: Prologue / Epilogue for Constructor / Destructor for error handling :ENHANCEMENT:
Constructor (and destructor) need to use user-defined prologue / epilogue.
This is in order to register the constructed object into a proper Exception
Handling Stack so that throwing exceptions may work reliably.
Proposal:
- M_CONSTRUCTOR_PROLOGUE(object, oplist);
- M_CONSTRUCTOR_EPILOGUE(object, oplist);
- M_DESTRUCTOR_PROLOGUE(object, oplist);
- M_DESTRUCTOR_EPILOGUE(object, oplist);
Object creation will need to add all sub-objects into the stack,
then unstack all to push instead the root object (which recursively remove them).
See also http://freetype.sourceforge.net/david/reliable-c.html#cseh
- How to handle like allocation of the object?
- How to avoid calling the destructor multiple times? (It is needed?)
- How the code can be factorized with RETCODE needs?
* TODO #14: Memory allocation enhancement :ENHANCEMENT:
* DONE #14 : Memory allocation enhancement :ENHANCEMENT:
Enhancement of the memory allocation scheme to find way to deal properly with advanced allocators:
@@ -270,9 +635,10 @@ Needs some formal operator in the oplist to support it fully and an example.
It is a kind of object inheritance where the container inherits some extra data from its base.
Duplicate with #32 which is more generic ==> Closed
* TODO #12: Atomic shared pointer :ENHANCEMENT:
* TODO #12 : New: Atomic shared pointer :ENHANCEMENT:
** State
Add an extension to the SHARED_PTR API:
- New type atomic_shared_ptr
@@ -345,13 +711,14 @@ Other alternative solution is to use the bit 0 to mark the pointer as being upda
Other implementation seems to have it hard to be lock-free: cf. https://github.com/llvm-mirror/libcxx/commit/5fec82dc0db3623546038e4a86baa44f749e554f
* TODO #5: Concurrent dictionary Container :ENHANCEMENT:
* TODO #5 : New: Concurrent dictionary Container :ENHANCEMENT:
** State
Implement a more efficient dictionary than lock + std dictionary for all operations when dealing with threads.
See https://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx
The best parallel algorithm is still when there is as few synchronization as possible. A concurrent dictionary will fail at this and will result in average performance at best.
The typical best case will be in RCU context (a lot of readers, few writers), so the interface shall be compatible with such structure.
** Multiple locks within the dictionnary
A potential implementation may be to request at initialization time the number of concurrent thread N.
@@ -372,33 +739,24 @@ See also https://github.com/simonhf/sharedhashfile
** Lock Free dictionnary
Evaluate also lock-free dictionary (easier with open addressing).
It needs a complete rewrite of the inner loop through. The hard part is the dynamic resizing of the internal array (see http://preshing.com/20160222/a-resizable-concurrent-map/ for a potential solution and http://www.cs.toronto.edu/~tomhart/papers/tomhart_thesis.pdf for memory reclamation techniques). See also https://www.research.ibm.com/people/m/michael/spaa-2002.pdf
https://www.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.2017.11.22a.pdf persents different techniques used by linux kernel.
It needs a complete rewrite of the inner loop through. The hard part is the dynamic resizing of the internal array.
Ssee http://preshing.com/20160222/a-resizable-concurrent-map/ for a potential solution
and http://www.cs.toronto.edu/~tomhart/papers/tomhart_thesis.pdf for memory reclamation techniques).
and https://www.research.ibm.com/people/m/michael/spaa-2002.pdf
https://www.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.2017.11.22a.pdf presents different techniques used by linux kernel.
It needs before lock-free list: http://www.cse.yorku.ca/~ruppert/papers/lfll.pdf http://www.cse.yorku.ca/~ruppert/Mikhail.pdf
** Context
The best parallel algorithm is still when there is as few synchronization as possible. A concurrent dictionary will fail at this and will result in average performance at best.
The typical best case will be in RCU context (a lot of readers, few writers), so the interface shall be compatible with such structure.
** Linked list
Another solution is to create a huge list of items which is:
- atomically updated,
- in reverse order of the hash (bit 0 is highest bit, Bit 63 is the lowest bit).
Hash table will only give quick access to items to this list. Expanding the table won't change the order of the list (so the items will remain at the same place and always accessible by other threads) but just add sentinel in the sentinel at the right place (there won't be any reallocation of the list). Inserting will need to insert an item at the right place.
Not sure it will really help. To analyse.
Concurrent dictionary is possible now with CONCURRENT_DEF + DICT_DEF.
But it uses a global lock for all dictionary access.
** Open Addressing Indirect Table with a lock free node pool used as transaction pool.
A good way maybe Open Addessing table used only for indirection and a freelist memory reclamation container for handle the entries
(like a transaction).
Solution?
--------
Use of the concurrent pool (m-c-mempool) to allocate items.
The big table will only store pointers (+ part of hash in unused bits?) to such allocate items.
Atomic update is done by allocating a new node, update it, and atomicaly store it in the dict, putting the old one as logically deleted and to reclaim later.
(Other threads may still read its data so we cannot free immediatly).
* DONE #22: Enhanced services for SPSC Queue :ENHANCEMENT:
Add services:
@@ -436,6 +794,27 @@ push always succeed and the queue always keep the youngest element.
To simplify it, this interface could only support one kind of import/export
per compilation unit.
* DONE #15: Prologue / Epilogue for Constructor / Destructor for error handling :ENHANCEMENT:
Constructor (and destructor) need to use user-defined prologue / epilogue.
This is in order to register the constructed object into a proper Exception
Handling Stack so that throwing exceptions may work reliably.
Proposal:
- M_CONSTRUCTOR_PROLOGUE(object, oplist);
- M_CONSTRUCTOR_EPILOGUE(object, oplist);
- M_DESTRUCTOR_PROLOGUE(object, oplist);
- M_DESTRUCTOR_EPILOGUE(object, oplist);
Object creation will need to add all sub-objects into the stack,
then unstack all to push instead the root object (which recursively remove them).
See also http://freetype.sourceforge.net/david/reliable-c.html#cseh
- How to handle like allocation of the object?
- How to avoid calling the destructor multiple times? (It is needed?)
- How the code can be factorized with RETCODE needs?
Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Executable
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
mkdir -p /tmp/prepro-$USER
name=/tmp/prepro-$USER/$$.c
param1=""
param2=""
while test $# -gt 0 ; do
case $1 in
-c) param2="$param2 -c" ;;
-o) param2="$param2 -o $2" ; shift ;;
*\.c) param1="$param1 $1" ;;
*) param1="$param1 $1" ; param2="$param2 $1" ;;
esac
shift
done
cc $param1 -E |grep -v '^#' > ${name} \
&& perl -pi -e 's/\;/\;\n/g' ${name} \
&& cc $param2 ${name}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

After

Width:  |  Height:  |  Size: 106 KiB

+23 -7
View File
@@ -1,4 +1,4 @@
# Copyright (c) 2017-2021, Patrick Pelissier
# Copyright (c) 2017-2023, Patrick Pelissier
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -21,8 +21,9 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
CC=cc -std=c99
CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function -g
CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function -g
GMP_DIR=
MPFR_DIR=$(GMP_DIR)
CPPFLAGS=-I..
LDFLAGS=-pthread
RM=rm -f
@@ -30,18 +31,33 @@ RM=rm -f
.SUFFIXES: .c .exe
.c.exe:
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) `cat config` $< -o $@
$(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ `cat config` `cat config.curl` $(LDFLAGS)
.c.o:
@$(MAKE) config
$(CC) $(CFLAGS) $(CPPFLAGS) -O2 `cat config.link` -DNDEBUG -g $< -c -o $@
all: config
$(MAKE) `ls ex-*.c|sed -e 's/\.c/\.exe/g'`
if test "$(CC)" = "cc -std=c99" ; then $(MAKE) `ls ex11-*.c|sed -e 's/\.c/\.exe/g'` CC="cc -std=c11" ; fi
$(MAKE) exm.exe exn.exe
exm.exe: exm-lib.o exm-main.o
$(CC) `cat config.link` -g $^ -o $@
exn.exe: exn-lib.o exn-main.o
$(CC) `cat config.link` -g $^ -o $@
config:
printf "#include <gmp.h>\nint main(void){mpz_t z; mpz_init(z); return 0;}\n" > config-test.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -I$(GMP_DIR)/include -L$(GMP_DIR)/lib -lgmp config-test.c -o config-test.exe 2> /dev/null && echo "-DHAVE_GMP=1 -I$(GMP_DIR)/include -L$(GMP_DIR)/lib -lgmp" > config || echo "-DHAVE_GMP=0" > config
$(CC) $(CFLAGS) $(CPPFLAGS) -I$(GMP_DIR)/include -L$(GMP_DIR)/lib config-test.c -lgmp -o config-test.exe $(LDFLAGS) 2> /dev/null && echo "-DHAVE_GMP=1 -DHAVE_MPFR=0 -I$(GMP_DIR)/include -L$(GMP_DIR)/lib -lgmp" > config || echo "-DHAVE_GMP=0 -DHAVE_MPFR=0 " > config
printf "#include <mpfr.h>\nint main(void){mpfr_t z; mpfr_init(z); return 0;}\n" > config-test.c
$(CC) $(CFLAGS) $(CPPFLAGS) -I$(GMP_DIR)/include -I$(MPFR_DIR)/include -L$(GMP_DIR)/lib -L$(MPFR_DIR)/lib config-test.c -lmpfr -lgmp -o config-test.exe $(LDFLAGS) 2> /dev/null && echo "-DHAVE_GMP=1 -DHAVE_MPFR=1 -I$(GMP_DIR)/include -L$(GMP_DIR)/lib -I$(MPFR_DIR)/include -L$(MPFR_DIR)/lib -lmpfr -lgmp" > config || echo "MPFR not available"
printf "#include <curl/curl.h>\nint main(void){curl_global_init(CURL_GLOBAL_DEFAULT);}" > config-test.c
$(CC) $(CFLAGS) $(CPPFLAGS) config-test.c `curl-config --cflags --libs` -o config-test.exe 2> /dev/null && echo "-DHAVE_CURL=1 `curl-config --cflags --libs`" > config.curl || echo "-DHAVE_CURL=0 " > config.curl
printf "#include <stdio.h>\nint main(void){printf(\"Ok\"); return 0;}\n" > config-test.c
$(CC) $(CFLAGS) $(CPPFLAGS) config-test.c -ffunction-sections -fdata-sections -Wl,--gc-sections 2> /dev/null && echo "-ffunction-sections -fdata-sections -Wl,--gc-sections" > config.link || echo "" > config.link
$(RM) config-test.c config-test.exe
clean:
$(RM) *.exe *.s *~ *.o ./a.dat config
$(RM) *.exe *.s *~ *.o ./a.dat config config.link config.curl
+8 -8
View File
@@ -4,16 +4,16 @@
/* Define a dynamic array of int */
ARRAY_DEF(vector_int, int)
/* Register the oplist of this dynamic array globally */
/* Register the oplist of this dynamic array globally (using implicitely M_BASIC_OPLIST) */
#define M_OPL_vector_int_t() ARRAY_OPLIST(vector_int)
/* Define some standards algorithms on this dynamic array */
/* Define some standards algorithms on this dynamic array. We can reuse the prefix of the dynamic array */
ALGO_DEF(vector_int, vector_int_t)
/* Define a dynamic array of bool */
ARRAY_DEF(vector_bool, bool, M_BOOL_OPLIST)
ARRAY_DEF(vector_bool, bool)
/* Register the oplist of this dynamic array globally */
#define M_OPL_vector_bool_t() ARRAY_OPLIST(vector_bool, M_BOOL_OPLIST)
/* Define some standards algorithms on this dynamic array */
/* Define some standards algorithms on this dynamic array. We can reuse the prefix of the dynamic array */
ALGO_DEF(vector_bool, vector_bool_t)
/* ID function */
@@ -41,10 +41,10 @@ int main(void)
#else
for M_EACH(it, myvector, vector_int_t) {
printf(" %d", *it);
}
}
#endif
printf("\n");
}
} /* End of M_LET: myvector & tmp are automaticly cleared */
// Same thing but with booleans
M_LET(myvector, tmp, vector_bool_t) {
@@ -56,13 +56,13 @@ int main(void)
printf("myvector contains:");
for M_EACH(it, myvector, vector_bool_t) {
printf(" %d", (int)*it);
}
}
printf("\n");
printf ("ALL: %d ANY: %d NONE: %d\n",
vector_bool_all_of_p(myvector, id),
vector_bool_any_of_p(myvector, id),
vector_bool_none_of_p(myvector, id) );
}
} /* End of M_LET: myvector & tmp are automaticly cleared */
return 0;
}
+8 -9
View File
@@ -3,18 +3,18 @@
#include "m-algo.h"
#include "m-string.h"
/* Define a dictionnary (or hash_map or undordered_map)
/* Define a dictionnary (or hash_map or unordered_map)
* from a string_t to int */
DICT_DEF2(dict, string_t, int)
/* Register the oplist of this dictionnary globally */
#define M_OPL_dict_t() DICT_OPLIST(dict, STRING_OPLIST, M_DEFAULT_OPLIST)
#define M_OPL_dict_t() DICT_OPLIST(dict, STRING_OPLIST, M_BASIC_OPLIST)
/* Define an array of integer */
ARRAY_DEF(vector_int, int)
/* Register the oplist of this array of integer globally */
#define M_OPL_vector_int_t() ARRAY_OPLIST(vector_int)
/* Micro macro to detect if a string starts with the given pattern */
/* Micro macro to detect if the key string starts with the given pattern */
#define start_with(pattern, item) \
string_start_with_str_p((item).key, (pattern))
@@ -23,14 +23,13 @@ ARRAY_DEF(vector_int, int)
int main(void)
{
int s;
int s = 0;
// Init keys as a vector_int_t, initialize it (and prepare its destruction)
M_LET(keys, vector_int_t)
// Initialize m as a dictionnary and initialize it with the given database
// Initialize tmp as a dictionanry
M_LET( (m, (STRING_CTE("foo"), 1), (STRING_CTE("bar"), 42), (STRING_CTE("bluez"), 7), (STRING_CTE("stop"), 789) ), tmp, dict_t) {
/* Extract all elements of 'm' that starts with 'b' */
// Initialize m as a dictionnary and initialize it with the given database
// Initialize tmp as a dictionnary
M_LET( (m, (STRING_CTE("foo"), 1), (STRING_CTE("bar"), 42), (STRING_CTE("bluez"), 7), (STRING_CTE("stop"), 789) ), tmp, dict_t) {
/* Extract all elements of 'm' that starts with 'b' and fills tmp with it */
ALGO_EXTRACT(tmp, dict_t, m, dict_t, start_with, "b");
/* Extract the values of theses elements */
ALGO_TRANSFORM(keys, vector_int_t, tmp, dict_t, get_value);
+12 -9
View File
@@ -7,28 +7,31 @@ ARRAY_DEF(vector_int, int)
/* Register the oplist of this array of int globally */
#define M_OPL_vector_int_t() ARRAY_OPLIST(vector_int)
/* Set s (string_t) to the integer i */
#define str_ui(s, i) string_printf(s, "%d", i)
/* Concat two strings by insertion a '-' within them */
#define str_cat(s1, s2) (string_cat_str(s1, "-"), string_cat(s1, s2))
int main(void)
{
// Let s be a string_t and initilize it.
// Let 's' be a string_t and initialize it.
M_LET(s, string_t)
// Let v be a vector of integer and initialize it.
M_LET( (v, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), vector_int_t) {
int sum, product;
// Let 'v' be a vector of integer and initialize it.
M_LET( (v, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), vector_int_t) {
int sum = 0, product = 0;
// Compute the sum of theses integers.
// 'add' is a registered keyword, recognized by M*LIB to perform a sum.
ALGO_REDUCE(sum, v, vector_int_t, add);
// Compute the product of theses integers.
// 'mul' is a registered keyword, recognized by M*LIB to perform a product.
ALGO_REDUCE(product, v, vector_int_t, mul);
/* Example of reduction with a transformation of the type from int to string_t */
ALGO_REDUCE( (s, string_t), v, vector_int_t, str_cat, str_ui);
/* Example of reduction with a transformation of the type from int to string_t
By default, the result ("s") should be of the same type as the base type
of the container. This is not the case here, we want to transform the
type. As such, we add the precision of the type 'string_t' to 's'.
The transformation from string to integer is done by string_set_si */
ALGO_REDUCE( (s, string_t), v, vector_int_t, str_cat, string_set_si);
printf ("sum: %d\n"
"product: %d\n"
+109
View File
@@ -0,0 +1,109 @@
#include <stdio.h>
#include <stdlib.h>
////////////////////////////////////////////////////////////
static size_t allocated_size = 0;
static void* my_alloc(size_t s)
{
printf("Alloc called s=%lu!\n", s);
allocated_size += s;
return malloc(s);
}
static void my_free(void *ptr, size_t s)
{
printf("Free called s=%lu!\n", s);
allocated_size -= s;
free(ptr);
}
////////////////////////////////////////////////////////////
static void *last_alloc;
static void* my_array_alloc(size_t s, void *org, size_t n)
{
printf("Array Alloc called org=%p of n=%zu elements of size s=%lu!\n", org, n, s);
last_alloc = realloc(org, s*n);
return last_alloc;
}
static void my_array_free(void *ptr)
{
printf("Array Free called ptr=%p last_alloc=%p!\n", ptr, last_alloc);
if (ptr != last_alloc) {
printf("Somthing went wrong.\n");
exit(4);
}
free(ptr);
}
////////////////////////////////////////////////////////////
// Allocate for single object
# define M_MEMORY_ALLOC(ctx, type) my_alloc (sizeof (type))
# define M_MEMORY_DEL(ctx, ptr) my_free(ptr, sizeof *ptr)
// Allocate for array of objects
# define M_MEMORY_REALLOC(ctx, type, ptr, o, n) my_array_alloc (sizeof (type), ptr, n)
# define M_MEMORY_FREE(ctx, type, ptr, n) my_array_free(ptr)
#include "m-list.h"
#include "m-array.h"
////////////////////////////////////////////////////////////
LIST_DEF(list_int, int)
static void test_list(void)
{
printf("List demo\n");
list_int_t list;
list_int_init(list);
list_int_push_back(list, 34);
list_int_push_back(list, 34);
if (allocated_size == 0) {
printf("Nothing was allocated... Very strange...\n");
exit(1);
}
list_int_clear(list);
if (allocated_size != 0) {
printf("Nothing was freed (%lu)... Very strange...\n", allocated_size);
exit(2);
}
printf("Global custom allocator for list works!\n");
}
////////////////////////////////////////////////////////////
ARRAY_DEF(array_int, int)
static void test_array(void)
{
printf("Array demo\n");
array_int_t array;
array_int_init(array);
array_int_push_back(array, 34);
array_int_push_back(array, 34);
array_int_clear(array);
printf("Global custom allocator for array works!\n");
}
////////////////////////////////////////////////////////////
int main(void)
{
test_list();
test_array();
exit(0);
}
+109
View File
@@ -0,0 +1,109 @@
#include <stdio.h>
#include <stdlib.h>
#include "m-list.h"
#include "m-array.h"
////////////////////////////////////////////////////////////
static size_t allocated_size = 0;
static void* my_alloc(size_t s)
{
printf("Alloc called s=%lu!\n", s);
allocated_size += s;
return malloc(s);
}
static void my_free(void *ptr, size_t s)
{
printf("Free called s=%lu!\n", s);
allocated_size -= s;
free(ptr);
}
// Allocate for single object
# define MY_MEMORY_ALLOC(ctx, type) my_alloc (sizeof (type))
# define MY_MEMORY_DEL(ctx, ptr) my_free(ptr, sizeof *ptr)
////////////////////////////////////////////////////////////
// Override only for this container the memory allocation function
LIST_DEF(list_int, int, M_OPEXTEND(M_BASIC_OPLIST, NEW(MY_MEMORY_ALLOC), DEL(MY_MEMORY_DEL)))
static void test_list(void)
{
printf("List demo\n");
list_int_t list;
list_int_init(list);
list_int_push_back(list, 34);
list_int_push_back(list, 34);
if (allocated_size == 0) {
printf("Nothing was allocated... Very strange...\n");
exit(1);
}
list_int_clear(list);
if (allocated_size != 0) {
printf("Nothing was freed (%lu)... Very strange...\n", allocated_size);
exit(2);
}
printf("Global custom allocator for list works!\n");
}
////////////////////////////////////////////////////////////
static void *last_alloc;
static void* my_array_alloc(size_t s, void *org, size_t n)
{
printf("Array Alloc called org=%p of n=%zu elements of size s=%lu!\n", org, n, s);
last_alloc = realloc(org, s*n);
return last_alloc;
}
static void my_array_free(void *ptr)
{
printf("Array Free called ptr=%p last_alloc=%p!\n", ptr, last_alloc);
if (ptr != last_alloc) {
printf("Somthing went wrong.\n");
exit(4);
}
free(ptr);
}
// Allocate for array of objects
# define MY_MEMORY_REALLOC(ctx, type, ptr, o, n) my_array_alloc (sizeof (type), ptr, n)
# define MY_MEMORY_FREE(ctx, type, ptr, n) my_array_free(ptr)
////////////////////////////////////////////////////////////
// Override only for this container the memory allocation function
ARRAY_DEF(array_int, int, M_OPEXTEND(M_BASIC_OPLIST, REALLOC(MY_MEMORY_REALLOC), FREE(MY_MEMORY_FREE)))
static void test_array(void)
{
printf("Array demo\n");
array_int_t array;
array_int_init(array);
array_int_push_back(array, 34);
array_int_push_back(array, 34);
array_int_clear(array);
printf("Global custom allocator for array works!\n");
}
////////////////////////////////////////////////////////////
int main(void)
{
test_list();
test_array();
exit(0);
}
+27 -17
View File
@@ -24,7 +24,8 @@
/* Generate prototypes and inline functions
for basic types.
For integer and floats, there is no need to specify
an oplist. M_DEFAULT_OPLIST will be used.
an oplist. M_BASIC_OPLIST will be used.
For bool, M_BOOL_OPLIST will be used.
*/
ARRAY_DEF(r_bool, bool)
@@ -105,7 +106,7 @@ test_int(int n)
But with an explicit oplist.
This generates exactly the same code than r_int
*/
ARRAY_DEF(r_int2, signed int, M_DEFAULT_OPLIST)
ARRAY_DEF(r_int2, signed int, M_BASIC_OPLIST)
static int
test_int2(int n)
@@ -180,7 +181,7 @@ test_float(int n)
/* Same with type double and an explicit oplist*/
ARRAY_DEF(r_double, double, M_DEFAULT_OPLIST)
ARRAY_DEF(r_double, double, M_BASIC_OPLIST)
static int
test_double(int n)
@@ -214,9 +215,9 @@ static char *my_strdup(const char *p)
return d;
}
/* Same with type const char *, representing a contant string.
/* Same with type const char *, representing a contant C string.
We *** need *** an explicit oplist to tell M*LIB
to consider the type as a constant string.
to consider the type as a constant C string.
The oplist to use is M_CSTR_OPLIST.
We could have used M_PTR_OPLIST too,
but in this case, we won't get proper string order or
@@ -231,7 +232,7 @@ test_cstring(int n)
r_cstring_init(array);
for(int i = 0; i < n; i++) {
char buffer[10];
char buffer[16];
// Create a string from the integer
sprintf(buffer, "%d", i);
// We need to make an explicit copy of the string
@@ -245,13 +246,13 @@ test_cstring(int n)
for(int i = 0; i < n; i++) {
// Get back the string
const char *p = *r_cstring_get(array, i);
// Convert it to integer
// Convert it to an integer
int j = atoi(p);
s += j;
}
// We also need a special unalloc pass
// to free all constant strings we have allocated.
// to free all constant strings we have allocated using my_strdup
for(int i = 0; i < n; i++) {
const char *p = *r_cstring_get(array, i);
free((void*)(uintptr_t)p);
@@ -264,7 +265,7 @@ test_cstring(int n)
/* Same with type string_t of M*LIB, representing a variable string.
/* Same with type string_t of M*LIB, representing a dynamic string.
We don't need explicit oplist to tell M*LIB!
The oplist to use is STRING_OPLIST,
but it has been registered globaly, so we don't need to explicit
@@ -282,7 +283,7 @@ test_string(int n)
for(int i = 0; i < n; i++) {
// create a string from an integer
string_printf(str, "%d", i);
string_set_si(str, i);
// No need to make a copy in the container!
r_string_push_back(array, str);
}
@@ -294,7 +295,7 @@ test_string(int n)
s += j;
}
// No need to explicit dealloc !
// No need to explicit free each term of the array
string_clear(str);
r_string_clear(array);
@@ -304,7 +305,7 @@ test_string(int n)
/* Same with type string_t of M*LIB, representing a variable string
and its explicit oplist. And said above, it generates exactly the
and its explicit oplist. As said above, it generates exactly the
same code. */
ARRAY_DEF(r_string2, string_t, STRING_OPLIST)
@@ -340,6 +341,9 @@ test_vintptr(int n)
int s = 0;
for(int i = 0; i < n; i++) {
// Get the pointer to the integer.
// As the basic type of the container is a pointer,
// and r_vintptr_get return a pointer to the basic type
// we need to dereference its return value to get the pointer value.
volatile unsigned *p = *r_vintptr_get(array, i);
s += *p;
}
@@ -374,6 +378,7 @@ test_rockme(int n)
for(int i = 0; i < n; i++) {
struct rock_me_out rock;
rock.n = i*i - i;
rock.other = 0.0f;
// Push the struct in the array
r_rockme_push_back(array, rock);
}
@@ -414,6 +419,7 @@ test_rockme2(int n)
for(int i = 0; i < n; i++) {
rock_me_in rock;
rock->n = i*i - i;
rock->other = 0.0f;
r_rockme2_push_back(array, rock);
}
@@ -458,6 +464,7 @@ test_rockme2b(int n)
for(int i = 0; i < n; i++) {
rock_me_in rock;
rock->n = i*i - i;
rock->other = 0.0f;
r_rockme2b_push_back(array, rock);
}
@@ -478,15 +485,18 @@ test_rockme2b(int n)
/* Same with a structure type defined as a tuple.
We first define a tuple. No need to specify the oplist as it uses basic C types
so M_DEFAULT_OPLIST is used.
so M_BASIC_OPLIST is used by default.
Then we define the array, giving it the oplist definition of the tuple:
the macro TUPLE_OPLIST is used to build it based on the tuple name,
and the oplists of the tuple.
The main advantage of a tuple over a classic structure is that you get
free classic methods of your structure.
*/
TUPLE_DEF2(rock_you, (n, int), (other, float))
ARRAY_DEF(r_rockme3, rock_you_t, TUPLE_OPLIST(rock_you, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST))
ARRAY_DEF(r_rockme3, rock_you_t, TUPLE_OPLIST(rock_you, M_BASIC_OPLIST, M_BASIC_OPLIST))
static int
test_rockme3(int n)
@@ -520,7 +530,7 @@ test_rockme3(int n)
/* Same with a structure type defined as a tuple using global registeration.
We first define a tuple. No need to specify the oplist as it uses basic C types
so M_DEFAULT_OPLIST is used.
so M_BASIC_OPLIST is used.
Then we register the oplist of rock_us_t by defining a macro based
on M_OPL_ + type name + () which expands with the oplist of the type.
@@ -533,7 +543,7 @@ test_rockme3(int n)
*/
TUPLE_DEF2(rock_us, (n, int), (other, float))
#define M_OPL_rock_us_t() TUPLE_OPLIST(rock_us, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
#define M_OPL_rock_us_t() TUPLE_OPLIST(rock_us, M_BASIC_OPLIST, M_BASIC_OPLIST)
ARRAY_DEF(r_rockme4, rock_us_t)
@@ -612,7 +622,7 @@ int main (int argc, const char *argv[])
s = test_rockme3(n);
printf ("S[rockme3] = %d\n", s);
s = test_rockme3(n);
s = test_rockme4(n);
printf ("S[rockme4] = %d\n", s);
exit(0);
+4 -2
View File
@@ -13,8 +13,10 @@ ALGO_DEF(array_mpz, ARRAY_OPLIST(array_mpz, M_CLASSIC_OPLIST(mpz)))
static inline void my_mpz_inc(mpz_t *d, const mpz_t a){
mpz_add(*d, *d, a);
}
static inline void my_mpz_sqr(mpz_t *d, const mpz_t a){
static inline bool my_mpz_sqr(mpz_t *d, const mpz_t a, void *data){
(void) data;
mpz_mul(*d, a, a);
return true;
}
int main(void)
@@ -31,7 +33,7 @@ int main(void)
}
/* Compute z = sum (a[i]^2) */
array_mpz_map_reduce (&z, a, my_mpz_inc, my_mpz_sqr);
array_mpz_transform_reduce (&z, a, my_mpz_inc, my_mpz_sqr, NULL);
gmp_printf ("Z=%Zd\n", z);
array_mpz_clear(a);
+1
View File
@@ -96,6 +96,7 @@ static void data_node_clear(data_node *obj)
and gives the minimum oplist allowing M*LIB to handle
properly the object 'data_node' with the API convention
to respect for calling the methods.
The Manual defines the different supported API.
*/
ARRAY_DEF(/* the array prefix */ array_data_node,
/* the object type */ data_node,
+119
View File
@@ -0,0 +1,119 @@
//
// -- An A* pathfinder inspired by the tutorial at Red Blob Games --
// https://www.redblobgames.com/pathfinding/a-star/introduction.html
// Code based on:
// https://github.com/glouw/ctl/blob/master/examples/astar.c
#include <stdio.h>
#include "m-array.h"
#include "m-string.h"
#include "m-tuple.h"
#include "m-prioqueue.h"
#include "m-dict.h"
// Create a tuple of point, but don't use its priority field for comparison.
TUPLE_DEF2( point, (x, int), (y, int), (priority, int, M_OPEXTEND( M_OPL_int(), CMP(0), HASH(0), EQUAL(0) ) ) )
#define M_OPL_point_t() TUPLE_OPLIST(point, M_OPL_int(), M_OPL_int(), M_OPL_int())
static inline int point_cmp_prio(const point_t a, const point_t b)
{
return a->priority < b->priority ? -1 : a->priority > b->priority;
}
PRIOQUEUE_DEF(prio_point, point_t, M_OPEXTEND(M_OPL_point_t(), CMP(point_cmp_prio) ) )
#define M_OPL_prio_point_t() PRIOQUEUE_OPLIST(prio_point, M_OPL_point_t() )
ARRAY_DEF(array_point, point_t)
#define M_OPL_array_point_t() ARRAY_OPLIST(array_point, M_OPL_point_t() )
DICT_DEF2(cost_point, point_t, int)
#define M_OPL_cost_point_t() DICT_OPLIST(cost_point, M_OPL_point_t(), M_OPL_int())
DICT_DEF2(step_point, point_t, point_t)
#define M_OPL_step_point_t() DICT_OPLIST(step_point, M_OPL_point_t(), M_OPL_point_t())
static inline int point_index(const point_t p, int width)
{
return p->x + width * p->y;
}
static inline void point_set_from(point_t p, const string_t maze, int width, const char pattern[])
{
size_t s = string_search_str(maze, pattern);
point_emplace(p, s % width, s / width , 0);
}
static void astar(array_point_t path, const string_t maze, int width)
{
M_LET(front, prio_point_t)
M_LET(from, step_point_t)
M_LET(costs, cost_point_t)
M_LET(start, goal, current, next, point_t)
{
point_set_from(start, maze, width, "@");
point_set_from(goal, maze, width, "!");
cost_point_set_at(costs, start, 0);
prio_point_push(front, start);
while (!prio_point_empty_p(front)) {
prio_point_pop(&current, front);
if (point_equal_p(current, goal))
break;
const struct { int x; int y; } deltas[] = {
{ -1, +1 }, { 0, +1 }, { 1, +1 },
{ -1, 0 }, /* ~ ~ */ { 1, 0 },
{ -1, -1 }, { 0, -1 }, { 1, -1 },
};
for (size_t i = 0; i < 8; i++) {
point_emplace(next, current->x + deltas[i].x, current->y + deltas[i].y, 0);
if (string_get_char(maze, point_index(next, width)) != '#') {
int new_cost = *cost_point_get(costs, current);
int *cost = cost_point_get(costs, next);
if (cost == NULL || new_cost < *cost) {
cost_point_set_at(costs, next, new_cost);
next->priority = new_cost + abs(goal->x - next->x) + abs(goal->y - next->y);
prio_point_push(front, next);
step_point_set_at(from, next, current);
}
}
}
}
point_set(current, goal);
while (!point_equal_p(current, start)) {
array_point_push_back(path, current);
point_set(current, *step_point_get(from, current));
}
array_point_push_back(path, start);
}
}
int main(void)
{
M_LET( (maze,
("#########################################################################\n"
"# # # # # # #\n"
"# # ######### # ##### ######### ##### ##### ##### # ! #\n"
"# # # # # # # # # #\n"
"######### # ######### ######### ##### # # # ######### #\n"
"# # # # # # # # # # #\n"
"# # ############# # # ######### ##### # ######### # #\n"
"# # # # # # # # # #\n"
"# ############# ##### ##### # ##### ######### # ##### #\n"
"# # # # # # # # # #\n"
"# ##### ##### # ##### # ######### # # # #############\n"
"# # # # # # # # # # # #\n"
"############# # # # ######### # ##### # ##### ##### #\n"
"# # # # # # # # # #\n"
"# ##### # ######### ##### # ##### ##### ############# #\n"
"# # # # # # # # # #\n"
"# # ######### # ##### ######### # # ############# # #\n"
"# # # # # # # # # # #\n"
"# ######### # # # ##### ######### ######### # #########\n"
"# # # # # # # # # #\n"
"# @ # ##### ##### ##### ######### ##### # ######### # #\n"
"# # # # # # #\n"
"#########################################################################\n")), string_t)
M_LET(path, array_point_t)
{
int width = string_search_str(maze, "\n") + 1;
astar(path, maze, width);
for M_EACH(it, path, array_point_t) {
string_set_char(maze, point_index(*it, width), 'x');
}
printf("%s", string_get_cstr(maze));
}
}
+9 -4
View File
@@ -5,13 +5,13 @@
// The number 5 is the number of elements in a node of the B+TREE
BPTREE_DEF2(map_employee_id, 5, int, string_t)
// Register the oplist of this map globally.
#define M_OPL_map_employee_id_t() BPTREE_OPLIST2(map_employee_id, M_DEFAULT_OPLIST, STRING_OPLIST)
#define M_OPL_map_employee_id_t() BPTREE_OPLIST2(map_employee_id, M_BASIC_OPLIST, STRING_OPLIST)
// Define a map string -> int named map_employee_name
// The number 5 is the number of elements in a node of the B+TREE
BPTREE_DEF2(map_employee_name, 5, string_t, int)
// Register the oplist of this map globally.
#define M_OPL_map_employee_name_t() BPTREE_OPLIST2(map_employee_name, STRING_OPLIST, M_DEFAULT_OPLIST)
#define M_OPL_map_employee_name_t() BPTREE_OPLIST2(map_employee_name, STRING_OPLIST, M_BASIC_OPLIST)
int main(void)
{
@@ -25,7 +25,9 @@ int main(void)
map_employee_id_set_at(Employees, 11632, STRING_CTE("John Do"));
map_employee_id_set_at(Employees, 852, STRING_CTE("Peter"));
map_employee_id_set_at(Employees, 530, STRING_CTE("Amanda"));
map_employee_id_set_at(Employees, 4258, STRING_CTE("Elisabeth"));
// You can also emplace the structure
map_employee_id_emplace_val(Employees, 4258, "Elisabeth");
printf("Number of employees: %zu\n", map_employee_id_size(Employees));
@@ -57,9 +59,12 @@ int main(void)
}
// Print
printf("\nElisabeth has id = %d\n", *map_employee_name_get(Employees_r, STRING_CTE("Elisabeth")));
printf("\nElisabeth has id = %d\n", *map_employee_name_get(Employees_r, STRING_CTE("Elisabeth")));
// Print using emplace (we give a const char [] isntead of a const string_t, avoiding macro STRING_CTE)
printf("\nElisabeth has id = %d\n", *map_employee_name_get_emplace(Employees_r, "Elisabeth"));
} /* Employees_r is cleared beyond this point */
// But employee is not since we don't use M_LET
map_employee_id_clear(Employees);
return 0;
}
+55
View File
@@ -0,0 +1,55 @@
#include <stdlib.h>
#include "m-bptree.h"
BPTREE_MULTI_DEF2(multimap, 5, int, M_BASIC_OPLIST, int, M_BASIC_OPLIST)
#define M_OPL_map_multimap_t() BPTREE_OPLIST2(multimap, M_BASIC_OPLIST, M_BASIC_OPLIST)
// Fill in with multiple value
static void
fill_in(multimap_t map)
{
for(int i = 1 ; i < 100; i++)
multimap_set_at(map, i, i);
for(int i = 1 ; i < 100; i+=2)
multimap_set_at(map, i, i*i);
for(int i = 1 ; i < 100; i+=3)
multimap_set_at(map, i, i*i*i);
}
// Count the number of occurence of a key
static int
count(multimap_t map, int key)
{
int n = 0;
multimap_it_t it;
// it_from is O(n*ln n) complexity
// it_while_p and next are O(1) complexity
for(multimap_it_from(it, map, key); multimap_it_while_p(it, key); multimap_next(it))
n++;
return n;
}
// Print the map in details
static void
print(multimap_t map)
{
for(int i = 0; i < 101;i++) {
printf("Key=%d Count=%d ", i, count(map, i));
multimap_it_t it;
for(multimap_it_from(it, map, i); multimap_it_while_p(it, i); multimap_next(it)) {
printf("Value=%d ", *multimap_ref(it)->value_ptr );
}
printf("\n");
}
}
int main(void)
{
multimap_t map;
multimap_init(map);
fill_in(map);
print(map);
multimap_clear(map);
exit(0);
}
+8 -9
View File
@@ -1,8 +1,8 @@
#include <stdio.h>
#include "m-buffer.h"
#include "m-shared.h"
#include "m-mutex.h"
#include "m-shared-ptr.h"
#include "m-thread.h"
/* Global variable to stop scheduling */
atomic_bool continue_threading_g;
@@ -99,8 +99,8 @@ SHARED_PTR_DEF(shared_bigdata, bigdata_t)
* - we change the semantics of _push / _pop into buffer as push a new item and pop it as a move (ideal semantics for shared_ptr interface).
*/
#define MY_QUEUE_SIZE 10
BUFFER_DEF(buffer_bigdata, shared_bigdata_t, MY_QUEUE_SIZE,
BUFFER_QUEUE|BUFFER_PUSH_INIT_POP_MOVE, SHARED_PTR_OPLIST(shared_bigdata))
BUFFER_DEF(buffer_bigdata, shared_bigdata_t *, MY_QUEUE_SIZE,
BUFFER_QUEUE|BUFFER_PUSH_INIT_POP_MOVE, SHARED_PTR_OPLIST(shared_bigdata, M_OPL_bigdata_t()))
/* Let's build a Thread synchros tree:
*
@@ -134,8 +134,7 @@ static void thread1 (void *arg)
{
(void) arg;
while (atomic_load(&continue_threading_g)) {
shared_bigdata_t ptr;
shared_bigdata_init_new (ptr);
shared_bigdata_t *ptr = shared_bigdata_new ();
perform_acquisition(*shared_bigdata_ref(ptr));
buffer_bigdata_push(buf_t1tot2, ptr);
buffer_bigdata_push(buf_t1tot3, ptr);
@@ -146,7 +145,7 @@ static void thread2 (void *arg)
{
(void) arg;
while (atomic_load(&continue_threading_g)) {
shared_bigdata_t ptr;
shared_bigdata_t *ptr;
buffer_bigdata_pop(&ptr, buf_t1tot2); // NOTE: Pop has been configured to init ptr
perform_computation2(*shared_bigdata_ref(ptr));
shared_bigdata_clear(ptr);
@@ -156,7 +155,7 @@ static void thread3 (void *arg)
{
(void) arg;
while (atomic_load(&continue_threading_g)) {
shared_bigdata_t ptr;
shared_bigdata_t *ptr;
buffer_bigdata_pop(&ptr, buf_t1tot3); // NOTE: Pop has been configured to init ptr
perform_computation3(*shared_bigdata_ref(ptr));
buffer_bigdata_push(buf_t3tot4, ptr);
@@ -167,7 +166,7 @@ static void thread4 (void *arg)
{
(void) arg;
while (atomic_load(&continue_threading_g)) {
shared_bigdata_t ptr;
shared_bigdata_t *ptr;
buffer_bigdata_pop(&ptr, buf_t3tot4); // NOTE: Pop has been configured to init ptr
perform_computation4(*shared_bigdata_ref(ptr));
shared_bigdata_clear(ptr);
+160
View File
@@ -0,0 +1,160 @@
#if HAVE_CURL
#include <curl/curl.h>
#include "m-dict.h"
#include "m-tuple.h"
#include "m-string.h"
#include "m-list.h"
#include "m-serial-json.h"
/////////////////////////////////////////
// Define container types
// First a generic map string to string
DICT_DEF2(map_str, string_t, string_t)
#define M_OPL_map_str_t() DICT_OPLIST(map_str, STRING_OPLIST, STRING_OPLIST)
// This structure matches the JSON structure returns by the used WEB server
// for the GET command.
// It can be whatever you want provided it matches what is expected by the WEB server
TUPLE_DEF2(web_data,
(args, map_str_t),
(headers, map_str_t),
(origin, string_t),
(url, string_t))
#define M_OPL_web_data_t() TUPLE_OPLIST(web_data, M_OPL_map_str_t(), M_OPL_map_str_t(), STRING_T, STRING_T)
/////////////////////////////////////////
static size_t
write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
(void) size; // Parameter not used
char *src = buffer;
string_ptr str = userp;
for(size_t i = 0; i < nmemb; i++) {
string_push_back(str, src[i]);
}
return nmemb;
}
static bool get_data(web_data_t data, const char url[])
{
m_serial_return_code_t r = M_SERIAL_FAIL;
CURLcode res;
string_t str;
CURL *handle = curl_easy_init();
if (handle) {
string_init(str);
// Perform an http GET request and fill in str with the JSON answer
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, str);
res = curl_easy_perform(handle);
curl_easy_cleanup(handle);
if (res == CURLE_OK) {
// Parse the string and fill in the object
m_serial_str_json_read_t serial;
m_serial_str_json_read_init(serial, string_get_cstr(str));
r = web_data_in_serial(data, serial);
m_serial_str_json_read_clear(serial);
}
string_clear(str);
}
return r == M_SERIAL_OK_DONE;
}
/////////////////////////////////////////
static size_t
ignore_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
(void) buffer; // Parameter not used
(void) size; // Parameter not used
(void) userp; // Parameter not used
return nmemb;
}
static bool post_data(web_data_t data, const char url[], bool display_answer)
{
m_serial_return_code_t r = M_SERIAL_FAIL;
CURLcode res = 0;
string_t str;
CURL *handle = curl_easy_init();
if (handle) {
string_init(str);
// Get a JSON string
m_serial_str_json_write_t serial;
m_serial_str_json_write_init(serial, str);
r = web_data_out_serial(serial, data);
m_serial_str_json_write_clear(serial);
if (r == M_SERIAL_OK_DONE) {
// Post JSON string
struct curl_slist *headers=NULL;
headers = curl_slist_append(headers, "Content-Type: text/json");
if (headers != NULL) {
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, string_get_cstr(str));
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
if (display_answer == false) {
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ignore_data);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
}
res = curl_easy_perform(handle);
curl_slist_free_all(headers);
}
}
curl_easy_cleanup(handle);
string_clear(str);
}
return (r == M_SERIAL_OK_DONE) && (res == CURLE_OK);
}
/////////////////////////////////////////
// Remote server URL
#define URL_GET "https://httpbin.org/get"
#define URL_POST "https://httpbin.org/post"
int main(void)
{
CURLcode ret = curl_global_init(CURL_GLOBAL_DEFAULT);
if (ret != CURLE_OK) abort();
web_data_t data;
web_data_init(data);
// Test http GET
bool b = get_data(data, URL_GET);
if (b) {
// We success receiving the JSON object and fill in the C object web_data with it.
// Let's display the object content:
printf("SUCCESS. Receive data =\n");
web_data_out_str(stdout, data);
printf("\n");
} else {
printf("ERROR: Cannot GET data or get data are not in expected format\n");
}
// Test http POST
web_data_emplace_origin(data, "This is the origin");
web_data_emplace_url(data, "This is the URL");
//web_data_set_origin(data, STRING_CTE("This is the origin"));
//web_data_set_url(data, STRING_CTE("This is the URL"));
b = post_data(data, URL_POST, false);
if (b) {
printf("SUCCESS: Post\n");
} else {
printf("ERROR post\n");
}
web_data_clear(data);
curl_global_cleanup();
return 0;
}
#else
int main(void) { return 0; }
#endif
+5
View File
@@ -1,5 +1,10 @@
#include "m-core.h"
/* This example show how to use the M_LET_IF macro
that enables to construct an object and continue
if the construction succeeds.
*/
// Stubs defined for the example. Real code will use soundio library.
struct SoundIo { int x; };
struct SoundIoDevice { int x; };
+12 -11
View File
@@ -4,44 +4,45 @@
#include "m-dict.h"
#include "m-string.h"
// Define a dictionnary of string --> int
// Define a dictionary of string --> int
// named 'dict_str'
DICT_DEF2(dict_str, string_t, STRING_OPLIST, int, M_DEFAULT_OPLIST)
DICT_DEF2(dict_str, string_t, STRING_OPLIST, int, M_BASIC_OPLIST)
int main(void)
{
// Declare the dictionnary 'h'
// Declare the dictionary 'h'
dict_str_t h;
int max = 1;
// Declare the string 'key'
string_t key;
// Initialize the dictionnary & the string
// Initialize the dictionary & the string
dict_str_init(h);
string_init (key);
// While there is some data in the stream
while (!feof(stdin))
while (true)
{
// Read a complete line from the stream and fill in the string 'key'
string_fgets (key, stdin, STRING_READ_PURE_LINE);
// If the 'key' exists in the dictionnary
if (feof(stdin)) break;
// If the 'key' exists in the dictionary
int *v = dict_str_get (h, key);
if (v != NULL) {
// Increment the counter in the dictionnary
// Increment the counter in the dictionary
(*v)++;
max = M_MAX(*v, max);
} else {
// Update the dictionnary with h[key] = 1
// Update the dictionary with h[key] = 1
dict_str_set_at(h, key, 1);
}
}
printf ("Max occurence = %d\n", max);
printf ("Max occurrence = %d\n", max);
// Iterate on the dictionnary
// Iterate on the dictionary
dict_str_it_t it;
for(dict_str_it(it, h); !dict_str_end_p(it); dict_str_next(it)) {
// Get a constant reference on the pair stored in the dictionnary
// Get a constant reference on the pair stored in the dictionary
const struct dict_str_pair_s *pair = dict_str_cref(it);
printf ("Key=%s Value=%d\n",
string_get_cstr(pair->key), pair->value);
+3 -3
View File
@@ -1,10 +1,10 @@
#include "m-dict.h"
// Let's define a dictionary of 'unsigned int' --> 'char
DICT_DEF2(dict_m32, unsigned int, M_DEFAULT_OPLIST, char, M_DEFAULT_OPLIST)
DICT_DEF2(dict_m32, unsigned int, M_BASIC_OPLIST, char, M_BASIC_OPLIST)
// Let's create a synonym for its oplist.
#define M32_OPLIST DICT_OPLIST(dict_m32, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
#define M32_OPLIST DICT_OPLIST(dict_m32, M_BASIC_OPLIST, M_BASIC_OPLIST)
#if 1 // Non macro version.
@@ -14,7 +14,7 @@ int main(void) {
dict_m32_set_at (h, 5, 10); // h[5] = 10
char *k = dict_m32_get(h, 10); // No 10 in h, so k == NULL
int is_missing = (k != NULL); // true
assert (is_missing);
assert (is_missing); (void) is_missing;
dict_m32_erase(h, 5); // h is now empty
dict_m32_it_t it; // iterate over all dictionnary
for (dict_m32_it (it, h) ; !dict_m32_end_p (it); dict_m32_next(it)) {
+56
View File
@@ -0,0 +1,56 @@
#include <stdio.h>
#include "m-dict.h"
/*
* Provide OOR methods for OA Hashmap.
* See documentation for definition of OOR
* OOR values are represented as:
* empty (0) is INT_MIN
* deleted (1) is INT_MIN + 1
* So valid range for integers are [INT_MIN+2, INT_MAX]
*/
static inline bool oor_equal_p(int k, char n)
{
return k == INT_MIN + n;
}
static inline int oor_set(char n)
{
return INT_MIN + n;
}
/*
* Provide a custom hash function (optional for OA)
*/
static inline size_t hash(int n)
{
return (size_t) n; // Identity hash!
}
/* Define an OA dictionnay which performs a hashmap between an int to an int */
DICT_OA_DEF2(dict_oa,
int, M_OPEXTEND(M_BASIC_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(API_4(oor_set)), HASH(hash)),
int, M_BASIC_OPLIST)
int main(void)
{
dict_oa_t d;
dict_oa_init(d);
for(int i = 0; i < 10; i++) {
dict_oa_set_at(d, i*i, 4*i);
}
dict_oa_set_at(d, 3, -17);
printf("DICT[3] = %d\n", *dict_oa_get(d, 3));
dict_oa_it_t it;
printf("DICT=");
for(dict_oa_it(it, d); !dict_oa_end_p(it); dict_oa_next(it)) {
printf("%d:%d, ", dict_oa_cref(it)->key, dict_oa_cref(it)->value);
}
printf("\n");
dict_oa_clear(d);
return 0;
}
+64
View File
@@ -0,0 +1,64 @@
#include <stdio.h>
#include "m-dict.h"
/*
* Provide OOR methods for OA Hashmap.
* See documentation for definition of OOR
* OOR values are represented as:
* empty (0) is "EMPTY"
* deleted (1) is "DELETED"
*/
static const char empty_str[] = "EMPTY";
static const char deleted_str[] = "DELETED";
static const char *const oor_table[] = { empty_str, deleted_str };
static inline bool oor_equal_p(const char *k, int n)
{
return k == oor_table[n];
}
static inline const char *oor_set(int n)
{
return oor_table[n];
}
/*
* Provide a custom hash function (optional for OA)
*/
static inline size_t hash(const char *k)
{
size_t r = 17;
while (*k) {
r = *k * 33 + r;
k++;
}
return r;
}
/* Define an OA dictionnay which performs a hashmap between a CSTR to an int */
DICT_OA_DEF2(dict_oa,
const char *, M_OPEXTEND(M_CSTR_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(API_4(oor_set)), HASH(hash)),
int, M_BASIC_OPLIST)
int main(void)
{
dict_oa_t d;
dict_oa_init(d);
dict_oa_set_at(d, "THIS", -17);
dict_oa_set_at(d, "IS", -170);
dict_oa_set_at(d, "AN", 7);
dict_oa_set_at(d, "EXAMPLE", 77);
printf("DICT[\"AN\"] = %d\n", *dict_oa_get(d, "AN"));
dict_oa_it_t it;
printf("DICT=");
for(dict_oa_it(it, d); !dict_oa_end_p(it); dict_oa_next(it)) {
printf("%s:%d, ", dict_oa_cref(it)->key, dict_oa_cref(it)->value);
}
printf("\n");
dict_oa_clear(d);
return 0;
}
+1 -1
View File
@@ -34,7 +34,7 @@ int main(int argc, const char *argv[])
// While it reads some word from the file
while (string_fget_word(word, " \t\n\r\"(),=", f)) {
// Get the reference to the array of this word in the dictionnary (or create it if needed)
array_size_t *array = map_pos_get_at(positions, word);
array_size_t *array = map_pos_safe_get(positions, word);
// Push the new offset to this word in the associated array
array_size_push_back(*array, (size_t)ftell(f) - string_size(word));
}
+56
View File
@@ -0,0 +1,56 @@
#include "m-i-list.h"
typedef struct data_s {
M_ILIST_INTERFACE(list1, struct data_s);
char *ptr;
int n;
} data_t;
static void
data_init(data_t *p)
{
M_ILIST_INIT_FIELD(list1, *p);
p->ptr = malloc(100);
p->n = 100;
}
static void
data_clear(data_t *p)
{
free(p->ptr);
p->n = 0;
}
static void
data_init_set(data_t *p, data_t s)
{
p->ptr = malloc(s.n);
p->n = s.n;
memcpy(p->ptr, s.ptr, s.n);
}
#define DATA_OP (INIT(API_2(data_init)), INIT_SET(API_2(data_init_set)), CLEAR(API_2(data_clear)) )
M_ILIST_DEF(list1, data_t, DATA_OP)
data_t pool[100];
int main(void)
{
list1_t l;
list1_init(l);
data_init(&pool[0]);
list1_push_back(l, &pool[0]);
data_init(&pool[1]);
list1_push_back(l, &pool[1]);
list1_it_t it;
list1_it(it, l);
data_init(&pool[2]);
list1_insert(l, it, &pool[2]);
list1_clear(l);
exit(0);
}
+58 -22
View File
@@ -8,43 +8,54 @@
#include "m-string.h"
#include "m-algo.h"
// Let's create a list of string.
// Let's create a list of string by using the M*LIB dynamic string 'string_t'
// The prefix used for generating functions will be 'list_string'
LIST_DEF(list_string, string_t)
// Let's register the oplist globally so that other m*lib macros
// Let's register the oplist globally so that other M*LIB macros
// can get the oplist without us giving it explictly to them.
// An oplist is the association of operators to the provided methods
// so that generic code can use correctly an object of such type.
// LIST_OPLIST is a macro used to generate the oplist associated to the
// list itself. It needs the prefix used for generating the list (aka list_string here)
// and the oplist of the item in the list (aka the string oplist)
#define M_OPL_list_string_t() LIST_OPLIST(list_string, STRING_OPLIST)
// Let's define some basic algorithms over this list of string.
ALGO_DEF(astring, M_OPL_list_string_t())
// We reuse the prefix of the list to simplify usage, but algorithms can use separate namespace.
ALGO_DEF(list_string, M_OPL_list_string_t())
int main(void)
{
// Let's create a variable named 'grow' which is a list of string_t
// Let's create a variable named 'list' which is a list of string_t
// This variable is only defined within the associated '{' '}' block.
// The constructor/destructor of the variable will be called within this block
// You can also define the variable (list_string_t) and use explicitly
// its constructor (list_string_init) / destructor (list_string_clear).
M_LET (grow, list_string_t)
M_LET (list, list_string_t)
M_LET (tmpstr, string_t) { // And let's create also a string_t
// add string elements to the list
list_string_push_back (grow, STRING_CTE("AB"));
// add string elements to the list in different ways
// First is pushing a const string.
// The macro STRING_CTE creates a const string_t based on the given const char * string.
list_string_push_back (list, STRING_CTE("AB"));
// Second is creating a separate string_t and then pushing it in the list
string_printf(tmpstr, "%d", 12);
list_string_push_back (grow, tmpstr);
list_string_push_back (grow, STRING_CTE("CD"));
list_string_push_back (list, tmpstr);
// Third is to emplace directly in the list by constructing a new string_t based on the given const char *
list_string_emplace_back (list, "CD");
// Serialize the list of string into a big string.
list_string_get_str (tmpstr, grow, false);
list_string_get_str (tmpstr, list, false);
// print out
printf("Number of elements = %zu\n", list_string_size(grow));
// print it
printf("Number of elements = %zu\n", list_string_size(list));
printf("Final string = %s\n", string_get_cstr(tmpstr));
// Let's iterate over each element of the list
// using the macro for iteration over a container.
printf ("Using macro EACH :\n");
for M_EACH (item, grow, list_string_t) {
printf ("Using macro EACH:\n");
for M_EACH (item, list, list_string_t) {
printf ("Item = ");
string_fputs (stdout, *item);
printf ("\n");
@@ -52,34 +63,59 @@ int main(void)
// You can also use classic iterator:
list_string_it_t it;
printf ("Using iterators :\n");
for(list_string_it(it, grow) ; !list_string_end_p(it) ; list_string_next(it)) {
printf ("Using iterators:\n");
for(list_string_it(it, list) ; !list_string_end_p(it) ; list_string_next(it)) {
const string_t *item = list_string_cref (it);
printf ("Item = ");
string_fputs (stdout, *item);
printf ("\n");
}
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
// Another way: we map each element to the M_PRINT function.
printf ("Using macro ALGO_FOR_EACH:");
ALGO_FOR_EACH(list, list_string_t, M_PRINT, "\nItem = ");
printf ("\n");
#endif
// Get the min and the max of the list
string_t *p = astring_min(grow);
string_t *p = list_string_min(list);
printf ("Min string is %s\n", string_get_cstr(*p));
p = astring_max(grow);
p = list_string_max(list);
printf ("Max string is %s\n", string_get_cstr(*p));
// We can even sort the list.
astring_sort(grow);
for M_EACH (item, grow, list_string_t) {
list_string_sort(list);
for M_EACH (item, list, list_string_t) {
printf ("Sort Item = %s\n", string_get_cstr(*item) );
}
// Split a string into a list.
string_set_str(tmpstr, "HELLO;JOHN;HOW;ARE;YOU");
astring_split(grow, tmpstr, ';');
for M_EACH (item, grow, list_string_t) {
list_string_split(list, tmpstr, ';');
// Iterate over the splitted list
for M_EACH (item, list, list_string_t) {
printf ("Split Item = %s\n", string_get_cstr(*item) );
}
} // Everything is cleared after this point.
// Let's create another list of string and init it.
list_string_t list;
list_string_init(list);
// Let's put some elements in it:
list_string_emplace_back (list, "A");
list_string_emplace_back (list, "B");
list_string_emplace_back (list, "C");
list_string_emplace_back (list, "D");
// Reverse it
list_string_reverse(list);
// Let's display the string by serializing the elements of the list:
printf ("List of string = ");
list_string_out_str(stdout, list);
printf ("\n");
// Don't forget to clear the list before leaving
list_string_clear(list);
return 0;
}
+8 -5
View File
@@ -25,8 +25,8 @@
/* Define the needed data structure : */
// Define a dictionnary of constant string --> integer and register it.
DICT_DEF2(dict_mph, const char *, M_CSTR_OPLIST, uint32_t, M_DEFAULT_OPLIST)
#define M_OPL_dict_mph_t() DICT_OPLIST(dict_mph, M_CSTR_OPLIST, M_DEFAULT_OPLIST)
DICT_DEF2(dict_mph, const char *, M_CSTR_OPLIST, uint32_t, M_BASIC_OPLIST)
#define M_OPL_dict_mph_t() DICT_OPLIST(dict_mph, M_CSTR_OPLIST, M_BASIC_OPLIST)
// Define an array of integer to store the value and register it.
ARRAY_DEF(array_value, uint32_t) // Start from 1. 0 is 'None'
@@ -124,7 +124,7 @@ CreateMinimalPerfectHash2(array_seed_t seed, array_value_t value,
enought. */
for(bool cont = true; cont ; ) {
cont = false;
array_seed_clean(slots);
array_seed_reset(slots);
for M_EACH(it, *b, array_cstr_t) {
size_t s = hash(d, *it) % size;
if (*array_value_get(value, s) != 0 || array_seed_contain_p(slots, s)){
@@ -208,11 +208,14 @@ dict_read_from_file(dict_mph_t dict, array_string_t arr, const char filename[])
// Not clean as items of 'dict' points are linked to items of 'arr'
// and the containers are not aware of this link.
array_string_push_back (arr, str);
dict_mph_set_at(dict, string_get_cstr(*array_string_back(arr)), line);
line++;
}
}
}
// Now 'arr' won't change anymore and we can get reliable pointers from it.
for M_EACH(item, arr, array_string_t) {
dict_mph_set_at(dict, string_get_cstr(*item), line);
line++;
}
fclose(f);
}
+2 -2
View File
@@ -48,8 +48,8 @@ static void program_init(program_t p, string_t text) {
int left;
array_int_pop_back(&left, leftstack);
int right = pc;
*array_int_get_at (p->bracket_map, left) = right;
*array_int_get_at (p->bracket_map, right) = left;
*array_int_safe_get (p->bracket_map, left) = right;
*array_int_safe_get (p->bracket_map, right) = left;
}
pc++;
-70
View File
@@ -1,70 +0,0 @@
#if HAVE_GMP
#include <stdio.h>
#include <gmp.h>
#include "m-variant.h"
#include "m-string.h"
#include "m-dict.h"
#include "m-array.h"
/* Define a variant over two integers named integer_t
Notice than mpz_t has special init & clear functions
mpz_init & mpz_clear.
This is handle by the library.
*/
VARIANT_DEF2(my_integer,
(n, long long, M_DEFAULT_OPLIST),
(z, mpz_t, M_CLASSIC_OPLIST(mpz)))
/* Define the oplist associated to this variant */
#define MY_INTEGER_OPLIST VARIANT_OPLIST(my_integer, M_DEFAULT_OPLIST, M_CLASSIC_OPLIST(mpz))
/* Define a dictionary of string --> integer named dict_my_t */
DICT_DEF2(my_dict,
string_t, STRING_OPLIST,
my_integer_t, MY_INTEGER_OPLIST)
/* Define the oplist associated to this dictionary */
#define MY_DICT_OPLIST DICT_OPLIST(my_dict, STRING_OPLIST, MY_INTEGER_OPLIST)
/* Define an array of such dictionary named array_my_t */
ARRAY_DEF(my_array, my_dict_t, MY_DICT_OPLIST)
/* Define the oplist associated to this array of dictionary of variant */
#define MY_ARRAY_OPLIST ARRAY_OPLIST(my_array, MY_DICT_OPLIST)
int main(void)
{
M_LET(z, MY_INTEGER_OPLIST) /* Define & init & clear an instance of a variant of integer */
M_LET(dict, MY_DICT_OPLIST) /* Define & init & clear an instance of a dictionary of variant */
M_LET(array, MY_ARRAY_OPLIST) /* Define & init & clear an intance of an array of dictionary of variant */
M_LET(gmp, M_CLASSIC_OPLIST(mpz)) /* M_LET allows even with non container type */
{
my_integer_set_n (z, 17LL); // Set z as the long long 17
my_dict_set_at(dict, STRING_CTE("n1"), z); // Push it in the dictionary
mpz_set_str(gmp, "25446846874687468746874687468746874686874", 10); // Set gmp to a very long integer.
my_integer_set_z (z, gmp); // Set z as the mpz_t variable
my_dict_set_at(dict, STRING_CTE("n2"), z); // Push it in the dictionary
my_array_push_back (array, dict); // Push the dictionary in the array
// Iterate over the array container
for M_EACH(item, array, MY_ARRAY_OPLIST) {
// Iterate over the dictionary container
for M_EACH(p, *item, MY_DICT_OPLIST) {
// Dictionary iterator are pair (key,value)
if (my_integer_n_p(p->value)) {
printf ("It is a long long, value = %lld\n",
*my_integer_cget_n(p->value));
}
if (my_integer_z_p(p->value)) {
printf ("It is a mpz_t, value =");
mpz_out_str(stdout, 10, *my_integer_cget_z(p->value));
printf("\n");
}
}
}
} /* All variables are automatically cleared beyond this point */
}
#else
// Nothing to do
int main(void) { return 0; }
#endif
+3 -3
View File
@@ -4,7 +4,7 @@
/* Register a dynamic seed to M*LIB hash function.
This shall be done before any M*LIB header inclusion. */
unsigned long long rand_seed;
#define M_HASH_SEED rand_seed
#define M_USE_HASH_SEED rand_seed
#include "m-array.h"
#include "m-dict.h"
@@ -84,8 +84,8 @@ DICT_DEF2(dict_json, string_t, STRING_OPLIST, json_t, JSON_OPLIST)
ARRAY_DEF(array_json, json_t, JSON_OPLIST)
VARIANT_DEF2(variant_json,
(boolean, bool, M_OPEXTEND(M_DEFAULT_OPLIST, OUT_STR(boolean_out_str), IN_STR(boolean_in_str M_IPTR)) ),
(real, float, M_OPEXTEND (M_DEFAULT_OPLIST, OUT_STR(real_out_str), IN_STR(real_in_str M_IPTR))),
(boolean, bool, M_OPEXTEND(M_BASIC_OPLIST, OUT_STR(boolean_out_str), IN_STR(boolean_in_str M_IPTR)) ),
(real, float, M_OPEXTEND (M_BASIC_OPLIST, OUT_STR(real_out_str), IN_STR(real_in_str M_IPTR))),
(array, array_json_t, ARRAY_OPLIST(array_json, JSON_OPLIST)),
(dict, dict_json_t, DICT_OPLIST(dict_json, STRING_OPLIST, JSON_OPLIST)))
+5 -5
View File
@@ -10,7 +10,7 @@
order to show/test the good chaining of the structures */
TUPLE_DEF2(symbol, (type, int), (name, string_t))
#define M_OPL_symbol_t() TUPLE_OPLIST(symbol, M_DEFAULT_OPLIST, STRING_OPLIST)
#define M_OPL_symbol_t() TUPLE_OPLIST(symbol, M_BASIC_OPLIST, STRING_OPLIST)
ARRAY_DEF(symbol_list, symbol_t)
#define M_OPL_symbol_list_t() ARRAY_OPLIST(symbol_list, M_OPL_symbol_t())
@@ -19,13 +19,13 @@ TUPLE_DEF2(record, (fields, symbol_list_t))
#define M_OPL_record_t() TUPLE_OPLIST(record, M_OPL_symbol_list_t())
TUPLE_DEF2(my_tuple, (name, string_t), (value, int))
#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple)
#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple, STRING_OPLIST, M_BASIC_OPLIST)
ARRAY_DEF(my_list_of_tuple, my_tuple_t)
#define M_OPL_my_list_of_tuple_t() ARRAY_OPLIST(my_list_of_tuple)
TUPLE_DEF2(my_tuple_of_tuple, (name, string_t), (inner_tuple, my_tuple_t))
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple)
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple, STRING_OPLIST, M_OPL_my_tuple_t() )
LIST_DEF(list_of_tuple_of_tuple, my_tuple_of_tuple_t)
#define M_OPL_list_of_tuple_of_tuple_t() LIST_OPLIST(list_of_tuple_of_tuple, M_OPL_my_tuple_of_tuple_t() )
@@ -37,11 +37,11 @@ BUFFER_DEF(trbuff, my_triple_tuple_t, 100, BUFFER_QUEUE)
#define M_OPL_trbuff_t() BUFFER_OPLIST(trbuff, M_OPL_my_triple_tuple_t())
TUPLE_DEF2(my_junction, (active, bool), (buffer, trbuff_t))
#define M_OPL_my_junction_t() TUPLE_OPLIST(my_junction, M_DEFAULT_OPLIST, M_OPL_trbuff_t())
#define M_OPL_my_junction_t() TUPLE_OPLIST(my_junction, M_BASIC_OPLIST, M_OPL_trbuff_t())
TUPLE_DEF2(mlib_point, (x, int), (y, int))
#define M_OPL_mlib_point_t() \
TUPLE_OPLIST(mlib_point, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
TUPLE_OPLIST(mlib_point, M_BASIC_OPLIST, M_BASIC_OPLIST)
TUPLE_DEF2(mlib_points, (first_ref, mlib_point_ptr, M_PTR_OPLIST),
(second_ref, mlib_point_ptr, M_PTR_OPLIST),
+8 -1
View File
@@ -3,7 +3,14 @@
#include "m-array.h"
#include "m-string.h"
// Let's create an array of string_t and register it globaly
/* This example show ARRAY_DEF usage with string,
M_LET macro usage with complex initialization condition:
how to initialize a dynamic array and initialize it with the given arguments.
It show also the M_EACH keywork
*/
// Let's create a dynamic array of string_t and register it globaly
// a so called std::vector<std::string> in C++
ARRAY_DEF(vector_string, string_t)
#define M_OPL_vector_string_t() ARRAY_OPLIST(vector_string, STRING_OPLIST)
+16
View File
@@ -0,0 +1,16 @@
/*
* Micro example to test if M*LIB supports not using stdio.h
*/
#define M_USE_STDIO 0
#define M_RAISE_FATAL(...) abort()
#include "m-array.h"
ARRAY_DEF(arr, int)
int main(void) {
arr_t a;
arr_init(a);
arr_push_back(a, 4);
arr_clear(a);
return 0;
}
+1 -2
View File
@@ -5,8 +5,7 @@
#include "m-rbtree.h"
// Let's define one utility function.
void *xmalloc(size_t n);
void *xmalloc(size_t n)
static void *xmalloc(size_t n)
{
void *p = malloc (n);
if (!p) abort();
+7 -1
View File
@@ -20,6 +20,9 @@ static void main_macrofree(void)
// Overwrite element 1 of the array.
str_array_set_at(tab_name, 1, STRING_CTE("DVD"));
// Finaly rewrite 1 element of the array
string_set_str(*str_array_get(tab_name, 1), "BLU-RAY");
// Format some strings and push them back in the array
string_t format;
string_init_printf(format, "There are %d elements", str_array_size(tab_name));
@@ -54,6 +57,9 @@ static void main_macro(void)
// Overwrite element 1 of the array.
str_array_set_at(tab_name, 1, STRING_CTE("DVD"));
// Finaly rewrite 1 element of the array
string_set_str(*str_array_get(tab_name, 1), "BLU-RAY");
// Format some strings and push them back in the array
M_LET(format, string_t) {
string_printf(format, "There are %d elements", str_array_size(tab_name));
@@ -67,7 +73,7 @@ static void main_macro(void)
// Set format to a formated string
// In C11, we can mix string_t and char *.
// We can also use M_CSTR to create a printf formated string.
string_sets(format, "FILE=", getenv("PWD"), "/", *str_array_get(tab_name, 2), M_CSTR("-%d.txt", str_array_size(tab_name) ));
string_sets(format, "FILE=", getenv("PWD"), "/", *str_array_get(tab_name, 2), M_CSTR("-%zu.txt", str_array_size(tab_name) ));
str_array_push_back(tab_name, format);
#endif
} // beyond this point format is cleared
+45
View File
@@ -0,0 +1,45 @@
#include <stdio.h>
#include "m-string.h"
#include "m-dict.h"
#include "m-array.h"
/* Definition of an associative map string_t --> size_t */
DICT_DEF2(dict_str, string_t, size_t)
#define M_OPL_dict_str_t() DICT_OPLIST(dict_str, STRING_OPLIST, M_BASIC_OPLIST)
/* Definition of an array of string_t */
ARRAY_DEF(vector_str, string_t)
#define M_OPL_vector_str_t() ARRAY_OPLIST(vector_str, STRING_OPLIST)
int main(void)
{
// Construct an array of string, performing a convertion of the C const char *
// into a proper string_t at real time and push then into a dynamic array
// that is declared, initialized and cleared.
M_LET( (words, ("This"), ("is"), ("a"), ("useless"), ("sentence"), ("."),
("It"), ("is"), ("used"), ("a"), ("bit"), ("to"), ("count"), ("words"), (".") ),
vector_str_t) {
// Print the arrays.
printf("The words are: ");
vector_str_out_str(stdout, words);
printf("\n");
// Count the words.
M_LET(map, dict_str_t) {
// Count the words into the dictionnary 'map'
for M_EACH(w, words, vector_str_t) {
(*dict_str_safe_get(map, *w)) ++;
}
// Print the count:
for M_EACH(p, map, dict_str_t) {
// In C11 version we can use the M_PRINT macro that simplifies formatting.
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
M_PRINT(p->value, " occurences of ", p->key, "\n");
#else
printf ("%zu occurences of %s\n", p->value, string_get_cstr(p->key));
#endif
}
}
}
}
+39
View File
@@ -0,0 +1,39 @@
#include <stdio.h>
#include "m-tree.h"
TREE_DEF(tree, int)
// Compute sum of the tree using iterator and a pre-order walk
static int tree_sum_iter(tree_t t)
{
int s = 0;
for(tree_it_t it = tree_it(t); !tree_end_p(it); tree_next(&it)) {
s += *tree_cref(it);
}
return s;
}
// Compute sum of the tree using recursive call
static int tree_sum_recur(tree_it_t it)
{
if (tree_end_p(it))
return 0;
if (tree_leaf_p(it))
return *tree_cref(it);
assert( tree_degree(it) == 2);
return *tree_cref(it) + tree_sum_recur(tree_down(it)) + tree_sum_recur(tree_right(tree_down(it)));
}
int main(void)
{
tree_t t;
tree_init(t);
tree_it_t r = tree_set_root(t, 1);
tree_it_t l = tree_insert_child(r, 2);
tree_insert_child(r, 5);
tree_insert_child(l, 3);
tree_insert_child(l, 4);
printf("sum = %d vs %d\n", tree_sum_iter(t), tree_sum_recur(tree_it(t)));
tree_clear(t);
return 0;
}
+71
View File
@@ -0,0 +1,71 @@
#include "m-try.h"
#include "m-array.h"
// Define & register an array of int
ARRAY_DEF(array, int)
#define M_OPL_array_t() ARRAY_OPLIST(array, M_BASIC_OPLIST)
// This shall be defined once per program to define the global variables needed
// to handle the exceptions.
M_TRY_DEF_ONCE()
static void f(void)
{
M_TRY(f_exception) {
// Let's define a variable and do stuff:
// Using M_LET allows the register of destructors for the exception handler.
M_LET(a, array_t) {
array_push_back(a, 5);
array_push_back(a, 4);
array_push_back(a, 3);
array_push_back(a, 2);
array_push_back(a, 1);
// Throw a M_ERROR_MEMORY exception
M_THROW(M_ERROR_MEMORY);
printf("This should never be printed!\n");
}
} M_CATCH(f_exception, M_ERROR_MEMORY) {
// Exception handler than catches the M_ERROR_MEMORY errors.
// Here the destructor of variable a has been called to free memory
printf("Memory exception %d received in f function, thrown by %s:%d\n",
f_exception->error_code, f_exception->filename, f_exception->line);
}
}
static void g(void)
{
M_TRY(f_exception) {
// Let's define a variable and do stuff:
// Using M_LET allows the register of destructors for the exception handler.
M_LET(a, array_t) {
array_push_back(a, 5);
array_push_back(a, 4);
array_push_back(a, 3);
array_push_back(a, 2);
array_push_back(a, 1);
// Throw an unkown exception
M_THROW(42);
printf("This should never be printed!\n");
}
} M_CATCH(f_exception, M_ERROR_MEMORY) {
printf("Memory exception %d received in f function, thrown by %s:%d\n",
f_exception->error_code, f_exception->filename, f_exception->line);
printf("This should never be printed!\n");
}
}
int main(void)
{
// Let's do a global exception handler
M_TRY(main_exception) {
f();
g();
} M_CATCH(main_exception, 0) {
// Exception handler than catches all errors.
// Here the destructor of variable a has been called to free memory
printf("Exception %d received in main function, thrown by %s:%d\n",
main_exception->error_code, main_exception->filename, main_exception->line);
}
printf("You should run it under valgrind to check that all memory allocations are freed.\n");
exit(0);
}
+8 -10
View File
@@ -5,20 +5,21 @@
#include "m-serial-json.h"
#include "m-string.h"
/* Define the employee */
/* Define the employee class */
TUPLE_DEF2(employee,
(name, string_t),
(age, int),
(idnum, int))
#define M_OPL_employee_t() TUPLE_OPLIST(employee, STRING_OPLIST, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
/* Register globaly the employee_t oplist */
#define M_OPL_employee_t() TUPLE_OPLIST(employee, STRING_OPLIST, M_BASIC_OPLIST, M_BASIC_OPLIST)
/* Define an array of employee and some algorithms on it */
/* Define an array of employee, register the oplist and define further algorithms on it */
ARRAY_DEF(vector_employee, employee_t)
#define M_OPL_vector_employee_t() ARRAY_OPLIST(vector_employee, M_OPL_employee_t())
ALGO_DEF(vector_employee, vector_employee_t)
/* Define the function object to select the sort order
* named 'compare_by' which is an instance of the interface
/* Define the function object to select the sort order.
* It is named 'compare_by' and is an instance of the interface
* 'vector_employee_cmp_obj' created by ALGO_DEF.
*/
FUNC_OBJ_INS_DEF(compare_by /* name of the instance */,
@@ -75,15 +76,12 @@ int main(void)
// Sort the database by employee ID number
M_LET( (cmp, STRING_CTE("idnum")), compare_by_t )
vector_employee_sort_fo(emps, compare_by_as_interface(cmp));
printf("Employees sorted by idnum are: ");
vector_employee_out_str(stdout, emps);
M_PRINT("Employees sorted by idnum are: ", (emps, vector_employee_t), "\n" );
// Sort the database by employee name
M_LET( (cmp, STRING_CTE("name")), compare_by_t )
vector_employee_sort_fo(emps, compare_by_as_interface(cmp));
printf("\nEmployees sorted by name are: ");
vector_employee_out_str(stdout, emps);
printf("\n");
M_PRINT("Employees sorted by name are: ", (emps, vector_employee_t), "\n" );
// End
}
+69
View File
@@ -0,0 +1,69 @@
#include <stdio.h>
#include "m-array.h"
#include "m-algo.h"
#include "m-string.h"
ARRAY_DEF(array_int, int)
#define M_OPL_array_int_t() ARRAY_OPLIST(array_int, M_BASIC_OPLIST)
ALGO_DEF(array_int, array_int_t)
static bool callback1(int *out, int in, void *data)
{
int *cpt = data;
bool ret = true;
if (*cpt == -1 && in == 11)
*cpt = 0; // Start when first reach 11
ret &= (*cpt >= 0); // Skip initial numbers unequal 11
ret &= (in % 2 != 0); // Collect odd numbers
(*cpt) += ret;
ret &= (*cpt <= 5); // Only take five numbers
*out = in * in; // Square each number
return ret;
}
static void callback_add_int(int *out, int in)
{
*out += in;
}
static void demo(void)
{
M_LET( (t, M_SEQ(0, 30)), vector, array_int_t) {
printf("t="); array_int_out_str(stdout, t);
int b = -1;
array_int_transform(vector, t, callback1, &b);
printf("\nvector="); array_int_out_str(stdout, vector); printf("\n");
array_int_reduce(&b, vector, callback_add_int);
printf("Sum=%d\n", b);
}
}
ARRAY_DEF(array_str, string_t)
#define M_OPL_array_str_t() ARRAY_OPLIST(array_str, M_STRING_OPLIST)
ALGO_DEF(array_str, array_str_t)
static bool callback2(string_t *out, const string_t in, void *data)
{
char *cp = data, c = *cp;
if (string_search_char(in, c) == M_STRING_FAILURE)
return false;
string_set(*out, in);
return true;
}
static void demo_split(void)
{
M_LET( (s, ("This is a sentence in C11.")), string_t)
M_LET(words, f_words, array_str_t) {
array_str_split(words, s, ' ');
array_str_transform(f_words, words, callback2, &(char){'i'});
printf("f_words="); array_str_out_str(stdout, f_words); printf("\n");
}
}
int main(void)
{
demo();
demo_split();
return 0;
}
+232
View File
@@ -0,0 +1,232 @@
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "m-tuple.h"
#include "m-tree.h"
#include "m-worker.h"
#include "m-string.h"
#include "m-atomic.h"
/* Define the comparison function for atomic_uint type
to sort the atomic unsigned int with the biggest value first. */
static inline int atomic_uint_cmp(const atomic_uint *a, const atomic_uint *b)
{
unsigned ai = atomic_load(a), bi = atomic_load(b);
return ai > bi ? -1 : ai < bi;
}
/* Define the oplist for atomic_uint and register it globally.
This oplist extends the basic oplist by:
* disabling HASH for atomic as the default hash method won't work.
* providing the methods for CMP, INIT_SET and SET operators (with their API adaptator) */
#define M_OPL_atomic_uint() M_OPEXTEND(M_BASIC_OPLIST, HASH(0), CMP(API_6(atomic_uint_cmp)), INIT_SET(API_2(atomic_store)), SET(API_2(atomic_store)))
/* Define a directory as a tree where each node contains:
* the number of lines of the files in this directory,
* and the name of the directory/
Since we want to sort with the number of lines only, we extend the oplist of a string by disabling the compare method.
So first, let's define the node as a tuple of such elements:
*/
M_TUPLE_DEF2( dir, (nlines, atomic_uint), (name, m_string_t, M_OPEXTEND(M_STRING_OPLIST, CMP(0))))
/* Register globally the oplist of this tuple */
#define M_OPL_dir_t() M_TUPLE_OPLIST(dir, M_OPL_atomic_uint(), M_STRING_OPLIST)
/* Define a hierarchical tree of directory.
Note that it will use the globally registered oplist associated to dir_t to use it */
M_TREE_DEF(tree, dir_t)
/* Maximum number of characters read by file */
#define MAX_READ_BUFFER 8192
/* Maximum number of directory to scan */
#define MAX_DIRECTORY 100000
/* Define the pool of worker threads */
m_worker_t workers;
/* Global synchronous block for all threads */
m_worker_sync_t workers_block;
/* Add a specialization of the spawn function for the scan_file function.
This functions takes as input an iterator of a tree (treated as a POD data),
and a file name */
M_WORKER_SPAWN_DEF2(scan_file, (parent, tree_it_t, M_POD_OPLIST), (filename, m_string_t) )
/* Add either the root node or a child to parent in function of the existence of parent */
static tree_it_t
add_directory(tree_it_t parent, const m_string_t dirname)
{
if (tree_end_p(parent)) {
return tree_emplace_root( tree_tree(parent), 0, dirname);
} else {
return tree_emplace_child(parent, 0, dirname);
}
}
/* count the number of end of line character in the buffer */
static unsigned
count_eol(size_t num, const char buffer[num])
{
unsigned count = 0;
for(size_t i = 0; i < num; i++) {
count += buffer[i] == '\n';
}
return count;
}
/* Test if a filename suffix ends with a C++ or C suffix */
static bool
is_a_c_file(const m_string_t filename)
{
return (m_string_end_with_str_p(filename, ".c")
|| m_string_end_with_str_p(filename, ".h")
|| m_string_end_with_str_p(filename, ".cpp")
|| m_string_end_with_str_p(filename, ".hpp"));
}
/* Scan the file and count its number of lines */
static void
scan_file(tree_it_t parent, m_string_t filename)
{
FILE *f = fopen(m_string_get_cstr(filename), "rt");
if (f == NULL) {
fprintf(stderr, "ERROR: Cannot open %s as a text file.\n", m_string_get_cstr(filename) );
exit(1);
}
/* Read the FILE per bulk of MAX_READ_BUFFER */
char buffer[MAX_READ_BUFFER];
unsigned count = 0;
size_t num;
do {
num = fread (buffer, 1, MAX_READ_BUFFER, f);
count += count_eol(num, buffer);
} while (num == MAX_READ_BUFFER);
fclose(f);
/* Adding the number of lines to the parent directory */
dir_t *d = tree_ref(parent);
/* atomic add because the scan of files is done in parallel */
atomic_fetch_add( &(*d)->nlines, count );
}
/* Scan the directories recursively for all files */
static void
scan_directories(tree_it_t parent, const m_string_t dirname)
{
tree_it_t it = add_directory(parent, dirname);
m_string_t filename;
m_string_init(filename);
DIR *dir = opendir(m_string_get_cstr(dirname));
if (dir == NULL) {
fprintf(stderr, "ERROR: Cannot open %s as a directory.\n", m_string_get_cstr(dirname) );
exit(1);
}
// Scan all entries in the directory
struct dirent *entry = readdir(dir);
while (entry) {
// Ignore hidden entries (including '.' and '..')
if (entry->d_name[0] != '.') {
// Construct the path to the filename by concatenating dirname, "/" and d_name
m_string_sets(filename, dirname, "/", entry->d_name);
// Get the property of this filename
struct stat buf;
int err = stat(m_string_get_cstr(filename), &buf);
if (err != 0) {
fprintf(stderr, "ERROR: Cannot stat %s\n", m_string_get_cstr(filename));
exit(2);
}
// Further scanning in function of the kind of entry
if (S_ISDIR(buf.st_mode)) {
scan_directories(it, filename);
} else if (is_a_c_file(filename)) {
// Spawn a scan of file to available workers or run it ourselves
m_worker_spawn_scan_file(workers_block, scan_file, it, filename);
}
}
// Next entry in the directory
entry = readdir(dir);
}
closedir(dir);
m_string_clear(filename);
}
/* Consolidate all lines number to the parent directory */
static void
consolidate_directories(tree_t directories)
{
// Scan all entries, first the children, then the parent
for(tree_it_t it = tree_it_post(directories) ; !tree_end_p(it) ; tree_next_post(&it) ) {
dir_t *parent = tree_up_ref(it);
dir_t *myself = tree_ref(it);
if (parent != NULL) {
// Add the child number of lines to the parent
atomic_fetch_add_explicit(&(*parent)->nlines, (*myself)->nlines, memory_order_relaxed);
}
// Sort the data of the children by the number of lines
tree_sort_child(it);
}
}
/* Print the consolidated results on stdout */
static void
print_result(tree_t directories)
{
// Scan all entries, first the parent, then the children
for(tree_it_t it = tree_it(directories) ; !tree_end_p(it) ; tree_next(&it) ) {
int i, depth = tree_depth(it);
for(i = 0; i < depth; i++) printf("+");
for( ; i < 8; i++) printf(" ");
const dir_t *d = tree_cref(it);
printf("%6u %s\n", (unsigned) (*d)->nlines, m_string_get_cstr( (*d)->name ) );
}
}
int main(int argc, const char *argv[])
{
tree_t directories;
m_string_t str;
printf("Count the number of C/C++ lines of code\n");
if (argc < 2) {
fprintf(stderr, "ERROR. Usage is '%s <directory>'.\n", argv[0]);
exit(1);
}
/* Initialize the worker threads */
m_worker_init(workers);
/* Init the tree, reserve for at least the number of max directory
and prevent any further increase of allocation:
this is to ensure that other threads can deref a dir safely */
tree_init(directories);
tree_reserve(directories, MAX_DIRECTORY);
tree_lock(directories, true);
m_string_init_set_cstr(str, argv[1]);
tree_it_t it = tree_it_end(directories);
/* Main processing */
m_worker_start(workers_block, workers);
scan_directories(it, str);
worker_sync(workers_block);
consolidate_directories(directories);
print_result(directories);
/* Clear everything & quit */
m_string_clear(str);
tree_clear(directories);
m_worker_clear(workers);
exit(0);
}
Loaded 100 of 222 files, more files were not shown because too many files have changed in this diff. Show more