1711 Commits
Author SHA1 Message Date
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
Patrick Pelissier 91d40a0f43 V0.5.0 2021-01-13 20:18:01 +01:00
Patrick Pelissier 25fe26deaa Happy new year 2021-01-13 20:18:01 +01:00
Patrick Pelissier cd357c5eb7 Rewrite the wrappers of strncpy & strncat:
Add one argument about the allocation of the dest buffer
Theses wrappers are internal (so no impact to API)
and only used in a few place in m-string.
This make the wrappers able to use the function
strncpy_s & strncat_s for MSVC rather than using
reimplementation of the original functions.
2021-01-13 08:34:47 +01:00
Patrick Pelissier 561f67b3b9 Update list of ignored files 2021-01-13 08:27:00 +01:00
Patrick Pelissier 15a02e3306 Update final message 2021-01-10 20:04:14 +01:00
Patrick Pelissier 944d29e8bc Workaround CLANG preprocessor failure on Windows platform 2021-01-10 20:03:28 +01:00
Patrick Pelissier aefba70c1e Rework once again how to detect a failure in an application:
IF errorlevel 1 only works for positive error code
  IF not errorlevel 0 only works for negative error code
There are not reliable. So, use && and || instead.

Remove expected failure on test as all tests pass now
(and it was broken).
2021-01-10 18:08:48 +01:00
Patrick Pelissier c9ed4ba820 Fix compiler error with MSVC with new implementation of offsetof 2021-01-10 18:01:19 +01:00
Patrick Pelissier df97ea848c Fix error for C++ 2021-01-10 10:01:54 +01:00
Patrick Pelissier 93d810421d Fix warning with newest gcc 2021-01-10 09:57:07 +01:00
Patrick Pelissier f560839516 Add example of string_sets 2021-01-10 09:51:53 +01:00
Patrick Pelissier 8a9d5f6a00 Add macro string_sets (like string_cats) 2021-01-10 09:51:38 +01:00
Patrick Pelissier 5f05c1e169 Make stdarg an optional header. Some works remain to do to make stdio fully optional 2021-01-10 09:40:37 +01:00
Patrick Pelissier 3df2408ffb Add macro M_CSTR 2021-01-10 09:26:27 +01:00
Patrick Pelissier ffc2ec8c4b Fix format 2021-01-10 09:25:27 +01:00
Patrick Pelissier b0ebbb306e Update 2021-01-10 09:20:42 +01:00
Patrick Pelissier c3574aa290 Update comments 2021-01-10 09:02:52 +01:00
Patrick Pelissier eabc867c2a Rename used namespace for C++ to m_lib 2021-01-10 08:48:46 +01:00
Patrick Pelissier a03b2e80c6 Document string_cats 2021-01-07 22:13:10 +01:00
Patrick Pelissier c4f23640d5 Add test for string_cats 2021-01-07 22:13:10 +01:00
Patrick Pelissier a42b854f14 Add macro string_cats to concat multiple strings 2021-01-07 22:13:10 +01:00
Patrick Pelissier 9aa08bfc59 Add support for struct in M_AS_TYPE 2021-01-07 22:13:10 +01:00
Patrick Pelissier 06b79a6caa Add tests for M_AS_TYPE 2021-01-07 22:13:10 +01:00
Patrick Pelissier 6d533bd52a Add (internal) macro M_CONDITIONAL 2021-01-07 22:13:10 +01:00
Patrick Pelissier 1b4c608087 Rename operator TEST_EMPTY into EMPTY_P to be compliant with iterator operator 2021-01-07 22:13:10 +01:00
Patrick Pelissier 6ccc81fd92 Remove unused operator UPDATE_TYPE 2021-01-07 22:13:09 +01:00
Patrick Pelissier 6f7d3fcd79 Add limiation on M_EMPTY_P 2020-12-31 00:12:36 +01:00
Patrick Pelissier 7484dee707 Fix a corner case for M_EMPTY_P where it performs too much evaluation steps 2020-12-31 00:12:21 +01:00
Patrick Pelissier a580aaac83 Add more test cases for M_EMPTY_P 2020-12-31 00:11:37 +01:00
Patrick Pelissier 52bef353e0 Workaround WIN clang that claims to be C11 but fails to deliver a working assert.h (See #85) 2020-12-30 19:03:10 +01:00
Patrick Pelissier 826ecf76c0 Workaround a compiler warning 2020-12-30 19:02:00 +01:00
Patrick Pelissier 2cf5bff32d Fix negative error code termination for MSVS (See #86) 2020-12-30 17:58:43 +01:00
Patrick Pelissier 1377d7a1c2 Fix usage of strncpy_s and strncat_s
Provides a full wrapper around strncpy & strncat
(for MSVS as it complains on using strncpy & strncat).
See #86
2020-12-28 23:35:50 +01:00
Patrick Pelissier ab9284ca20 Update documentation 2020-12-27 10:44:41 +01:00
Patrick Pelissier 5dab01c1c7 Fix spelling 2020-12-26 09:08:42 +01:00
Patrick Pelissier f9c434401b Fix M_GET_STRING_ARG (See #84) 2020-12-26 09:00:39 +01:00
Patrick Pelissier 76b9f9a715 Add test cases for M_GET_STRING 2020-12-26 08:58:52 +01:00
Patrick Pelissier 2ee82c478b Remove useless type (see #82) 2020-12-24 10:58:51 +01:00
Patrick Pelissier 211121435d Fix warning in C++ mode with G++ 10 2020-12-24 08:13:44 +01:00
Patrick Pelissier fffd1702a5 CLANG 3.8 stdatomic works. Update minimun version 2020-12-24 07:35:45 +01:00
Patrick Pelissier 9aa99bf230 Update package list before installing multilib 2020-12-21 15:23:49 +01:00
Patrick Pelissier 1671ca8d67 Add more assertions 2020-12-21 15:16:16 +01:00
Patrick Pelissier ad16b310e1 Fix overflow issue in bitset_last_p (see #81) 2020-12-21 15:08:19 +01:00
Patrick Pelissier 4dbcfd25b3 Fix non support of break in M_LET_IF 2020-12-16 15:27:41 +01:00
Patrick Pelissier 01167b09c4 Add an example of M_LET_IF 2020-12-16 11:07:11 +01:00
Patrick Pelissier 15d0b86c62 Update documentation & add tests as per lastest changes 2020-12-16 11:07:11 +01:00
Patrick Pelissier edbcecb272 Add support for else condition in M_LET_IF. Fix also a bug in computing unique variable per line 2020-12-16 11:07:11 +01:00
Patrick Pelissier 1689db7b9c Fix spelling 2020-12-16 11:07:11 +01:00
Patrick Pelissier f5bc8796f7 Add functions:
* string_vprintf
* string_init_vprintf
2020-12-15 22:14:43 +01:00
Patrick Pelissier e893560a48 Add macros M_LET_IF and M_DEFER to help handling with runtime errors 2020-12-14 21:26:07 +01:00
Patrick Pelissier a4ff7c71f2 Update documentation 2020-12-13 00:18:53 +01:00
Patrick Pelissier 9f780805f0 Update 2020-12-10 07:59:28 +01:00
Patrick Pelissier 749273d1bb Update list of methods 2020-12-06 08:32:54 +01:00
Patrick Pelissier d8fd2e3e69 Update doc as per latest changes 2020-12-06 00:16:53 +01:00
Patrick Pelissier d443a84254 Remove deprecated funtion 2020-12-06 00:15:17 +01:00
Patrick Pelissier ef614b19ee Fix ISO C warning. 2020-12-05 18:33:26 +01:00
Patrick Pelissier 1c5c4aa50f Fix compatibility with C++
which doesn't support designated init.
2020-12-05 18:28:30 +01:00
Patrick Pelissier 5533ffffaa Add tests for intrusive shared pointers. 2020-12-05 18:14:38 +01:00
Patrick Pelissier 34c990e259 Add function _init_once for intrusive shared pointer 2020-12-05 18:14:22 +01:00
Patrick Pelissier 5f0b6b9f26 Fix format 2020-12-05 12:42:45 +01:00
Patrick Pelissier 26eb882a30 Rename tuple function :
* _init_set2 in _init_emplace
* _set2 in _emplace
due to better & clearer naming.
(API break)
2020-12-05 12:29:20 +01:00
Patrick Pelissier 4d0e799c7a Remove obsolete function. 2020-12-05 12:27:33 +01:00
Patrick Pelissier 6801f688a4 Clarify atomic thin layer limitation (see #79) 2020-12-01 07:27:14 +01:00
Patrick Pelissier bdf29af9e9 * Add DJB Xor hash * Rename function (see #78) 2020-11-29 22:05:24 +01:00
Patrick Pelissier 79dabfc52f Update documentation as per #76 2020-11-29 20:34:05 +01:00
Patrick Pelissier de2268c406 Factorization of comparaison by using memcmp 2020-11-29 20:06:56 +01:00
Patrick Pelissier 85ea1f40dc Use classic hash rather than fast one for C-String (fix assertion failure for C-String hash) 2020-11-29 19:36:28 +01:00
Patrick Pelissier f89ba94689 Add test for computing C-string hash (raise assertion failure) 2020-11-29 19:35:52 +01:00
Patrick Pelissier 0279dcc3cc Fix issue on MacOS 2020-11-25 22:56:51 +01:00
Patrick Pelissier 62c8e005bb Add a new example of array of strings. 2020-11-25 22:41:25 +01:00
Patrick Pelissier 2a28f8d407 Add string_init_printf 2020-11-25 22:41:11 +01:00
Patrick Pelissier 9802fc5098 Remove rapidstring as it is no longer maintained, and the author deleted the repository. 2020-11-24 23:04:33 +01:00
Patrick Pelissier f372a72fd8 Update list of libraries 2020-11-23 20:29:30 +01:00
Patrick Pelissier 9d661852b2 Factorization of replace_all function for all libraries 2020-11-23 20:14:17 +01:00
Patrick Pelissier b343d356c3 Add support for empty replaced string 2020-11-22 23:29:38 +01:00
Patrick Pelissier 2e4404ca7e Fix a (strange) warning for gcc 8 without assertions.
Add back the assertions as compile hints.
2020-11-22 23:20:04 +01:00
Patrick Pelissier 29eebaf38d Factorization of the allocation. 2020-11-22 23:11:09 +01:00
Patrick Pelissier d0d69aebfa Add final null char in computation of the needed size for the new function _replace_all 2020-11-22 23:09:37 +01:00
Patrick Pelissier 477c5853f1 Update bench to use new function. 2020-11-22 23:04:50 +01:00
Patrick Pelissier 55e7b3083a Add function string_replace_all[_str]
to replace all occurences of a string by another.
2020-11-22 23:04:32 +01:00
Patrick Pelissier 0b9e27fb7f Add note on 32 bits systems where atomic library is needed 2020-11-21 11:45:25 +01:00
Patrick Pelissier 36ac6d5104 Fix issue on single core system 2020-11-21 10:53:11 +01:00
Patrick Pelissier d898d6d4cc Remove duplicate function 2020-11-21 10:26:02 +01:00
Patrick Pelissier e7388929c4 Migrate to msys2 v2 for github actions. 2020-11-19 22:43:05 +01:00
Patrick Pelissier 45f8b31efc Add function string_subset 2020-11-19 22:31:33 +01:00
Patrick Pelissier ebf440731d Fix address sanitizer issue 2020-11-15 09:43:41 +01:00
Patrick Pelissier 501a4a65ec Add test cases 2020-11-15 09:39:29 +01:00
Patrick Pelissier 800d03f728 Update documentation. 2020-11-15 09:39:15 +01:00
Patrick Pelissier 19ff6bfeac Add equal_p method for m-prioqueue 2020-11-15 09:39:01 +01:00
Patrick Pelissier 24f5739a3b Update documentation. 2020-11-14 23:56:28 +01:00
Patrick Pelissier b658598e02 Update documentation for _update & _erase of priority queues. 2020-11-14 23:48:46 +01:00
Patrick Pelissier 47343a2893 Add proper test cases for _update of priority queue 2020-11-14 23:48:23 +01:00
Patrick Pelissier c1f99359be Fix issue in update of priority in priority queue:
* Rename _update_further into _update.
* it now supports increase or decrease of priority.
* _update_further is deprecated (and was broken).
2020-11-14 23:48:08 +01:00
Patrick Pelissier bd89e162fc Add support for additional parameter id 2020-11-14 23:45:38 +01:00
Patrick Pelissier 983a63fbbc Add more comments to explain how it works. 2020-11-14 22:45:39 +01:00
Patrick Pelissier 978e0ea5d7 Fix format 2020-11-14 22:45:18 +01:00
Patrick Pelissier 85c4b50b6f Improve coverage of prioriy queue. 2020-11-08 01:00:17 +01:00
Patrick Pelissier e77aec4619 Reduce test case for MacOS / MINGW (returning incorrect return value for printf) 2020-11-05 23:33:26 +01:00
Patrick Pelissier d67e084010 Fix introduced warning 2020-11-05 22:55:03 +01:00
Patrick Pelissier b0a74f162e Fix string_printf in case of error in formating. 2020-11-05 22:51:28 +01:00
Patrick Pelissier d92126b97e Add more tests (improve coverage) 2020-11-05 22:51:02 +01:00
Patrick Pelissier c055358fa2 Reformat 2020-11-05 22:50:38 +01:00
Patrick Pelissier 9f89148b69 Remove valgrind
(not working in Multithread code)
2020-11-05 22:02:44 +01:00
Patrick Pelissier ef1145603a Update comments. 2020-10-31 17:30:14 +01:00
Patrick Pelissier d169a06f79 Rename STRING_ASSERT_SLOW into M_ASERT_SLOW 2020-10-31 17:30:14 +01:00
Patrick Pelissier 8e15a8cfe9 Fix warnings of CodeQL 2020-10-31 00:35:28 +01:00
Patrick Pelissier 6466cefbf4 Fix yml syntax 2020-10-31 00:17:13 +01:00
Patrick Pelissier bec9a897c9 Update codeql to use test executable 2020-10-31 00:13:03 +01:00
Patrick Pelissier 37d47cb0f1 Cleanup static analyser 2020-10-31 00:12:40 +01:00
Patrick Pelissier 0854136005 Add target exe for analyser
Cleanup of static analyzer
2020-10-31 00:12:02 +01:00
Patrick Pelissier 9427931e45 Add CodeQL in continuous integration backend 2020-10-31 00:01:05 +01:00
Patrick Pelissier 6aa28b4cfe Fix warnings on ARM 2020-10-30 08:02:37 +01:00
Patrick Pelissier a29682ca29 Create M_ASSERT macro to encapsulate assert within M*LIB
The goal is to enable the user to override this macro if needed so that it can enable or disable the M*LIB witout impacting its own assertions.
2020-10-29 22:46:17 +01:00
Patrick Pelissier f5afd6e275 Update comments. 2020-10-25 21:16:43 +01:00
Patrick Pelissier 7b5fd14bcf Update comment. 2020-10-24 23:29:02 +02:00
Patrick Pelissier 22ce001f03 Remove incorrect use of M_ASSUME by assert 2020-10-24 23:14:14 +02:00
Patrick Pelissier 6f761091cc Update comment. 2020-10-24 23:07:29 +02:00
Patrick Pelissier bb9e0e4f6e Adding test for M_LET for bounded string 2020-10-24 14:03:31 +02:00
Patrick Pelissier 5e658a81fe Adding INIT_WITH support for bounded string within M_LET 2020-10-24 14:03:27 +02:00
Patrick Pelissier ddc722bf78 Add FIXME 2020-10-23 21:50:57 +02:00
Patrick Pelissier 0818d0ac7c Fix macro formatting. 2020-10-23 21:46:34 +02:00
Patrick Pelissier 2f315793cd Use of M_ASSERT_INDEX for deque 2020-10-23 21:45:37 +02:00
Patrick Pelissier 067a034bc9 Use of M_ASSERT_INDEX for list. 2020-10-23 21:39:33 +02:00
Patrick Pelissier 201cc45fd8 Use of M_ASSERT_INDEX for bitset. 2020-10-23 21:37:44 +02:00
Patrick Pelissier 7a270ffacb Update documentation 2020-10-23 21:32:06 +02:00
Patrick Pelissier 27bb62533a Use of M_ASSERT_INDEX
to validate user input.
2020-10-21 23:57:52 +02:00
Patrick Pelissier 032388b790 Update message 2020-10-21 23:57:24 +02:00
Patrick Pelissier f1e2f81e79 Improve formating of macros:
if the line is too long
and can be reduced,
reduce it.
2020-10-21 23:56:55 +02:00
Patrick Pelissier 54d4b80368 Reformat macro to 80 characters 2020-10-21 23:23:40 +02:00
Patrick Pelissier 8a0a556604 Add utility to reformat automatically
macro to 80 characters.
2020-10-21 23:23:16 +02:00
Patrick Pelissier 895f362628 Fix a majorant stack usage of B+TREE 2020-10-17 22:46:43 +02:00
Patrick Pelissier d24b52586d Put a type within internal namespaces. 2020-10-17 22:25:22 +02:00
Patrick Pelissier d76585cb0e Update test as per latest changes. 2020-10-17 22:25:05 +02:00
Patrick Pelissier fb44be6efe Remove argument itret_t from *SET_DEF_AS
as it is useless
(Return type IS the key type for a set).
2020-10-17 22:24:53 +02:00
Patrick Pelissier 0b6a5aaa97 Port to last API version of CMC 2020-10-17 20:14:06 +02:00
Patrick Pelissier c00fdc65a2 Change installation directory
so that all M*LIB headers are in one directory.
2020-10-17 13:22:17 +02:00
Patrick Pelissier ab7490eb8a Fix list of distributed files. 2020-10-17 13:17:47 +02:00
Patrick Pelissier 1a46c0cd3f Clarify should usage in the documentation. 2020-10-17 13:07:41 +02:00
Patrick Pelissier 22f595c015 Update comment 2020-10-17 12:39:09 +02:00
Patrick Pelissier 68c76ad146 Update example with latest changes. 2020-10-16 21:59:53 +02:00
Patrick Pelissier 0b18792b96 Document _DEF_AS macros
Fix #60
2020-10-16 21:56:42 +02:00
Patrick Pelissier 464e8e5f8f Clean usage of 'shall' within the documentation. 2020-10-16 21:33:01 +02:00
Patrick Pelissier 45410f3f0c Update README. 2020-10-16 21:04:07 +02:00
Patrick Pelissier 556e706343 Update doc as per last rename 2020-10-16 21:01:41 +02:00
Patrick Pelissier 1e534bd307 Rename derefence type of an iterator of a dict or a B+Treee into _ittref_t. 2020-10-16 21:01:29 +02:00
Patrick Pelissier 7a517ee3ae Upate comments. 2020-10-16 20:53:34 +02:00
Patrick Pelissier 9bb1957afa Rename internal types. 2020-10-16 20:51:24 +02:00
Patrick Pelissier 86f942ee5f Fix forgotten external type in internal function. 2020-10-15 22:15:01 +02:00
Patrick Pelissier a23df528e4 Add DICT_*_AS macros. 2020-10-15 22:05:18 +02:00
Patrick Pelissier 0e9af6dfac Prepare user name integration for OA dictionnaries. 2020-10-15 21:53:11 +02:00
Patrick Pelissier 99a8db1111 Prepare integration for custom names for dict. 2020-10-15 21:41:53 +02:00
Patrick Pelissier 24cdf1ca5c Use of internal types within the code
instead of external ones.
2020-10-03 16:07:32 +02:00
Patrick Pelissier f1b794b239 Use of external documented type
instead of internal type.
2020-10-03 16:07:14 +02:00
Patrick Pelissier b4fdcbc547 Factorization of the it_deref name for overloading 2020-10-03 15:48:44 +02:00
Patrick Pelissier ce9986f6d8 Factorization of common pattern for bucket dictionnaries. 2020-10-03 14:47:47 +02:00
Patrick Pelissier ad4dcae1db Add macro VARIANT_DEF2_AS 2020-10-03 14:07:14 +02:00
Patrick Pelissier b3fa63c971 Factorization of name usage 2020-10-03 14:07:14 +02:00
Patrick Pelissier 364101592b Remove unused file 2020-10-03 14:07:14 +02:00
Patrick Pelissier 5b89196cd7 Add macro TUPLE_DEF2_AS 2020-10-03 14:07:14 +02:00
Patrick Pelissier feb8b30048 Factorization of M_C(name, _t) 2020-10-03 14:07:14 +02:00
Patrick Pelissier 8340cf70fb Add macros
FUNC_OBJ_ITF_DEF_AS
FUNC_OBJ_INS_DEF_AS
2020-10-03 14:07:14 +02:00
Patrick Pelissier affb3778a0 Rename internal types to _ct 2020-10-03 14:07:14 +02:00
Patrick Pelissier c039f07f2d Add macros
BPTREE_DEF2_AS
BPTREE_DEF_AS
BPTREE_MULTI_DEF2_AS
BPTREE_MULTI_DEF_AS
2020-10-03 14:07:14 +02:00
Patrick Pelissier c180981768 Add macros
CONCURRENT_DEF_AS
CONCURRENT_RP_DEF_AS
2020-10-03 14:07:14 +02:00
Patrick Pelissier 2cfac5c332 Fix build issue in C11 for new macros. 2020-10-03 14:07:14 +02:00
Patrick Pelissier 8ba489eef3 Add macros
SNAPSHOT_SPSC_DEF_AS
SNAPSHOT_SPMC_DEF_AS
SNAPSHOT_MPMC_DEF_AS
2020-10-03 14:07:14 +02:00
Patrick Pelissier a4cb6e3681 Add macros SHARED_PTR_DEF_AS, SHARED_PTR_RELAXED_DEF_AS, SHARED_RESOURCE_DEF_AS 2020-10-03 14:07:14 +02:00
Patrick Pelissier 379e0be211 Use of new macro to define internal types not exported. 2020-10-03 14:07:14 +02:00
Patrick Pelissier acb886c391 Add macro RBTREE_DEF_AS 2020-10-03 14:07:14 +02:00
Patrick Pelissier 7f26ef0f1c Add new macros to define container
with the full given name.
2020-10-03 14:07:14 +02:00
Patrick Pelissier 1d8e541205 Add macros BUFFER_DEF_AS, QUEUE_MPMC_DEF_AS, QUEUE_SPSC_DEF_AS 2020-10-03 14:07:14 +02:00
Patrick Pelissier a4fa70a478 Add macro DEQUE_DEF_AS 2020-10-03 14:07:14 +02:00
Patrick Pelissier 3d3a473716 Add macro ILIST_DEF_AS 2020-10-03 14:07:14 +02:00
Patrick Pelissier e04b120d41 Add new macros _DEF_AS so that
user can define its own name for the generated types.
2020-10-03 14:07:14 +02:00
Patrick Pelissier 63eee6bba3 Update comments 2020-10-03 14:07:14 +02:00
Patrick Pelissier b396b42808 Update comments 2020-10-03 14:07:14 +02:00
Patrick Pelissier eb8b106f48 Update comments. 2020-10-03 14:07:14 +02:00
Patrick Pelissier 5d144991cb Reformat & add more assertions. 2020-10-03 14:07:14 +02:00
Patrick Pelissier 35718ae551 Rename type as internal types 2020-10-03 14:07:14 +02:00
Patrick Pelissier 1dd9aff402 Factorize the name of the object at top level. 2020-10-03 14:07:14 +02:00
Patrick Pelissier 6d47074457 Rename internal types of m-core 2020-10-03 14:07:14 +02:00
Patrick Pelissier 1943650ca3 Factorization of the name of the object
at the top level to be able to create
new high level macros that enables
to select the full name of the type.
2020-10-03 14:07:14 +02:00
Patrick Pelissier 5722f19939 Update comments 2020-10-03 14:07:14 +02:00
Patrick Pelissier 7cf14b5d8a Update formatting 2020-10-03 14:07:14 +02:00
Patrick Pelissier b3a1a75f6f Rename internal types:
a suffix ending with _ct means confidential type
ans is reserved for M*LIB internal usage.

OPLIST doesn't use the external types
but rather the internal types.
It enables to be independent of the real names
of the external types.
Such external names are planned to be fully customizable
(i.e. the user may define a name that suits its coding style)
2020-10-03 14:07:14 +02:00
Patrick Pelissier eb7556f88f Replace abort by assert for static analyszer 2020-08-22 18:58:48 +02:00
Patrick Pelissier 805c747c60 Add more assertions (help static analyzer) 2020-08-22 18:54:51 +02:00
Patrick Pelissier 5f9feb833c Replace TAB by SPACE 2020-07-25 19:17:25 +02:00
Patrick Pelissier efef35c1e1 Reformat 2020-07-25 18:20:17 +02:00
Patrick Pelissier b1b32f565d Transform TAB into SPACE. 2020-07-25 18:15:57 +02:00
Patrick Pelissier f4cd8eaff9 Rename internal macro to TUPLEI_ 2020-07-25 18:01:34 +02:00
Patrick Pelissier 2cd5258f89 Add comments
Replace TAB by SPACE.
2020-07-25 17:54:01 +02:00
Patrick Pelissier 1b206931df Transform TAB into SPACE 2020-07-22 20:51:45 +02:00
Patrick Pelissier f68840ef8c Update doc 2020-07-19 01:12:12 +02:00
Patrick Pelissier 779c15ec08 Update tests as per new semantics 2020-07-19 01:11:15 +02:00
Patrick Pelissier 29bcc00202 Update format 2020-07-19 01:06:48 +02:00
Patrick Pelissier 1ff0d9fac0 Add test for _sort_intersect 2020-07-19 01:01:53 +02:00
Patrick Pelissier 4488853642 Factorization of _sort_union 2020-07-19 00:59:11 +02:00
Patrick Pelissier d5dc5d083d Fix _sort_union bug 2020-07-19 00:55:51 +02:00
Patrick Pelissier 784c42d850 Update _insert functions to update
iterators as per new specification.
2020-07-19 00:55:35 +02:00
Patrick Pelissier 8c1eb1fcb5 Add tests for _sort_union 2020-07-19 00:53:58 +02:00
Patrick Pelissier 49180bfbe5 Add documentation on IT_INSERT operator 2020-07-19 00:53:43 +02:00
Patrick Pelissier a3116dd813 Update comments 2020-07-18 09:54:12 +02:00
Patrick Pelissier 23df465401 Update comments 2020-07-14 14:44:10 +02:00
Patrick Pelissier 966170452f Improve test representativity by simulating various speeds for readers and writers 2020-07-14 14:43:14 +02:00
Patrick Pelissier eaf7ae7dee Fix spelling 2020-07-14 00:47:25 +02:00
Patrick Pelissier 8a6652646a Fix formatting (Replace TAB with SPACE) 2020-07-14 00:34:59 +02:00
Patrick Pelissier 2063bf879d Formatting: replace TAB by SPACE. 2020-07-14 00:26:26 +02:00
Patrick Pelissier 2529d4ae49 Update comments & remove warning about _Atomic 2020-07-12 22:52:36 +02:00
Patrick Pelissier 439bc06423 Fix unused value warning 2020-07-12 00:32:09 +02:00
Patrick Pelissier ab6c90f42f Fix issue with a warning that it triggers now but now before, whereas the code has not changed. Another random warning 2020-07-11 20:39:27 +02:00
Patrick Pelissier ac9e9a83b9 Fix issue with warnings on MacOS 2020-07-11 20:38:51 +02:00
Patrick Pelissier e495b92ae5 Workaround warnings about unused return value 2020-07-11 20:29:55 +02:00
Patrick Pelissier 50b1bedc54 Workaround some warnings 2020-07-11 20:13:31 +02:00
Patrick Pelissier 4a80ccd5f4 Add optimization to enable more warnings 2020-07-11 20:13:13 +02:00
Patrick Pelissier 6ca65dd60c Update comment 2020-07-11 18:36:46 +02:00
Patrick Pelissier b2be4d5397 Improve checking of failure detection 2020-07-11 18:02:27 +02:00
Patrick Pelissier de34cefa83 add test for detecting call to disable method 2020-07-11 18:02:11 +02:00
Patrick Pelissier 40c8dbae1e Update detection of disabled method 2020-07-11 18:01:48 +02:00
Patrick Pelissier 18af53cf38 Disable Wformat-nonliteral in the protected section 2020-07-11 17:18:43 +02:00
Patrick Pelissier 8510318ba5 Another minor warning about casting a double into a float 2020-07-11 17:17:59 +02:00
Patrick Pelissier 6ad02ffe56 Stop on warnings for CI 2020-07-11 16:57:03 +02:00
Patrick Pelissier 535e45d564 Update flags 2020-07-10 13:00:07 +02:00
Patrick Pelissier e2c60aa45c Fix another warnings that are triggered in another random combinaison of compiler settings 2020-07-10 12:59:31 +02:00
Patrick Pelissier 56d2a74818 Fix some warnings 2020-07-09 23:38:34 +02:00
Patrick Pelissier 8a36b5ff15 Workaround to avoid CLANG unused function warnings 2020-07-09 22:14:00 +02:00
Patrick Pelissier 7607645636 Reeanble Wunused-function 2020-07-09 22:13:24 +02:00
Patrick Pelissier cbb84accfe Add build on linux 32 bits 2020-07-09 17:31:16 +02:00
Patrick Pelissier 3e70cf7b5f TCC doesn't support -MM, so use cc to generate them 2020-07-09 10:45:09 +02:00
Patrick Pelissier 1a7deef735 Add TCC target 2020-07-09 10:38:35 +02:00
Patrick Pelissier 748771ab72 Update comment 2020-07-09 10:37:37 +02:00
Patrick Pelissier 6ef279dd2f Add comments 2020-07-07 18:30:14 +02:00
Patrick Pelissier abcf37dc72 Update 2020-07-07 13:07:54 +02:00
Patrick Pelissier 690b7bf9c1 Fix other warning for msys2 2020-07-05 23:53:06 +02:00
Patrick Pelissier 71cec5155a Fix uncompliant m-atomic support
if __STDC_NO_ATOMICS__ is defined, then in C11, there is no stdatomic header
2020-07-04 23:34:24 +02:00
Patrick Pelissier d2b0873a95 Add missing make for msys2 2020-07-04 23:09:37 +02:00
Patrick Pelissier 4cecdbb93e Add missing packages for msys2 as per https://www.msys2.org/docs/ci/ 2020-07-04 23:01:47 +02:00
Patrick Pelissier 2abca7d244 Update command line for msys2 as per https://www.msys2.org/docs/ci/ 2020-07-04 22:58:16 +02:00
Patrick Pelissier c26b467e86 Update command line for msys2 2020-07-04 22:48:41 +02:00
Patrick Pelissier 19514b09b0 Add msys2 target 2020-07-04 22:34:07 +02:00
Patrick Pelissier ab98577deb Fix warning 2020-07-04 12:50:34 +02:00
Patrick Pelissier aae5f00dbd Add new benchmark 2020-07-04 00:47:06 +02:00
Patrick Pelissier 04706d48b9 Fix further warnings 2020-07-03 23:03:12 +02:00
Patrick Pelissier c7df60c78d Fix some warnings 2020-07-03 22:44:34 +02:00
Patrick Pelissier f03a4503eb Fix some warnings 2020-07-03 22:15:54 +02:00
Patrick Pelissier a6951fe5e3 Fix warnings for clang-cl 2020-07-03 21:59:25 +02:00
Patrick Pelissier 6def48a0d1 Fix clang-cl to target x64 mode 2020-07-03 21:30:19 +02:00
Patrick Pelissier 8b5d1e07ce Fix build with MSVC in 32 bits mode 2020-07-03 21:25:20 +02:00
Patrick Pelissier 3182c39280 Add clang-cl in the continuous Integration 2020-07-03 21:18:17 +02:00
Patrick Pelissier e0b5dc2f02 Add test for clang-cl 2020-07-03 20:59:42 +02:00
Patrick Pelissier 6e5181e405 Fix doc on B+TREE 2020-07-02 23:22:44 +02:00
Patrick Pelissier 75f4f23144 Add comments and fix Pn level 2020-07-02 21:41:57 +02:00
Patrick Pelissier bc1402f66a Udpate documentation 2020-07-02 10:40:41 +02:00
Patrick Pelissier fc5ffcb404 Update API 2020-07-02 10:39:22 +02:00
Patrick Pelissier bd20a021ce Update documentation 2020-07-02 10:39:15 +02:00
Patrick Pelissier dfd12107de Add new function _clear_ptr 2020-07-02 10:39:05 +02:00
Patrick Pelissier 6743cb9456 Add posibility for user to select Thread backend directly 2020-07-02 00:09:54 +02:00
Patrick Pelissier 4aa93325e9 Update documentation 2020-07-01 12:08:24 +02:00
Patrick Pelissier f2a06ede62 Add mechanism to disable temporary compiler warnings in a sequence of code. 2020-07-01 11:47:55 +02:00
Patrick Pelissier a36752b8ce Update documentation (Fix #66) 2020-07-01 11:45:24 +02:00
Patrick Pelissier 3b347f2ba5 Reduce some warnings using the atomic compatibility layer (cannot fix all) 2020-07-01 11:06:58 +02:00
Patrick Pelissier 47296e5c11 The user can define M_USE_C11_NO_THREADS to disable C11 header (Support for broken C11 implementation) 2020-06-29 21:53:09 +02:00
Patrick Pelissier a24c530ec6 Update documentation on _init_new method 2020-06-29 16:03:54 +02:00
Patrick Pelissier 7ebe0608ae Define _init_new method only if NEW method has not been disabled 2020-06-29 16:03:38 +02:00
Patrick Pelissier 2a3021c021 Adding more code generation. 2020-06-29 16:01:38 +02:00
Patrick Pelissier 4d313aa72b Fix warning about unused function 2020-06-29 15:16:37 +02:00
Patrick Pelissier 7906a39647 Fix warning about unused function 2020-06-29 15:16:03 +02:00
Patrick Pelissier 86254958f0 Add precision on C11 thread layer (#65) 2020-06-29 15:02:34 +02:00
Patrick Pelissier 0089c1af61 Remove clang-cl as it is not available 2020-06-28 23:08:44 +02:00
Patrick Pelissier 6b5a3ddef7 Add clang-cl version 2020-06-28 23:04:06 +02:00
PpHd 42c2fd69a2 Merge pull request #64 from vladipus/patch-2
Update m-core.h
2020-06-27 21:12:44 +02:00
Vladislav Dmitrievich Turbanov bcb9b831db Update m-core.h
A tiny typo. MSVS should be referred to as MSVC - that is the standard way.
2020-06-27 19:08:52 +03:00
Patrick Pelissier f6483cbb30 It seems GNUC is force to 4 for APPLE/CLANG 2020-06-27 01:00:46 +02:00
Patrick Pelissier f742707699 Always use atomic in C++ 2020-06-27 00:31:58 +02:00
Patrick Pelissier aee02d86ab Workaround issue with CLANG++ on MAC 2020-06-27 00:10:40 +02:00
Patrick Pelissier dfbf34daf6 Remove a warning with some compiler by encoding 0 as UINT_MAX+1 2020-06-26 23:48:59 +02:00
Patrick Pelissier 494cbbecf0 Try to make Apple Make working in C11 mode 2020-06-26 23:40:49 +02:00
Patrick Pelissier a1513777f1 Activate C++ build too 2020-06-26 23:38:54 +02:00
Patrick Pelissier 9784a16d47 Get ride of modular arithmetic 2020-06-26 00:25:15 +02:00
Patrick Pelissier a8648e0cc1 Fix variable name for conditional code 2020-06-25 23:49:28 +02:00
Patrick Pelissier 3f8e93ad7a Use of intrinsic for clz within MSVS 2020-06-25 23:45:39 +02:00
Patrick Pelissier b040bc411f Add tests for builtin core functions 2020-06-25 23:35:34 +02:00
Patrick Pelissier ae8c3e5300 Update documentation about array & mandatory operators 2020-06-25 22:49:54 +02:00
Patrick Pelissier 01d390c3e9 Test array without INIT_SET & SET 2020-06-25 22:49:36 +02:00
Patrick Pelissier 56e4cda76c Make INIT_SET & SET operators of arrays as optional 2020-06-25 22:49:25 +02:00
Patrick Pelissier c59d585c22 Add new macro to test method1 or method2 in oplist 2020-06-25 22:49:08 +02:00
PpHd 81c97682a7 Merge pull request #62 from vladipus/patch-1
Update README.md
2020-06-25 21:21:18 +02:00
Patrick Pelissier a432628df6 Fix warnings for CLANG/WINDOWS (#61) 2020-06-25 21:18:01 +02:00
Vladislav Dmitrievich Turbanov d16effb4c5 Update README.md
Fixed a small typo in the ALGO_DEF example, that features an ARRAY_OPLIST with `int` instead of `array_int`
2020-06-25 22:13:53 +03:00
Patrick Pelissier 6279f98bb5 Run also in C11 mode for CI 2020-06-24 21:15:51 +02:00
Patrick Pelissier 3cbc474e76 Document M_ENUM_OPLIST 2020-06-24 21:14:00 +02:00
Patrick Pelissier c80fb7bebe Add test for M_ENUM_OPLIST (in particular I/O tests) 2020-06-24 21:13:43 +02:00
Patrick Pelissier 68788a6fb8 Add M_ENUM_OPLIST 2020-06-24 21:13:13 +02:00
Patrick Pelissier fd3cb50249 Remove temporary file 2020-06-22 00:38:19 +02:00
Patrick Pelissier 7e0bd8414d Fix warnings for mingw 2020-06-22 00:33:10 +02:00
Patrick Pelissier 70de571dc8 Fix warnings in test suite. 2020-06-22 00:14:55 +02:00
Patrick Pelissier cc6da8941c * Fix wanings for reduce precision on integers.
* Add wrapper for strncat
2020-06-22 00:14:37 +02:00
Patrick Pelissier d27c448a94 Fix some warnings with MSVS
for the test suite.
2020-06-21 23:52:12 +02:00
Patrick Pelissier 06a1590645 Add missing assertion. 2020-06-21 23:51:49 +02:00
Patrick Pelissier 652653af0b Fix some warnings by casting
for compilers which cannot detect the affectations as ok.
2020-06-21 23:50:49 +02:00
Patrick Pelissier c520b7d0be Enable Annex K for MSVS 2020-06-21 23:36:47 +02:00
Patrick Pelissier 4f4605befb Use of Annex K for MSVS to reduce warnings. 2020-06-21 23:36:34 +02:00
Patrick Pelissier 3f84f54d65 Add casts to avoid some compiler warnings
if the compiler is not able to detect the cast if safe.
2020-06-21 23:03:40 +02:00
Patrick Pelissier bf49b8e933 Enable warnings for MSVS 2020-06-21 22:43:06 +02:00
Patrick Pelissier 1edb204ec6 Update documentation 2020-06-19 21:14:46 +02:00
Patrick Pelissier dd5c9ac8ad Fix corner case of string_fget_word when it doesn't end with a separator 2020-06-19 21:11:05 +02:00
Patrick Pelissier 32b6f82249 Add corner case for string_fget_word when it doesn't end with a separator 2020-06-19 21:10:46 +02:00
Patrick Pelissier 44b3895698 Fix m_core_fscan_* in case of EOF 2020-06-19 21:02:17 +02:00
Patrick Pelissier 5ce6ccde3d Add bench for deque 2020-06-18 22:04:56 +02:00
Patrick Pelissier ee64e068f9 Add bench for rapidjson 2020-06-14 21:12:02 +02:00
Patrick Pelissier 8d89e7c958 Add leak sanitizer to sanitize target. 2020-06-14 11:33:01 +02:00
Patrick Pelissier ef74f8eb55 Fix other warnings about conversion but in C++ 2020-06-14 01:10:37 +02:00
Patrick Pelissier a7749e944f Fix strange warning with gcc 2020-06-14 00:48:58 +02:00
Patrick Pelissier 18bf06ff5f Add m_core_serial_fail for make debugging easier for serialization
Fix issue in saving size_t for 32 bits system
2020-06-14 00:40:11 +02:00
Patrick Pelissier b27f490acb Fix typing 2020-06-14 00:18:26 +02:00
Patrick Pelissier e84fa859c6 Fix implicit conversion. 2020-06-14 00:17:44 +02:00
Patrick Pelissier 4c57ca69bc Support for 32 bits system. 2020-06-14 00:17:22 +02:00
Patrick Pelissier b0d2557ea1 string_fgets:
Fix buffer overflow for very big string
2020-06-14 00:17:09 +02:00
Patrick Pelissier 82906e03e9 Add warning also for GCC. 2020-06-13 20:02:29 +02:00
Patrick Pelissier 1859868838 Fix sign conversion for algorithm tests. 2020-06-13 20:02:14 +02:00
Patrick Pelissier 4ab3a3605b Fix -Wsign-conversion warnings in tests. 2020-06-13 19:43:52 +02:00
Patrick Pelissier 279b46b4e2 Fix -Wsign-conversion warnings. 2020-06-13 19:43:38 +02:00
Patrick Pelissier 17950c5fe5 Fix corner cases for string_reserve 2020-06-13 18:57:53 +02:00
Patrick Pelissier 45b94c8abc Add corner cases for string_reserve 2020-06-13 18:57:39 +02:00
Patrick Pelissier a98ebd3b20 Fix test. 2020-06-13 18:53:40 +02:00
Patrick Pelissier cb7cd1ac67 Simplify code 2020-06-13 18:53:28 +02:00
Patrick Pelissier 9a41faf40a Fix -Wsign-conversion warning for strings. 2020-06-13 18:41:23 +02:00
Patrick Pelissier 8c44362f74 More test case. 2020-06-13 18:41:06 +02:00
Patrick Pelissier 548c0c0c61 Fix -Wsign-conversion warning 2020-06-13 18:37:10 +02:00
Patrick Pelissier 607221f480 Fix expected result due to change in list + INIT_WITH 2020-06-13 18:19:29 +02:00
Patrick Pelissier 160c76361b Add -Wsign-conversion when checking with clang 2020-06-13 18:15:53 +02:00
Patrick Pelissier 2fadad0c8d Fix warnings raised by -Wsign-conversion of clang
in m-core.h
2020-06-13 18:15:26 +02:00
Patrick Pelissier 4d4973abcc Fix warning 2020-06-13 17:57:31 +02:00
Patrick Pelissier f8ae9eb677 Add bench of serialization of integers 2020-06-13 17:38:14 +02:00
Patrick Pelissier de825203cf Ignore other temporary files 2020-06-13 17:37:54 +02:00
Patrick Pelissier 4f865176d3 Add bench for serialization. 2020-06-13 17:30:58 +02:00
Patrick Pelissier cb4b43e2e8 * Add length param for seralization write_string
to increase a little bit the performance for big strings.
* Change the format of storing strings for serial-bin.
2020-06-13 17:26:07 +02:00
Patrick Pelissier 89b6e1aac0 Adding serialization for bounded string 2020-06-13 11:30:52 +02:00
Patrick Pelissier daeaa242b8 Add new types to be used for M_LET:
* m_serial_bin_write_t
* m_serial_bin_read_t
2020-06-13 11:21:33 +02:00
Patrick Pelissier 100af17328 Make copyright notice explicit 2020-06-13 10:44:47 +02:00
Patrick Pelissier 7527bfec85 Update comments 2020-06-13 00:17:35 +02:00
Patrick Pelissier f73d25c92d Update documentation after renaming 2020-06-12 20:00:20 +02:00
Patrick Pelissier 9080f5d52f Add basic tests for M_KEEP_ARGS / M_SKIP_ARGS / M_MID_ARGS 2020-06-12 20:00:04 +02:00
Patrick Pelissier 6beb142bbe Fix conflict with SVID2/XPG mallopt options #53 2020-06-12 19:58:18 +02:00
PpHd 9b8b93288a Merge pull request #51 from vladipus/patch-1
Update README.md
2020-06-12 19:42:51 +02:00
Vladislav Dmitrievich Turbanov 6a2a549ec5 Update README.md
Fixed a M_IPTR missing *
2020-06-11 19:46:40 +03:00
Patrick Pelissier 468b7e7a0c Add bench for CMC 2020-06-10 22:29:59 +02:00
Patrick Pelissier fd640e9232 Update change of behaviors 2020-06-08 22:58:52 +02:00
Patrick Pelissier d13d7feae3 Update test as per new behavior 2020-06-08 22:58:41 +02:00
Patrick Pelissier 17f69326e2 Reverse order of a list initialized with M_LET to match the behavior of array 2020-06-08 22:58:30 +02:00
Patrick Pelissier 273fcd51b6 Add bench for rigtorp MPMCQueue 2020-06-06 12:00:52 +02:00
Patrick Pelissier f4b9185ceb Update documentation on QUEUE_MPMC 2020-06-06 11:09:55 +02:00
Patrick Pelissier b722227b39 Update comment 2020-06-05 21:06:06 +02:00
Patrick Pelissier 3d7e2f5c6b Fix m*lib version 2020-06-05 21:01:11 +02:00
Patrick Pelissier 9369530068 Comments & formating 2020-06-05 20:50:34 +02:00
Patrick Pelissier 4e968c3777 Comment the exponential backoff object. 2020-06-05 20:39:16 +02:00
Patrick Pelissier 9a5302ac19 Rename internal backoff
to avoid consummign too much namespace
2020-06-05 20:34:31 +02:00
Patrick Pelissier 8216ef0f7b Factorization of check of index
So that it can be reused for other modules.
2020-06-05 20:30:07 +02:00
Patrick Pelissier b897027021 Add user customizable ARRAY macro
for checking if index is within the allowedd bounds even in release mode
2020-06-05 00:11:22 +02:00
Patrick Pelissier 6095cf8610 Reindent file. 2020-06-04 23:51:17 +02:00
Patrick Pelissier e917ac5663 Update comments and simplify 2020-06-02 22:57:38 +02:00
Patrick Pelissier 2b44892aad Add more comments 2020-05-31 00:36:47 +02:00
Patrick Pelissier 294e45c7e1 Add comments 2020-05-31 00:15:46 +02:00
Patrick Pelissier 467acfdd10 Use of M_BOOL_OPLIST
to avoid warnings.
2020-05-30 23:45:46 +02:00
Patrick Pelissier d3823951b5 Add M_BOOL_OPLIST 2020-05-30 23:45:29 +02:00
Patrick Pelissier cc33079d43 Add comments 2020-05-30 23:38:31 +02:00
Patrick Pelissier 78d0bfb286 Port new error oplist format to all containers. 2020-05-30 18:00:43 +02:00
Patrick Pelissier b2f5ae6917 Proper generation. 2020-05-30 17:54:58 +02:00
Patrick Pelissier 9c723da768 Change format of errror on oplist
This is to enable M_GLOBAL_OPLIST_OR_DEF to properly expand the erroneous oplist to the backend generator, that will report the error.
As such the erreneous oplist is surrounded by two pairs of brackets (())
2020-05-30 17:54:22 +02:00
Patrick Pelissier 70c3932f6e Add new test on proper error checking 2020-05-30 17:52:31 +02:00
Patrick Pelissier 92bddcaab4 Fix preprocessing issue
in case of recursive tuple or variant.
2020-05-30 12:13:43 +02:00
Patrick Pelissier 79a8401d75 Fix oplist definiiton
Improve test suite
2020-05-30 12:07:21 +02:00
Patrick Pelissier 570473e465 Improve test suite. 2020-05-30 11:33:37 +02:00
Patrick Pelissier 990b7b02d7 Update list of expected failures 2020-05-30 11:23:53 +02:00
Patrick Pelissier 0b301d1cea Fix oplist definition. 2020-05-30 11:12:15 +02:00
Patrick Pelissier f35db79792 Work around C++ warnings 2020-05-30 10:46:17 +02:00
Patrick Pelissier dc1f163716 Fix option name with new cl 2020-05-30 10:41:51 +02:00
Patrick Pelissier 4d6bb407ee Reenable MSVC test suite with new compiler version (16.6) 2020-05-30 10:34:02 +02:00
Patrick Pelissier 37cef298c6 Update format 2020-05-29 21:49:03 +02:00
Patrick Pelissier 0396d1f648 Go to next development version 2020-05-29 21:07:43 +02:00
Patrick Pelissier e694d83cc4 V0.4.0 2020-05-27 21:50:03 +02:00
Patrick Pelissier 19fc150763 Discard warning with clang++ 2020-05-27 21:41:31 +02:00
Patrick Pelissier 3784f653d9 Fix warning with CLANG 2020-05-27 21:41:11 +02:00
Patrick Pelissier eb40cff6a1 Improve checkall target to stop on warning 2020-05-27 21:09:07 +02:00
Patrick Pelissier b7f84236d3 * Update comments
* Micro optimization
2020-05-25 21:41:16 +02:00
Patrick Pelissier 65e3f1049b * Update comments.
* Fix position of const for some prototypes.
2020-05-25 00:23:12 +02:00
Patrick Pelissier cc45b9c1fe Fix issue in test suite. 2020-05-24 20:39:20 +02:00
Patrick Pelissier 9340c2e55c Fix memory leak for _parse_str in case of error. 2020-05-24 19:50:32 +02:00
Patrick Pelissier 9710e014f2 Reindent function 2020-05-24 19:19:19 +02:00
Patrick Pelissier 7761fb6bf1 Add contract for tuple & variant. 2020-05-24 19:08:18 +02:00
Patrick Pelissier 2f4df5f67c Fix potential read before init in test. 2020-05-24 19:07:29 +02:00
Patrick Pelissier b841f81416 Fix package name for MS Windows
The filesystem doesn't support '*'
2020-05-24 18:14:25 +02:00
Patrick Pelissier 72fd53ab44 Update comments 2020-05-24 12:01:56 +02:00
Patrick Pelissier 8335bc525b Add comments 2020-05-23 16:09:18 +02:00
Patrick Pelissier 9e5d14ce36 Factorization & add tests 2020-05-21 13:10:50 +02:00
Patrick Pelissier 3bafede8b7 * Make the test more pertinent 2020-05-21 12:32:33 +02:00
Patrick Pelissier 3f2904ab0d * Add comment 2020-05-21 12:32:20 +02:00
Patrick Pelissier 933b495ed1 * Optimization for M_LET for a string_t in case of constant non formatted string
* Support for string_t in M_LET for string_t in C11 mode.
* Adding associate test
2020-05-21 12:19:17 +02:00
Patrick Pelissier 77813adc00 Add example of formatted C string for string in M_LET 2020-05-21 11:55:35 +02:00
Patrick Pelissier ce2adea6c0 Update documentation 2020-05-21 09:54:08 +02:00
Patrick Pelissier 3ecdfff8f0 Remove more cleanly generated configuration file. 2020-05-21 00:54:24 +02:00
Patrick Pelissier a103ceb850 Add new example of array of string. 2020-05-21 00:36:35 +02:00
Patrick Pelissier 9f24b89487 Add debug flag for example 2020-05-21 00:36:13 +02:00
Patrick Pelissier 8be06cadb3 Add comments on description. 2020-05-20 23:21:27 +02:00
Patrick Pelissier c488d979cf Ignore Visual Code directory if any. 2020-05-20 23:05:28 +02:00
Patrick Pelissier f4c24f07af Update comment description of macros and functions 2020-05-20 22:36:36 +02:00
Patrick Pelissier 3d2ce63d63 Fix performance issue in benchmarks 2020-05-19 23:21:00 +02:00
Patrick Pelissier 0ac2c62ffe Port to new API 2020-05-19 22:57:08 +02:00
Patrick Pelissier 6001781e68 Cleanup namespace, add comments, and remove dead code 2020-05-17 21:39:24 +02:00
Patrick Pelissier d90cb7caf3 Update doc 2020-05-17 12:11:10 +02:00
Patrick Pelissier 88a4835025 Fix issue when defining algorithm with same prefix than container 2020-05-17 12:11:04 +02:00
Patrick Pelissier 75ae7a06e5 Add missing tests 2020-05-17 11:53:43 +02:00
Patrick Pelissier 3885cb29a2 Add control of type and oplists 2020-05-17 11:53:27 +02:00
Patrick Pelissier bf3ffd1766 Add test cases for new control 2020-05-17 11:10:06 +02:00
Patrick Pelissier d884d257bb Export TYPE operator in oplist 2020-05-17 10:53:17 +02:00
Patrick Pelissier a87cac84dd Move up control so that it is the first error reported by the compiler. 2020-05-17 10:52:54 +02:00
Patrick Pelissier d1ae26f0fd * Add control than the type and the oplist are compatible 2020-05-17 10:27:30 +02:00
Patrick Pelissier 9c58e73c37 * Add M_CHECK_COMPATIBLE
* Fix issue in oplist
2020-05-17 10:26:40 +02:00
Patrick Pelissier 024b62a7a7 Add instance for M_CHECK_COMPATIBLE to be able to check multiple types within one container. 2020-05-17 10:26:08 +02:00
Patrick Pelissier c59731775e * Provide alternative for M_STATIC_ASSERT in GNUC + C11 with improved error messages
* Add internal macro M_CHECK_COMPATIBLE_OPLIST to check if a type and an oplist could match.
2020-05-17 09:36:50 +02:00
Patrick Pelissier 4668476c6a Fix issue with old version of ICC 2020-05-16 14:47:30 +02:00
Patrick Pelissier 743959ebde Fix micro performance issue 2020-05-16 14:09:49 +02:00
Patrick Pelissier dd27fa7e72 Add coverage for Function Object 2020-05-16 10:24:29 +02:00
Patrick Pelissier f2025f83d3 Fix help usage 2020-05-16 09:41:05 +02:00
Patrick Pelissier 8c06b43b2b Update tests for new controls 2020-05-15 21:46:18 +02:00
Patrick Pelissier 3cde7a1731 Add protection for use of oplist within a container oplist 2020-05-15 21:46:03 +02:00
Patrick Pelissier e9db1d28b8 Try to work around to print the oplist 2020-05-15 21:45:21 +02:00
Patrick Pelissier adffaf0e87 Fix illegal usage of oplist for function object 2020-05-15 21:45:02 +02:00
Patrick Pelissier 49a2e600c4 Add control of sub-oplist when creating a new oplist of a container
Add test case of this new control
Fix some corner bugs in some containers evolving their own oplists.
2020-05-15 21:19:39 +02:00
Patrick Pelissier 0bedcba32b Rewrite M_STATIC_ASSERT to include an error code and message
Add more control on the default expanded macros to check if arguments are compatible
2020-05-15 14:51:20 +02:00
Patrick Pelissier c531f805b0 Define _reduce only if SET method is properly set 2020-05-15 14:31:47 +02:00
Patrick Pelissier da0ab5ea98 Update failure tests as per latest checks 2020-05-11 20:55:16 +02:00
Patrick Pelissier 6774afd751 Add checks of missing oplist in the last _DEF macros 2020-05-11 20:54:50 +02:00
Patrick Pelissier 6d489136e7 Update help 2020-05-10 22:18:19 +02:00
Patrick Pelissier 4ea6dbc7fa Update makefile as per latest version of library 2020-05-10 20:21:03 +02:00
Patrick Pelissier defc58f6a3 Update bench code to latest version of the library. 2020-05-10 20:20:37 +02:00
Patrick Pelissier 006d0d16a5 Fix error 2020-05-10 20:20:03 +02:00
Patrick Pelissier b8af8bb344 Redisable MSVC testing with new version of compiler 2020-05-10 12:40:37 +02:00
Patrick Pelissier e249be1142 Reenable MSVC testing with new version of compiler 2020-05-10 12:38:36 +02:00
Patrick Pelissier 05fde6c3cf Display MSVC compiler full version 2020-05-10 12:06:31 +02:00
Patrick Pelissier aaa1d7dc4b Update description of test 2020-05-10 11:20:16 +02:00
Patrick Pelissier 8c479b2e5a Update tests 2020-05-10 11:17:25 +02:00
Patrick Pelissier 45d2a529b5 Add more validation of oplists before expanding data 2020-05-10 11:16:46 +02:00
Patrick Pelissier 7d17223332 Update comments 2020-05-10 11:15:56 +02:00
Patrick Pelissier 12bc65b6a8 Fix spelling 2020-05-10 11:15:28 +02:00
Patrick Pelissier a849d5c031 Make check-failure tests parallel 2020-05-09 21:39:01 +02:00
Patrick Pelissier f195b09657 Add more tests 2020-05-09 21:38:48 +02:00
Patrick Pelissier 439177ec71 Add protection against wrong oplist in more headers 2020-05-09 21:38:32 +02:00
Patrick Pelissier aadd4f11b1 Update tests as per new checks 2020-05-09 17:16:11 +02:00
Patrick Pelissier 113fdbf388 Add more controls on proper presence of oplist for _DEF macros 2020-05-09 17:16:00 +02:00
Patrick Pelissier 648406a99a Update tests as per new checks 2020-05-09 16:11:11 +02:00
Patrick Pelissier 055e74d350 Add more check for valid oplists before expanding further 2020-05-09 16:10:56 +02:00
Patrick Pelissier ac3d7568f2 Update test 2020-05-09 11:20:05 +02:00
Patrick Pelissier 6c222b9ad7 Raise proper failure if M_let is used without an oplist
Raise proper failure if a TYPE operator is used in an oplist that doesn't export it.
2020-05-09 11:15:44 +02:00
Patrick Pelissier 4426a60904 Add test for testing expected failures 2020-05-09 10:56:31 +02:00
Patrick Pelissier 34f70a031f Use M_STATIC_FAILURE to stop expanding methods in case of detected failure 2020-05-09 10:56:05 +02:00
Patrick Pelissier 79f2f396b9 Add macro M_STATIC_FAILURE to abort expansion in case of error 2020-05-09 10:55:25 +02:00
Patrick Pelissier 88143f7d52 Update ignore file 2020-05-09 10:54:30 +02:00
Patrick Pelissier c1261dd0f2 Fix doc 2020-05-08 21:47:19 +02:00
Patrick Pelissier 8f7a60ea73 Add documentation for function object 2020-05-08 21:43:35 +02:00
Patrick Pelissier 4758bbd6cc Add more tests 2020-05-08 21:23:48 +02:00
Patrick Pelissier 3f66325c19 Add new example for function object, json & algorithms 2020-05-08 17:50:07 +02:00
Patrick Pelissier 6f10d7deb9 Add synonym of serialisater with specialized oplists to be used in RAII 2020-05-08 17:49:44 +02:00
Patrick Pelissier 919900c90a Update documentation 2020-05-08 17:48:56 +02:00
Patrick Pelissier e6daaf429c Add some tests for function objects 2020-05-08 11:37:38 +02:00
Patrick Pelissier 1200f30695 * Add more Function Object support in algorithm
* Fix bug of selection sort
2020-05-08 11:35:22 +02:00
Patrick Pelissier fca1120990 No longer export IT_REF for map containers (See API changes) 2020-05-08 11:33:28 +02:00
Patrick Pelissier 3735704c95 Update new API change 2020-05-08 11:30:57 +02:00
Patrick Pelissier 8c0c1b3102 Update documentation of reduce if the container is empty 2020-05-08 11:30:38 +02:00
Patrick Pelissier db192993f1 Reduce constraint as the dictionnary iteration is not modifiable 2020-05-08 00:27:15 +02:00
Patrick Pelissier 4f44b3f60b Add CMP callback 2020-05-07 22:13:36 +02:00
Patrick Pelissier b196fcc3c0 Rename _cmp_cb_t into _eq_cb_t 2020-05-07 22:10:53 +02:00
Patrick Pelissier 395f1af19e Implement more function object algorithm 2020-05-07 22:09:07 +02:00
Patrick Pelissier d8f761e889 Update Makefile for dist 2020-05-05 23:44:27 +02:00
Patrick Pelissier 563ffb4275 Add first support for function object for certain algos (WIP) 2020-05-05 23:34:34 +02:00
Patrick Pelissier 9ba2de4b70 Add macro M_IF_FUNCOBJ to handle conditional expression if the function object is defined 2020-05-05 23:34:12 +02:00
Patrick Pelissier 0ac6a53fe9 Define callback types 2020-05-05 22:57:19 +02:00
Patrick Pelissier 4431e9f9ae Factorization / Split of the definition of the algorithm 2020-05-05 22:40:03 +02:00
Patrick Pelissier 48526ff5c7 Simplify logic due to fix of M_PARENTHESIS_P 2020-05-04 00:33:00 +02:00
Patrick Pelissier 4ee453025c Add comments 2020-05-04 00:32:40 +02:00
Patrick Pelissier 1e7b543c0f Fix issue with oplists with 3 arguments and fix warnings 2020-05-04 00:30:14 +02:00
Patrick Pelissier 8c2b4f8cf9 Add test cases for function object 2020-05-04 00:29:42 +02:00
Patrick Pelissier 13cadfa470 Update description of the list of headers 2020-05-03 18:00:46 +02:00
Patrick Pelissier deb595372b Add first version of Function Object 2020-05-03 17:49:02 +02:00
Patrick Pelissier 01fd5d929e * Fix M_RET_ARG so that it accepts also a list of the exact number of arguments (instead of one more) * Add more keywords for pattern recognation 2020-05-03 13:13:45 +02:00
Patrick Pelissier 2d60bd2c1b Fix a bug in M_PARENTHESIS_P 2020-05-02 10:19:31 +02:00
Patrick Pelissier 9655b13203 Add more corner cases for M_PARENTHESIS_P 2020-05-02 10:18:52 +02:00
Patrick Pelissier 6b97a7436d Add basic tests for dispathing init_with based on their number of args 2020-05-02 10:06:30 +02:00
Patrick Pelissier 1c792dd0a4 Add option for init_with to dispatch to different methods in function of the number of args 2020-05-02 10:06:08 +02:00
Patrick Pelissier dcbd9f496f Document NAME operator 2020-05-02 09:56:23 +02:00
Patrick Pelissier 9804120cde * Add simple test for registration of int global operator 2020-05-02 09:56:11 +02:00
Patrick Pelissier a9b06718f0 * Add simple test for NAME operator 2020-05-02 09:55:28 +02:00
Patrick Pelissier 963d819e22 * Add NAME operator. * Register default oplist for char,short,int,long,float,double 2020-05-02 09:55:10 +02:00
Patrick Pelissier 28847af43f Update constraints on MOVE & INIT_MOVE operators 2020-04-27 23:12:06 +02:00
Patrick Pelissier 130fa36970 Update iterator constraint 2020-04-27 22:55:53 +02:00
Patrick Pelissier ab99035291 Add another example 2020-04-20 23:50:05 +02:00
Patrick Pelissier 6de43d8a45 Add doc for ALGO_REDUCE with different type 2020-04-20 23:49:48 +02:00
Patrick Pelissier 7b46891622 Add test for ALGO_REDUCE with different type 2020-04-20 23:49:35 +02:00
Patrick Pelissier a0a32d8c6c ALGO_REDUCE accept dest with different type than the container 2020-04-20 23:49:16 +02:00
Patrick Pelissier 1ffd07dc6e Update format 2020-04-11 00:25:40 +02:00
Patrick Pelissier cb49cd7100 * Fix integer overflow in test of mul reduction 2020-04-10 08:35:44 +02:00
Patrick Pelissier 923b340a80 * Update documentation 2020-04-10 08:29:55 +02:00
Patrick Pelissier 5b8750ee2a * Add support for product in ALGO_REDUCE 2020-04-10 08:28:16 +02:00
Patrick Pelissier d438d089fb Add note on the provided oplists 2020-04-10 08:19:59 +02:00
Patrick Pelissier 843ddac3dd Proper prefix internal variables of macros by '_' 2020-04-01 23:40:41 +02:00
Patrick Pelissier c5238e0a4c Add new example for algorithm 2020-04-01 23:40:16 +02:00
Patrick Pelissier f99ee8aa40 Update documentation 2020-04-01 23:28:07 +02:00
Patrick Pelissier 18c7d0e11a Add test for SET_KEY only containers for ALGO_EXTRACT 2020-04-01 23:27:38 +02:00
Patrick Pelissier 4e67823593 Add support for SET_KEY only containers for ALGO_EXTRACT 2020-04-01 23:27:20 +02:00
Patrick Pelissier e7fcefb391 * Dict supports INIT_WITH method too. 2020-03-29 00:49:36 +01:00
Patrick Pelissier be06426783 Add documentation for ALGO_TRANSFORM 2020-03-28 17:41:29 +01:00
Patrick Pelissier e558e83be3 Add test case for ALGO_TRANSFORM 2020-03-28 17:41:16 +01:00
Patrick Pelissier d77a235b2a Add macro ALGO_TRANSFORM 2020-03-28 17:41:04 +01:00
Patrick Pelissier 3add6bb5bf Improve test suite 2020-03-28 17:17:43 +01:00
Patrick Pelissier 4367daaa00 Add documentation for _transform method. 2020-03-28 13:34:17 +01:00
Patrick Pelissier 4d46b3d126 Add basic test cases for _transform method. 2020-03-28 13:34:02 +01:00
Patrick Pelissier 548cd84a7f Add _transform method for algorithm. 2020-03-28 13:33:43 +01:00
Patrick Pelissier d87ffaa572 Improve documentation. 2020-03-28 13:07:35 +01:00
Patrick Pelissier 370cdb4e45 Add another example. 2020-03-28 13:05:15 +01:00
Patrick Pelissier 068d023917 Factorize in m-core.h the pattern recognication. 2020-03-28 11:36:51 +01:00
Patrick Pelissier 86b6ad54d5 Rename filln, filla, fillan into fill_n, fill_a, fill_an (same name as C++) 2020-03-28 11:10:02 +01:00
Patrick Pelissier bdf999a9fc Disable fully VC++ build as the build is fully broken due to regression in version 16.5 vs 16.4 2020-03-26 22:34:51 +01:00
Patrick Pelissier 39f8b6828b Try workaround against regression with new VisualC++ 2020-03-26 22:03:11 +01:00
Patrick Pelissier 11f84ab34b Document new algorithms 2020-03-26 21:49:04 +01:00
Patrick Pelissier c3a5306266 Add function _fill, _filln, _filla, _fillan as algorithms 2020-03-26 21:48:46 +01:00
Patrick Pelissier 1fe9e4c14c Export ADD / MUL / DIV / SUB for basic C types. 2020-03-26 21:44:19 +01:00
Patrick Pelissier e69203dc50 Remove exported PUSH / POP methods as they don't follow stricly the prototypes of such functions. 2020-03-26 21:43:44 +01:00
Patrick Pelissier 342954f272 Fix introduced build error for Mingw 2020-03-25 11:56:38 +01:00
Patrick Pelissier 741d6b8828 Test string + algorithm 2020-03-25 11:44:35 +01:00
Patrick Pelissier f1f41ef320 * Add missing iterator functions * Export iterators in oplist so that it is usable in algorithm 2020-03-25 11:43:55 +01:00
Patrick Pelissier 785792d1f4 Allow build of examples in C11 mode 2020-03-25 11:17:06 +01:00
Patrick Pelissier 9affe3106c Add example of ALGO_FOR_EACH and ALGO_REDUCE 2020-03-25 11:16:19 +01:00
Patrick Pelissier eb9fd14e2c Fix documentation. 2020-03-25 10:19:43 +01:00
Patrick Pelissier c281a2c339 Update CI script to include VC++ 2020-03-02 18:09:53 +01:00
Patrick Pelissier cb109eb479 Add proper progression for special script 2020-03-02 14:35:49 +01:00
Patrick Pelissier 3c6d194974 Add script to launch the test suite with VC++ 2020-03-02 14:25:42 +01:00
Patrick Pelissier 653a0d9734 Fix build issue for systems where double==long double 2020-03-02 14:23:59 +01:00
Patrick Pelissier a5fbd8405c Avoid C99 construct incompatible with strict C++ compiler 2020-02-24 22:27:43 +01:00
Patrick Pelissier 70994d4f60 Update doc 2020-02-16 11:06:43 +01:00
Patrick Pelissier f15203afb2 Comment a little bit more the examples 2020-02-10 06:47:24 +01:00
Patrick Pelissier 0a0d707afd Document bitset 2020-02-08 23:39:30 +01:00
Patrick Pelissier e206c3fe48 Document SPSC buffer 2020-01-23 23:18:33 +01:00
Patrick Pelissier 7f5704d321 Document MPMC buffer 2020-01-09 22:52:02 +01:00
Patrick Pelissier 4f7b0b9455 Happy new year 2020 2020-01-04 15:41:06 +01:00
Patrick Pelissier f5f16015df In quiet mode, if the result of the bench is not assumed to be reliable, display -1 instead of the result. 2020-01-04 15:12:59 +01:00
Patrick Pelissier 935325e0cb Add bench of emilib 2020-01-04 15:06:24 +01:00
Patrick Pelissier 7b9530ac58 Fix name of bench 2020-01-04 15:05:12 +01:00
Patrick Pelissier a9fc259420 ALGO_EXTRACT func argument is now optional 2019-12-30 14:31:21 +01:00
Patrick Pelissier 6f603b52df Update comments 2019-12-30 14:11:41 +01:00
Patrick Pelissier aeb2a47952 Add comments to example 2019-12-30 13:44:03 +01:00
Patrick Pelissier ca7cea3fe3 Use of linear probing and the same hash function as other libraries 2019-12-30 00:12:05 +01:00
Patrick Pelissier f14aca8808 Port to new UDB2 protocol 2019-12-29 23:51:30 +01:00
Patrick Pelissier f1e5e9d9db Simplify code to use get_at method with its get & create semantic 2019-12-29 23:45:17 +01:00
Patrick Pelissier cecba9777a Update documentation on buffer/queues 2019-12-27 16:42:54 +01:00
Patrick Pelissier 4352267034 Update deprecated API 2019-12-27 16:42:00 +01:00
Patrick Pelissier 0c3730d9a3 Migrate version to 0.3.1 2019-12-27 16:41:42 +01:00
Patrick Pelissier 5111b0c726 Deprecated some buffer options since the _blocking functions are much more usefull 2019-12-27 16:39:42 +01:00
Patrick Pelissier 8ecd3f1592 Add best_within and variance 2019-12-23 23:05:48 +01:00
Patrick Pelissier 0a6f8851c9 Update list of bench to launch automatically 2019-12-20 21:37:51 +01:00
Patrick Pelissier f0d3e93d9d Tune for Windows CI: C11 is broken, so switch to C99 and requests ISO C compatible printf function. 2019-12-16 12:44:56 +01:00
Patrick Pelissier e77ff2451b Try setup CCI for windows 2019-12-16 12:31:10 +01:00
Patrick Pelissier 142c224f84 Add another example on complex structure usage 2019-12-15 19:53:46 +01:00
Patrick Pelissier 29e8d9199d Update doc about new API 2019-12-15 19:43:38 +01:00
Patrick Pelissier 7128f5add2 * Add support for API_6 & API_7. * Fix issue for DO_INIT_MOVE that doesn't support API calls 2019-12-15 19:43:26 +01:00
Patrick Pelissier 1b7bcda4e1 Add quiet mode. Add usage 2019-12-15 10:30:40 +01:00
Patrick Pelissier 03b6146ef0 Add option to print only the best or only the average 2019-12-15 10:12:38 +01:00
Patrick Pelissier e99735d2b6 Add repeat option for bench 2019-12-15 10:01:32 +01:00
Patrick Pelissier 7263629c55 Add rigtop hashmap 2019-12-14 20:59:01 +01:00
Patrick Pelissier 605ce9b938 * Update version * Update comments * Improve robustness 2019-12-14 11:12:59 +01:00
Patrick Pelissier 049d8b6ca6 Port to new libdynamic API 2019-12-13 23:00:57 +01:00
Patrick Pelissier 90d3dda830 Clean up generated plot files too 2019-12-09 07:53:43 +01:00
Patrick Pelissier 2022a66db3 * Update makefile (missing coverage) * Refactor 2019-12-08 22:17:56 +01:00
Patrick Pelissier 78c786070e Add coverage support 2019-12-08 22:17:27 +01:00
Patrick Pelissier c5c72007af Update list of files to distribute 2019-12-08 21:53:20 +01:00
Patrick Pelissier c60d59cb7a Port all benchs to new infrastructure 2019-12-07 19:21:21 +01:00
Patrick Pelissier 00111e3e3c Port more bench to new infrzastructure 2019-12-07 14:45:06 +01:00
Patrick Pelissier 5cc2ac17d9 Add support for generating gnuplot graph 2019-12-07 12:22:33 +01:00
Patrick Pelissier d37ea84ab5 Cleanup redundant 'time' word 2019-12-07 11:59:23 +01:00
Patrick Pelissier 5e335bc8bd * Port to generic parser 2019-12-07 11:58:47 +01:00
Patrick Pelissier 65765763ae * Add generic parser for bench. * Factorization 2019-12-07 11:58:19 +01:00
Patrick Pelissier 90f248fbe8 Rename interface field of serial object into m_interface (WINDOWS compatibility as it defines a macro called interface) 2019-12-06 21:13:37 +01:00
Patrick Pelissier a39cf23697 Remove a warning (WINDOWS) 2019-12-06 21:10:00 +01:00
Patrick Pelissier 261776762c Update debugging documentation 2019-12-02 23:38:29 +01:00
Patrick Pelissier f207f9441c Remove linker warning for examples 2019-11-30 00:33:53 +01:00
Patrick Pelissier ffed880e0a Fix static assert for C++ (disable them totally as static_assert doesn't work -- It can't be used in expressions) 2019-11-30 00:08:59 +01:00
Patrick Pelissier a79b67cea2 Generate better error message in case of missing methods in OPLIST for GCC/CLANG 2019-11-29 23:45:48 +01:00
Patrick Pelissier bc3c8b5bcd Fix M_DO_INIT_MOVE / M_DO_MOVE to be more conservative. M_MOVE_DEFAULT doesn't work for all types ([1] structure). A MOVE operator should be defined however. 2019-11-29 23:23:27 +01:00
Patrick Pelissier 3489bb42bc Add static assertion and use it for move/copy/cmp default 2019-11-29 23:13:28 +01:00
Patrick Pelissier 7fe36f7bd7 Add test for M_MOVE_DEFAULT 2019-11-29 23:12:34 +01:00
Patrick Pelissier 82fd4c94db Update CI (Simplify CI tests) 2019-11-25 23:09:54 +01:00
Patrick Pelissier 4fc48b490e Update CI 2019-11-25 23:05:25 +01:00
Patrick Pelissier 750e5e6d95 Add target checkall at root Makefile 2019-11-25 22:50:50 +01:00
Patrick Pelissier cb564128e6 Update doc 2019-11-24 09:16:43 +01:00
PpHd 047fc986f2 Setup github workflows for Continuous Integration 2019-11-24 09:05:44 +01:00
Patrick Pelissier aca800ef8a Fix warning with lastest GCC about strict overflow 2019-11-24 08:50:55 +01:00
Patrick Pelissier dde090d4b0 Make GMP optional for the examples 2019-11-24 08:34:39 +01:00
Patrick Pelissier 87183573ce Ignore generated configuration 2019-11-24 08:27:40 +01:00
Patrick Pelissier baddcc3855 Avoid warning about variable being unused (C11) 2019-11-23 23:28:36 +01:00
Patrick Pelissier ba531774a0 Fix doc 2019-11-21 06:28:28 +01:00
Patrick Pelissier 708d17a4d2 Update README on details on OPLIST 2019-11-21 06:27:32 +01:00
Patrick Pelissier 7d802c03e5 Update README on details on OPLIST 2019-11-21 06:26:10 +01:00
Patrick Pelissier 787e1e9965 Merge branch 'master' of https://github.com/P-p-H-d/mlib 2019-11-05 19:56:09 +01:00
Patrick Pelissier 625691d279 Clarify doc on m-worker 2019-11-05 08:13:16 +01:00
Patrick Pelissier 4f0148dc77 Update doc with new container 2019-11-02 12:56:00 +01:00
Patrick Pelissier c78f2b992f Add support for set based on OA hashmap (DICT_OASET_DEF) 2019-11-02 08:40:24 +01:00
Patrick Pelissier 9857db0d15 Prepare integration of set based on OA hashmap for _ref and _cref 2019-11-02 08:29:44 +01:00
Patrick Pelissier 8b71064643 Simplify code for SET (since EQUAL returns TRUE as an EMPTY method) 2019-11-02 08:24:42 +01:00
Patrick Pelissier bc39034f6d Prepare integration of set based on OA hashmap 2019-11-02 08:17:44 +01:00
Patrick Pelissier e6a9b8fc8e Add M_EMPTY_OPLIST 2019-11-02 08:16:45 +01:00
Patrick Pelissier 3db43dc2db Update comments 2019-11-02 07:33:48 +01:00
Patrick Pelissier d384d5ad6c Always use INIT_MOVE when shrinking or enlarging the OA hashmap (Reversing the order of the last scanning) 2019-11-01 20:01:02 +01:00
Patrick Pelissier 7b2004caad Remove item 2019-10-29 12:32:51 +01:00
Patrick Pelissier 6754f88861 Update 2019-10-29 12:32:36 +01:00
Patrick Pelissier 9393809dfd Update todo 2019-10-26 19:22:33 +02:00
Patrick Pelissier 79ecacb6c0 Clarify what dict to use 2019-10-26 11:11:37 +02:00
Patrick Pelissier 853acbad4b Update doc 2019-10-21 23:13:37 +02:00
Patrick Pelissier e158eac10a Update doc 2019-10-21 22:56:28 +02:00
Patrick Pelissier 48ca2a2384 Add bench for OA for big objects (it confirms that OA dict is not suited for such object) 2019-10-21 22:56:15 +02:00
Patrick Pelissier d9d3d3cbe3 Update doc 2019-10-16 07:03:43 +02:00
Patrick Pelissier 6b4f10bf45 Prepare common macros for both hash tables 2019-10-15 07:33:31 +02:00
Patrick Pelissier 3b647b982f Add linear bench 2019-10-14 21:29:27 +02:00
Patrick Pelissier 00b875ea53 Add linear hash map bench 2019-10-14 20:57:29 +02:00
Patrick Pelissier 545fc4d93c Update doc 2019-10-11 07:50:26 +02:00
Patrick Pelissier c41342739a Reformulate 2019-10-02 08:12:09 +02:00
Patrick Pelissier ed99c5aaa3 Fix spelling 2019-09-28 17:17:14 +02:00
PpHd 08842811e8 Merge pull request #48 from taboege/string-clear-get-str-stack
Fix string_clear_get_str when stack allocated
2019-09-26 07:19:14 +02:00
Tobias Boege 3ea063d1e0 Fix string_clear_get_str when stack allocated
If a string_t is stack-allocated, string_clear_get_str would still try
to copy it from the NULL heap pointer, resulting in a failed assertion.
Copy from the stack instead. Also add a test for this.
2019-09-26 05:39:49 +02:00
Patrick Pelissier a905f12915 Document _cmp_order for tuple 2019-09-22 08:06:56 +02:00
Patrick Pelissier 5d8548b92b Update 2019-09-04 07:41:46 +02:00
Patrick Pelissier 99b63e9c77 Update 2019-08-26 08:04:06 +02:00
Patrick Pelissier 4002ef5aff Fix spelling 2019-08-23 06:42:47 +02:00
Patrick Pelissier d31ccfe8a4 Simplify example code 2019-08-11 10:43:35 +02:00
Patrick Pelissier c4ab76a330 More examples 2019-08-09 08:14:12 +02:00
Patrick Pelissier 84d4277be3 Add new example with basic types usage 2019-08-08 22:23:06 +02:00
Patrick Pelissier 0a99814ce2 Fix comments 2019-08-06 20:47:24 +02:00
Patrick Pelissier 11d695cb57 Update doc 2019-07-31 07:45:31 +02:00
Patrick Pelissier 13e2d6b473 Update issues 2019-07-25 07:10:45 +02:00
Patrick Pelissier e8137e4218 Fix spelling 2019-07-24 21:27:06 +02:00
Patrick Pelissier fe5df08d6e Update comments 2019-07-20 09:32:09 +02:00
Patrick Pelissier f77017f35f Update current limitation 2019-07-16 23:21:52 +02:00
Patrick Pelissier ce93c00a7b Workaround limitation of M_MOVE_DEFAULT for [1] structure (==> It supposes now that the destination parameter is **not** a type with [1] tricks or at least not a pointer to it, instead of having this constraint for both arguments). 2019-07-16 23:21:41 +02:00
Patrick Pelissier b8f44cc219 Fix bug (number of reader was too big, resulting in potential segfault) 2019-07-16 23:00:10 +02:00
Patrick Pelissier 2c921fdefe Improve test suite of snapshot to detect incorrect issues of INIT/CLEAR call by a container. 2019-07-16 23:00:10 +02:00
Patrick Pelissier 20eb95ba45 Update comments 2019-07-16 23:00:10 +02:00
Patrick Pelissier 7a6239912e Simplify code 2019-07-12 12:30:04 +02:00
Patrick Pelissier 9067311788 Update comment 2019-07-12 11:50:46 +02:00
Patrick Pelissier 23b2e07132 Add basic testing for _push_move method 2019-07-11 13:38:58 +02:00
Patrick Pelissier c8f2c0e06e Add _push_move method for SPSC 2019-07-11 13:38:40 +02:00
Patrick Pelissier 72c4eb80a2 Add doc on non documented operators 2019-07-11 12:56:00 +02:00
Patrick Pelissier 1f18e788e6 Update comments 2019-07-11 12:36:01 +02:00
Patrick Pelissier f855e24b56 Add description of operator INC_ALLOC 2019-07-11 12:29:00 +02:00
Patrick Pelissier 84d1b7ad50 Update doc 2019-07-08 21:35:59 +02:00
Patrick Pelissier 9f82649aa8 Add test for multiset 2019-07-08 21:25:19 +02:00
Patrick Pelissier 791f586c7e Add back contract support for multimap / multiset 2019-07-08 21:18:59 +02:00
Patrick Pelissier 8d3b0cc94b Prepare support in contract for multimap/multiset 2019-07-08 21:14:15 +02:00
Patrick Pelissier 70d1dfeb8b Add test case for multimap 2019-07-08 16:23:59 +02:00
Patrick Pelissier 9a4c6ba0d5 WIP for multimap / multiset. 2019-07-08 16:23:45 +02:00
Patrick Pelissier ef2dbf89ee Improve test 2019-07-08 11:36:09 +02:00
Patrick Pelissier d30b776fb0 Add more test 2019-07-08 11:33:42 +02:00
Patrick Pelissier 6408b28513 Update comments, function name and prepare for multimap / multiset 2019-07-08 11:17:08 +02:00
Patrick Pelissier 32b3e21564 Start supporting multimap/multiet 2019-07-07 21:18:34 +02:00
Patrick Pelissier 1ef28bedcb Rename internal functions for clarity 2019-07-07 21:16:04 +02:00
Patrick Pelissier 1356bb746e Add more tests 2019-07-06 10:44:49 +02:00
Patrick Pelissier 23240a44d5 Change how the keys are split. Before key[i] ==> node[i] has all keys < key[i], node[i+1] has all keys >= key[i]. After key[i] ==> node[i] has all keys <= key[i], node[i+1} has all keys > key[i]. 2019-07-06 00:03:26 +02:00
Patrick Pelissier 589c023622 Update test 2019-07-06 00:01:13 +02:00
Patrick Pelissier 047b6c5a58 Update 2019-07-04 21:10:38 +02:00
Patrick Pelissier 951425e963 Update comments 2019-07-04 10:42:24 +02:00
Patrick Pelissier e69cbfcab3 Add parameter isMulti 2019-07-04 09:53:58 +02:00
Patrick Pelissier 37f3cd6a72 Rename method _it_to_p into _it_until_p. Add method _it_while_p 2019-07-03 18:57:24 +02:00
Patrick Pelissier ec7b5dd120 Remove deprecated methods 2019-07-03 18:06:52 +02:00
Patrick Pelissier d50a78171f Bump to version 0.3.0 2019-07-03 18:06:39 +02:00
Patrick Pelissier b422aec2cd Add new example 2019-06-25 07:04:33 +02:00
Patrick Pelissier 7ba0e03b4f Add comments 2019-06-20 21:36:12 +02:00
Patrick Pelissier c535766c22 Update/Clean up basic type 2019-06-17 07:26:11 +02:00
Patrick Pelissier 289a3fdc71 Fix confusing position of { 2019-06-10 23:20:36 +02:00
Patrick Pelissier 7f0b6208a4 Propose a shorter version of the example. 2019-06-10 22:59:47 +02:00
Patrick Pelissier 60a10eb799 Uniformize the macro names 2019-06-09 12:02:38 +02:00
Patrick Pelissier 5321085856 Uniformize & add intermediary evaluation step for dict oplist
(like all other containers)
2019-06-09 11:39:15 +02:00
Patrick Pelissier 03be814a4d Uniformize macro names 2019-06-09 11:38:39 +02:00
Patrick Pelissier 6c3f7683a5 Uniformize API 2019-06-09 11:26:45 +02:00
Patrick Pelissier 06d6a90a21 Uniformize internal macros 2019-06-09 11:02:45 +02:00
Patrick Pelissier 747da27489 Uniformize 2019-06-09 10:49:18 +02:00
Patrick Pelissier 2869345920 Add test dor dual-push list for algo 2019-06-09 10:05:34 +02:00
Patrick Pelissier 6b8938cf76 Update comments.
Rename / Uniformize internal macros.
2019-06-09 10:01:50 +02:00
Patrick Pelissier 8e7eae5751 Update comments. 2019-06-09 09:32:35 +02:00
Patrick Pelissier 1882148a7c Add more assertions 2019-06-08 10:45:24 +02:00
Patrick Pelissier e46746ce01 Fix format string 2019-06-08 10:33:26 +02:00
Patrick Pelissier 32917e2cfa Add variant & prioqueue to tests then with concurrent 2019-06-08 10:07:03 +02:00
Patrick Pelissier 65a243fc13 Add missing const 2019-06-08 10:06:47 +02:00
Patrick Pelissier 1e011cb851 Add missing const in prototypes. 2019-06-08 09:59:16 +02:00
Patrick Pelissier 48f585a4ee Update comments 2019-06-08 09:47:49 +02:00
Patrick Pelissier bc10b616ae Update doc 2019-06-08 09:31:18 +02:00
Patrick Pelissier 851f08131d Update 2019-06-07 07:46:54 +02:00
Patrick Pelissier e294f4557e Update 2019-06-06 22:07:09 +02:00
Patrick Pelissier 9e5775fc16 Add example of serialization 2019-06-06 07:44:33 +02:00
Patrick Pelissier 8eb95d0cdc Update doc 2019-06-05 22:05:02 +02:00
Patrick Pelissier 42f807d64b Rename test file 2019-06-02 10:39:55 +02:00
Patrick Pelissier d1bb97ac52 Add new serializer 2019-06-02 10:39:24 +02:00
Patrick Pelissier f502b16b1d Fix bug 2019-06-02 10:31:25 +02:00
Patrick Pelissier 51e5764258 Add comment 2019-06-02 10:05:27 +02:00
Patrick Pelissier ec2281c29a Use of proper cast 2019-06-02 09:25:19 +02:00
Patrick Pelissier acfe1cb7e8 Update documentation for serialization 2019-05-28 22:50:16 +02:00
Patrick Pelissier 594aebd903 Fix comment 2019-05-28 22:50:06 +02:00
Patrick Pelissier 8bca63ac08 Fix MD syntax 2019-05-28 21:54:12 +02:00
Patrick Pelissier c02ec4f94c Update comments 2019-05-19 10:27:23 +02:00
Patrick Pelissier 797ac1f0da Fix for 32 bits system 2019-05-18 18:55:51 +02:00
Patrick Pelissier 058d3202ff Amend 2019-05-18 14:09:10 +02:00
Patrick Pelissier 62fcdac9cb Update list of headers 2019-05-18 14:08:17 +02:00
Patrick Pelissier b9131353b6 Add test 2019-05-18 11:17:15 +02:00
Patrick Pelissier a34deb2f3b Workaround warning. 2019-05-18 11:17:15 +02:00
Patrick Pelissier 9ef4b5c93f Fix cast 2019-05-18 11:17:14 +02:00
Patrick Pelissier 417b0295be Add C++ compatibility 2019-05-18 11:17:14 +02:00
Patrick Pelissier d11409bcc6 Add proper cast 2019-05-18 11:17:14 +02:00
Patrick Pelissier 928b81f454 Fix return value for in_serial/out_serial 2019-05-18 11:17:14 +02:00
Patrick Pelissier 05a68157bc Add local argument to serial interface to enable serial interface to create local parameters if needed (for example for serial binary) 2019-05-18 11:17:14 +02:00
Patrick Pelissier b6d5b5462b Update interface needed for serial 2019-05-18 11:17:14 +02:00
Patrick Pelissier 1c77082a29 Update comments 2019-05-18 11:17:14 +02:00
Patrick Pelissier 363c55668d Add in_serial / out_serial methods for several containers 2019-05-18 11:17:14 +02:00
Patrick Pelissier 7ed85fb97a Add in_serial / out_serial for concurrent containers 2019-05-18 11:17:14 +02:00
Patrick Pelissier 585ea1293d Add in_serial / out_serial for lists 2019-05-18 11:17:14 +02:00
Patrick Pelissier 448072555f Update comments 2019-05-18 11:17:14 +02:00
Patrick Pelissier 4701d5919b Fix serial import/export for variant 2019-05-18 11:17:14 +02:00
Patrick Pelissier 0997f59665 Update for variant 2019-05-18 11:17:14 +02:00
Patrick Pelissier dcf7a94728 Add in_serial / out_serial for variant 2019-05-18 11:17:14 +02:00
Patrick Pelissier 12ba563416 Add assertions 2019-05-18 11:17:14 +02:00
Patrick Pelissier f2fffb9219 Factor comment 2019-05-18 11:17:14 +02:00
Patrick Pelissier 3f03615ed2 Simplify code by factoring fscanf calls 2019-05-18 11:17:14 +02:00
Patrick Pelissier bc6bda057c Add in_serial / out_serial for array 2019-05-18 11:17:14 +02:00
Patrick Pelissier aeebe42bfb Fix issues for EOF & parsing arrays 2019-05-18 11:17:14 +02:00
Patrick Pelissier 5c4c93b62f Add missing export/import JSON interface 2019-05-18 11:17:14 +02:00
Patrick Pelissier c3ddd48d38 Simplify code 2019-05-18 11:17:14 +02:00
Patrick Pelissier 98f3c40ac5 add export/import of JSON string 2019-05-18 11:17:14 +02:00
Patrick Pelissier ada1b9861f Add size_of_type field for reading too 2019-05-18 11:17:13 +02:00
Patrick Pelissier 50cc8689bb Add serial methods for string_t 2019-05-18 11:17:13 +02:00
Patrick Pelissier 83da861a9c Simplify code by using more fscanf possibility 2019-05-18 11:17:13 +02:00
Patrick Pelissier 1cb1d16e77 Simplify code by using fscanf behvior on white space 2019-05-18 11:17:13 +02:00
Patrick Pelissier b525723084 Implement Serial Json Read tuple 2019-05-18 11:17:13 +02:00
Patrick Pelissier 4accdc994d Add JSON/read interface 2019-05-18 11:17:13 +02:00
Patrick Pelissier ad9bee0eec Add JSON serializer 2019-05-18 11:17:13 +02:00
Patrick Pelissier 6c7ff1c723 Update/fix bugs 2019-05-18 11:17:13 +02:00
Patrick Pelissier 3b2aad1b2e Export new methods for tuple 2019-05-18 11:17:13 +02:00
Patrick Pelissier 5222fabf02 Add tuple support for serial 2019-05-18 11:17:13 +02:00
Patrick Pelissier 44abead174 Update IN_SERIAL & OUT_SERIAL for default types. 2019-05-18 11:17:13 +02:00
Patrick Pelissier 492d5f0f9a Add IN_SERIAL & OUT_SERIAL for default types. 2019-05-18 11:17:13 +02:00
Patrick Pelissier 9bc5ac3df8 Start implementating generic serialization 2019-05-18 11:17:13 +02:00
Patrick Pelissier 5c726d63f4 Fix 2019-05-15 07:38:16 +02:00
Patrick Pelissier 2cd0a8db74 Uniformize the way of displaying the location of errors in the error message 2019-05-11 01:16:54 +02:00
Patrick Pelissier 0fa0445fa9 Fix C++ warning -Wclass-memaccess with G++ >= 8 2019-05-10 23:13:54 +02:00
Patrick Pelissier 1e171f9cc0 Increase NARGS support to 75 2019-05-10 21:39:18 +02:00
Patrick Pelissier 8d16ea4bf4 Increase maximum number of operators per oplist to 75 2019-05-10 21:26:18 +02:00
Patrick Pelissier a0c2ead91d Fix bug for M_AS_TYPE and small types 2019-05-10 10:20:38 +02:00
Patrick Pelissier b2875f6ba0 Add BSTRLIB for MASTER STRING BENCHMARK 2019-05-10 08:18:38 +02:00
Patrick Pelissier edb4ccf63e Add algo functions _remove_val & _remove_if 2019-05-07 16:35:39 +02:00
Patrick Pelissier 481009d18b Add function _end_with for strings. 2019-05-07 16:12:43 +02:00
Patrick Pelissier 6153383dab Update indent 2019-05-07 16:05:47 +02:00
Patrick Pelissier 74fed41818 Update version 2019-05-07 16:01:50 +02:00
Patrick Pelissier 2d5de1b9ea Update comments 2019-04-29 12:32:29 +02:00
Patrick Pelissier e23691c743 Fix spelling 2019-04-24 07:47:15 +02:00
Patrick Pelissier aaac236db6 Update README 2019-04-22 18:31:47 +02:00
Patrick Pelissier ccccedc2d5 Rework failure messages. 2019-04-22 18:30:46 +02:00
Patrick Pelissier 446afb04c7 Remove unused macro M_INIT_FAILURE 2019-04-22 12:07:53 +02:00
Patrick Pelissier 87cd964329 Uniformize error messages 2019-04-22 11:45:29 +02:00
Patrick Pelissier 80a344e46d Update version 2019-04-22 11:34:35 +02:00
Patrick Pelissier f2eb5014ac Fix regression on 32 bits for strings. 2019-04-21 23:50:42 +02:00
Patrick Pelissier d6c72061ce add new bench on strings 2019-04-21 23:13:29 +02:00
Patrick Pelissier 7c26fd25c9 Add SDS & RAPIDSTRING replace function implemented at used level 2019-04-21 19:54:20 +02:00
Patrick Pelissier 10e12d2b5c Update 2019-04-21 11:21:45 +02:00
Patrick Pelissier b9070f89d9 Update 2019-04-21 10:43:17 +02:00
Patrick Pelissier 46d41a8882 Fix bad merge 2019-04-20 12:33:09 +02:00
Patrick Pelissier b5dc3481d4 Update doc 2019-04-20 12:33:08 +02:00
Patrick Pelissier c18cd81dde Add more assumes needed for static analysis. 2019-04-20 12:33:08 +02:00
Patrick Pelissier eaf5a26157 Minor speed up 2019-04-20 12:33:08 +02:00
Patrick Pelissier 547c67b676 Modify string_t so that it can still be trivially movable once again. 2019-04-20 12:33:08 +02:00
Patrick Pelissier c89d6ef0ce Fix test. 2019-04-20 12:33:08 +02:00
Patrick Pelissier a54041c340 Minor fix 2019-04-20 12:33:08 +02:00
Patrick Pelissier 352e0972cd Comment code 2019-04-20 12:33:08 +02:00
Patrick Pelissier 91ebd7cc9f Cleanup code 2019-04-20 12:33:08 +02:00
Patrick Pelissier d8854c276b Cleanup code 2019-04-20 12:33:08 +02:00
Patrick Pelissier cc61840ae8 Refactor code 2019-04-20 12:33:08 +02:00
Patrick Pelissier 67a7a4762a Refactor code 2019-04-20 12:33:08 +02:00
Patrick Pelissier c28597014f Add more hypothesis 2019-04-20 12:33:08 +02:00
Patrick Pelissier d00f29bf26 Fix bug 2019-04-20 12:33:08 +02:00
Patrick Pelissier 1432fbabca Update buffer to have proper alignement so that we can perform hash computation properly. 2019-04-20 12:33:08 +02:00
Patrick Pelissier f3b6ee0190 Continue porting to new format. 2019-04-20 12:33:08 +02:00
Patrick Pelissier 229d21ef72 Add assume 2019-04-20 12:33:08 +02:00
Patrick Pelissier 00f1b1fc4f Update comment 2019-04-20 12:33:08 +02:00
Patrick Pelissier 277d8b37af Continue porting to new format. 2019-04-20 12:33:08 +02:00
Patrick Pelissier 7b83761ef4 Update 2019-04-20 12:33:08 +02:00
Patrick Pelissier a96e9c7e11 Update string contract 2019-04-20 12:33:08 +02:00
Patrick Pelissier 866721d067 Add first prototype of string with stack allocation. 2019-04-20 12:33:08 +02:00
Patrick Pelissier b356c29c89 Add PGO 2019-04-20 12:29:59 +02:00
Patrick Pelissier a2f7cb7670 Add C Macro Collections ref 2019-04-20 10:24:20 +02:00
Patrick Pelissier 08887c1df0 Add PGO 2019-04-20 09:08:10 +02:00
Patrick Pelissier 8b0a9f2da9 Cleanup Makefile 2019-04-20 08:51:52 +02:00
Patrick Pelissier e6c958c0df Fix data race. 2019-04-19 07:57:10 +02:00
Patrick Pelissier 01ad221972 Rewrite RP so that writers cannot starve and avoid warnings with thread sanitizer. 2019-04-11 20:07:27 +02:00
Patrick Pelissier c269a36e8b Add thread test for RP_CONCURRENT 2019-04-07 19:03:03 +02:00
Patrick Pelissier 95fcd054a3 Fix error in lock orders. 2019-04-04 21:22:37 +02:00
Patrick Pelissier 7760f16260 Fix memory leaks 2019-04-04 08:31:26 +02:00
Patrick Pelissier 6d016d732b Update tags 2019-03-31 22:37:00 +02:00
Patrick Pelissier b9aebf875e Update comments. 2019-03-31 22:36:52 +02:00
Patrick Pelissier 1eb0e8730d Use algorithm with dictionary too. 2019-03-24 08:38:52 +01:00
Patrick Pelissier 7eb26a29f1 Reduce the number of mandatory operators for algorithm:
* EQUAL
* INIT
are not optional (methods depending on them won't be generated
if the operators are not defined).
2019-03-24 08:37:57 +01:00
Patrick Pelissier 0ef051e6d2 Add GLIB to string bench 2019-03-24 08:29:32 +01:00
Patrick Pelissier 0d641f0d17 Update documentation 2019-03-22 07:53:13 +01:00
Patrick Pelissier ce6a7f6cb3 Add missing _it_end for normal dict & export it for both dict 2019-03-15 07:44:58 +01:00
Patrick Pelissier 07b4c1a9f4 Update image 2019-03-12 21:43:33 +01:00
Patrick Pelissier 4d3a82583d Update doc 2019-03-12 21:43:18 +01:00
Patrick Pelissier 2835d53ef1 Clean up code. 2019-03-12 21:42:53 +01:00
Patrick Pelissier 620ecadec1 Update doc 2019-03-12 07:49:04 +01:00
Patrick Pelissier dc803f23bb Add missing const 2019-03-09 16:38:44 +01:00
Patrick Pelissier a6d11fe897 Update doc (ALGO part) 2019-03-09 16:38:25 +01:00
Patrick Pelissier 78b05690e7 Update README 2019-03-07 19:28:46 +01:00
Patrick Pelissier 958a79ad73 Add another example 2019-03-07 19:25:39 +01:00
Patrick Pelissier ead25c905a Factorize common macro for FLA 2019-03-07 07:42:50 +01:00
Patrick Pelissier 97f80450ca Update issue 2019-02-21 20:19:04 +01:00
Patrick Pelissier 8e62537604 Update ISSUE 2019-02-20 11:46:58 +01:00
Patrick Pelissier 7813182e2b Update test. 2019-02-19 20:22:55 +01:00
Patrick Pelissier b199fef674 Update comments and move commented asm into common function. 2019-02-18 11:02:13 +01:00
Patrick Pelissier e27c06c227 Fix regression build with SDS & rapidstring 2019-02-18 10:55:51 +01:00
Patrick Pelissier 41b04f34e2 Fix: Uses of __thread after static keyword 2019-02-18 10:53:27 +01:00
Patrick Pelissier b091f84f90 Update code after benching empty creation of string. 2019-02-18 10:48:03 +01:00
Patrick Pelissier 05ae9f382b Update the barrier used to prevent the compiler from over-optimizing.
Shall be could enought except if using FLTO.
2019-02-18 10:47:28 +01:00
Patrick Pelissier a36efcd888 Create new helper compiler_barrier to prevent compiler from over-optimizing bench. 2019-02-18 10:46:21 +01:00
Patrick Pelissier af2fe9ccf9 Fix issue (sizeof instead of offsetof) 2019-02-17 09:54:56 +01:00
Patrick Pelissier c4a5727c2a Fix deref of NULL pointer. 2019-02-17 09:50:04 +01:00
Patrick Pelissier 31ca762c62 Add a new test case for empty string. 2019-02-17 09:49:49 +01:00
Patrick Pelissier 30bda70319 Fix issue. 2019-02-17 09:36:18 +01:00
Patrick Pelissier 7fa9d375b8 Add bench of small non empty constructor 2019-02-17 08:35:11 +01:00
Patrick Pelissier 91ae3fd4f2 Add memory barrier to limiting the effect of the optimizer on inline implementation 2019-02-16 23:20:36 +01:00
Patrick Pelissier b00d6a9655 Add CSV output to string bench 2019-02-16 22:30:39 +01:00
Patrick Pelissier 013aa58524 Update documentation 2019-02-16 09:01:57 +01:00
Patrick Pelissier 8ce7e0483f Update comment 2019-02-13 08:24:21 +01:00
Patrick Pelissier 582c413cd2 Add VLA allocation compatible with concurrent mempool & gc 2019-02-13 08:19:07 +01:00
Patrick Pelissier 22e16e983b Separate mempool in two concepts:
* A Garbage Collector that centralizes the connexion with the threads
  and registers all mempools
* the mempool that is responsible for alloc/dec of nodes.

It allows having multiple mempools registered in a GC.
2019-02-10 10:26:20 +01:00
Patrick Pelissier 7c0c16260a Update doc 2019-02-05 22:56:02 +01:00
Patrick Pelissier e496fbd152 Add test for string_t + OA DICT 2019-01-27 22:59:03 +01:00
Patrick Pelissier e025de91ab Adding OOR methods for string_t 2019-01-27 22:32:47 +01:00
Patrick Pelissier 69e2fc432f Update doc about limitation of operator TEST_EQUAL 2019-01-27 21:16:19 +01:00
Patrick Pelissier 78ba83ce42 * Fix BOUNDED_STRING_CTE macro. In OOR context, it may create invalid constant that triggers
assumption fault.
* Fix _equal_p in OOR context for bounded string. This method can be called in OOR context,
so the contracts may not be verified.
2019-01-27 17:33:47 +01:00
Patrick Pelissier 6d9b61c119 Reindent 2019-01-27 17:33:17 +01:00
Patrick Pelissier 61cfa5cedd Use of proper contract for BOUNDED_STRING. 2019-01-26 14:00:32 +01:00
Patrick Pelissier 0507d94306 Add test for IO for BOUNDED STRING 2019-01-26 13:39:47 +01:00
Patrick Pelissier 7e8919080b Add IO for BOUNDED STRING 2019-01-26 13:38:54 +01:00
Patrick Pelissier 8406efcaab Add test case of BOUNDED_STRING + OA DICT 2019-01-26 12:03:13 +01:00
Patrick Pelissier 2d87eb1e6a Adding default OOR_EQUAL & OOR_SET for BOUNDED_STRING
to be used in OA dict
2019-01-26 12:02:50 +01:00
Patrick Pelissier 4685aac454 Add test for hash of empty string 2019-01-26 09:10:36 +01:00
Patrick Pelissier 9863a8325c Fix assertion. NULL pointer is accepted for HASH providing the size is 0 2019-01-26 09:10:18 +01:00
Patrick Pelissier b9514cbe72 Fix usage of API with OOR EQUAL of OA Dict 2019-01-25 20:37:33 +01:00
Patrick Pelissier 7b085d18fc Add test case of OA DICT + concurrent 2019-01-25 20:19:52 +01:00
Patrick Pelissier 91e73520f3 Fix issue of non being able to use API_2 with OOR_SET for OA dict 2019-01-25 20:19:31 +01:00
Patrick Pelissier aebf5c83ba Update description of STORED_HASH dict as per remark of #44 2019-01-25 19:47:47 +01:00
Patrick Pelissier 42ff47f511 Fix issue described in #44 (missing types for OA dict) 2019-01-25 19:47:46 +01:00
Patrick Pelissier 746bdf144b Fix warning with CLANG7 2019-01-24 07:44:36 +01:00
Patrick Pelissier 4e8f5f7b51 Add test for queue SPSC 2019-01-21 22:20:28 +01:00
Patrick Pelissier 50d89f71cb Update 2019-01-21 22:06:31 +01:00
Patrick Pelissier d70ef53283 Add _push_force for QUEUE SPSC 2019-01-20 23:59:33 +01:00
Patrick Pelissier 1b6182c1cd Update 2019-01-20 23:57:33 +01:00
Patrick Pelissier 73b50c852a Add bench for SPSC in BULK mode 2019-01-16 05:08:03 +01:00
Patrick Pelissier 063011d8e9 Adding yield in case of failure of push/pop 2019-01-16 04:46:06 +01:00
Patrick Pelissier 0f3bf6ab82 Add _bulk version for SPSC queue. To test/bench 2019-01-15 23:27:02 +01:00
Patrick Pelissier 475836e851 Use of new macro M_CACHELINE_ALIGN 2019-01-15 19:11:10 +01:00
Patrick Pelissier 325ca30c61 Add M_CACHELINE_ALIGN macro 2019-01-15 19:10:39 +01:00
Patrick Pelissier 72e872c768 Remove outdated comment 2019-01-15 07:34:19 +01:00
Patrick Pelissier c2a837b30b Update 2019-01-15 07:32:13 +01:00
Patrick Pelissier 08822ac7d5 Update 2019-01-15 07:25:11 +01:00
Patrick Pelissier 7f9007ca1a Add UPDATE_TYPE 2019-01-11 07:58:20 +01:00
Patrick Pelissier f067cb334c Add missing return after M_MEMORY_FULL 2019-01-05 19:57:53 +01:00
Patrick Pelissier 60ee253fa7 Update 2019-01-05 13:15:50 +01:00
Patrick Pelissier 4642e0b506 Workaround issue of stdatomic on MSYS2/GCC 2019-01-05 00:19:09 +01:00
Patrick Pelissier bd29680b62 Add explanations as comment 2019-01-03 07:45:08 +01:00
Patrick Pelissier c337462af6 Use extension to silent warnings about C11 features used in C99 2019-01-02 22:37:40 +01:00
Patrick Pelissier c990277855 Add extension attribute support 2019-01-02 22:34:39 +01:00
Patrick Pelissier 8870a1c2f9 Remove atomic qualifier for one variable (useless) 2019-01-02 22:16:08 +01:00
Patrick Pelissier 60f1454550 Fix incorrect qualifier position for emulation layer (issue for atomic pointer definition) 2019-01-02 22:15:47 +01:00
Patrick Pelissier 38eb1c26c6 Variable number of threads for concurrent memory pool 2019-01-02 21:48:53 +01:00
Patrick Pelissier af050d0100 Port to C++ madness 2019-01-02 21:21:24 +01:00
Patrick Pelissier 14f3ae5cea Fix issue 2019-01-02 21:21:06 +01:00
Patrick Pelissier f4ed750d39 Add first test case for concurrent memory pool 2019-01-02 21:13:01 +01:00
Patrick Pelissier 4b3adc8d35 Add first WIP Concurrent Memory Allocator 2019-01-02 20:45:06 +01:00
Patrick Pelissier 8b3a4a802c Happy new year! 2019-01-02 18:12:07 +01:00
Patrick Pelissier 8b9f605ffa Add exponential backoff structure & functions 2019-01-02 18:09:16 +01:00
Patrick Pelissier 3c56f24db2 Update analysis 2018-12-29 00:16:50 +01:00
Patrick Pelissier 82dbf60a4c Use of the standard naming for User Defined macro that can customize the code generation. Rename macros WORKER_DISABLE. 2018-12-23 23:49:19 +01:00
Patrick Pelissier b596e81e88 Regenerate depend 2018-12-14 21:48:21 +01:00
Patrick Pelissier b7bbe15547 Fix missing header in install 2018-12-14 21:46:38 +01:00
Patrick Pelissier cb5f8c20c8 Update analysis 2018-12-11 23:23:09 +01:00
Patrick Pelissier 61a1e15103 Update analysis 2018-12-11 23:19:33 +01:00
Patrick Pelissier 2416c2e466 Fix bug of overflow of 'alloc-num' if alloc < num (case where the service is called with a big number to insert 2018-12-05 17:52:02 +01:00
Patrick Pelissier b898ce3c56 update analysis 2018-11-29 23:24:11 +01:00
Patrick Pelissier 061e83b9e1 Add basic test for CONCURRENT_RP_DEF 2018-11-29 22:18:44 +01:00
Patrick Pelissier 0a8f727908 Remove CONCURRENT_RP2_DEF (Insuficient performance) 2018-11-27 07:47:06 +01:00
Patrick Pelissier ba584ab096 Use M_THREAD_ATTR 2018-11-26 23:26:42 +01:00
Patrick Pelissier 1fb1fa2e0a Add M_THREAD_ATTR 2018-11-26 23:26:08 +01:00
Patrick Pelissier 8cf780a60f Update comment 2018-11-25 22:43:37 +01:00
Patrick Pelissier ae171115bc Export method _size in concurrent if operator GET_SIZE defined. 2018-11-25 18:03:25 +01:00
Patrick Pelissier a8620c3aff Export method _size for operator GET_SIZE 2018-11-25 18:00:47 +01:00
Patrick Pelissier c154cdf46c Add operator GET_SIZE 2018-11-25 17:52:24 +01:00
Patrick Pelissier 77c59e2b85 Fix const issue. 2018-11-25 17:49:36 +01:00
Patrick Pelissier f07656757f Add another candidate for concurrent with parallel reader. 2018-11-25 11:44:28 +01:00
Patrick Pelissier a1c22fb679 Add first alpha version of Concurrent Container with support concurrent reading. 2018-11-24 19:31:31 +01:00
Patrick Pelissier 3640041c47 Port internal functions of concurrent to use the local lock interface. 2018-11-24 12:20:37 +01:00
Patrick Pelissier d3934dccb9 Add missing const in prototypes. 2018-11-24 11:46:28 +01:00
Patrick Pelissier 10cf2f2270 Prepare concurent for using different lock strategy 2018-11-24 11:37:09 +01:00
Patrick Pelissier c180b2b96d Update analysisd 2018-11-22 07:49:15 +01:00
Patrick Pelissier 5d5c2380ed Update release notes due to valgrind being unable to launch the test suite and scan-build producing too many false positives. 2018-11-16 22:54:04 +01:00
Patrick Pelissier a8b5c3ff4e Improve assertions 2018-11-10 17:54:13 +01:00
Patrick Pelissier 16587aeb93 Update doc 2018-11-08 20:55:28 +01:00
Patrick Pelissier 629a3a3dc1 Update depend 2018-11-08 20:54:42 +01:00
Patrick Pelissier ea46379d24 Update long term issue. 2018-11-07 19:54:07 +01:00
Patrick Pelissier ee0c77edc8 Replace SET+CLEAR by MOVE. 2018-11-04 20:28:56 +01:00
Patrick Pelissier c0610b2d60 Update doc 2018-11-04 20:15:15 +01:00
Patrick Pelissier 13ab545246 Update example for concurrent 2018-11-03 19:05:57 +01:00
Patrick Pelissier d85d6bcb13 Update doc 2018-11-01 17:21:11 +01:00
Patrick Pelissier 138662d6a0 Update checkall 2018-11-01 16:29:55 +01:00
Patrick Pelissier e45437e19f Add missing const 2018-11-01 16:11:42 +01:00
Patrick Pelissier 725846e155 Add missing type 2018-11-01 16:11:27 +01:00
Patrick Pelissier 74aa514903 Add missing const 2018-11-01 16:11:12 +01:00
Patrick Pelissier 7f7230be90 Fix doc 2018-10-31 17:38:04 +01:00
Patrick Pelissier d4a6e8c47a Add doc for m-concurrent 2018-10-31 17:37:17 +01:00
Patrick Pelissier 9c19ed4471 Add more encapsulation tests. 2018-10-31 11:33:58 +01:00
Patrick Pelissier 357c37c69d Add missing const qualifier 2018-10-31 11:33:41 +01:00
Patrick Pelissier 7c2d9c8643 Add missing const 2018-10-31 11:31:48 +01:00
Patrick Pelissier 69d699b80e Add contract 2018-10-31 11:26:00 +01:00
Patrick Pelissier 40832dd727 Add assertions 2018-10-31 08:24:06 +01:00
Patrick Pelissier 31c3baa42b Update comment 2018-10-30 20:10:15 +01:00
Patrick Pelissier 0ed03224c2 Update test 2018-10-30 20:04:01 +01:00
Patrick Pelissier f8d82ae74a Fix oplist definition. 2018-10-30 20:00:50 +01:00
Patrick Pelissier 16234bde82 Add const 2018-10-30 17:23:59 +01:00
Patrick Pelissier 31a5d7ee3b Add oplist 2018-10-30 10:56:02 +01:00
Patrick Pelissier f908c7e04d Update 2018-10-30 10:27:29 +01:00
Patrick Pelissier eb20f66bd9 Update 2018-10-30 10:25:22 +01:00
Patrick Pelissier 3b3e853cf8 Add first test cases 2018-10-29 23:07:34 +01:00
Patrick Pelissier 998ae05a5b Update dict_set to be like a B+TREE (API breakage). _ref returns pointer to the data 2018-10-29 22:59:31 +01:00
Patrick Pelissier 155d01b8c3 Fix blocking=false for _pop & _get 2018-10-29 18:10:07 +01:00
Patrick Pelissier 1a4cce7efd Add concurrent benchmark 2018-10-29 17:17:14 +01:00
Patrick Pelissier 3a0dd2ffe7 Fix errors 2018-10-29 17:15:20 +01:00
Patrick Pelissier 68b705b16a Proper export of additional methods for DICT_SET 2018-10-29 17:02:58 +01:00
Patrick Pelissier fe245e76cf Fix DICT_SET_DEF macro 2018-10-29 16:51:33 +01:00
Patrick Pelissier 618e37b07c Remove pop operator as there is no method for it. 2018-10-29 16:51:17 +01:00
Patrick Pelissier 3dde8d45c1 Add _empty_p & _pop_move_blocking 2018-10-29 13:26:16 +01:00
Patrick Pelissier 4691f95b73 Add blocking methods for concurrent container. 2018-10-29 11:18:20 +01:00
Patrick Pelissier 02d4bf0e09 Export method _empty_p for operator TEST_EMPTY for all containers. 2018-10-29 11:06:54 +01:00
Patrick Pelissier 5ecf4f37c0 Change deprecated functions. 2018-10-29 11:06:29 +01:00
Patrick Pelissier 15f6484dd2 Fix comment 2018-10-29 11:02:55 +01:00
Patrick Pelissier 2ead3905e5 Rename m-protect to m-concurrent 2018-10-28 22:17:33 +01:00
Patrick Pelissier 99d883253c Add TEST_EMPTY operator 2018-10-28 22:13:48 +01:00
Patrick Pelissier ed4d4f9f23 Fix formatting 2018-10-28 17:53:41 +01:00
Patrick Pelissier d76f9565b2 Add new primitives. 2018-10-28 17:53:16 +01:00
Patrick Pelissier 1c637f1182 Proper export of KEY_OPLIST & VALUE_OPLIST 2018-10-28 11:17:05 +01:00
Patrick Pelissier 4dbe5de79c Fix in progress 2018-10-28 11:16:46 +01:00
Patrick Pelissier afcb88d04c Add PROTECT module that automaticaly add a lock on container access. 2018-10-28 10:41:10 +01:00
Patrick Pelissier 1ea1deef94 Update doc with last changes. 2018-10-28 10:40:18 +01:00
Patrick Pelissier 08d2af22db Add KEY_OPLIST & VALUE_OPLIST operators 2018-10-28 10:38:41 +01:00
Patrick Pelissier 70179bb1d7 Add VALUE_TYPE operator 2018-10-28 10:33:25 +01:00
Patrick Pelissier 83226c5ce8 Add KEY_TYPE operator 2018-10-28 10:03:47 +01:00
Patrick Pelissier 3d6b737c46 Export *KEY operators in OPLIST for array, dict, B+tree 2018-10-27 23:37:06 +02:00
Patrick Pelissier fff511101c Add _erase for array 2018-10-27 23:30:38 +02:00
Patrick Pelissier 6672becdd5 Add _erase for array 2018-10-27 23:30:21 +02:00
Patrick Pelissier bd315c7e43 Add method ERASE_KEY 2018-10-27 23:04:56 +02:00
Patrick Pelissier fbfe28c087 Port the test suite to use _erase instead of _remove. 2018-10-27 22:59:33 +02:00
Patrick Pelissier adbafc0b02 Fix usage of pop_at after later change. 2018-10-27 22:59:19 +02:00
Patrick Pelissier 4e6dad939a API Compatibility change: rename _remove for DICT & B+TREE into _erase for API uniformization. 2018-10-27 22:56:00 +02:00
Patrick Pelissier 12bf9c0f59 ERASE method returns bool (like dictionnary) 2018-10-27 22:43:06 +02:00
Patrick Pelissier f7f7d7bc38 Add asertion 2018-10-27 22:34:53 +02:00
Patrick Pelissier c169c05bba Clarify name of old methods SET_KEY, GET_KEY, GET_SET_KEY 2018-10-27 22:34:34 +02:00
Patrick Pelissier 19d48740cd Modify prototype of buffer _init_set & _set to allow const argument for src. Not proud of the solution. 2018-10-27 16:13:02 +02:00
Patrick Pelissier 7a067a4b90 Add M_PTR_OPLIST 2018-10-27 11:13:09 +02:00
Patrick Pelissier 13f3dab23a Update with more examples. 2018-10-27 11:12:55 +02:00
Patrick Pelissier fd9d308b28 Allow tuple initilization in M_LET 2018-10-27 09:28:17 +02:00
Patrick Pelissier 1047d842d0 Add OPLIST for buffer & an example. Still a WIP for the constness of the BUFFER source. 2018-10-26 23:30:04 +02:00
Patrick Pelissier 77385e53f7 Add _init1 for buffer (internal use) 2018-10-26 22:23:44 +02:00
Patrick Pelissier f7b3de2750 Add test cases for _init_set & _set for buffers 2018-10-26 22:05:14 +02:00
Patrick Pelissier a65e6de66b Add more cases. 2018-10-26 21:44:25 +02:00
Patrick Pelissier 41cf523dfc Adding _set & _init_set for buffer (to test) 2018-10-26 21:21:29 +02:00
Patrick Pelissier 3774f8fd11 Fix M_POD_OPLIST in C11 mode 2018-10-26 20:18:32 +02:00
Patrick Pelissier b9e26b1c2c Add test with musl-gcc to test C11 library thread.h 2018-10-26 20:09:32 +02:00
Patrick Pelissier 609175713b Fix C11 backend. 2018-10-26 19:40:51 +02:00
Patrick Pelissier d56b794177 Fix bug in _get method of deque container. 2018-10-21 22:41:29 +02:00
Patrick Pelissier 608a929fcb Added another test case for _get method for DEQUE container. 2018-10-21 22:40:56 +02:00
Patrick Pelissier 4bf045e3d6 Make INIT conditional for DEQUE containers. 2018-10-21 22:31:22 +02:00
Patrick Pelissier 6b5434d64f Fix regression:
even if there is no INIT method for the base type,
the container still defines a INIT method.
2018-10-21 22:27:52 +02:00
Patrick Pelissier abb5480890 Port DEQUE to CALL infrastructure. 2018-10-20 19:02:48 +02:00
Patrick Pelissier 95069b0d4c Update doc 2018-10-20 16:59:56 +02:00
Patrick Pelissier 8f15b50b5f Update documentation of arrays. 2018-10-20 16:57:55 +02:00
Patrick Pelissier c7a1505f9b Update doc 2018-10-10 21:54:34 +02:00
Patrick Pelissier ff098c91f4 Add _capacity for deque 2018-10-07 09:05:09 +02:00
Patrick Pelissier fb40a4f904 Update state 2018-10-03 22:03:08 +02:00
Patrick Pelissier c87696f5c1 Add _hash, _equal_p, _out_str, _in_str, _get_str, _parse_str
for intrusive list.
2018-10-03 22:01:40 +02:00
Patrick Pelissier 4f3dad4bea Add _reverse for I-LIST 2018-10-01 21:22:19 +02:00
Patrick Pelissier 46c2e33096 Remove WIP 2018-09-29 10:23:31 +02:00
Patrick Pelissier 66ee266b90 Move depend.png in doc folder. 2018-09-29 10:22:03 +02:00
Patrick Pelissier 14883b1e26 Update image 2018-09-29 10:10:30 +02:00
Patrick Pelissier 33f74988b1 Update doc 2018-09-29 10:09:18 +02:00
Patrick Pelissier 78b157ff7f Update documentation. 2018-09-29 10:05:40 +02:00
Patrick Pelissier 546b756932 Port TUPLE & VARIANT to API transformation infrastructure. 2018-09-25 21:38:31 +02:00
Patrick Pelissier 5b74d54c64 Remove unused macro. 2018-09-25 20:10:44 +02:00
Patrick Pelissier fc608b21ee Update comment 2018-09-25 20:02:58 +02:00
Patrick Pelissier 2b6a266b93 Optimize _pop_back for dual push list. 2018-09-22 11:58:22 +02:00
Patrick Pelissier 7cb5092010 Update document on dual_push list 2018-09-22 11:58:05 +02:00
Patrick Pelissier a1c3681002 Optimization of _init_set for list. 2018-09-22 11:37:23 +02:00
Patrick Pelissier 91f35aa3bb Update documentation of LIST. 2018-09-22 11:36:38 +02:00
Patrick Pelissier 49a6715dfe Merge branch 'master' of https://github.com/P-p-H-d/mlib 2018-09-19 22:22:57 +02:00
Patrick Pelissier b799725bef Update comment. 2018-09-19 22:22:48 +02:00
Patrick Pelissier 1ada22462f Update comment. 2018-09-19 22:20:11 +02:00
Patrick Pelissier b0ec9680a1 Merge branch 'master' of https://github.com/P-p-H-d/mlib 2018-09-19 07:58:38 +02:00
Patrick Pelissier 7a8a6b1bb1 Rewrite in order to be easier to read. 2018-09-19 07:57:59 +02:00
Patrick Pelissier 1380a91bf1 Update comments. 2018-09-17 22:20:39 +02:00
Patrick Pelissier 83208f74ec Add one more test. 2018-09-17 22:20:26 +02:00
Patrick Pelissier 5f571418d0 Clarify documentation 2018-09-16 00:01:41 +02:00
Patrick Pelissier a7d8ff208f Fix. 2018-09-15 19:42:54 +02:00
Patrick Pelissier 1046f3e220 Add more structure in example. 2018-09-15 19:38:18 +02:00
Patrick Pelissier 6406f97f56 Clarify documentation about oplist usage. 2018-09-15 18:28:43 +02:00
Patrick Pelissier e0c456490a Fix definition of oplist for containers:
if no argument is given, it shall behave as if it was defined with
a standard C type.
2018-09-15 17:59:50 +02:00
Patrick Pelissier 6a1b2a3964 Add new example. 2018-09-15 15:46:22 +02:00
Patrick Pelissier 3452b72add Fix regression of M*LIB:
oplist of tuple/variant wasn't able to detect the default INIT creation
as no valid OPLIST was passed in the absence of OPLIST.
Give the explicit default OPLIST in this case.
2018-09-15 15:30:03 +02:00
Patrick Pelissier 2e3b312fab Fix issue of recursive usage of M_GLOBAL_OPLIST_OR_DEF
Update the way to use the macro to avoid being limited by the
preprocessor limitation.
2018-09-14 20:57:55 +02:00
Patrick Pelissier 8f67ca339b Rename internal macros. 2018-09-13 22:59:38 +02:00
Patrick Pelissier 1679b7b5cf Mark ALGO_INIT_VA & ALGO_LET_INIT_VA as obsolete:
the M_LET macro supports their feature in a more generic way.
2018-09-10 22:57:52 +02:00
Patrick Pelissier 757049543d Port to M_CALL infrastructure the M-ALGO 2018-09-10 22:50:26 +02:00
Patrick Pelissier 38b098b547 Port to M_CALL for M-STRING 2018-09-10 21:59:29 +02:00
Patrick Pelissier 60478e3f61 Port to M_CALL for M-SNAPSHOT 2018-09-10 21:55:18 +02:00
Patrick Pelissier 6325f01122 Port to M_CALL M-SHARED 2018-09-10 21:39:38 +02:00
Patrick Pelissier 74c12e6ea2 Port to M_CALL for R/B TREE. 2018-09-10 21:34:18 +02:00
Patrick Pelissier fd3453bb2a Port to M_CALL infrastructure M-I-SHARED 2018-09-10 07:55:47 +02:00
Patrick Pelissier 2ff7631c9c Port to M_CALL infrastructure. 2018-09-10 07:53:07 +02:00
Patrick Pelissier 7a6b0ab641 Port dict to new M_CALL infrastructure to support API transformation. 2018-09-09 14:04:49 +02:00
Patrick Pelissier 8fd0003548 Update 2018-09-08 22:51:46 +02:00
Patrick Pelissier bb8de993b6 Start porting to M_CALL infrastructure, enabling support for
API transformation.
2018-09-08 22:49:12 +02:00
Patrick Pelissier 7c83d733cd Fix grammar 2018-09-08 20:34:12 +02:00
Patrick Pelissier 6f49a1905c Minor fix 2018-09-08 20:32:49 +02:00
Patrick Pelissier d0378aadeb Update doc 2018-09-08 20:25:38 +02:00
Patrick Pelissier 4834318742 Update doc about missing parse_str methods. 2018-09-08 09:56:25 +02:00
Patrick Pelissier 1838a490ba Update doc 2018-09-08 09:47:47 +02:00
Patrick Pelissier de3cbe45b4 Make INIT method optional. 2018-09-08 09:47:36 +02:00
Patrick Pelissier a34cb6c89d Simplification 2018-09-08 09:34:01 +02:00
Patrick Pelissier 9c0724ddb9 Simplification. 2018-09-08 09:10:37 +02:00
Patrick Pelissier ce948bd9ce Make INIT optional for TUPLE. 2018-09-08 09:02:54 +02:00
Patrick Pelissier 5eb5d2420e Make INIT method optional for oplists. 2018-09-08 08:57:02 +02:00
Patrick Pelissier 7510e36f6b Update doc 2018-09-08 08:56:53 +02:00
Patrick Pelissier 8bfdf2bd5f Add M_IF_METHOD2_BOTH 2018-09-08 08:48:09 +02:00
Patrick Pelissier 2174c28aa2 Make INIT operator optionnal for ARRAY & LIST. 2018-09-08 08:21:13 +02:00
Patrick Pelissier 7a55667a5d Remove lib (link broken) 2018-09-04 22:15:44 +02:00
Patrick Pelissier 79d0452427 Instead of fixed string, enable using printf like formatting for initialization of a string. 2018-09-02 11:05:27 +02:00
Patrick Pelissier ad5c141a7c Enable support to initialize a string_t with a const char[] within M_LET. 2018-09-02 11:00:14 +02:00
Patrick Pelissier d4cd327ea3 Add API transform call for all operators. 2018-09-02 10:40:09 +02:00
Patrick Pelissier 27b29d5ffe Clean up & fix DICT_SET_OPLIST 2018-09-01 21:40:17 +02:00
Patrick Pelissier b52222cad9 Add operator INIT_WITH for oplist with PUSH. 2018-09-01 21:22:18 +02:00
Patrick Pelissier 822c27399c Add M_INIT_VAI to initialize a container with a VA.
(pretty much like it was done for ALGO).
Use if for array & list so that you can init them in M_LET
by giving it a VA.
2018-09-01 21:12:02 +02:00
Patrick Pelissier 0e717389c1 Add API transform support for the method in an oplist. 2018-09-01 20:42:51 +02:00
Patrick Pelissier 2197c4ce81 Add more cases to test. 2018-09-01 09:50:28 +02:00
Patrick Pelissier b894d64063 Add support for INIT_WITH in M_LET in C99 mode. 2018-09-01 09:47:32 +02:00
Patrick Pelissier d95a11365a * New method INIT_WITH
* Prepare variable number of arguments for M_LET with INIT_WITH
2018-09-01 09:39:09 +02:00
Patrick Pelissier dbcade3087 Add support for given an argument for the initialization of a variable in M_LET
if the variable is within parenthesis:
 M_LET((a,b), string_t)
 ==> It will init a & set it to b.

For the moment, we can only init with value of the same type (through init_set)
2018-08-31 00:02:03 +02:00
Patrick Pelissier 7ac54c0eb8 Update doc 2018-08-29 22:17:52 +02:00
Patrick Pelissier 91c74b863d Update comments 2018-08-26 09:26:44 +02:00
Patrick Pelissier 8c0b6f1e9d Fix spellings. 2018-08-25 21:35:37 +02:00
Patrick Pelissier 539f388e66 Update doc (fix spelling). 2018-08-25 09:00:19 +02:00
Patrick Pelissier b03c312b4e Update doc 2018-08-25 08:32:51 +02:00
Patrick Pelissier 71db5f9a79 Support for break to break the execution of M_LET 2018-08-25 00:11:20 +02:00
Patrick Pelissier e33e77595f Simplify the logic for parsing bool. 2018-08-24 21:03:25 +02:00
Patrick Pelissier d4016b310d Add support for conditionnal support for stdio.h
(needed for special environnement where no stdio is supported).
2018-08-24 20:59:54 +02:00
Patrick Pelissier a41177a110 Add support for bool in default type support.
Needs to rewritefully how to dispatch the default type for IN_STR method
Add also proper non-support for const char* & char * for IN_STR & PARSE_STR
(We cannot do it reliabelty, so the function says it always fail).
2018-08-24 20:45:26 +02:00
Patrick Pelissier f8600296f0 Add missing const for dict's equal_p 2018-08-24 19:18:29 +02:00
Patrick Pelissier e1147fb33d Add support for IN_STR for default C types. 2018-08-23 19:58:02 +02:00
Patrick Pelissier ec0d020669 Fix documentation about right prototype of in_str. 2018-08-23 19:38:19 +02:00
Patrick Pelissier e8eab86546 Fix issue in warning about discarding const attribute. 2018-08-22 00:21:23 +02:00
Patrick Pelissier c9ebedb01f Rename _get_ methods for tuple & variants into _get_at_ methods.
Add _cget_at_ methods too.
2018-08-21 23:58:03 +02:00
Patrick Pelissier af5742ce2d Change the value used to generate the enumerate of a variant:
the previous values didn't prevent to have a name collision
with other methods defined for the variant.
2018-08-21 22:53:07 +02:00
Patrick Pelissier 8f85c71654 Rename some internal macros to a better name. 2018-08-21 22:15:11 +02:00
Patrick Pelissier 70753c1082 Add method parse_str for the oplist of default C type. 2018-08-21 20:04:11 +02:00
Patrick Pelissier 2ab2b9efd6 Add primitive to parse standard C types (except const char*) 2018-08-21 19:53:55 +02:00
Patrick Pelissier dbb34b75fd Add method for the operator OUT_STR for the default type. 2018-08-21 19:26:18 +02:00
Patrick Pelissier 7447492c76 Fix issue with deque in case of successive _clean:
the CLEAR method was called more than once for an object.
2018-08-20 23:13:55 +02:00
Patrick Pelissier 492e4c33db Adding more assertions to check the good call of the test object. 2018-08-20 23:11:13 +02:00
Patrick Pelissier cbb08bdcfc Amend previous commit. 2018-08-19 20:28:46 +02:00
Patrick Pelissier 0de829741a Add synonimous for pointers. 2018-08-19 20:27:45 +02:00
Patrick Pelissier 0fa7aed1c4 Add missing synonim 2018-08-19 20:07:58 +02:00
Patrick Pelissier 3b0e940284 Add missing _ptr & _srcptr alias. 2018-08-19 17:58:23 +02:00
Patrick Pelissier 48a970ceb9 Avoid using '__' within words.
It seems to be a reserved naming of C++.
2018-08-19 11:31:09 +02:00
Patrick Pelissier c7b533f21e Cleanup terminology 2018-08-19 10:54:48 +02:00
Patrick Pelissier 839d4da191 Update doc 2018-08-19 10:36:30 +02:00
Patrick Pelissier b76ddfe93c Update doc 2018-08-19 10:07:04 +02:00
Patrick Pelissier 4ba0156ad8 Backport solution from tuple to variant. 2018-08-19 08:45:10 +02:00
Patrick Pelissier 6ef9936e24 Fix issue of recusrive definition of TUPLE using GLOBAL oplist:
There was a recursive call of M_REDUCE2 that fails to expand properly on its second invocation
Rewrite fully how global oplists are implemented:
it performs a first pass to expand the oplists, and the a separate pass to define the functions.
This enables to separate the pass, and use M_REDUCE2 in both.
2018-08-19 08:28:17 +02:00
Patrick Pelissier e835dbc7c6 Update Makefile for also testing clang++ 2018-08-19 08:27:51 +02:00
Patrick Pelissier 5c8429a7bb Reformating 2018-08-16 07:29:22 +02:00
Patrick Pelissier 824011657a Improve once again mapping of the buffer structure to avoid
false sharing.
2018-08-15 10:33:20 +02:00
Patrick Pelissier 8e2031bf5a Add comments. 2018-08-15 10:30:17 +02:00
Patrick Pelissier 8bb5f5475e Avoid putting the push mutex & the pop mutex inside the same cache line.
Avoid false sharing for multi-threading scenario and should increase performance.
2018-08-15 10:21:23 +02:00
Patrick Pelissier eb4f249a54 Add missing CLEAN method in export OPLIST. 2018-08-14 23:09:12 +02:00
Patrick Pelissier 3aa3b87709 Add missing CLEAN method in export OPLIST. 2018-08-14 23:08:33 +02:00
Patrick Pelissier 0046157862 Fix issue for SWAP method not exported correctly for tuple. 2018-08-14 08:00:16 +02:00
Patrick Pelissier acbf1efad6 Fix issue: CLEAN method was not properly exported by tuple. 2018-08-14 07:58:37 +02:00
Patrick Pelissier 5d1eb45d5c Export CLEAN method. 2018-08-14 07:49:31 +02:00
Patrick Pelissier c52c41c885 Export CLEAN method for tuple if it is defined. 2018-08-13 20:14:37 +02:00
Patrick Pelissier 822f9aacf6 Add CLEAN method for tuple. 2018-08-13 20:05:32 +02:00
Patrick Pelissier 7d5608ca0e Export CLEAN method for string. 2018-08-13 20:03:06 +02:00
Patrick Pelissier 937bbef818 Add method _erase & _update_further for priority queue. 2018-08-12 21:35:09 +02:00
Patrick Pelissier c506443ed0 Add comment about ALGO_EXTRACT 2018-08-08 22:54:56 +02:00
Patrick Pelissier 5f42f26587 Fix warning about shadowed variables 2018-08-08 22:49:49 +02:00
Patrick Pelissier f84e96d790 Reexport IT_INSERT for array.
Even it is slow, it may be useful.
2018-08-08 22:49:25 +02:00
Patrick Pelissier ede57a20be Add ALGO ALGO_INSERT that allows inserting a container into another one. 2018-08-08 22:44:17 +02:00
Patrick Pelissier df8306c721 Export IT_INSERT method 2018-08-08 22:43:44 +02:00
Patrick Pelissier 1bb144e256 VARIANT: Oplist is now optional for their definition. 2018-08-07 23:18:37 +02:00
Patrick Pelissier 7d83603646 TUPLE: Oplist is now optional for tuple definition. 2018-08-06 23:20:02 +02:00
Patrick Pelissier 7e4d51bab0 Add support for global oplist for deque 2018-08-05 22:33:13 +02:00
Patrick Pelissier 4ef1b079cb Can omit optlist in B+TREE definition 2018-08-05 11:08:18 +02:00
Patrick Pelissier e95d13adb1 Add support for multiple M_LET on the same line
without warning about shadow variables.
2018-08-04 08:34:35 +02:00
Patrick Pelissier 92d7009804 Fis issue if given type is a T * = TYPE:
token pasting created const T *, which is not the same as
const TYPE = T * const
2018-08-03 20:35:37 +02:00
Patrick Pelissier 354327e40b Fix issue for string_strim if string was empty and not allocated. 2018-08-03 20:23:24 +02:00
Patrick Pelissier 34d56c54c8 Test strim with an empty string.
(Shall do nothing).
2018-08-03 20:22:32 +02:00
Patrick Pelissier 143a5fdf4f Fix issue if given type is a T * = TYPE:
token pasting created const T *, which is not the same as
const TYPE = T * const
2018-08-03 20:20:57 +02:00
Patrick Pelissier 030510613c Add more assertions. 2018-08-03 19:57:38 +02:00
Patrick Pelissier 984b8e7da0 Fix const cast issue for 'void *' pointer. 2018-08-03 18:55:01 +02:00
Patrick Pelissier aba1ac1646 Fix issue in 64 bits with overwriting enabled for buffer. 2018-08-02 23:31:48 +02:00
Patrick Pelissier 6b93d7644a Proper constant definition for unicode error. 2018-08-02 23:31:17 +02:00
Patrick Pelissier 68c737dcef Clean up interface if (internal) genint:
it returns at most an 2048, so an unsigned int is more enought
(and internally it was already used!).
So transform the interface to take as input unsigned int.

Fix maximum size supported by the genint package.

Add proper constant used for error, and use it in the code.
2018-08-02 23:19:05 +02:00
Patrick Pelissier b8f8ffe0a2 Perform same optimization than previous commit for
M_GLOBAL_OPLIST_OR_DEF
2018-08-02 22:48:28 +02:00
Patrick Pelissier 02e8681f76 M_GLOBAL_OPLIST:
More robust implementation that delays the evaluation of the concatenation
2018-08-02 20:02:15 +02:00
Patrick Pelissier 603fb9db62 Replace some size displayed with '%lu' as unsigned long
with proper '%zu' as size_t.
2018-08-02 19:34:10 +02:00
Patrick Pelissier b01459d1ef Add out_str for CSTR_OPLIST 2018-08-01 23:36:04 +02:00
Patrick Pelissier 667f1f5951 Update documentation. 2018-08-01 23:28:01 +02:00
Patrick Pelissier 660c5a2db4 Add M_GET_STRING to transform a standard numerical C type into a string_t
(with a method compatible with the operator GET_STR).
2018-08-01 23:26:58 +02:00
Patrick Pelissier 8a4d013354 Fix issues (normal contract where used for I/O whereas they could be used
with OA Dict)
2018-08-01 22:55:54 +02:00
Patrick Pelissier faedca81d1 Add M_CORE_VERSION_* macros. 2018-08-01 22:28:50 +02:00
Patrick Pelissier 166d408f5e Add support for out_str for the default C types if C11 is enabled. 2018-08-01 20:12:24 +02:00
Patrick Pelissier 017f25d9d5 M_PRINT_ARG & M_FPRINT_ARG don't put a final semicolon at the end
of their expansion anymore (cleaner and no longer needed with the
new available tools).
2018-08-01 19:59:57 +02:00
Patrick Pelissier 6a70eba83f Document some missing methods for priority queues. 2018-08-01 19:35:54 +02:00
Patrick Pelissier ef13ab6938 Add rapidstring 2018-08-01 00:31:58 +02:00
Patrick Pelissier 75cb61fd36 Fix issue of deque's _init_move. 2018-07-31 23:11:43 +02:00
Patrick Pelissier 9c31f8aa92 Complete test to show failure of _init_move for deque. 2018-07-31 23:11:26 +02:00
Patrick Pelissier 27a08da430 Add node contract check. 2018-07-31 08:19:45 +02:00
Patrick Pelissier fdada9661f Update comment. 2018-07-30 22:45:24 +02:00
Patrick Pelissier f1a52439bb Add more tests. 2018-07-30 22:42:33 +02:00
Patrick Pelissier d13849c173 Update formatting. 2018-07-30 22:42:09 +02:00
Patrick Pelissier d8a0e73899 Update comment. 2018-07-30 22:24:03 +02:00
Patrick Pelissier b6a3387f8a User are able to customize the number of elements of a mempool globaly. 2018-07-30 22:02:46 +02:00
Patrick Pelissier 04dd708941 Delayed the inclusion of the common headers, so that the backend may properly
set up additional parameters for the headers.
2018-07-29 19:40:37 +02:00
Patrick Pelissier 39ffe1c95a Fix issue for 32 bits build due to previous modification of limb size to 64 bits. 2018-07-29 19:40:08 +02:00
Patrick Pelissier 7b5ae3c15b Update API so that the worker_t parameter is given on creating the sync bloc.
(API breakage), more RAII like.
2018-07-28 19:09:07 +02:00
Patrick Pelissier 7678625071 Review:
* add comments
* change error code from assertion to proper memory failure
* add new assertions
2018-07-28 13:48:30 +02:00
Patrick Pelissier dbe8817d95 Add bitset_clz 2018-07-27 06:19:54 +02:00
Patrick Pelissier 09e117cd57 Update comments.
Update _new_node: it shall never return NULL.
2018-07-24 00:34:35 +02:00
Patrick Pelissier 4b8779d8d3 Update formula for increasing the size. 2018-07-24 00:24:50 +02:00
Patrick Pelissier 79158dabbc Rename _map into _for_each. 2018-07-22 21:32:46 +02:00
Patrick Pelissier f962bc8da5 Avoid overflow in case of huge computations.
Add more comments.
2018-07-22 21:32:19 +02:00
Patrick Pelissier 28e8dde06d Make target uninstall PHONY 2018-07-21 12:12:50 +02:00
Patrick Pelissier 6c3d41a124 Add target uninstall 2018-07-21 12:12:19 +02:00
Patrick Pelissier 9c2967f8df Cleanup install target with proper use of COMMAND VARIABLES. 2018-07-19 22:55:56 +02:00
Patrick Pelissier 99311364e7 Regenerate the dependency graph. 2018-07-18 22:35:25 +02:00
Patrick Pelissier 16e86b8291 Don't regenerate depend.png everytime but only if the headers have been updated.
Optimize the generation of the PNG.
2018-07-18 22:34:52 +02:00
Patrick Pelissier 5741af8fd3 Add 'dist' target in the Makefile. 2018-07-18 22:31:53 +02:00
Patrick Pelissier 6bdd47a557 Don't remove depend with a make clean
otherwise you'll get a regeneration of the dependency file for each clean command
which is useless.
make distclean shall be used to remove the dependency file.
2018-07-18 22:28:19 +02:00
Patrick Pelissier 750ba93c14 Add note. 2018-07-18 21:43:27 +02:00
Patrick Pelissier 18be930507 Fix bug in case of error returned by vsnprintf:
the buffer may have been corrupted in case of error.
Clean it before returning.
2018-07-18 21:41:52 +02:00
Patrick Pelissier be26176828 Add one more test case. 2018-07-18 21:41:14 +02:00
Patrick Pelissier 540e01f1fe Fix prototype of the callback to InitOnceExecuteOnce: Missing CALLBACK.
(Some version of the compilers for windows produced warnings)
2018-07-18 21:21:35 +02:00
Patrick Pelissier 7cfb6b16e4 Update cross compilation information. 2018-07-18 01:01:13 +02:00
Patrick Pelissier d5a8b9648f Simplify 2018-07-18 01:01:04 +02:00
Patrick Pelissier 1657d7af7d Support of LOG_COMPILER for cross-compilation test. 2018-07-18 00:28:35 +02:00
Patrick Pelissier 318f1a2818 Update/Add comments. 2018-07-17 23:03:45 +02:00
Patrick Pelissier 8b0b115709 Update comment. 2018-07-17 23:03:33 +02:00
Patrick Pelissier 7d2494b7f9 Fix bug of SPMC / MPMC snapshots: not all items in buffers
were properly cleared.
2018-07-17 21:10:14 +02:00
Patrick Pelissier 3b642ffeb3 Update after internal review. 2018-07-17 21:00:55 +02:00
Patrick Pelissier 815bf5f0e0 Include proper header and do not depend on other headers to include it. 2018-07-16 21:45:28 +02:00
Patrick Pelissier 4af48724ce Update after internal review. 2018-07-16 21:43:17 +02:00
Patrick Pelissier 001272820c Update example to latests API. 2018-07-15 23:11:00 +02:00
Patrick Pelissier 4aca0664ef Add methods _find_again, _find_again_if, _mismatch_again and _mismatch_again_if 2018-07-15 23:06:22 +02:00
Patrick Pelissier 6721a86768 Add method _mismatch and _mismatch_if 2018-07-15 22:34:29 +02:00
Patrick Pelissier 5025b3690d Add test. 2018-07-15 22:26:59 +02:00
Patrick Pelissier 42b37a718f Add test. 2018-07-15 22:26:21 +02:00
Patrick Pelissier fcdfd836ec Add method _count_if 2018-07-15 11:05:58 +02:00
Patrick Pelissier b2f005239b API breakage:
rename _constains into _contain_p
to be more uniform with other predicate functions,
and to use infinitive form for the method.
2018-07-15 10:54:38 +02:00
Patrick Pelissier bc3fa890bd Add method _find_if. 2018-07-15 10:48:22 +02:00
Patrick Pelissier 95dbbf6e75 Simplification of the example. 2018-07-15 02:53:35 +02:00
Patrick Pelissier 22f2ae7341 Add methods _all_of_p, _any_of_p and _none_of_p. 2018-07-14 18:21:46 +02:00
Patrick Pelissier 96202aa78f Do not use reserved identifiers of the C standard (See 7.1.3 Reserved identifiers) 2018-07-14 14:35:14 +02:00
Patrick Pelissier cef8a13cc2 Add a new test. 2018-07-14 14:18:25 +02:00
Patrick Pelissier 54271231a0 Update doc. 2018-07-14 14:13:18 +02:00
Patrick Pelissier d1bb651596 Update doc. 2018-07-14 14:03:17 +02:00
Patrick Pelissier 10b7f65437 Update DEV. 2018-07-13 10:54:41 +02:00
Patrick Pelissier 3a70324d43 Fix spelling. 2018-07-13 10:42:26 +02:00
Patrick Pelissier 21b72cd174 Update 2018-07-13 10:40:45 +02:00
Patrick Pelissier ce8656f1b2 Update 2018-07-13 10:40:40 +02:00
Patrick Pelissier 9277dc967b Update 2018-07-11 00:04:45 +02:00
Patrick Pelissier 67b1e65d97 Update comment 2018-07-08 00:33:18 +02:00
Patrick Pelissier 79fe9da2da Update 2018-07-05 12:21:02 +02:00
Patrick Pelissier 3164e2698d Improve comments. 2018-07-05 12:12:16 +02:00
Patrick Pelissier ffae33e6f7 Update 2018-07-05 12:12:09 +02:00
Patrick Pelissier 8dafe3b7a6 Add macro M_GET_AT. 2018-07-04 17:39:03 +02:00
Patrick Pelissier e23616169b Improve comments. 2018-07-04 17:38:48 +02:00
Patrick Pelissier 9d7fc942f7 Rename DICT_SET_DEF2 into DICT_SET_DEF 2018-07-03 15:50:14 +02:00
Patrick Pelissier 982d8cf19d DICT_*_DEF* doesn't require anymore oplists for defining the function:
it can get them from global oplists or default oplits.
2018-07-03 15:44:40 +02:00
Patrick Pelissier aae460623d Replace _set_at by _push 2018-07-03 15:07:36 +02:00
Patrick Pelissier df14e5bcb6 Update 2018-07-03 10:42:51 +02:00
Patrick Pelissier 15d5a83c16 Update doc 2018-07-03 10:42:11 +02:00
Patrick Pelissier 4b0f7543ee Rename _set_at to _push method for SET dictionnary.
Add proper _splice method for SET dictionnary.
2018-07-03 10:40:26 +02:00
Patrick Pelissier 362c64aa9c Fix URL to show preview. 2018-07-03 10:11:40 +02:00
Patrick Pelissier 56c497cf2c Add ref card. 2018-07-03 10:08:16 +02:00
Patrick Pelissier e0dc2da80a Add synthesis of the API. 2018-07-03 09:35:35 +02:00
Patrick Pelissier 41362f12ea Add comment about _hash for dict. 2018-07-01 22:54:19 +02:00
Patrick Pelissier 3765c0b0fb Add _equal_p method for OA dictionary. 2018-07-01 22:44:56 +02:00
Patrick Pelissier d1f2b62f66 Replace _set_at2 by _get_at for array.
(Break API)
2018-07-01 22:35:05 +02:00
Patrick Pelissier 26b8c1d0a2 Add method _move & _init_move. 2018-07-01 17:16:36 +02:00
Patrick Pelissier aa195f9f6f Add methods _cget. 2018-07-01 17:16:25 +02:00
Patrick Pelissier cd1d59264e Fix build issue with C++ 2018-06-29 22:50:41 +02:00
Patrick Pelissier 923e009fd3 Fix issue for new method _get_at for OA dict. 2018-06-29 22:32:10 +02:00
Patrick Pelissier 70a4fd99f4 iFix buiild issue with mutex based atomics. 2018-06-29 21:43:33 +02:00
Patrick Pelissier feb4011f57 Add new example. 2018-06-29 19:41:55 +02:00
Patrick Pelissier bf2a04ff66 Add method _get_at:
_get or create an entry.
2018-06-29 19:41:34 +02:00
Patrick Pelissier e16d352e71 Fix prototype (forgot const) 2018-06-29 19:41:20 +02:00
Patrick Pelissier 817724ce39 Fix issue for get_word:
the separators need to be skipped first.
2018-06-29 19:40:35 +02:00
Patrick Pelissier 0fda117ffe Add push/pop_front/back_move methods. 2018-06-27 20:10:42 +02:00
Patrick Pelissier e5be1e1f05 Add a name to the structure. 2018-06-27 20:10:28 +02:00
Patrick Pelissier 7d7af8cf59 Add a name to the structure. 2018-06-27 20:10:12 +02:00
Patrick Pelissier cbc09f83d4 Disable MOVE & INIT_MOVE for such containers (TBC). 2018-06-27 20:09:45 +02:00
Patrick Pelissier 31913ae80e Add bench for DualPushList. 2018-06-27 20:09:24 +02:00
Patrick Pelissier 522632bea6 Remove deprecated macro SNAPSHOT_DEF.
Shall use SNAPSHOT_SPSC_DEF
2018-06-27 20:04:18 +02:00
Patrick Pelissier 397f75a4db Add missing method _front for bitset. 2018-06-27 07:33:23 +02:00
Patrick Pelissier 0bf84a321b Add missing methods _capacity for MPMC queue & SPSC queue. 2018-06-27 07:28:34 +02:00
Patrick Pelissier 5915208dee API breakage:
Rename _pop method into _pop_at method
as the provided function is a _pop_at method, not a _pop method.
Remove _pop from the oplist as it doesn't follow _pop convention.
2018-06-27 07:17:33 +02:00
Patrick Pelissier 2167931e3f Remove _pop method from OPLIST as it doesn't follow _pop
convention.
2018-06-27 07:17:09 +02:00
Patrick Pelissier 2d18171914 Rename _pop method into _pop_at methods
as the provided function follow the prototype of a _pop_at method
rather than a _pop method.
2018-06-27 07:13:10 +02:00
Patrick Pelissier 28f6a7d399 Add missing _empty_p methods for dictionnaries. 2018-06-27 07:10:18 +02:00
Patrick Pelissier 8e042435e5 Update comment and use of a different hash function. 2018-06-23 13:26:46 +02:00
Patrick Pelissier cddf8712e4 Update comment. 2018-06-23 13:12:28 +02:00
Patrick Pelissier 88fd96e022 Add a more complete example of use. 2018-06-23 13:10:33 +02:00
Patrick Pelissier 17e715f408 Remove _last as it is a duplicate with _back! 2018-06-23 11:07:06 +02:00
Patrick Pelissier c821d9ea65 Add methods _front & _last for arrays. 2018-06-23 11:05:29 +02:00
Patrick Pelissier 5cb8a9ddd0 Document priority queue API. 2018-06-20 23:25:41 +02:00
Patrick Pelissier f0131b2c39 Fix prototype of _front:
missing const.
2018-06-20 23:25:25 +02:00
Patrick Pelissier bc3c68a3cb Move a section. 2018-06-14 22:34:42 +02:00
Patrick Pelissier b81d387778 Simplify the code by factoring similar branches. 2018-06-11 23:08:56 +02:00
Patrick Pelissier 0afbe72672 Fix spelling. 2018-06-11 21:09:20 +02:00
Patrick Pelissier 5fc63485f3 Update 2018-06-07 21:56:09 +02:00
Patrick Pelissier 1bc84c98f8 Update 2018-06-07 21:51:19 +02:00
Patrick Pelissier 737af45c85 Adding the long term ISSUES in configuration. 2018-06-07 21:47:23 +02:00
Patrick Pelissier e08fbc7d86 Move all core macros to support up to 52 arguments. 2018-06-06 23:33:23 +02:00
Patrick Pelissier 91090d20de Remove non defined operators from the oplist. 2018-06-06 00:00:08 +02:00
Patrick Pelissier 05a22e20b8 Add documentation on B+TREE. 2018-06-05 23:58:49 +02:00
Patrick Pelissier 7c43f343a3 Update 2018-06-05 00:39:07 +02:00
Patrick Pelissier 029e6aa251 Remove reference to libraries without working sites. 2018-06-04 23:11:18 +02:00
Patrick Pelissier 2f26d4ffd3 Add more tests / improve coverage. 2018-06-02 21:26:54 +02:00
Patrick Pelissier d306bae035 Generate cleaner coverage. 2018-06-02 21:26:32 +02:00
Patrick Pelissier 34dc8b32cb Fix broken _swap 2018-06-02 21:26:20 +02:00
Patrick Pelissier fe38244d7c Micro optimisation. 2018-06-02 19:31:07 +02:00
Patrick Pelissier 25e8c9f637 Update comments. 2018-06-02 19:23:46 +02:00
Patrick Pelissier 337b568b5e Update comments. 2018-06-02 19:21:59 +02:00
Patrick Pelissier e696192ef7 Update comments.
Cosmetic change.
2018-05-31 23:09:11 +02:00
Patrick Pelissier 928fc077b8 Remove a warning. 2018-05-30 23:17:37 +02:00
Patrick Pelissier 2a448b932c Update doc 2018-05-30 23:17:30 +02:00
Patrick Pelissier d40d23a50e Add test for _splice_at for Intrusive list. 2018-05-30 20:21:37 +02:00
Patrick Pelissier c4548c4355 Fix splice_at which was broken. 2018-05-30 20:21:27 +02:00
Patrick Pelissier 50fdea813b Update doc 2018-05-30 19:26:13 +02:00
Patrick Pelissier 0ff163e541 Fix issue for intrusive list and _splice_back. 2018-05-29 23:00:25 +02:00
Patrick Pelissier 38cd8847a2 Adding a generic merge sort if container has both _splice_back & _splice_at
methods
2018-05-28 23:51:41 +02:00
Patrick Pelissier e62ae9fb94 Fix the iterators calculation of _splice_at.
NOTE: iterator seems broken for _splice_back. To check
2018-05-28 23:51:10 +02:00
Patrick Pelissier 187b6cf072 Update to new specification. 2018-05-28 23:46:30 +02:00
Patrick Pelissier a3fad5966a Update test to reflect the new specifications. 2018-05-28 23:46:10 +02:00
Patrick Pelissier 74350f3638 Reuse a local variable instead of reading once again from memory. 2018-05-28 23:45:40 +02:00
Patrick Pelissier ee2c7caac2 Update _splice_at with new specification.
Fix issue of _splice_at (iterator not properly set).
Export _split_at methods in oplist.
2018-05-28 23:44:15 +02:00
Patrick Pelissier c915a6912e Update specification of _splice_at.
It is more interressing to have the iterator of the target list
to advance too. It allows copying items from list to list in the same order.
2018-05-28 23:43:05 +02:00
Patrick Pelissier d5cd232441 Add method SPLICE_AT as a generic method. 2018-05-28 23:42:46 +02:00
Patrick Pelissier c4c14b0fc6 Add _splice_at 2018-05-28 22:08:55 +02:00
Patrick Pelissier e5f5563249 Add method _splice_at for dual_push_list 2018-05-28 21:58:45 +02:00
Patrick Pelissier 2a6893efb4 Add method _splice_at for singly list. 2018-05-28 21:22:14 +02:00
Patrick Pelissier 9fd920945a Remove condition that the list shall be different for splice_back.
No need.
2018-05-28 20:59:27 +02:00
Patrick Pelissier a116daa7a1 Splice_back may work if old & new are the same list. 2018-05-28 20:58:51 +02:00
Patrick Pelissier 0b8759380b Fix name of called method to avoid infinite recursion... 2018-05-27 11:17:11 +02:00
Patrick Pelissier 00c5e3544f Export _splice_back methods.
Add _push_move & _pop_move methods for dual push list.
2018-05-27 11:16:16 +02:00
Patrick Pelissier 53a79e3170 Export splice_back method for list 2018-05-27 11:06:35 +02:00
Patrick Pelissier 5810bf9acd Add method SPLICE_BACK. 2018-05-27 11:05:00 +02:00
Patrick Pelissier 7815feddba Proper expand algorithms for intrusive list. 2018-05-24 22:58:16 +02:00
Patrick Pelissier f529a5eea8 Use of a trick to make the function compatible with other
definition of the _it method (use of const for the container).
2018-05-24 22:57:27 +02:00
Patrick Pelissier 40e9550b29 Generate algo for intrusive list. 2018-05-23 21:10:58 +02:00
Patrick Pelissier 64d0202f95 ALGO macros accept now a type instead of an oplist
if a global oplist has been registered for the type.

Add macro ALGO_LET_INIT_VA which declares, initializes, sets and clears
a container.
2018-05-22 20:39:51 +02:00
Patrick Pelissier da9483aa3a Add reference to C standard about CONST_CAST. 2018-05-22 19:38:38 +02:00
Patrick Pelissier 0221e555fe Fix bug in deque: _clean doesn't call CLEAR on all created objects. 2018-05-22 05:46:37 +02:00
Patrick Pelissier 494ee2c099 Add proper check of allocation for testing object. 2018-05-22 05:46:04 +02:00
Patrick Pelissier dc92ad9c02 Fix compatbility issue with C++ which doesn't support
compound literal...
2018-05-21 23:00:48 +02:00
Patrick Pelissier 8a4a019973 Fix build issue with C++ 2018-05-21 07:23:19 +02:00
Patrick Pelissier a1a49ebf4b Update comment 2018-05-20 22:38:00 +02:00
Patrick Pelissier 45263a6261 Fix parenthesis 2018-05-20 18:07:58 +02:00
Patrick Pelissier 7ccede36b1 Test with deque too. 2018-05-19 12:52:40 +02:00
Patrick Pelissier 482e1631fa Remove warning in case of some kind of type
(Famous problem of C not allowing to cast
a T (*)[N] into a const T (*)[N].
2018-05-19 12:51:31 +02:00
Patrick Pelissier d0fe7f3e25 Add method _push_move & _pop_move.
Add assertion on _pop_back to check that the container is not empty.
2018-05-19 11:21:57 +02:00
Patrick Pelissier 86083e3a92 Add methods push_move & pop_move.
Rewrite _pop_back to be a little bit faster for complex structure as it used
DO_MOVE instead of plain _set.
2018-05-19 11:21:18 +02:00
Patrick Pelissier 281f567d97 Add proper usage of const. 2018-05-19 11:10:09 +02:00
Patrick Pelissier 7f887720cc Add methods PUSH_MOVE & POP_MOVE. 2018-05-19 11:09:36 +02:00
Patrick Pelissier 717268add9 Simplify the macro usage. 2018-05-19 11:09:20 +02:00
Patrick Pelissier 2f7e3b1596 Update documentation. 2018-05-19 11:08:54 +02:00
Patrick Pelissier 1a3cd2f626 Add experimental support for cmp function with user define order. 2018-05-16 22:36:26 +02:00
Patrick Pelissier 2fbea43a5c Add M_MAP3 macro. 2018-05-16 20:00:41 +02:00
Patrick Pelissier 70788e932e Update doc 2018-05-16 19:47:06 +02:00
Patrick Pelissier 949d12052e Update 2018-05-16 07:52:37 +02:00
Patrick Pelissier 2af35673bb Update comments about TODO. 2018-05-15 21:02:34 +02:00
Patrick Pelissier 4a64ca58ac Update tested systems. 2018-05-15 20:41:15 +02:00
Patrick Pelissier 815c594fa6 Add new libraries 2018-05-15 20:41:06 +02:00
Patrick Pelissier fc4dba4569 Add DSC versions of the _sort function to reverve the sort (DSC=descending). 2018-05-14 23:08:46 +02:00
Patrick Pelissier 1d8df98339 Rename undocumented methods _union & _intersect to _sort_union & _sort_intersect
as they depend on the sort order.
2018-05-14 22:58:52 +02:00
Patrick Pelissier 745aabcfd5 Factorisation of all calls to GET_CMP within the sort functions
to a single function.
2018-05-14 22:55:17 +02:00
Patrick Pelissier be100790f1 Uniformize the comparaisons to always be in the same order. 2018-05-14 22:51:07 +02:00
Patrick Pelissier afc5e82906 Externalize _sort generation from the main macro. 2018-05-14 22:49:11 +02:00
Patrick Pelissier 2951d4b7fa Document new methods. 2018-05-14 22:30:08 +02:00
Patrick Pelissier dcd300211f Add methods _cmp_field for tuples. 2018-05-14 22:29:58 +02:00
Patrick Pelissier f796d27bb4 Update 2018-05-13 09:55:08 +02:00
Patrick Pelissier 47a2553356 Add new test on B*TREE as set. 2018-05-11 22:41:56 +02:00
Patrick Pelissier 67bf199254 Fix comparison of object.
memcmp compares object as little endian, which is not what we want.
2018-05-11 22:41:22 +02:00
Patrick Pelissier 4b1ed25ef3 Rewrite inner loop. should be a little bit faster. 2018-05-11 22:41:00 +02:00
Patrick Pelissier a5ac43e5f3 Fix issue with oplist of set. 2018-05-11 17:57:33 +02:00
Patrick Pelissier 0557527bfe Update format of serialisation for B+TREE:
as the tree is ordered, a '[]' has to be used.
2018-05-11 17:32:32 +02:00
Patrick Pelissier dc1445e0d6 Remove TODO comment. 2018-05-10 23:12:38 +02:00
Patrick Pelissier 431401bc96 Improve example. 2018-05-10 01:59:05 +02:00
Patrick Pelissier fded6c404a Add new libraries. 2018-05-10 01:34:20 +02:00
Patrick Pelissier 680a850618 Add test of _in_str, _out_str, _get_str and _parse_str 2018-05-09 21:48:42 +02:00
Patrick Pelissier 7d08a7ba1a Fix issue in _parse_str 2018-05-09 21:48:32 +02:00
Patrick Pelissier e9f603fa30 Rename internal calls to my_mpz* to testobj* 2018-05-08 10:40:29 +02:00
Patrick Pelissier 1a064e033b Rename mympz.h --> test-obj.h
as it is used only for testing purpose.
2018-05-08 10:29:51 +02:00
Patrick Pelissier ebcfcf9bfa Add I/O test for B+TREE 2018-05-07 23:08:47 +02:00
Patrick Pelissier cf063b75ff Update oplist to reflect all methods. 2018-05-07 23:08:12 +02:00
Patrick Pelissier 951a9d7989 Fix issue in parse. 2018-05-07 23:08:01 +02:00
Patrick Pelissier 37191a53c3 Fix unclear variable. 2018-05-04 00:14:52 +02:00
Patrick Pelissier 42d420db6a Add generation for string. 2018-05-03 22:12:32 +02:00
Patrick Pelissier 122cf63a3f Preshift the state by 8, to avoid a shift within the decoder.
Rewrite the size_u to avoid a branch.
2018-05-03 22:11:43 +02:00
Patrick Pelissier fafce60f9e Add method _parse_str
NOTE: _in_str, _out_str, _get_str & _parse_str remain to be tested.
2018-05-03 18:06:11 +02:00
Patrick Pelissier e855f27c8c Add method _parse_str for RBTREE.
NOTE: A refactorisation seems needed as all the in_str / parse_str
share a lot of the same algorithms. Maybe move them into algo?
2018-05-03 17:59:34 +02:00
Patrick Pelissier f01a593ff7 Update 2018-05-03 17:59:21 +02:00
Patrick Pelissier 6af34b1c16 Update doc to add _parse_str method 2018-05-03 17:51:36 +02:00
Patrick Pelissier 188b329eae Add method _parse_str for dict. 2018-05-03 17:43:40 +02:00
Patrick Pelissier 7b0f71cc99 Add method _parse_str for deque
(missing tests for in, out, get_str & parse_str).
2018-05-03 17:34:17 +02:00
Patrick Pelissier 73f8baf464 Add method _parse_str for array. 2018-05-03 17:29:10 +02:00
Patrick Pelissier 3a09efde91 Skip spaces in serialisation. 2018-05-03 17:22:50 +02:00
Patrick Pelissier 4efa8c1ef9 Add function _parse_str for list. 2018-05-03 17:14:10 +02:00
Patrick Pelissier 9f178208f2 Fix bug in new function. 2018-05-03 17:13:47 +02:00
Patrick Pelissier 0f2113ee12 Fix 2018-05-03 17:03:09 +02:00
Patrick Pelissier 139e003b0b Add method _parse_str for variant. 2018-05-03 17:01:03 +02:00
Patrick Pelissier 1bf80cf315 Add function _parse_str 2018-05-03 13:37:19 +02:00
Patrick Pelissier bcf182f515 Add _parse_str method 2018-05-03 13:30:39 +02:00
Patrick Pelissier c34fb94e77 Proper export of the method PARSE_STR 2018-05-03 13:19:36 +02:00
Patrick Pelissier 64080fadd3 Update comments. 2018-05-03 13:07:52 +02:00
Patrick Pelissier 1009cd6ed4 Export _parse_str function. 2018-05-03 13:05:45 +02:00
Patrick Pelissier 839c1af124 Export _parse_str function. 2018-05-03 13:04:04 +02:00
Patrick Pelissier 6b24842704 Add _parse_str interface.
Rewrite _set_str to use the _parse_str
2018-05-03 12:59:58 +02:00
Patrick Pelissier 2ad8ae3451 Rewrite parse_str interface to be more like strol 2018-05-03 12:59:10 +02:00
Patrick Pelissier b1597f6f61 Rewrite comments. 2018-05-02 23:57:24 +02:00
Patrick Pelissier 47a49263ae Add function _parse_str for string. 2018-05-02 19:36:51 +02:00
Patrick Pelissier 9fed336c9e Add proper const to prototype. 2018-05-01 12:44:43 +02:00
Patrick Pelissier ac5b689950 Add method _set2 for tuple. 2018-04-30 20:00:26 +02:00
Patrick Pelissier 3d43bb260a Update 2018-04-30 13:32:24 +02:00
Patrick Pelissier 2eaeb26d4c Make Serialization input of array / dict more flexible
by supporting space characters within the input.
2018-04-30 11:02:42 +02:00
Patrick Pelissier 34d0f8ec81 Add missing function for variant:
variant_init_element
variant_init_set_element
2018-04-30 10:24:37 +02:00
Patrick Pelissier ddc1c7e98f Update to display checksum correctly. 2018-04-30 08:24:31 +02:00
Patrick Pelissier e41475f672 Rewrite 2018-04-29 11:52:19 +02:00
Patrick Pelissier e954622925 Rewrite 2018-04-29 11:48:02 +02:00
Patrick Pelissier fae899e52e Add benchmark udb2. 2018-04-29 10:45:03 +02:00
Patrick Pelissier 7b11f5afbc Add benchmark UDB 2018-04-28 19:44:52 +02:00
Patrick Pelissier 40c0bf79b1 Update 2018-04-28 19:09:30 +02:00
Patrick Pelissier df2df593b6 Replace complex convertion from int to string into a simple call to to_string 2018-04-27 21:54:57 +02:00
Patrick Pelissier 1dc59d610d Use of new function m_thread_yield 2018-04-27 21:54:34 +02:00
Patrick Pelissier 8fc8decd09 Add m_thread_yield & m_thread_sleep.
Rewrite the windows package (it wasn't fully working before) and use functions
available since WINDOWS VISTA (increasing minimum supported version).
2018-04-27 20:12:44 +02:00
Patrick Pelissier 08f44845ce Fix issue for SPSC queue:
computing the number of elements in the queue is not reliable enough
as we can get more than than the size of the queue.
2018-04-26 22:41:11 +02:00
Patrick Pelissier 4fbffc4788 Use plain 'unsigned int' instead of 'unsigned long long'
for index of SPSC queues. There is no issue as we don't compare
the index, but only substract them.
2018-04-26 22:38:43 +02:00
Patrick Pelissier 8cf4050d3d Remove uneeded alignment constraint for SPSC queue. 2018-04-26 22:26:30 +02:00
Patrick Pelissier 31c18fc56d Bench SPSC queues too. 2018-04-26 22:05:54 +02:00
Patrick Pelissier 005207cfd6 Remove a warning in release mode. 2018-04-26 22:05:36 +02:00
Patrick Pelissier c8d668ad96 Merge branch 'master' of https://github.com/P-p-H-d/mlib 2018-04-25 22:04:42 +02:00
Patrick Pelissier a39c4ba9a4 Rewrite the code by adding an additional cast to avoid new warning with GCC8. 2018-04-25 22:03:52 +02:00
Patrick Pelissier f4deea05bf Update doc. 2018-04-24 22:42:19 +02:00
Patrick Pelissier 1c18133603 Close the handle of the thread in case of joining thread. 2018-04-22 19:30:24 +02:00
Patrick Pelissier 15566b4b65 Add bench of library SDS for string 2018-04-21 18:53:38 +02:00
Patrick Pelissier 737185752c Merge branch 'master' of https://github.com/P-p-H-d/mlib 2018-04-21 12:46:26 +02:00
Patrick Pelissier a12e3534c6 Rewrite I/O functions so that they handle properly
non printable characters.
2018-04-21 10:26:05 +02:00
Patrick Pelissier 51575b341b Use of static library for liblfds. 2018-04-20 22:24:20 +02:00
Patrick Pelissier 06b330ec51 Update doc 2018-04-20 21:44:59 +02:00
Patrick Pelissier e0a6bce5b0 Add SDS 2018-04-20 21:43:19 +02:00
Patrick Pelissier da07a5b613 string_strim allows optionnal second argument which list the characters to strim. 2018-04-20 20:46:44 +02:00
Patrick Pelissier fbbca37b55 Ignore a*.dat file too. 2018-04-20 19:51:56 +02:00
Patrick Pelissier 7fa1c2264e Fix issue for C++ layer (memory order constants have to be put in the current namespace too). 2018-04-20 19:34:22 +02:00
Patrick Pelissier dcfbe53713 Fix conformity bug in _splice. 2018-04-20 19:30:45 +02:00
Patrick Pelissier 8b2993c979 Add more assertions to help scan-build with false positive. 2018-04-20 19:30:15 +02:00
Patrick Pelissier 131da660c8 Fix bug in _clean. 2018-04-20 19:30:01 +02:00
Patrick Pelissier f3de34a62b Optimization for MPMC queues:
* use of atomic_explicit functions to give the memory order we want,
* reduce the size of the index to unsigned int: even if there is an
overflow, it doesn't matter as we don't compare the index with < or >
but with ==.
2018-04-19 22:15:37 +02:00
Patrick Pelissier 928d6bafcb Fix issue if there is no working stdatomic / atomic header:
definition of atomic_compare_exchange_strong_explicit was wrong.
Same for atomic_compare_exchange_weak_explicit
2018-04-19 22:14:16 +02:00
Patrick Pelissier 704fb0cbd9 Add a cast to avoid a warning with some compilers
(I am not sure the warning was justified).
2018-04-19 22:13:53 +02:00
Patrick Pelissier 3be27aefa3 Fix the format for size_t 2018-04-19 22:13:27 +02:00
Patrick Pelissier 8be81ac09e Update the list of tested systems. 2018-04-19 22:13:05 +02:00
Patrick Pelissier e2fc9c3699 Update 2018-04-19 20:21:54 +02:00
Patrick Pelissier 472eaff6f0 Add gene queue 2018-04-19 20:20:18 +02:00
Patrick Pelissier 805b016aee Reformat test and reduce pressure on thread creation for some tests
(Some systems didn't handle so much thread creation).
2018-04-17 23:01:05 +02:00
Patrick Pelissier 624a13ba1a Update version with added parallelism for long computation. 2018-04-17 00:00:56 +02:00
Patrick Pelissier 9692bf3991 Start list of API breakage. 2018-04-17 00:00:29 +02:00
Patrick Pelissier 3f5406f1d4 API breakage:
worker_sync takes an extra parameter (worker_t) to perform a
wait-on-event instead of a busy waiting, reducing consummer ressources.

worker_init takes an int instead of an unsigned int for the number of workers.
It allows additional extra value -1 to initialize the number of workers to
twice the number of CPU, allowing to overload the CPU with loads and keep
them fully working in some scenario.
2018-04-16 23:57:28 +02:00
Patrick Pelissier b684a62f8b Add more local information about the origin of a failure. 2018-04-16 22:05:17 +02:00
Patrick Pelissier 6bb94db22f Add function dict_splice 2018-04-15 21:02:14 +02:00
Patrick Pelissier d70a971d2e Add note 2018-04-15 20:59:04 +02:00
Patrick Pelissier b05b515f3d Reformat 2018-04-15 20:58:52 +02:00
Patrick Pelissier 12b15e0037 Add function array_splice just like function list_splice
as it can be done faster at low level.
2018-04-15 11:41:32 +02:00
Patrick Pelissier 2c9169308b Add code generation for OA dict 2018-04-15 10:53:55 +02:00
Patrick Pelissier 74a3d50c88 Minor optimization for _clean
No need to fill in the complete array with invalid param
as the array will be reduced.
2018-04-15 10:53:15 +02:00
Patrick Pelissier 6b8bb33221 Convert unsigned long to size_t in function prototypes for 32 bits systems. 2018-04-15 01:10:49 +02:00
Patrick Pelissier 175fb46508 Fix issue for 32 bits system 2018-04-15 00:48:31 +02:00
Patrick Pelissier 2f65400641 Add target checkall to lanch the test suite wih multiple compilers / options. 2018-04-15 00:40:48 +02:00
Patrick Pelissier b5f4f2fc4b Finish splitting m_core_clz into m_core_clz32 & m_core_clz64 2018-04-15 00:10:38 +02:00
Patrick Pélissier 8c34f44dae Finish fixing for 32 bits / clz 2018-04-14 23:14:21 +02:00
Patrick Pélissier d97f46133b Fix issue for 32 bits systems
mpz_core_clz wasn't reproductible for 32 bits system.
2018-04-14 23:08:53 +02:00
Patrick Pélissier a94a5feb84 Fix issue with 32 bits systems (size_t != unsigned long) 2018-04-14 20:52:29 +02:00
Patrick Pelissier ead5d7511a Use of proper oplist with the CMP method. 2018-04-14 08:33:37 +02:00
Patrick Pelissier 1cd7446013 Add more instantiation of the containter 2018-04-14 08:27:26 +02:00
Patrick Pelissier 40747a463b Remove dependecies from GMP header, allowing to run the test suite without GMP 2018-04-14 08:16:31 +02:00
Patrick Pelissier 8e20118ab6 Reformat 2018-04-14 08:12:58 +02:00
Patrick Pelissier 19f330e670 Rename also MYMPZ2_OPLIST into MY_MPZ_CMP_OPLIST 2018-04-14 08:12:27 +02:00
Patrick Pelissier 20d549b5e1 Rename MYMPZ_OPLIST into MY_MPZ_OPLIST 2018-04-14 08:11:14 +02:00
Patrick Pelissier e09fa89781 Little bit rewrite to help the compiler optimizes the loop a bit more:
as the variables are not longer on the stack, it uses more registers
and more instructions in the critical loop than before. By
copying the data into stack local variable, the compiler is once again
able to optimize the loop properly.
2018-04-14 08:07:01 +02:00
Patrick Pelissier 70b1421114 Update after review 2018-04-13 20:56:48 +02:00
Patrick Pelissier b80a30785a Fix 2018-04-13 20:28:57 +02:00
Patrick Pelissier c3245ac301 Full refactorisation and proper use of M*LIB.
Should be as fast as before.
2018-04-13 20:28:01 +02:00
Patrick Pelissier 085d5b411c Add oplist for B*TREE 2018-04-13 20:16:23 +02:00
Patrick Pelissier 8c26d6d0b5 Update 2018-04-12 23:39:19 +02:00
Patrick Pelissier 76f5085e84 Merge branch 'master' of https://github.com/P-p-H-d/mlib 2018-04-11 22:42:46 +02:00
Patrick Pelissier 80d78e3270 Add bounded string cte macro 2018-04-11 22:42:22 +02:00
Patrick Pelissier 654521b74c Add some tests of _equal_p 2018-04-10 23:25:04 +02:00
Patrick Pelissier 353d2d4cc9 Fix issue in copy of B*TREE:
the _next field wasn't properly set for the deepest nodes.
2018-04-10 23:23:36 +02:00
Patrick Pelissier b38d84419a Add methods hash, eqal_p, out_str, in_str & get_str
Format of serialisation needs to be properly uniformised between:
dictionnary,
red-black tree,
set,
b+tree with key,value,
b+tree with only key.
2018-04-09 18:42:34 +02:00
Patrick Pelissier 0d085771e4 Add tests for new methods 2018-04-09 18:07:03 +02:00
Patrick Pelissier f3b2b6b41e Add methods _swap, _move & _init_move 2018-04-09 18:06:48 +02:00
Patrick Pelissier fb35ad7ab3 Update due no new LIBSRT API. 2018-04-08 21:43:25 +02:00
Patrick Pelissier cf6e721994 Fix wrong usage of CollectionC by the benchmark. 2018-04-08 21:32:57 +02:00
Patrick Pelissier 9faea5ff15 Rewrite bench code so that it computes what is expected. 2018-04-08 21:10:29 +02:00
Patrick Pelissier fe18009bc0 Rewrite the loop so that the result is the same for dict and dict_oa. 2018-04-08 21:07:20 +02:00
Patrick Pelissier 10f900ea3e Rewrite code to avoid warning if optimisations are turned on. 2018-04-08 20:27:37 +02:00
Patrick Pelissier 63874694f8 Rewrite the code to avoid some silly warnings on some implementation. 2018-04-08 20:01:04 +02:00
Patrick Pelissier 9b9e246e66 More tests 2018-04-08 11:16:31 +02:00
Patrick Pelissier e6a6eb9be5 Fix issue in it_from for B+TREE 2018-04-08 11:13:48 +02:00
Patrick Pelissier 050bb5dbfa Add tests for it_from & it_to_p for B+TREE 2018-04-08 11:13:22 +02:00
Patrick Pelissier b005ec1845 Fix function max for B+TREE 2018-04-08 10:48:02 +02:00
Patrick Pelissier f158a94e0a Add tests for min & max 2018-04-08 10:47:52 +02:00
Patrick Pelissier a166620a6d Add method _from, _to_p, _min & _max for B+TREE 2018-04-08 10:39:27 +02:00
Patrick Pelissier 47fb467878 Add basic it test for B+tree 2018-04-08 07:24:56 +02:00
Patrick Pelissier 67af80c772 Fix issue in it_end for B+TREE 2018-04-08 07:22:34 +02:00
Patrick Pelissier 1f44155127 Add one more corner case 2018-04-07 12:11:50 +02:00
Patrick Pelissier 87a3ac4a76 Add test for methods _init_set & _set for B+tree 2018-04-07 12:10:50 +02:00
Patrick Pelissier 73354a04d5 Add method _init_set & _set for B+tree 2018-04-07 12:10:19 +02:00
Patrick Pelissier cb3038e73c Add more checks 2018-04-07 11:51:38 +02:00
Patrick Pelissier b6ec31fe11 Add more test. 2018-04-07 11:50:18 +02:00
Patrick Pelissier c7059a60ee Add more tests 2018-04-07 11:44:16 +02:00
Patrick Pelissier af49aaf8b1 Add more tests. 2018-04-07 11:42:12 +02:00
Patrick Pelissier 4149b8388b Improve quality of coverage report by not expanding contract function. 2018-04-07 11:41:43 +02:00
Patrick Pelissier df0d723714 Compute coverage for B+TREE 2018-04-07 11:28:50 +02:00
Patrick Pelissier 44209ed93e Add more tests 2018-04-07 11:19:58 +02:00
Patrick Pelissier 930a3c8637 More tests. 2018-04-07 11:14:31 +02:00
Patrick Pelissier d2f5698397 iMake oplist optional for BPTREE_DEF 2018-04-07 11:10:13 +02:00
Patrick Pelissier 42d9fc3284 Update doc 2018-04-07 00:43:51 +02:00
Patrick Pelissier 91db494898 Add basic iterator for B+tree
I can't match the exact interface of a dictionary of the key and the value are in separate place in the structure
(so I can't return a pair of (key,value)). Instead I return a pair of pointer (key_ptr, value_ptr).
I don't see any other way which doesn't evolve copy of the key/value.
For the RBtree interface, no such problem occurs.
2018-04-05 22:44:36 +02:00
Patrick Pelissier 75217d4914 Rewrite / cleanup 2018-04-04 22:57:47 +02:00
Patrick Pelissier ceaf004719 Remove wrong comment 2018-04-04 22:55:19 +02:00
Patrick Pelissier 27b7380433 B+TREE: Add _size operator 2018-04-04 22:54:39 +02:00
Patrick Pelissier 7ca254ade9 B+TREE: Add _pop function. 2018-04-04 22:39:46 +02:00
Patrick Pelissier c91864c2a7 B+TREE: _remove returns a boolean indicating if the item
removed was present or not
2018-04-04 22:35:47 +02:00
Patrick Pelissier 4925297a35 Update doc 2018-04-04 20:27:44 +02:00
Patrick Pelissier d7ece50ed0 Replace "Dict" by "DictOA" since KLIB uses an OpenAddressing dictionnary. 2018-04-03 20:13:18 +02:00
Patrick Pelissier 3ef4a9f413 Fix issue with the way of benching the BTREE of KLIB.
Forgot to initialize the key in the search pass.
2018-04-03 20:10:11 +02:00
Patrick Pelissier 9768b5b37a Add bench of B+TREE 2018-04-03 20:07:21 +02:00
Patrick Pelissier e4cd999bd0 Test expansion of new container. 2018-04-03 20:01:24 +02:00
Patrick Pelissier 8e335535cc Add new container without a value. 2018-04-03 20:01:04 +02:00
Patrick Pelissier 2f53d98806 Fix issue with kind_s being redefined if the macro is used again.
Fix issue of not using proper method for type.
Render usage of value optional so that we can create B+TREE with only keys.
2018-04-03 18:29:28 +02:00
Patrick Pelissier 5d99331358 Add expansion of a user type. 2018-04-03 18:29:16 +02:00
Patrick Pelissier 316022cde4 Add oplist with CMP operator 2018-04-03 18:28:51 +02:00
Patrick Pelissier 8d1abca8de Add link to the comparison between STL & M*LIB 2018-04-03 12:47:44 +02:00
Patrick Pelissier 1b2e73eaa2 Prepare doc 2018-04-03 12:43:30 +02:00
Patrick Pelissier 6127371920 Add B+TREE container.
Fix #4
2018-04-03 12:40:29 +02:00
Patrick Pelissier 7936dbbf8c Minor fix 2018-03-31 16:31:47 +02:00
Patrick Pelissier 8aa45309a2 Update doc 2018-03-31 12:10:50 +02:00
167 changed files with 43517 additions and 12608 deletions

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
name: C/C++ CI
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v1
- name: make check C99
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 && make check -j 2 CC="cc -std=c11 -Wno-unknown-warning-option -Werror"
- name: make check C++
working-directory: ./tests
run: make clean && make check -j 2 CC="c++ -std=c++11"
build_linux32:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: update package list
run: sudo apt-get update
- name: install multilib
run: sudo apt-get install gcc-multilib g++-multilib
- name: make check C99 (32bits)
working-directory: ./tests
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 && 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
- name: Clone TCC
shell: bash
run: git clone https://repo.or.cz/tinycc.git
- name: Configure, build & install TCC
shell: bash
run: cd tinycc && ./configure --prefix=/tmp/tcc && make && make install
- name: make depend
shell: bash
run: make depend
- name: make check
shell: bash
run: make CC="/tmp/tcc/bin/tcc -std=c99" check
build_windows_mingw:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: make check
shell: bash
run: mingw32-make -j 2 CC="gcc -std=c99 -D__USE_MINGW_ANSI_STDIO=1" check
build_windows_msys2:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v2
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: git mingw-w64-x86_64-toolchain make
- name: make 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
- name: make check
shell: cmd
working-directory: ./tests
run: Make-check-cl.bat cl
build_windows_clang_cl:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: make check
shell: cmd
working-directory: ./tests
run: Make-check-cl.bat clang-cl
+53
View File
@@ -0,0 +1,53 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['cpp']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
steps:
- name: Checkout repository
uses: actions/checkout@v2
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
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- name: Autobuild
working-directory: ./tests
run: make exe
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
+7
View File
@@ -36,3 +36,10 @@ depend
# Others
other/
a*.dat
config
*.log
.vscode
.vs
tmp-serial.*
*~
+1 -1
View File
@@ -1,6 +1,6 @@
BSD 2-Clause License
Copyright (c) 2017-2018, Patrick Pelissier
Copyright (c) 2017-2021, Patrick Pelissier
All rights reserved.
Redistribution and use in source and binary forms, with or without
+90 -9
View File
@@ -1,8 +1,49 @@
PREFIX=/usr/local
# 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.
# Environnement variable. To customize if needed.
RM=rm -f
MKDIR=mkdir -p
RMDIR=rmdir
INSTALL=install
INSTALL_PROGRAM=${INSTALL}
INSTALL_DATA=${INSTALL} -m 644
.PHONY: all test check doc clean distclean depend depend.png install
# Installation directory
PREFIX=/usr/local
DESTDIR=
# Package name & version.
PACKAGE=m_lib-$(VERSION)
VERSION=0.6.0
# 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
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 example/ex-defer01.c example/ex-string01.c example/ex-string02.c example/ex-astar.c example/ex-string03.c example/ex11-tstc.c
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/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/test-mishared.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
.PHONY: all test check doc clean distclean depend install uninstall dist
all:
@echo "Nothing to be done."
@@ -13,25 +54,65 @@ check:
cd tests && $(MAKE) check
cd example && $(MAKE) all
doc: README.md
checkall:
cd tests && $(MAKE) checkall
cd example && $(MAKE) all
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) -f README.html depend.dot
$(RM) README.html depend.dot
$(RM) -r 'm*lib-$(VERSION)'
$(RM) 'm*lib-$(VERSION).tar.bz2'
distclean:
distclean: clean
cd tests && $(MAKE) distclean
depend:
cd tests && $(MAKE) depend
depend.png:
doc/depend.png: $(HEADER)
(echo "digraph g { " ; for i in *.h ; do list=$$(grep "include \"" $$i |cut -f2 -d\") ; for j in $$list ; do echo "\"$$i\" -> \"$$j\" ;" ; done ; done ; echo "}" )> depend.dot
dot -Tpng depend.dot -o depend.png
dot -Tpng depend.dot -o doc/depend.png
optipng -o7 doc/depend.png
dist: $(HEADER) $(DOC1) $(DOC2) $(EXAMPLE) $(TEST) Makefile clean versioncheck
$(MKDIR) '$(PACKAGE)'
$(MKDIR) '$(PACKAGE)/doc'
$(MKDIR) '$(PACKAGE)/tests'
$(MKDIR) '$(PACKAGE)/example'
cp $(HEADER) $(DOC1) Makefile '$(PACKAGE)'
cp $(EXAMPLE) '$(PACKAGE)/example'
cp $(TEST) '$(PACKAGE)/tests'
cp $(DOC2) '$(PACKAGE)/doc'
cd '$(PACKAGE)/tests' && $(MAKE) depend
tar jcf '$(PACKAGE).tar.bz2' '$(PACKAGE)'
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
cp m-*.h $(DESTDIR)$(PREFIX)/include
$(MKDIR) $(DESTDIR)$(PREFIX)/include/m-lib
$(INSTALL_DATA) $(HEADER) $(DESTDIR)$(PREFIX)/include/m-lib
uninstall:
for i in $(HEADER) ; do $(RM) $(DESTDIR)$(PREFIX)/include/m-lib/$$i ; done
$(RMDIR) $(DESTDIR)$(PREFIX)/include/m-lib/
format:
cd example && $(MAKE) ex-string01.exe
for i in $(HEADER) ; do ./example/ex-string01.exe $$i > tmp.h && mv tmp.h $$i ; done
+4863 -1216
View File
File diff suppressed because it is too large. Load diff
+172 -48
View File
@@ -1,20 +1,48 @@
# 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 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-hopscotchmap bench-mlib-thread bench-liblfds bench-concurrentqueue bench-boost bench-mempool bench-string bench-plain
.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-sparsepp bench-collectionc bench-tommyds bench-flathashmap bench-hopscotchmap
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 bench-ctl
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
queue: bench-mlib-thread bench-liblfds bench-concurrentqueue bench-boost
queue: bench-mlib-thread bench-liblfds bench-concurrentqueue bench-boost bench-rigtorp-mpmc-queue
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
mempool: bench-mempool
@@ -32,42 +60,56 @@ plain: bench-plain
bench-mlib:
$(CC) $(CFLAGS) $(CPPFLAGS) -pthread bench-mlib.c -o bench-mlib.exe
$(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 -DUSE_MEMPOOL -pthread -o bench-mlib-mempool.exe
$(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 -DMULTI_THREAD_MEASURE -pthread -o bench-mlib-thread.exe
$(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) $(CPPFLAGS) bench-stl.cpp -o bench-stl.exe
$(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
@@ -76,7 +118,7 @@ bench-stl:
bench-qt:
@if test -n "$${QT}" ; then $(MAKE) bench-qt0 ; else echo "Nothing to be done for QT." ; fi
bench-qt0:
$(CXX) $(CFLAGS) $(CPPFLAGS) -fPIC `PKG_CONFIG_PATH="$${QT}" pkg-config --libs --cflags Qt5Core` bench-qt.cpp -o bench-qt.exe
$(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
@@ -89,7 +131,7 @@ bench-qt0:
bench-glib:
@if test -n "$${GLIB}" ; then $(MAKE) bench-glib0 ; else echo "Nothing to be done for GLIB." ; fi
bench-glib0:
$(CC) $(CFLAGS) $(CPPFLAGS) bench-glib.c -o bench-glib.exe `PKG_CONFIG_PATH="$${GLIB}" pkg-config --libs --cflags glib-2.0`
$(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
@@ -102,7 +144,7 @@ bench-klib:
@if test -n "$${KLIB}" ; then $(MAKE) bench-klib0 ; else echo "Nothing to be done for KLIB." ; fi
bench-klib0:
$(CC) $(CFLAGS) $(CPPFLAGS) -I $${KLIB} bench-klib.c -o bench-klib.exe
$(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
@@ -110,25 +152,32 @@ bench-klib0:
@./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) $(CPPFLAGS) bench-libdynamic.c -o bench-libdynamic.exe `PKG_CONFIG_PATH="$${LIBDYNAMIC}" pkg-config --libs --cflags libdynamic`
@./bench-libdynamic.exe 10
$(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 30
@./bench-libdynamic.exe 40
@./bench-libdynamic.exe 41
@./bench-libdynamic.exe 50
# 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) $(CPPFLAGS) -I "$${SPARSEPP}" -I "$${SPARSEPP}/.." bench-sparsepp.cpp -o bench-sparsepp.exe
$(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
@@ -138,17 +187,17 @@ bench-densehashmap:
@if test -n "$${DENSEHASHMAP}" ; then $(MAKE) bench-densehashmap0 ; else echo "Nothing to be done Google DENSEHASHMAP." ; fi
bench-densehashmap0:
$(CXX) $(CFLAGS) $(CPPFLAGS) -I "$${DENSEHASHMAP}" -I "$${DENSEHASHMAP}/.." bench-densehashmap.cpp -o bench-densehashmap.exe
$(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 the 'src' directory is.
# 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) $(CPPFLAGS) -I "$${COLLECTIONC}/include" -L "$${COLLECTIONC}" -static bench-collectionc.c -lcollectc -o bench-collectionc.exe
$(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
@@ -161,7 +210,7 @@ bench-tommyds:
@if test -n "$${TOMMYDS}" ; then $(MAKE) bench-tommyds0 ; else echo "Nothing to be done for TOMMYDS." ; fi
bench-tommyds0:
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${TOMMYDS}" bench-tommyds.c $${TOMMYDS}/tommyds/tommyarray.c $${TOMMYDS}/tommyds/tommylist.c $${TOMMYDS}/tommyds/tommytree.c $${TOMMYDS}/tommyds/tommyhashlin.c -o bench-tommyds.exe
$(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
@@ -173,17 +222,29 @@ 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) $(CPPFLAGS) -I "$${FLATHASHMAP}" bench-flathashmap.cpp -o bench-flathashmap.exe
$(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) $(CPPFLAGS) -I "$${HOPSCOTCHMAP}" bench-hopscotchmap.cpp -o bench-hopscotchmap.exe
$(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
@@ -193,12 +254,11 @@ bench-uthash:
@if test -n "$${UTHASH}" ; then $(MAKE) bench-uthash0 ; else echo "Nothing to be done for UTHASH." ; fi
bench-uthash0:
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${UTHASH}" bench-uthash.c -o bench-uthash.exe
$(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 42
@./bench-uthash.exe 43
@./bench-uthash.exe 50
# QLIBC shall point to the directory where the library is installed.
@@ -206,24 +266,18 @@ bench-qlibc:
@if test -n "$${QLIBC}" ; then $(MAKE) bench-qlibc0 ; else echo "Nothing to be done for QLIBC." ; fi
bench-qlibc0:
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${QLIBC}/include" -L "$${QLIBC}/lib" -lqlibc -pthread bench-qlibc.c -o bench-qlibc.exe
$(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
@LD_LIBRARY_PATH="$${QLIBC}/lib:$${LD_LIBRARY_PATH}" ./bench-qlibc.exe 42
@LD_LIBRARY_PATH="$${QLIBC}/lib:$${LD_LIBRARY_PATH}" ./bench-qlibc.exe 41
# LIBSRT shall point to the directory where the source are
# 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) $(CPPFLAGS) -I "$${LIBSRT}/src" bench-libsrt.c -o bench-libsrt.exe $${LIBSRT}/libsrt.a
@./bench-libsrt.exe 10
$(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 41
@./bench-libsrt.exe 42
@./bench-libsrt.exe 43
@./bench-libsrt.exe 50
@@ -232,7 +286,7 @@ bench-libsrt0:
bench-liblfds:
@if test -n "$${LIBLFDS}" ; then $(MAKE) bench-liblfds0 ; else echo "Nothing to be done for LIBLFDS." ; fi
bench-liblfds0:
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${LIBLFDS}/inc" -Wno-unknown-pragmas bench-liblfds.c -o bench-liblfds.exe $${LIBLFDS}/bin/liblfds711.so -lpthread
$(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
@@ -241,36 +295,81 @@ bench-liblfds0:
bench-concurrentqueue:
@if test -n "$${CONCURRENTQUEUE}" ; then $(MAKE) bench-concurrentqueue0 ; else echo "Nothing to be done for CONCURRENTQUEUE." ; fi
bench-concurrentqueue0:
$(CXX) $(CFLAGS) $(CPPFLAGS) -I "$${CONCURRENTQUEUE}/" bench-concurrentqueue.cpp -o bench-concurrentqueue.exe -lpthread
$(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) $(CPPFLAGS) -I "$${XXHASH}/" bench-xxhash.c "$${XXHASH}/libxxhash.a" -o bench-xxhash.exe
$(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) $(CPPFLAGS) -I "$${BOOST}" bench-boost.cpp -o bench-boost.exe -lpthread
$(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) $(CPPFLAGS) -I "$${NEDTRIES}" bench-nedtries.c -o bench-nedtries.exe
$(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
# CTL shall point to the source directory (not where the headers are)
bench-ctl:
@if test -n "$${CTL}" ; then $(MAKE) bench-ctl0 ; else echo "Nothing to be done for CTL." ; fi
bench-ctl0:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I $${CTL} bench-ctl.c common.c -o bench-ctl.exe
@./bench-ctl.exe 10
@./bench-ctl.exe 20
@./bench-ctl.exe 30
@./bench-ctl.exe 40
@./bench-ctl.exe 50
############################################################################
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) $(CPPFLAGS) bench-plain-c.c -o bench-plain-c.exe
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) bench-plain-c.c -o bench-plain-c.exe
@./bench-plain-c.exe
############################################################################
@@ -278,34 +377,59 @@ bench-plain:
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) $(CPPFLAGS) pool.cc $(BENCH_DEF) -o bench-mempool.exe
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) pool.cc $(BENCH_DEF) -o bench-mempool.exe
@./bench-mempool.exe
############################################################################
bench-maxdict:
$(CC) $(CFLAGS) $(CPPFLAGS) max-dict.c -o bench-max-dict.exe
$(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 sources
# LIBSRT shall point to the LIBSRT install directory
bench-string:
@if test -n "$${BSTRLIB}" ; then $(MAKE) bench-string-with BENCH_DEF="-DBENCH_CAN_USE_BSTRLIB -I ${BSTRLIB} $${BSTRLIB}/obj/bstrlib.o $${BSTRLIB}/obj/bstraux.o $${BSTRLIB}/obj/bstrwrap.o" ; else $(MAKE) bench-string-with ; fi
@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-with:
@if test -n "$${LIBSRT}" ; then $(MAKE) bench-string-exe BENCH_DEF="$(BENCH_DEF) -DBENCH_CAN_USE_LIBSRT -I$${LIBSRT}/src $${LIBSRT}/libsrt.a" ; else $(MAKE) bench-string-exe BENCH_DEF="$(BENCH_DEF)"; 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
bench-string-exe:
$(CXX) $(CFLAGS) $(CPPFLAGS) -I "$${BSTRLIB}" -DBENCH_CAN_USE_STL -DBENCH_CAN_USE_MSTARLIB bench-string.cpp -o bench-string.exe $(BENCH_DEF)
#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 -f *.o bench-*.exe bench-*.s *~ massif.out.*
$(RM) *.o bench-*.exe
$(RM) bench-*.s *~ massif.out.*
$(RM) plot-*.dat
$(RM) pgo
$(RM) tmp-serial.*
cd nucleotide && $(MAKE) clean
############################################################################
+6 -8
View File
@@ -6,11 +6,8 @@
#include <boost/lockfree/queue.hpp>
#include "m-mutex.h"
#define MULTI_THREAD_MEASURE
#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;
@@ -51,7 +48,7 @@ static void prod(void *arg)
}
}
static void test_buffer(size_t n)
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
@@ -88,11 +85,12 @@ static void test_buffer(size_t n)
/********************************************************************************************/
const config_func_t table[] = {
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
};
int main(int argc, const char *argv[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 60)
test_function("Buffer time", 1000000, test_buffer);
test("BOOST-LOCKFREE", numberof(table), table, argc, argv);
exit(0);
}
+204
View File
@@ -0,0 +1,204 @@
#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);
}
+24 -19
View File
@@ -93,7 +93,7 @@ static void test_rbtree(size_t n)
stat = treetable_new(compare, &tree);
if (stat != CC_OK) abort();
for (size_t i = 0; i < n; i++) {
void *key = (void*)(uintptr_t) i;
void *key = (void*)(uintptr_t) rand_get();
stat = treetable_add(tree, key, key);
if (stat != CC_OK) abort();
}
@@ -122,11 +122,11 @@ 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;
return (pa < pb) ? -1 : pa > pb;
}
static void
test_dict(unsigned long n)
test_dict(size_t n)
{
HashTable *dict;
enum cc_stat stat;
@@ -138,8 +138,8 @@ test_dict(unsigned long n)
if (stat != CC_OK) abort();
for (size_t i = 0; i < n; i++) {
void *key = (void*)(uintptr_t) rand_get();
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();
}
@@ -164,7 +164,7 @@ 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)==0;
return strcmp(*pa,*pb);
}
static size_t char_hash(const void *a, int l, uint32_t seed)
@@ -178,7 +178,7 @@ static size_t char_hash(const void *a, int l, uint32_t seed)
}
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
HashTable *dict;
enum cc_stat stat;
@@ -189,9 +189,14 @@ test_dict_big(unsigned long n)
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 );
@@ -209,6 +214,9 @@ test_dict_big(unsigned long n)
}
g_result = s;
hashtable_destroy(dict);
if (cpt != 2*n) abort();
for(size_t i = 0; i < 2*n;i++)
free(tab[i]);
}
/********************************************************************************************/
@@ -242,20 +250,17 @@ static void test_sort(size_t n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 30)
test_function("Rbtree time", 1000000, test_rbtree);
if (n == 40)
test_function("Dict time", 1000000, test_dict);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
test("CollectionC", numberof(table), table, argc, argv);
exit(0);
}
+6 -8
View File
@@ -6,11 +6,8 @@
#include "concurrentqueue.h"
#include "m-mutex.h"
#define MULTI_THREAD_MEASURE
#include "common.h"
/********************************************************************************************/
moodycamel::ConcurrentQueue<unsigned int> g_buff;
moodycamel::ConcurrentQueue<unsigned long long> g_final;
@@ -51,7 +48,7 @@ static void prod(void *arg)
}
}
static void test_buffer(size_t n)
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
@@ -88,11 +85,12 @@ static void test_buffer(size_t n)
/********************************************************************************************/
const config_func_t table[] = {
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
};
int main(int argc, const char *argv[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 60)
test_function("Buffer time", 1000000, test_buffer);
test("CONCURRENT-QUEUE", numberof(table), table, argc, argv);
exit(0);
}
+182
View File
@@ -0,0 +1,182 @@
#define NDEBUG
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "m-core.h"
#include "common.h"
typedef unsigned int uint;
typedef unsigned long ulong;
/********************************************************************************************/
#define POD
#define T uint
#include "ctl/vector.h"
static void test_array(size_t n)
{
vec_uint a1 = vec_uint_init();
vec_uint a2 = vec_uint_init();
for(size_t i = 0; i < n; i++) {
vec_uint_push_back(&a1, rand_get() );
vec_uint_push_back(&a2, rand_get() );
}
unsigned int s = 0;
for(unsigned long i = 0; i < n; i++) {
s += *vec_uint_at(&a1, i ) * *vec_uint_at(&a2, i );
}
g_result = s;
vec_uint_free(&a1);
vec_uint_free(&a2);
}
/********************************************************************************************/
#define POD
#define T uint
#include "ctl/forward_list.h"
static void test_list (size_t n)
{
slist_uint a1 = slist_uint_init();
slist_uint a2 = slist_uint_init();
for(size_t i = 0; i < n; i++) {
slist_uint_push_front(&a1, rand_get());
slist_uint_push_front(&a2, rand_get());
}
unsigned int s = 0;
slist_uint_it it1 = slist_uint_begin(&a1);
slist_uint_it it2 = slist_uint_begin(&a2);
for( ; !slist_uint_it_done(&it1) ;
slist_uint_it_next(&it1), slist_uint_it_next(&it2)) {
s += *slist_uint_it_ref(&it1) * *slist_uint_it_ref(&it2);
}
g_result = s;
slist_uint_free(&a1);
slist_uint_free(&a2);
}
/********************************************************************************************/
#define POD
#define T ulong
#include "ctl/set.h"
static inline int
int_cmp(ulong *a, ulong *b) {
return *a < *b;
}
static void test_rbtree(size_t n)
{
set_ulong tree = set_ulong_init (int_cmp);
for (size_t i = 0; i < n; i++) {
set_ulong_insert (&tree, rand_get() );
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long j = rand_get();
if (set_ulong_find_node(&tree, j) != NULL)
s+= j;
}
g_result = s;
set_ulong_free(&tree);
}
/********************************************************************************************/
typedef struct {
unsigned long key;
unsigned long value;
} pair_ulong;
// Use of M*LIB hash function
static inline size_t
pair_ulong_hash(pair_ulong *a)
{
return M_HASH_DEFAULT(a->key);
}
static inline int
pair_ulong_equal(pair_ulong *a, pair_ulong *b)
{
return a->key == b->key;
}
static inline void
pair_ulong_free(pair_ulong *a) {
(void) a;
}
static inline pair_ulong
pair_ulong_copy(pair_ulong *self) {
return (pair_ulong) { .key = self->key, .value = self->value };
}
#define T pair_ulong
#include <ctl/unordered_map.h>
// It seems broken: it doesn't output the expected result.
static void
test_dict(size_t n)
{
umap_pair_ulong dict = umap_pair_ulong_init(pair_ulong_hash, pair_ulong_equal);
for (size_t i = 0; i < n; i++) {
umap_pair_ulong_insert(&dict, (pair_ulong) { rand_get(), rand_get() });
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
umap_pair_ulong_it it = umap_pair_ulong_find(&dict, (pair_ulong) { rand_get() , 0 } );
if (!umap_pair_ulong_it_done(&it) )
s += it.ref->value;
}
g_result = s;
umap_pair_ulong_free(&dict);
}
/********************************************************************************************/
#define POD
#define T float
#include "ctl/vector.h"
static void test_sort(size_t n)
{
vec_float a1 = vec_float_init();
for(size_t i = 0; i < n; i++) {
vec_float_push_back(&a1, rand_get());
}
vec_float_sort(&a1);
g_result = *vec_float_at(&a1, 0);
vec_float_free(&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},
{ 50, "Sort", 10000000, 0, test_sort, 0},
};
int main(int argc, const char *argv[])
{
test("CTL", numberof(table), table, argc, argv);
exit(0);
}
+10 -10
View File
@@ -25,7 +25,7 @@ using namespace std;
/********************************************************************************************/
static void
test_dict2(unsigned long n)
test_dict2(size_t n)
{
dense_hash_map<unsigned long, unsigned long> dict;
dict.set_empty_key(-1);
@@ -75,7 +75,7 @@ namespace std {
}
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
dense_hash_map<char_array_s, char_array_s> dict;
struct char_array_s empty, del;
@@ -104,7 +104,7 @@ test_dict_big(unsigned long n)
/********************************************************************************************/
static void
test_dict_str(unsigned long n)
test_dict_str(size_t n)
{
dense_hash_map<string, string> dict;
string empty, del;
@@ -131,14 +131,14 @@ test_dict_str(unsigned long n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 42)
test_function("Dict(u)time", 1000000, test_dict2);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 43)
test_function("DictS(u) time", 1000000, test_dict_str);
test("DENSE-HASPMAP", numberof(table), table, argc, argv);
exit(0);
}
+138
View File
@@ -0,0 +1,138 @@
#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
@@ -0,0 +1,101 @@
// 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;
}
+28 -10
View File
@@ -26,7 +26,7 @@ using namespace std;
/********************************************************************************************/
static void
test_dict2(unsigned long n)
test_dict2(size_t n)
{
flat_hash_map<unsigned long, unsigned long> dict;
for (size_t i = 0; i < n; i++) {
@@ -42,6 +42,23 @@ test_dict2(unsigned long n)
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];
@@ -62,7 +79,7 @@ namespace std {
}
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
flat_hash_map<char_array_s, char_array_s> dict;
@@ -86,7 +103,7 @@ test_dict_big(unsigned long n)
/********************************************************************************************/
static void
test_dict_str(unsigned long n)
test_dict_str(size_t n)
{
flat_hash_map<string, string> dict;
@@ -108,14 +125,15 @@ test_dict_str(unsigned long n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 42)
test_function("Dict(u)time", 1000000, test_dict2);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 43)
test_function("DictS(u) time", 1000000, test_dict_str);
test("FLAT-HASPMAP", numberof(table), table, argc, argv);
exit(0);
}
+12 -15
View File
@@ -97,7 +97,7 @@ static gboolean equal_func(gconstpointer a, gconstpointer b)
}
static void
test_dict(unsigned long n)
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++) {
@@ -140,7 +140,7 @@ static guint char_hash(gconstpointer a)
}
static void
test_dict_big(unsigned long n)
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++) {
@@ -186,20 +186,17 @@ static void test_sort(size_t n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 30)
test_function("Rbtree time", 1000000, test_rbtree);
if (n == 40)
test_function("Dict time", 1000000, test_dict);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
test("GLIB", numberof(table), table, argc, argv);
exit(0);
}
+12 -11
View File
@@ -15,7 +15,7 @@
#include <stdbool.h>
#include <string.h>
#include "src/hopscotch_map.h"
#include "hopscotch_map.h"
using namespace tsl;
using namespace std;
@@ -25,7 +25,7 @@ using namespace std;
/********************************************************************************************/
static void
test_dict2(unsigned long n)
test_dict2(size_t n)
{
tsl::hopscotch_map<unsigned long, unsigned long> dict;
@@ -63,7 +63,7 @@ namespace std {
}
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
hopscotch_map<char_array_s, char_array_s> dict;
@@ -87,7 +87,7 @@ test_dict_big(unsigned long n)
/********************************************************************************************/
static void
test_dict_str(unsigned long n)
test_dict_str(size_t n)
{
hopscotch_map<string, string> dict;
@@ -109,14 +109,15 @@ test_dict_str(unsigned long n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 42)
test_function("Dict(u)time", 1000000, test_dict2);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 43)
test_function("DictS(u) time", 1000000, test_dict_str);
test("HOPSCOTCHMAP", numberof(table), table, argc, argv);
exit(0);
}
+13 -16
View File
@@ -82,7 +82,7 @@ static void test_rbtree(size_t n)
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long j = 0;
unsigned long j = rand_get();
if (kb_getp(kTree, tree, &j) != 0)
s+= j;
}
@@ -98,7 +98,7 @@ static void test_rbtree(size_t n)
KHASH_INIT(iun, unsigned long, unsigned long, 1, hash_func, hash_eq)
static void
test_dict(unsigned long n)
test_dict(size_t n)
{
khash_t(iun) *dict = kh_init(iun);
@@ -137,7 +137,7 @@ static inline size_t char_hash(const char_array_t a) {
KHASH_INIT(iub, char_array_t, char_array_t, 1, char_hash, char_equal_p)
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
khash_t(iub) *dict = kh_init(iub);
@@ -185,21 +185,18 @@ static void test_sort(size_t n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]): 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 30)
test_function("B-tree time", 1000000, test_rbtree);
if (n == 40)
test_function("Dict time", 1000000, test_dict);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
test("KLIB", numberof(table), table, argc, argv);
exit(0);
}
+33 -20
View File
@@ -7,6 +7,9 @@
#include <stdint.h>
#include <unistd.h>
// Needed due to compilation error in pool.h
#include <pthread.h>
#include "dynamic.h"
#include "common.h"
@@ -45,6 +48,9 @@ static size_t hash_func (void *a)
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;
}
@@ -52,8 +58,12 @@ static int equal_func(void *a, void *b)
static void set_func(void *a, void *b)
{
unsigned long *pa = a;
const unsigned long *pb = b;
*pa = *pb;
if (b == NULL) {
*pa = -1U;
} else {
const unsigned long *pb = b;
*pa = *pb;
}
}
typedef struct map_element map_element;
@@ -64,13 +74,13 @@ struct map_element
};
static void
test_dict(unsigned long n)
test_dict(size_t n)
{
map dict;
map_construct(&dict, sizeof(map_element), (map_element[]) {{.key = -1}}, set_func);
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, equal_func, set_func, NULL);
map_insert(&dict, (map_element[]) {{.key = rand_get(), .value = rand_get()}}, hash_func, set_func, equal_func, NULL);
}
rand_init();
unsigned int s = 0;
@@ -90,6 +100,8 @@ 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;
}
@@ -103,8 +115,12 @@ static size_t char_hash(void *a)
static void char_set(void *a, void *b)
{
char_array_t *pa = (char_array_t *)a;
const char_array_t *pb = (const char_array_t *)b;
strcpy(*pa,*pb);
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;
@@ -115,19 +131,16 @@ struct big_map_element
};
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
map dict;
big_map_element empty;
strcpy(empty.key, "");
strcpy(empty.value, "");
map_construct(&dict, sizeof(big_map_element), &empty, char_set);
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_equal, char_set, NULL);
map_insert(&dict, &el, char_hash, char_set, char_equal, NULL);
}
rand_init();
unsigned int s = 0;
@@ -144,14 +157,14 @@ test_dict_big(unsigned long n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 40)
test_function("Dict time", 1000000, test_dict);
if (n == 41)
test_function("Dict B time", 1000000, test_dict_big);
test("LIBDYNAMIC", numberof(table), table, argc, argv);
exit(0);
}
+14 -28
View File
@@ -6,11 +6,8 @@
#include "liblfds711.h"
#include "m-mutex.h"
#define MULTI_THREAD_MEASURE
#include "common.h"
/********************************************************************************************/
struct lfds711_queue_bmm_state g_buff;
@@ -23,12 +20,9 @@ static void final(void *arg)
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++) {
int rv;
do {
void *p;
rv = lfds711_queue_bmm_dequeue(&g_final, &p, NULL);
j = (uintptr_t)p;
} while (rv == 0);
void *p;
while (0 == lfds711_queue_bmm_dequeue(&g_final, &p, NULL)) { m_thread_yield(); }
j = (uintptr_t)p;
s += j;
}
g_result = s;
@@ -42,18 +36,12 @@ static void conso(void *arg)
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++) {
int rv;
do {
void *p;
rv = lfds711_queue_bmm_dequeue(&g_buff, &p, NULL);
j = (uintptr_t) p;
} while (rv == 0);
void *p;
while (0 == lfds711_queue_bmm_dequeue(&g_buff, &p, NULL)) { m_thread_yield(); }
j = (uintptr_t) p;
s += j;
}
int rv;
do {
rv = lfds711_queue_bmm_enqueue(&g_final, (void*)(uintptr_t)s, NULL);
} while (rv == 0);
while (0 == lfds711_queue_bmm_enqueue(&g_final, (void*)(uintptr_t)s, NULL)) { m_thread_yield(); }
}
static void prod(void *arg)
@@ -63,15 +51,12 @@ static void prod(void *arg)
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++) {
int rv;
do {
rv = lfds711_queue_bmm_enqueue(&g_buff, (void*)(uintptr_t)r, NULL);
} while (rv == 0);
while (0 == lfds711_queue_bmm_enqueue(&g_buff, (void*)(uintptr_t)r, NULL)) { m_thread_yield(); }
r = r * 31421U + 6927U;
}
}
static void test_buffer(size_t n)
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int prod_count = cpu_count/2;
@@ -120,11 +105,12 @@ static void test_buffer(size_t n)
/********************************************************************************************/
const config_func_t table[] = {
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
};
int main(int argc, const char *argv[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 60)
test_function("Buffer time", 1000000, test_buffer);
test("LIBLFDS", numberof(table), table, argc, argv);
exit(0);
}
+10 -8
View File
@@ -14,8 +14,8 @@
static void test_array(size_t n)
{
sv_t *a1 = sv_alloc ( sizeof (unsigned int), 16, NULL);
sv_t *a2 = sv_alloc ( sizeof (unsigned int), 16, NULL);
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();
@@ -48,7 +48,7 @@ static int cmp_float (const void *a, const void *b)
static void test_sort(size_t n)
{
sv_t *a1 = sv_alloc(sizeof(float), 16, cmp_float);
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 );
@@ -60,13 +60,15 @@ static void test_sort(size_t n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
test("LIBSRT", numberof(table), table, argc, argv);
exit(0);
}
+654 -84
View File
@@ -7,12 +7,19 @@
#include "m-array.h"
#include "m-list.h"
#include "m-rbtree.h"
#include "m-bptree.h"
#include "m-deque.h"
#include "m-dict.h"
#include "m-algo.h"
#include "m-mempool.h"
#include "m-string.h"
#include "m-buffer.h"
#include "m-mutex.h"
#include "m-deque.h"
#include "m-concurrent.h"
#include "m-tuple.h"
#include "m-serial-bin.h"
#include "m-serial-json.h"
#include "common.h"
@@ -37,6 +44,30 @@ static void test_array(size_t n)
/********************************************************************************************/
DEQUE_DEF(deque_uint, unsigned int)
static void test_deque(size_t n)
{
M_LET(a1, a2, DEQUE_OPLIST(deque_uint)) {
for(size_t i = 0; i < n; i++) {
deque_uint_push_back(a1, rand_get() );
deque_uint_push_back(a2, rand_get() );
}
unsigned int s = 0;
deque_uint_it_t it1, it2;
deque_uint_it(it1, a1);
deque_uint_it(it2, a2);
while (!deque_uint_end_p(it1)) {
s += *deque_uint_cref(it1 ) * *deque_uint_cref(it2 );
deque_uint_next(it1);
deque_uint_next(it2);
}
g_result = s;
}
}
/********************************************************************************************/
// Two benched mode: with or without mempool
#ifdef USE_MEMPOOL
LIST_DEF(list_uint, unsigned int, (MEMPOOL( list_mpool), MEMPOOL_LINKAGE(static)))
@@ -68,6 +99,37 @@ static void test_list (size_t n)
/********************************************************************************************/
// Two benched mode: with or without mempool
#ifdef USE_MEMPOOL
LIST_DUAL_PUSH_DEF(dlist_uint, unsigned int, (MEMPOOL( dlist_mpool), MEMPOOL_LINKAGE(static)))
#else
LIST_DUAL_PUSH_DEF(dlist_uint, unsigned int)
#endif
static void test_dlist (size_t n)
{
#ifdef USE_MEMPOOL
dlist_uint_mempool_init(dlist_mpool);
#endif
M_LET(a1, a2, LIST_OPLIST(dlist_uint)) {
for(size_t i = 0; i < n; i++) {
dlist_uint_push_back(a1, rand_get() );
dlist_uint_push_back(a2, rand_get() );
}
unsigned int s = 0;
dlist_uint_it_t it1, it2;
for(dlist_uint_it(it1, a1), dlist_uint_it(it2,a2); !dlist_uint_end_p(it1); dlist_uint_next(it1), dlist_uint_next(it2)) {
s += *dlist_uint_cref(it1) * *dlist_uint_cref(it2);
}
g_result = s;
}
#ifdef USE_MEMPOOL
dlist_uint_mempool_clear(dlist_mpool);
#endif
}
/********************************************************************************************/
#ifdef USE_MEMPOOL
RBTREE_DEF(rbtree_ulong, unsigned long, (MEMPOOL( rbtree_mpool), MEMPOOL_LINKAGE(static)))
#else
@@ -99,6 +161,27 @@ static void test_rbtree(size_t n)
/********************************************************************************************/
BPTREE_DEF(bptree_ulong, 21, unsigned long, M_DEFAULT_OPLIST)
static void test_bptree(size_t n)
{
M_LET(tree, BPTREE_OPLIST(bptree_ulong)) {
for (size_t i = 0; i < n; i++) {
bptree_ulong_push(tree, rand_get());
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long *p = bptree_ulong_get(tree, rand_get());
if (p)
s += *p;
}
g_result = s;
}
}
/********************************************************************************************/
#ifdef USE_MEMPOOL
DICT_DEF2(dict_ulong, unsigned long, M_OPEXTEND(M_DEFAULT_OPLIST, MEMPOOL(dict_mpool), MEMPOOL_LINKAGE(static)), unsigned long, M_DEFAULT_OPLIST)
#else
@@ -106,15 +189,16 @@ DICT_DEF2(dict_ulong, unsigned long, M_DEFAULT_OPLIST, unsigned long, M_DEFAULT_
#endif
static void
test_dict(unsigned long n)
test_dict(size_t n)
{
#ifdef USE_MEMPOOL
dict_ulong_list_pair_mempool_init(dict_mpool);
#endif
M_LET(dict, DICT_OPLIST(dict_ulong)) {
for (size_t i = 0; i < n; i++) {
unsigned long value = rand_get();
unsigned long key = rand_get();
dict_ulong_set_at(dict, key, rand_get() );
dict_ulong_set_at(dict, key, value);
}
rand_init();
unsigned int s = 0;
@@ -147,7 +231,7 @@ DICT_OA_DEF2(dict_oa_ulong,
unsigned long, M_DEFAULT_OPLIST)
static void
test_dict_oa(unsigned long n)
test_dict_oa(size_t n)
{
M_LET(dict, DICT_OPLIST(dict_oa_ulong)) {
for (size_t i = 0; i < n; i++) {
@@ -164,26 +248,46 @@ test_dict_oa(unsigned long n)
}
}
static void
test_dict_oa_linear(size_t n)
{
M_LET(dict, DICT_OPLIST(dict_oa_ulong)) {
for (size_t i = 0; i < n; i++) {
dict_oa_ulong_set_at(dict, i, rand_get() );
}
rand_init();
unsigned int s = 0;
for (size_t i = 0; i < n; i++) {
unsigned long *p = dict_oa_ulong_get(dict, i);
if (p)
s += *p;
}
g_result = s;
}
}
/********************************************************************************************/
typedef char char_array_t[256];
#ifndef CHAR_ARRAY_SIZE
#define CHAR_ARRAY_SIZE 256
#endif
typedef char char_array_t[CHAR_ARRAY_SIZE];
static void char_init (char_array_t a) { a[0] = 0; }
static void char_set (char_array_t a, const char_array_t b) { strcpy(a, b); }
static bool char_equal_p (const char_array_t a, const char_array_t b) { return strcmp(a,b)==0; }
static size_t char_hash(const char_array_t a) { return m_core_hash (a, strlen(a)); }
// NOTE: Can't use the name OPLIST as a macro!
#define CHAR_OPLIST (INIT(char_init), INIT_SET(char_set), SET(char_set), CLEAR(char_init), HASH(char_hash), EQUAL(char_equal_p))
static bool char_oor_equal_p(const char_array_t a, unsigned char n) { return a[0] == 1+n; }
static void char_oor_set(char_array_t a, unsigned char n) { a[0] = 1+n; }
#define M_OPL_char_array_t() (INIT(char_init), INIT_SET(char_set), SET(char_set), CLEAR(char_init), HASH(char_hash), EQUAL(char_equal_p), OOR_EQUAL(char_oor_equal_p), OOR_SET(char_oor_set))
#ifdef USE_MEMPOOL
DICT_STOREHASH_DEF2(dict_char, char_array_t, M_OPEXTEND(CHAR_OPLIST,MEMPOOL(dict_mpool2), MEMPOOL_LINKAGE(static)), char_array_t, CHAR_OPLIST)
DICT_STOREHASH_DEF2(dict_char, char_array_t, M_OPEXTEND(M_OPL_char_array_t(),MEMPOOL(dict_mpool2), MEMPOOL_LINKAGE(static)), char_array_t, M_OPL_char_array_t())
#else
DICT_STOREHASH_DEF2(dict_char, char_array_t, CHAR_OPLIST, char_array_t, CHAR_OPLIST)
DICT_STOREHASH_DEF2(dict_char, char_array_t, M_OPL_char_array_t(), char_array_t, M_OPL_char_array_t())
#endif
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
#ifdef USE_MEMPOOL
dict_char_list_pair_mempool_init(dict_mpool2);
@@ -211,6 +315,31 @@ test_dict_big(unsigned long n)
#endif
}
DICT_OA_DEF2(dict_oa_char, char_array_t, char_array_t)
static void
test_dict_oa_big(size_t n)
{
M_LET(dict, DICT_OPLIST(dict_oa_char)) {
for (size_t i = 0; i < n; i++) {
char_array_t s1, s2;
sprintf(s1, "%u", rand_get());
sprintf(s2, "%u", rand_get());
dict_oa_char_set_at(dict, s1, s2);
}
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 = dict_oa_char_get(dict, s1);
if (p)
s ++;
}
g_result = s;
}
}
/********************************************************************************************/
#ifdef USE_MEMPOOL
@@ -220,7 +349,7 @@ DICT_DEF2(dict_str, string_t, STRING_OPLIST, string_t, STRING_OPLIST)
#endif
static void
test_dict_str(unsigned long n)
test_dict_str(size_t n)
{
#ifdef USE_MEMPOOL
dict_str_list_pair_mempool_init(dict_mpool3);
@@ -276,73 +405,76 @@ static void test_stable_sort(size_t n)
/********************************************************************************************/
#define SIZE_LIMIT (UINT_MAX/2)
BUFFER_DEF(buffer_uint, unsigned int, 0, BUFFER_QUEUE|BUFFER_BLOCKING)
buffer_uint_t g_buff;
buffer_uint_t g_buff_lock;
BUFFER_DEF(buffer_ull, unsigned long long, 0, BUFFER_QUEUE|BUFFER_BLOCKING)
buffer_ull_t g_final;
buffer_ull_t g_final_lock;
static void final(void *arg)
static void final_lock(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(int i = 0; i < n;i++) {
buffer_ull_pop(&j, g_final);
buffer_ull_pop(&j, g_final_lock);
s += j;
}
g_result = s;
}
static void conso(void *arg)
static void conso_lock(void *arg)
{
unsigned int j;
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long s = 0;
for(int i = 0; i < n;i++) {
buffer_uint_pop(&j, g_buff);
buffer_uint_pop(&j, g_buff_lock);
s += j;
}
buffer_ull_push(g_final, s);
buffer_ull_push(g_final_lock, s);
}
static void prod(void *arg)
static void prod_lock(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
size_t r = n;
for(unsigned int i = 0; i < n;i++) {
buffer_uint_push(g_buff, r );
buffer_uint_push(g_buff_lock, r );
r = r * 31421U + 6927U;
}
}
static void test_buffer(size_t n)
{
const int cpu_count = get_cpu_count();
const int cpu_count = n > SIZE_LIMIT ? 2 : 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;
}
n = n > SIZE_LIMIT ? n - SIZE_LIMIT : n;
// Init
buffer_uint_init(g_buff, 64*cpu_count);
buffer_ull_init (g_final, 64*cpu_count);
buffer_uint_init(g_buff_lock, 64*cpu_count);
buffer_ull_init (g_final_lock, 64*cpu_count);
// 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);
m_thread_create (idx_p[i], prod_lock, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso, &n);
m_thread_create (idx_c[i], conso_lock, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final, &n2);
m_thread_create(idx_final, final_lock, &n2);
// Wait for jobs to be done.
for(int i = 0; i < prod_count; i++) {
@@ -354,79 +486,80 @@ static void test_buffer(size_t n)
m_thread_join(idx_final);
// Clear & quit
buffer_ull_clear(g_final);
buffer_uint_clear(g_buff);
buffer_ull_clear(g_final_lock);
buffer_uint_clear(g_buff_lock);
}
/********************************************************************************************/
QUEUE_MPMC_DEF(queue_uint, unsigned int, BUFFER_QUEUE)
queue_uint_t g_buff2;
queue_uint_t g_buff_mpmc;
QUEUE_MPMC_DEF(queue_ull, unsigned long long, BUFFER_QUEUE)
queue_ull_t g_final2;
queue_ull_t g_final_mpmc;
static void final2(void *arg)
static void final_mpmc(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(int i = 0; i < n;i++) {
while (!queue_ull_pop(&j, g_final2));
while (!queue_ull_pop(&j, g_final_mpmc)) m_thread_yield();
s += j;
}
g_result = s;
}
static void conso2(void *arg)
static void conso_mpmc(void *arg)
{
unsigned int j;
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long s = 0;
for(int i = 0; i < n;i++) {
while (!queue_uint_pop(&j, g_buff2));
while (!queue_uint_pop(&j, g_buff_mpmc)) m_thread_yield();
s += j;
}
while (!queue_ull_push(g_final2, s));
while (!queue_ull_push(g_final_mpmc, s));
}
static void prod2(void *arg)
static void prod_mpmc(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
size_t r = n;
for(unsigned int i = 0; i < n;i++) {
while (!queue_uint_push(g_buff2, r ));
while (!queue_uint_push(g_buff_mpmc, r )) m_thread_yield();
r = r * 31421U + 6927U;
}
}
static void test_queue(size_t n)
{
const int cpu_count = get_cpu_count();
const int cpu_count = n > SIZE_LIMIT ? 2 : 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 Queue performance.\n");
return;
}
n = n > SIZE_LIMIT ? n - SIZE_LIMIT : n;
// Init
queue_uint_init(g_buff2, 64*cpu_count);
queue_ull_init (g_final2, 64*cpu_count);
queue_uint_init(g_buff_mpmc, 64*cpu_count);
queue_ull_init (g_final_mpmc, 64*cpu_count);
// 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], prod2, &n);
m_thread_create (idx_p[i], prod_mpmc, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso2, &n);
m_thread_create (idx_c[i], conso_mpmc, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final2, &n2);
m_thread_create(idx_final, final_mpmc, &n2);
// Wait for jobs to be done.
for(int i = 0; i < prod_count; i++) {
@@ -438,8 +571,265 @@ static void test_queue(size_t n)
m_thread_join(idx_final);
// Clear & quit
queue_ull_clear(g_final2);
queue_uint_clear(g_buff2);
queue_ull_clear(g_final_mpmc);
queue_uint_clear(g_buff_mpmc);
}
/********************************************************************************************/
QUEUE_SPSC_DEF(queue_single_uint, unsigned int, BUFFER_QUEUE)
queue_single_uint_t g_buff_spsc;
QUEUE_SPSC_DEF(queue_single_ull, unsigned long long, BUFFER_QUEUE)
queue_single_ull_t g_final_spsc;
static void final_spsc(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(int i = 0; i < n;i++) {
while (!queue_single_ull_pop(&j, g_final_spsc)) m_thread_yield();
s += j;
}
g_result = s;
}
static void conso_spsc(void *arg)
{
unsigned int j;
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long s = 0;
for(int i = 0; i < n;i++) {
while (!queue_single_uint_pop(&j, g_buff_spsc)) m_thread_yield();
s += j;
}
while (!queue_single_ull_push(g_final_spsc, s));
}
static void prod_spsc(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
size_t r = n;
for(unsigned int i = 0; i < n;i++) {
while (!queue_single_uint_push(g_buff_spsc, r )) m_thread_yield();
r = r * 31421U + 6927U;
}
}
static void test_queue_single(size_t n)
{
const int cpu_count = 2;
const int prod_count = cpu_count/2;
const int conso_count = cpu_count - prod_count;
// Init
queue_single_uint_init(g_buff_spsc, 64*cpu_count);
queue_single_ull_init (g_final_spsc, 64*cpu_count);
// 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_spsc, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso_spsc, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final_spsc, &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
queue_single_ull_clear(g_final_spsc);
queue_single_uint_clear(g_buff_spsc);
}
/********************************************************************************************/
#define BULK_SIZE 20
static void final_spsc_bulk(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(int i = 0; i < n;i++) {
while (!queue_single_ull_pop(&j, g_final_spsc)) m_thread_yield();
s += j;
}
g_result = s;
}
static void conso_spsc_bulk(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long s = 0;
unsigned tab[BULK_SIZE];
for(int i = 0; i < n;i+= BULK_SIZE) {
unsigned k = queue_single_uint_pop_bulk(BULK_SIZE, tab, g_buff_spsc);
while (k != BULK_SIZE) {
m_thread_yield();
k += queue_single_uint_pop_bulk(BULK_SIZE-k, tab+k, g_buff_spsc);
}
for(k = 0; k < BULK_SIZE;k++)
s += tab[k];
}
while (!queue_single_ull_push(g_final_spsc, s));
}
static void prod_spsc_bulk(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
if ((n % BULK_SIZE) != 0) abort();
size_t r = n;
unsigned tab[BULK_SIZE];
for(unsigned int i = 0; i < n;i+= BULK_SIZE) {
for(unsigned k = 0; k < BULK_SIZE; k++) {
tab[k] = r;
r = r * 31421U + 6927U;
}
unsigned k = queue_single_uint_push_bulk(g_buff_spsc, BULK_SIZE, tab);
while (k != BULK_SIZE) {
m_thread_yield();
k += queue_single_uint_push_bulk(g_buff_spsc, BULK_SIZE-k, tab+k);
}
}
}
static void test_queue_single_bulk(size_t n)
{
const int cpu_count = 2;
const int prod_count = cpu_count/2;
const int conso_count = cpu_count - prod_count;
// Init
queue_single_uint_init(g_buff_spsc, 64*cpu_count);
queue_single_ull_init (g_final_spsc, 64*cpu_count);
// 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_spsc_bulk, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso_spsc_bulk, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final_spsc_bulk, &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
queue_single_ull_clear(g_final_spsc);
queue_single_uint_clear(g_buff_spsc);
}
/********************************************************************************************/
CONCURRENT_DEF(cdeque_uint, deque_uint_t, M_OPEXTEND(DEQUE_OPLIST(deque_uint, M_DEFAULT_OPLIST), PUSH(deque_uint_push_front)))
DEQUE_DEF(deque_ull, unsigned long long)
CONCURRENT_DEF(cdeque_ull, deque_ull_t, M_OPEXTEND(DEQUE_OPLIST(deque_ull, M_DEFAULT_OPLIST), PUSH(deque_ull_push_front)))
cdeque_uint_t g_buff_conc;
cdeque_ull_t g_final_conc;
static void final_conc(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long j, s = 0;
for(int i = 0; i < n;i++) {
cdeque_ull_pop_blocking(&j, g_final_conc, true);
s += j;
}
g_result = s;
}
static void conso_conc(void *arg)
{
unsigned int j;
size_t *p_n = arg;
size_t n = *p_n;
unsigned long long s = 0;
for(int i = 0; i < n;i++) {
cdeque_uint_pop_blocking(&j, g_buff_conc, true);
s += j;
}
cdeque_ull_push(g_final_conc, s);
}
static void prod_conc(void *arg)
{
size_t *p_n = arg;
size_t n = *p_n;
size_t r = n;
for(unsigned int i = 0; i < n;i++) {
cdeque_uint_push(g_buff_conc, r );
r = r * 31421U + 6927U;
}
}
static void test_queue_concurrent(size_t n)
{
const int cpu_count = n > SIZE_LIMIT ? 2 : 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 CONCURRENT performance.\n");
return;
}
n = n > SIZE_LIMIT ? n - SIZE_LIMIT : n;
// Init
cdeque_uint_init(g_buff_conc);
cdeque_ull_init (g_final_conc);
// 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_conc, &n);
}
for(int i = 0; i < conso_count; i++) {
m_thread_create (idx_c[i], conso_conc, &n);
}
size_t n2 = conso_count;
m_thread_create(idx_final, final_conc, &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
cdeque_ull_clear(g_final_conc);
cdeque_uint_clear(g_buff_conc);
}
/********************************************************************************************/
@@ -476,45 +866,225 @@ static void test_core_hash(size_t n)
/********************************************************************************************/
ARRAY_DEF(vector_string, string_t)
vector_string_t vstring;
vector_string_t vstring2;
static void
bench_vector_string_init(size_t n)
{
vector_string_init(vstring);
for(size_t i = 0; i < n; i++)
{
M_LET( (s, "%zu", i, i, i, i), string_t) {
vector_string_push_back(vstring, s);
}
}
vector_string_init(vstring2);
}
static void
bench_vector_string_init_big(size_t n)
{
vector_string_init(vstring);
for(size_t i = 0; i < n; i++)
{
M_LET( (s, "%zu%zu%zu%zu%zu%zu", i, i, i, i, i, i), string_t) {
vector_string_push_back(vstring, s);
}
}
vector_string_init(vstring2);
}
static void
bench_vector_string_bin_run(size_t n)
{
if (vector_string_size(vstring) != n) {
printf("Size are different!\n");
abort();
}
FILE *f = fopen("tmp-serial.dat", "wb");
if (!f) abort();
M_LET( (serial, f), m_serial_bin_write_t) {
vector_string_out_serial(serial, vstring);
}
fclose(f);
f = fopen("tmp-serial.dat", "rb");
if (!f) abort();
M_LET( (serial, f), m_serial_bin_read_t) {
vector_string_in_serial(vstring2, serial);
}
fclose(f);
if (vector_string_size(vstring2) != n) {
printf("Size are different!\n");
abort();
}
}
static void
bench_vector_string_json_run(size_t n)
{
if (vector_string_size(vstring) != n) {
printf("Size are different!\n");
abort();
}
FILE *f = fopen("tmp-serial.json", "wt");
if (!f) abort();
M_LET( (serial, f), m_serial_json_write_t) {
vector_string_out_serial(serial, vstring);
}
fclose(f);
f = fopen("tmp-serial.json", "rt");
if (!f) abort();
M_LET( (serial, f), m_serial_json_read_t) {
vector_string_in_serial(vstring2, serial);
}
fclose(f);
if (vector_string_size(vstring2) != n) {
printf("Size are different!\n");
abort();
}
}
static void
bench_vector_string_clear(void)
{
if (!vector_string_equal_p(vstring, vstring2)) {
printf("Array are different!\n");
abort();
}
vector_string_clear(vstring);
vector_string_clear(vstring2);
}
/********************************************************************************************/
ARRAY_DEF(vector_ulong, unsigned long)
vector_ulong_t vulong;
vector_ulong_t vulong2;
static void
bench_vector_ulong_init(size_t n)
{
vector_ulong_init(vulong);
for(size_t i = 0; i < n; i++)
{
vector_ulong_push_back(vulong, i*i);
}
vector_ulong_init(vulong2);
}
static void
bench_vector_ulong_bin_run(size_t n)
{
if (vector_ulong_size(vulong) != n) {
printf("Size are different!\n");
abort();
}
FILE *f = fopen("tmp-serial.dat", "wb");
if (!f) abort();
M_LET( (serial, f), m_serial_bin_write_t) {
vector_ulong_out_serial(serial, vulong);
}
fclose(f);
f = fopen("tmp-serial.dat", "rb");
if (!f) abort();
M_LET( (serial, f), m_serial_bin_read_t) {
vector_ulong_in_serial(vulong2, serial);
}
fclose(f);
if (vector_ulong_size(vulong2) != n) {
printf("Size are different!\n");
abort();
}
}
static void
bench_vector_ulong_json_run(size_t n)
{
if (vector_ulong_size(vulong) != n) {
printf("Size are different!\n");
abort();
}
FILE *f = fopen("tmp-serial.json", "wt");
if (!f) abort();
M_LET( (serial, f), m_serial_json_write_t) {
vector_ulong_out_serial(serial, vulong);
}
fclose(f);
f = fopen("tmp-serial.json", "rt");
if (!f) abort();
M_LET( (serial, f), m_serial_json_read_t) {
vector_ulong_in_serial(vulong2, serial);
}
fclose(f);
if (vector_ulong_size(vulong2) != n) {
printf("Size are different!\n");
abort();
}
}
static void
bench_vector_ulong_clear(void)
{
if (!vector_ulong_equal_p(vulong, vulong2)) {
printf("Array are different!\n");
abort();
}
vector_ulong_clear(vulong);
vector_ulong_clear(vulong2);
}
/********************************************************************************************/
const config_func_t table[] = {
{ 10, "List", 10000000, 0, test_list, 0},
{ 11, "DPList", 10000000, 0, test_dlist, 0},
{ 20, "Array", 100000000, 0, test_array, 0},
{ 21, "Deque", 100000000, 0, test_deque, 0},
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
{ 31, "B+tree", 1000000, 0, test_bptree, 0},
{ 40, "dict", 1000000, 0, test_dict, 0},
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
{ 42,"dict(OA)", 1000000, 0, test_dict_oa, 0},
{ 43,"DictStr", 1000000, 0, test_dict_str, 0},
{ 46, "dictLinear(OA)", 1000000, 0, test_dict_oa_linear, 0},
{ 47, "dictBig(OA)", 1000000, 0, test_dict_oa_big, 0},
{ 50, "Sort",10000000, 0, test_sort, 0},
{ 51, "Stable Sort",10000000, 0, test_stable_sort, 0},
{ 60,"Buffer", 1000000, 0, test_buffer, 0},
{ 61,"Queue MPMC", 1000000, 0, test_queue, 0},
{ 62,"Buffer(P=2)", SIZE_LIMIT+1000000, 0, test_buffer, 0},
{ 63,"Queue MPMC (P=2)", SIZE_LIMIT+1000000, 0, test_queue, 0},
{ 64,"Queue SPSC (P=2)", 1000000, 0, test_queue_single, 0},
{ 65,"Queue Concurrent", 1000000, 0, test_queue_concurrent, 0},
{ 66,"Queue SPSC(Bulk)", 1000000, 0, test_queue_single_bulk, 0},
{ 70,"M_HASH", 100000000, test_hash_prepare, test_hash, test_hash_final},
{ 71,"Core Hash", 100000000, test_hash_prepare, test_core_hash, test_hash_final},
{100, "serial-bin STR", 10000000, bench_vector_string_init, bench_vector_string_bin_run, bench_vector_string_clear},
{101, "serial-bin STR.big", 10000000, bench_vector_string_init_big, bench_vector_string_bin_run, bench_vector_string_clear},
{102, "serial-bin INT", 10000000, bench_vector_ulong_init, bench_vector_ulong_bin_run, bench_vector_ulong_clear},
{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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 30)
test_function("Rbtree time", 1000000, test_rbtree);
if (n == 40)
test_function("Dict time", 1000000, test_dict);
if (n == 42)
test_function("DictOA time", 1000000, test_dict_oa);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 43)
test_function("DictS time", 1000000, test_dict_str);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
if (n == 51)
test_function("Stable Sort time", 10000000, test_stable_sort);
if (n == 60)
test_function("Buffer time", 1000000, test_buffer);
if (n == 61)
test_function("Queue MPMC time", 1000000, test_queue);
if (n == 70) {
n = (argc > 2) ? atoi(argv[2]) : 100000000;
test_hash_prepare(n);
test_function("M_HASH time", n, test_hash);
test_hash_final();
}
if (n == 71) {
n = (argc > 2) ? atoi(argv[2]) : 100000000;
test_hash_prepare(n);
test_function("CORE_HASH time", n, test_core_hash);
test_hash_final();
}
test("M-LIB", numberof(table), table, argc, argv);
exit(0);
}
+7 -9
View File
@@ -26,7 +26,7 @@ static inline size_t fookeyfunct(const foo_t *r)
NEDTRIE_GENERATE(static, foo_tree_s, foo_s, link, fookeyfunct, NEDTRIE_NOBBLEZEROS(foo_tree_s))
static void
test_dict(unsigned long n)
test_dict(size_t n)
{
foo_tree_t footree;
NEDTRIE_INIT(&footree);
@@ -58,7 +58,7 @@ test_dict(unsigned long n)
}
static void
test_dict_noalloc(unsigned long n)
test_dict_noalloc(size_t n)
{
foo_tree_t footree;
NEDTRIE_INIT(&footree);
@@ -87,15 +87,13 @@ test_dict_noalloc(unsigned long n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 40)
test_function("Dict time", 1000000, test_dict);
if (n == 45)
test_function("Dict No Alloc time", 1000000, test_dict_noalloc);
test("NEDTRIES", numberof(table), table, argc, argv);
exit(0);
}
+9 -7
View File
@@ -98,14 +98,16 @@ static void test_rbtree(size_t n)
/* 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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 30)
test_function("Rbtree time", 1000000, test_rbtree);
test("QLIBC", numberof(table), table, argc, argv);
exit(0);
}
+14 -18
View File
@@ -72,7 +72,7 @@ static void test_rbtree(size_t n)
/********************************************************************************************/
static void
test_dict1(unsigned long n)
test_dict1(size_t n)
{
QMap<unsigned long, unsigned long> dict;
@@ -92,7 +92,7 @@ test_dict1(unsigned long n)
/********************************************************************************************/
static void
test_dict2(unsigned long n)
test_dict2(size_t n)
{
QHash<unsigned long, unsigned long> dict;
@@ -126,7 +126,7 @@ uint qHash(const char_array_s &k)
};
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
QHash<char_array_s, char_array_s> dict;
@@ -162,22 +162,18 @@ static void test_sort(size_t n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 30)
test_function("Rbtree time", 1000000, test_rbtree);
if (n == 40)
test_function("Dict(m)time", 1000000, test_dict1);
if (n == 42)
test_function("Dict(u)time", 1000000, test_dict2);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
test("QT", numberof(table), table, argc, argv);
exit(0);
}
+185
View File
@@ -0,0 +1,185 @@
#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
@@ -0,0 +1,159 @@
#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
@@ -0,0 +1,96 @@
#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);
}
+10 -10
View File
@@ -25,7 +25,7 @@ using namespace std;
/********************************************************************************************/
static void
test_dict2(unsigned long n)
test_dict2(size_t n)
{
sparse_hash_map<unsigned long, unsigned long> dict;
@@ -63,7 +63,7 @@ namespace std {
}
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
sparse_hash_map<char_array_s, char_array_s> dict;
@@ -87,7 +87,7 @@ test_dict_big(unsigned long n)
/********************************************************************************************/
static void
test_dict_str(unsigned long n)
test_dict_str(size_t n)
{
sparse_hash_map<string, string> dict;
@@ -109,14 +109,14 @@ test_dict_str(unsigned long n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 42)
test_function("Dict(u)time", 1000000, test_dict2);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 43)
test_function("DictS(u) time", 1000000, test_dict_str);
test("SPARSEPP", numberof(table), table, argc, argv);
exit(0);
}
+63 -32
View File
@@ -1,6 +1,7 @@
#define NDEBUG
#include <vector>
#include <deque>
#include <list>
#include <iterator>
#include <map>
@@ -53,6 +54,23 @@ static void test_array(size_t n)
/********************************************************************************************/
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;
@@ -73,7 +91,7 @@ static void test_rbtree(size_t n)
/********************************************************************************************/
static void
test_dict1(unsigned long n)
test_dict1(size_t n)
{
map<unsigned long, unsigned long> dict;
@@ -93,7 +111,7 @@ test_dict1(unsigned long n)
/********************************************************************************************/
static void
test_dict2(unsigned long n)
test_dict2(size_t n)
{
unordered_map<unsigned long, unsigned long> dict;
@@ -110,6 +128,24 @@ test_dict2(unsigned long n)
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 {
@@ -131,7 +167,7 @@ namespace std {
}
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
unordered_map<char_array_s, char_array_s> dict;
@@ -155,19 +191,19 @@ test_dict_big(unsigned long n)
/********************************************************************************************/
static void
test_dict_str(unsigned long n)
test_dict_str(size_t n)
{
unordered_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();
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 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s1 = to_string (rand_get());
unordered_map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
@@ -176,19 +212,19 @@ test_dict_str(unsigned long n)
}
static void
test_dict_str2(unsigned long n)
test_dict_str2(size_t n)
{
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();
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 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s1 = to_string(rand_get());
map<string, string>::iterator it = dict.find(s1);
if (it != dict.end())
s ++;
@@ -220,28 +256,23 @@ static void test_stable_sort(size_t n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 30)
test_function("Rbtree time", 1000000, test_rbtree);
if (n == 40)
test_function("Dict(m)time", 1000000, test_dict1);
if (n == 42)
test_function("Dict(u)time", 1000000, test_dict2);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 43)
test_function("DictS(u) time", 1000000, test_dict_str);
if (n == 44)
test_function("DictS(m) time", 1000000, test_dict_str2);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
if (n == 51)
test_function("Stable Sort time", 10000000, test_stable_sort);
test("STL", numberof(table), table, argc, argv);
exit(0);
}
+258
View File
@@ -0,0 +1,258 @@
/*
* 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;
}
+590 -168
View File
@@ -35,14 +35,27 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Update of integrating M*LIB done by Patrick Pelissier */
/* Update of integrating M*LIB, LIBSRT, SDS & GLIB
Copyright (c) 2018-2021 Patrick Pelissier
*/
/*
* Benchmark based on the features tested by benchmark seen here:
* http://www.utilitycode.com/str/performance.aspx
*
* The idea is to measure the performance empty constructors, char *
* constructors, assignment, concatenation and scanning.
*
*/
#include <stdio.h>
#include <time.h>
#include <limits.h>
#ifdef BENCH_CAN_USE_MSTARLIB
#define NDEBUG
#include "common.h"
#ifdef BENCH_CAN_USE_MSTARLIB
#include "m-string.h"
#endif
@@ -56,55 +69,66 @@
#include "sstring.h"
#endif
/*
* Benchmark based on the features tested by benchmark seen here:
* http://www.utilitycode.com/str/performance.aspx
*
* The idea is to measure the performance empty constructors, char *
* constructors, assignment, concatenation and scanning. But rather than
* comparing MFC's CString to Str Library, we are going to compare STL to
* CBString.
*
* The results are interesting. CBString basically beats std::string quite
* severely, except for the empty constructor.
*/
#ifdef BENCH_CAN_USE_SDS
extern "C" {
#include "sds.h"
};
#endif
#if defined (BENCH_CAN_USE_STL)
#include <string>
#endif
#if defined(BENCH_CAN_USE_GLIB)
#include "gmodule.h"
#endif
/* Time of a test */
#define TEST_SECONDS (5)
/*
* This macro puts a memory barrier and prevents the optimizer from
* optimizing too much the inline functions and literraly breaking
* the benchmark by doing nothing.
* Better than nothing, but far from perfect.
*/
#define BARRIER(addr) compiler_barrier((void*) addr)
bool print_csv = false;
int timeTest (double &res, int (*testfn) (int count), int count) {
clock_t t0, t1;
int p = 0;
double x, c = 0;
t0 = clock ();
do {
p += testfn (count);
t1 = clock ();
c += count;
if (t1 == t0) {
if (count < (INT_MAX / 2)) count += count;
continue;
}
if (t1 - t0 >= TEST_SECONDS*CLOCKS_PER_SEC) break;
x = (TEST_SECONDS*CLOCKS_PER_SEC - (t1 - t0)) * c / (t1 - t0);
if (x > INT_MAX) x = INT_MAX;
count = (int) x;
if (count < 1000) count = 1000;
} while (1);
res = c * CLOCKS_PER_SEC / (t1 - t0);
return p;
clock_t t0, t1;
int p = 0;
double x, c = 0;
t0 = clock ();
do {
p += testfn (count);
t1 = clock ();
c += count;
if (t1 == t0) {
if (count < (INT_MAX / 2)) count += count;
continue;
}
if (t1 - t0 >= TEST_SECONDS*CLOCKS_PER_SEC) break;
x = (TEST_SECONDS*CLOCKS_PER_SEC - (t1 - t0)) * c / (t1 - t0);
if (x > INT_MAX) x = INT_MAX;
count = (int) x;
if (count < 1000) count = 1000;
} while (1);
res = c * CLOCKS_PER_SEC / (t1 - t0);
return p;
}
#define SMALLTESTSTRING1 ("hello")
#define TESTSTRING1 ("<sometag name=\"John Doe\" position=\"Executive VP Marketing\"/>")
#if defined (BENCH_CAN_USE_STL)
@@ -112,6 +136,7 @@ int testSTL_emptyCtor (int count) {
int i, c = 0;
for (i=0; i < count; i++) {
std::string b;
BARRIER(&b);
c += b.length () ^ i;
}
return c;
@@ -121,6 +146,17 @@ int testSTL_nonemptyCtor (int count) {
int i, c = 0;
for (i=0; i < count; i++) {
std::string b (TESTSTRING1);
BARRIER(&b);
c += b.length () ^ i;
}
return c;
}
int testSTL_smallnonemptyCtor (int count) {
int i, c = 0;
for (i=0; i < count; i++) {
std::string b (SMALLTESTSTRING1);
BARRIER(&b);
c += b.length () ^ i;
}
return c;
@@ -132,6 +168,7 @@ int testSTL_cstrAssignment (int count) {
for (i=0; i < count; i++) {
b = TESTSTRING1;
BARRIER(&b);
c += b.length () ^ i;
}
return c;
@@ -145,6 +182,7 @@ int testSTL_extraction (int count) {
c += b[(i & 7)];
c += b[(i & 7) ^ 8];
c += b.c_str()[(i & 7) ^ 4] ^ i;
BARRIER(&b);
}
return c;
}
@@ -157,6 +195,7 @@ int i, c = 0;
c += b.find ('.');
c += b.find ("123");
c += b.find_first_of ("sm") ^i;
BARRIER(&b);
}
return c;
}
@@ -171,6 +210,7 @@ int testSTL_concat (int count) {
for (i=0; i < 250; i++) {
accum += a;
accum += "!!";
BARRIER(&accum);
c += accum.length() ^i;
}
}
@@ -185,6 +225,7 @@ int testSTL_replace (int count) {
a.replace (11, 4, "XXXXXX");
a.replace (23, 2, "XXXXXX");
a.replace ( 4, 8, "XX");
BARRIER(&a);
c += a.length () ^ j;
}
return c;
@@ -197,6 +238,7 @@ int testCBS_emptyCtor (int count) {
int i, c = 0;
for (i=0; i < count; i++) {
CBString b;
BARRIER(&b);
c += b.length ()^i;
}
return c;
@@ -206,6 +248,17 @@ int testCBS_nonemptyCtor (int count) {
int i, c = 0;
for (i=0; i < count; i++) {
CBString b (TESTSTRING1);
BARRIER(&b);
c += b.length () ^i;
}
return c;
}
int testCBS_smallnonemptyCtor (int count) {
int i, c = 0;
for (i=0; i < count; i++) {
CBString b (SMALLTESTSTRING1);
BARRIER(&b);
c += b.length () ^i;
}
return c;
@@ -217,6 +270,7 @@ int testCBS_cstrAssignment (int count) {
for (i=0; i < count; i++) {
b = TESTSTRING1;
BARRIER(&b);
c += b.length () ^i;
}
return c;
@@ -230,6 +284,7 @@ int testCBS_extraction (int count) {
c += b[(i & 7)];
c += b[(i & 7) ^ 8];
c += ((const char *)b)[(i & 7) ^ 4] ^i;
BARRIER(&b);
}
return c;
}
@@ -242,6 +297,7 @@ int testCBS_scan (int count) {
c += b.find ('.');
c += b.find ("123");
c += b.findchr ("sm") ^i;
BARRIER(&b);
}
return c;
}
@@ -256,6 +312,7 @@ int testCBS_concat (int count) {
for (i=0; i < 250; i++) {
accum += a;
accum += "!!";
BARRIER(&accum);
c+= accum.length() ^i;
}
}
@@ -270,6 +327,7 @@ int testCBS_replace (int count) {
a.replace (11, 4, "XXXXXX");
a.replace (23, 2, "XXXXXX");
a.replace ( 4, 8, "XX");
BARRIER(&a);
c += a.length () ^j;
}
return c;
@@ -280,7 +338,8 @@ int testCBS_replace (int count) {
int testSRT_emptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
ss_t *b = ss_alloc(0);
srt_string *b = ss_alloc(0);
BARRIER(b);
c += ss_size(b) ^i;
ss_free(&b);
}
@@ -290,7 +349,19 @@ int testSRT_emptyCtor (int count) {
int testSRT_nonemptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
ss_t *b = ss_dup_c(TESTSTRING1);
srt_string *b = ss_dup_c(TESTSTRING1);
BARRIER(b);
c += ss_size(b) ^i;
ss_free(&b);
}
return c;
}
int testSRT_smallnonemptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
srt_string *b = ss_dup_c(SMALLTESTSTRING1);
BARRIER(b);
c += ss_size(b) ^i;
ss_free(&b);
}
@@ -299,9 +370,10 @@ int testSRT_nonemptyCtor (int count) {
int testSRT_cstrAssignment (int count) {
int i, c = 0;
ss_t *b = ss_alloc(0);
srt_string *b = ss_alloc(0);
for (c=i=0; i < count; i++) {
ss_cpy_cn(&b, TESTSTRING1, strlen(TESTSTRING1));
BARRIER(b);
c += ss_size(b) ^i;
}
ss_free(&b);
@@ -310,11 +382,12 @@ int testSRT_cstrAssignment (int count) {
int testSRT_extraction (int count) {
int i, c = 0;
ss_t *b = ss_dup_c(TESTSTRING1);
srt_string *b = ss_dup_c(TESTSTRING1);
for (c=i=0; i < count; i++) {
c += ss_at(b,(i & 7));
c += ss_at(b,(i & 7) ^ 8);
c += ss_at(b,(i & 7) ^ 4) ^i;
BARRIER(b);
}
ss_free(&b);
return c;
@@ -322,12 +395,13 @@ int testSRT_extraction (int count) {
int testSRT_scan (int count) {
int i, c = 0;
ss_t *b = ss_dup_c("Dot. 123. Some more data.");
srt_string *b = ss_dup_c("Dot. 123. Some more data.");
for (c=i=0; i < count; i++) {
c += ss_findc (b, 0, '.');
c += ss_find_cn (b, 0, "123", strlen("123"));
//c += ss_pbrk (b, 0, "sm") ^i;
c += ss_findb (b, 0) ^i;
BARRIER(b);
}
ss_free(&b);
return c;
@@ -336,14 +410,15 @@ int testSRT_scan (int count) {
int testSRT_concat (int count) {
int i, j, c = 0;
ss_t *a = ss_dup_c(TESTSTRING1);
ss_t *accum = ss_alloc(0);
srt_string *a = ss_dup_c(TESTSTRING1);
srt_string *accum = ss_alloc(0);
for (j=0; j < count; j++) {
ss_cpy_c(&accum, "");
for (i=0; i < 250; i++) {
ss_cat(&accum, a, NULL);
ss_cat_c(&accum, "!!", NULL);
BARRIER(accum);
c += ss_size(accum) ^i;
}
}
@@ -360,6 +435,7 @@ int testMLIB_emptyCtor (int count) {
for (c=i=0; i < count; i++) {
string_t b;
string_init(b);
BARRIER(&b);
c += string_size(b) ^i;
string_clear(b);
}
@@ -371,6 +447,19 @@ int testMLIB_nonemptyCtor (int count) {
for (c=i=0; i < count; i++) {
string_t b;
string_init_set_str(b, TESTSTRING1);
BARRIER(&b);
c += string_size(b) ^i;
string_clear(b);
}
return c;
}
int testMLIB_smallnonemptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
string_t b;
string_init_set_str(b, SMALLTESTSTRING1);
BARRIER(&b);
c += string_size(b) ^i;
string_clear(b);
}
@@ -383,6 +472,7 @@ int testMLIB_cstrAssignment (int count) {
string_init(b);
for (c=i=0; i < count; i++) {
string_set_str(b, TESTSTRING1);
BARRIER(&b);
c += string_size(b) ^i;
}
string_clear(b);
@@ -399,6 +489,7 @@ int testMLIB_extraction (int count) {
c += string_get_char(b, (i & 7));
c += string_get_char(b, (i & 7) ^ 8);
c += string_get_char(b, (i & 7) ^ 4) ^i;
BARRIER(&b);
}
string_clear(b);
return c;
@@ -413,12 +504,12 @@ int testMLIB_scan (int count) {
c += string_search_char (b, '.');
c += string_search_str (b, "123");
c += string_search_pbrk (b, "sm") ^i;
BARRIER(&b);
}
string_clear(b);
return c;
}
int testMLIB_concat (int count) {
int i, j, c = 0;
string_t a, accum;
@@ -430,6 +521,7 @@ int testMLIB_concat (int count) {
for (i=0; i < 250; i++) {
string_cat(accum, a);
string_cat_str(accum, "!!");
BARRIER(&accum);
c += string_size(accum) ^i;
}
}
@@ -447,6 +539,7 @@ int testMLIB_replace (int count) {
string_replace_at(a, 11, 4, "XXXXXX");
string_replace_at(a, 23, 2, "XXXXXX");
string_replace_at(a, 4, 8, "XX");
BARRIER(&a);
c += string_size(a) ^j;
}
@@ -455,141 +548,470 @@ int testMLIB_replace (int count) {
}
#endif
#define NTESTS 7
struct flags {
int runtest[NTESTS];
};
#ifdef BENCH_CAN_USE_SDS
int testSDS_emptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
sds b;
b = sdsempty();
BARRIER(b);
c += sdslen(b) ^ i;
sdsfree(b);
}
return c;
}
int benchTest (const struct flags * runflags) {
int c = 0;
double cps;
int testSDS_nonemptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
sds b;
b = sdsnew(TESTSTRING1);
BARRIER(b);
c += sdslen(b) ^i;
sdsfree(b);
}
return c;
}
int testSDS_smallnonemptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
sds b;
b = sdsnew(SMALLTESTSTRING1);
BARRIER(b);
c += sdslen(b) ^i;
sdsfree(b);
}
return c;
}
int testSDS_cstrAssignment (int count) {
int i, c = 0;
sds b;
b = sdsempty();
for (c=i=0; i < count; i++) {
b = sdscpy(b, TESTSTRING1);
BARRIER(b);
c += sdslen(b) ^i;
}
sdsfree(b);
return c;
}
int testSDS_extraction (int count) {
int i, c = 0;
sds b;
b = sdsnew(TESTSTRING1);
for (c=i=0; i < count; i++) {
c += b[(i & 7)];
c += b[(i & 7) ^ 8];
c += b[(i & 7) ^ 4] ^i;
BARRIER(b);
}
sdsfree(b);
return c;
}
int testSDS_scan (int count) {
int i, c = 0;
sds b;
b = sdsnew("Dot. 123. Some more data.");
for (c=i=0; i < count; i++) {
c += (intptr_t) strchr(b, '.');
c += (intptr_t) strstr (b, "123");
c += (intptr_t) strpbrk (b, "sm") ^i;
BARRIER(b);
}
sdsfree(b);
return c;
}
int testSDS_concat (int count) {
int i, j, c = 0;
sds a, accum;
a = sdsnew(TESTSTRING1);
accum = sdsempty();
for (j=0; j < count; j++) {
accum = sdscpy(accum, "");
for (i=0; i < 250; i++) {
accum = sdscat(accum, a);
accum = sdscat(accum, "!!");
BARRIER(accum);
c += sdslen(accum) ^i;
}
}
sdsfree(a);
sdsfree(accum);
return c;
}
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;
}
int testSDS_replace (int count) {
int j, c = 0;
sds a;
a = sdsnew(TESTSTRING1);
for (j=0; j < count; j++) {
a = SDS_replace_at(a, 11, 4, "XXXXXX");
a = SDS_replace_at(a, 23, 2, "XXXXXX");
a = SDS_replace_at(a, 4, 8, "XX");
BARRIER(&a);
c += sdslen(a) ^j;
}
sdsfree(a);
return c;
}
#if defined (BENCH_CAN_USE_STL)
if (runflags->runtest[0]) {
c += timeTest (cps, testSTL_emptyCtor, 100000);
printf ("std::string empty constructor: %20.1f per second\n", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testSTL_nonemptyCtor, 100000);
printf ("std::string non-empty constructor: %20.1f per second\n", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testSTL_cstrAssignment, 100000);
printf ("std::string char * assignment: %20.1f per second\n", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testSTL_extraction, 100000);
printf ("std::string char extraction: %20.1f per second\n", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testSTL_scan, 100000);
printf ("std::string scan: %20.1f per second\n", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testSTL_concat, 10);
printf ("std::string concatenation: %20.1f per second\n", cps * 250);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testSTL_replace, 10000);
printf ("std::string replace: %20.1f per second\n", cps);
}
#endif
#ifdef BENCH_CAN_USE_GLIB
int testGLIB_emptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
GString *b = g_string_new("");
BARRIER(b);
c += b->len;
g_string_free(b, TRUE);
}
return c;
}
int testGLIB_nonemptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
GString *b = g_string_new(TESTSTRING1);
BARRIER(b);
c += b->len;
g_string_free(b, TRUE);
}
return c;
}
int testGLIB_smallnonemptyCtor (int count) {
int i, c = 0;
for (c=i=0; i < count; i++) {
GString *b = g_string_new(SMALLTESTSTRING1);
BARRIER(b);
c += b->len;
g_string_free(b, TRUE);
}
return c;
}
int testGLIB_cstrAssignment (int count) {
int i, c = 0;
GString *b = g_string_new("");
for (c=i=0; i < count; i++) {
b = g_string_assign(b, TESTSTRING1);
BARRIER(b);
c += b->len ^i;
}
g_string_free(b, TRUE);
return c;
}
int testGLIB_extraction (int count) {
int i, c = 0;
GString *b = g_string_new(TESTSTRING1);
for (c=i=0; i < count; i++) {
c += b->str[(i & 7)];
c += b->str[(i & 7) ^ 8];
c += b->str[(i & 7) ^ 4] ^i;
BARRIER(b);
}
g_string_free(b, TRUE);
return c;
}
int testGLIB_scan (int count) {
int i, c = 0;
GString *b = g_string_new("Dot. 123. Some more data.");
for (c=i=0; i < count; i++) {
c += (strchr(b->str, '.')-b->str);
c += (strstr (b->str, "123")-b->str);
c += (strpbrk (b->str, "sm")-b->str) ^i;
BARRIER(b);
}
g_string_free(b, TRUE);
return c;
}
int testGLIB_concat (int count) {
int i, j, c = 0;
GString *a = g_string_new(TESTSTRING1);
GString *accum = g_string_new("");
for (j=0; j < count; j++) {
accum = g_string_assign(accum, "");
for (i=0; i < 250; i++) {
accum = g_string_append(accum, a->str);
accum = g_string_append(accum, "!!");
BARRIER(accum);
c += accum->len ^i;
}
}
g_string_free(a, TRUE);
g_string_free(accum, TRUE);
return c;
}
//int testGLIB_replace (int count): not available
#endif
#define NTESTS 8
struct flags {
int runtest[NTESTS];
};
static void
print(const char library[], const char function[], double cps)
{
if (print_csv == false)
{
printf ("%16s %30s : %20.1f per second\n", library, function, cps);
}
else
{
printf ("\"%s\";\"%s\";%f\n", library, function, cps);
}
}
int benchTest (const struct flags * runflags) {
int c = 0;
double cps;
#if defined (BENCH_CAN_USE_STL)
if (runflags->runtest[0]) {
c += timeTest (cps, testSTL_emptyCtor, 100000);
print ("std::string", "empty constructor", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testSTL_nonemptyCtor, 100000);
print ("std::string", "non-empty constructor", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testSTL_smallnonemptyCtor, 100000);
print ("std::string", "small non-empty constructor", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testSTL_cstrAssignment, 100000);
print ("std::string", "char * assignment", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testSTL_extraction, 100000);
print ("std::string", "char extraction", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testSTL_scan, 100000);
print ("std::string", "scan", cps);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testSTL_concat, 10);
print ("std::string", "concatenation", cps * 250);
}
if (runflags->runtest[7]) {
c += timeTest (cps, testSTL_replace, 10000);
print ("std::string", "replace", cps);
}
#endif
#ifdef BENCH_CAN_USE_BSTRLIB
if (runflags->runtest[0]) {
c += timeTest (cps, testCBS_emptyCtor, 100000);
printf ("CBString empty constructor: %20.1f per second\n", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testCBS_nonemptyCtor, 100000);
printf ("CBString non-empty constructor: %20.1f per second\n", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testCBS_cstrAssignment, 100000);
printf ("CBString char * assignment: %20.1f per second\n", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testCBS_extraction, 100000);
printf ("CBString char extraction: %20.1f per second\n", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testCBS_scan, 100000);
printf ("CBString scan: %20.1f per second\n", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testCBS_concat, 10);
printf ("CBString concatenation: %20.1f per second\n", cps * 250);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testCBS_replace, 10000);
printf ("CBString replace: %20.1f per second\n", cps);
}
if (runflags->runtest[0]) {
c += timeTest (cps, testCBS_emptyCtor, 100000);
print ("CBString", "empty constructor", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testCBS_nonemptyCtor, 100000);
print ("CBString", "non-empty constructor", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testCBS_smallnonemptyCtor, 100000);
print ("CBString", "small non-empty constructor", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testCBS_cstrAssignment, 100000);
print ("CBString", "char * assignment", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testCBS_extraction, 100000);
print ("CBString", "char extraction", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testCBS_scan, 100000);
print ("CBString", "scan", cps);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testCBS_concat, 10);
print ("CBString", "concatenation", cps * 250);
}
if (runflags->runtest[7]) {
c += timeTest (cps, testCBS_replace, 10000);
print ("CBString", "replace", cps);
}
#endif
#ifdef BENCH_CAN_USE_LIBSRT
if (runflags->runtest[0]) {
c += timeTest (cps, testSRT_emptyCtor, 100000);
printf ("LIBSRT string empty constructor: %20.1f per second\n", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testSRT_nonemptyCtor, 100000);
printf ("LIBSRT string non-empty constructor:%20.1f per second\n", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testSRT_cstrAssignment, 100000);
printf ("LIBSRT string char * assignment: %20.1f per second\n", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testSRT_extraction, 100000);
printf ("LIBSRT string char extraction: %20.1f per second\n", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testSRT_scan, 100000);
printf ("LIBSRT string scan: %20.1f per second\n", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testSRT_concat, 10);
printf ("LIBSRT string concatenation: %20.1f per second\n", cps * 250);
}
if (runflags->runtest[0]) {
c += timeTest (cps, testSRT_emptyCtor, 100000);
print ("LIBSRT", "empty constructor", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testSRT_nonemptyCtor, 100000);
print ("LIBSRT", "non-empty constructor", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testSRT_smallnonemptyCtor, 100000);
print ("LIBSRT", "small non-empty constructor", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testSRT_cstrAssignment, 100000);
print ("LIBSRT", "char * assignment", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testSRT_extraction, 100000);
print ("LIBSRT", "char extraction", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testSRT_scan, 100000);
print ("LIBSRT", "scan", cps);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testSRT_concat, 10);
print ("LIBSRT", "concatenation", cps * 250);
}
#endif
#ifdef BENCH_CAN_USE_MSTARLIB
if (runflags->runtest[0]) {
c += timeTest (cps, testMLIB_emptyCtor, 100000);
print ("M*LIB", "empty constructor", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testMLIB_nonemptyCtor, 100000);
print ("M*LIB", "non-empty constructor", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testMLIB_smallnonemptyCtor, 100000);
print ("M*LIB", "small non-empty constructor", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testMLIB_cstrAssignment, 100000);
print ("M*LIB", "Char * assignment", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testMLIB_extraction, 100000);
print ("M*LIB", "char extraction", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testMLIB_scan, 100000);
print ("M*LIB", "scan", cps);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testMLIB_concat, 10);
print ("M*LIB", "concatenation", cps * 250);
}
if (runflags->runtest[7]) {
c += timeTest (cps, testMLIB_replace, 10000);
print ("M*LIB", "replace", cps);
}
#endif
#ifdef BENCH_CAN_USE_MSTARLIB
if (runflags->runtest[0]) {
c += timeTest (cps, testMLIB_emptyCtor, 100000);
printf ("M*LIB string empty constructor: %20.1f per second\n", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testMLIB_nonemptyCtor, 100000);
printf ("M*LIB string non-empty constructor:%20.1f per second\n", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testMLIB_cstrAssignment, 100000);
printf ("M*LIB string char * assignment: %20.1f per second\n", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testMLIB_extraction, 100000);
printf ("M*LIB string char extraction: %20.1f per second\n", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testMLIB_scan, 100000);
printf ("M*LIB string scan: %20.1f per second\n", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testMLIB_concat, 10);
printf ("M*LIB string concatenation: %20.1f per second\n", cps * 250);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testMLIB_replace, 10000);
printf ("M*LIB string replace: %20.1f per second\n", cps);
}
#ifdef BENCH_CAN_USE_SDS
if (runflags->runtest[0]) {
c += timeTest (cps, testSDS_emptyCtor, 100000);
print ("SDS", "empty constructor", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testSDS_nonemptyCtor, 100000);
print ("SDS", "non-empty constructor", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testSDS_smallnonemptyCtor, 100000);
print ("SDS", "small non-empty constructor", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testSDS_cstrAssignment, 100000);
print ("SDS", "char * assignment", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testSDS_extraction, 100000);
print ("SDS", "char extraction", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testSDS_scan, 100000);
print ("SDS", "scan", cps);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testSDS_concat, 10);
print ("SDS", "concatenation", cps * 250);
}
if (runflags->runtest[7]) {
c += timeTest (cps, testSDS_replace, 10);
print ("SDS", "replace", cps);
}
#endif
return c;
#ifdef BENCH_CAN_USE_GLIB
if (runflags->runtest[0]) {
c += timeTest (cps, testGLIB_emptyCtor, 100000);
print ("GLIB", "empty constructor", cps);
}
if (runflags->runtest[1]) {
c += timeTest (cps, testGLIB_nonemptyCtor, 100000);
print ("GLIB", "non-empty constructor", cps);
}
if (runflags->runtest[2]) {
c += timeTest (cps, testGLIB_smallnonemptyCtor, 100000);
print ("GLIB", "small non-empty constructor", cps);
}
if (runflags->runtest[3]) {
c += timeTest (cps, testGLIB_cstrAssignment, 100000);
print ("GLIB", "Char * assignment", cps);
}
if (runflags->runtest[4]) {
c += timeTest (cps, testGLIB_extraction, 100000);
print ("GLIB", "char extraction", cps);
}
if (runflags->runtest[5]) {
c += timeTest (cps, testGLIB_scan, 100000);
print ("GLIB", "scan", cps);
}
if (runflags->runtest[6]) {
c += timeTest (cps, testGLIB_concat, 10);
print ("GLIB", "concatenation", cps * 250);
}
#endif
return c;
}
int main (int argc, char * argv[]) {
struct flags runflags;
int i, j;
if (argc > 1 && strcmp(argv[1], "--csv") == 0) {
print_csv = true;
argc --;
argv++;
}
for (i=0; i < NTESTS; i++) runflags.runtest[i] = argc < 2;
for (i=1; i < argc; i++) {
if (1 == sscanf (argv[i], "%d", &j)) {
+11 -13
View File
@@ -124,7 +124,7 @@ static int equal_func(const void* arg, const void *obj_p)
}
static void
test_dict(unsigned long n)
test_dict(size_t n)
{
tommy_hashlin dict;
tommy_hashlin_init(&dict);
@@ -174,7 +174,7 @@ static size_t char_hash(const char *s)
}
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
tommy_hashlin dict;
tommy_hashlin_init(&dict);
@@ -206,18 +206,16 @@ test_dict_big(unsigned long n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 30)
test_function("Rbtree time", 1000000, test_rbtree);
if (n == 40)
test_function("Dict time", 1000000, test_dict);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
test("TommyDS", numberof(table), table, argc, argv);
exit(0);
}
+12 -14
View File
@@ -1,4 +1,5 @@
#define NDEBUG
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
@@ -85,7 +86,7 @@ struct hash_i_node_s {
};
static void
test_dict(unsigned long n)
test_dict(size_t n)
{
struct hash_i_node_s *dict = NULL;
@@ -131,7 +132,7 @@ struct hash_b_node_s {
};
static void
test_dict_big(unsigned long n)
test_dict_big(size_t n)
{
struct hash_b_node_s *dict = NULL;
@@ -199,19 +200,16 @@ static void test_sort(size_t n)
/********************************************************************************************/
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[])
{
int n = (argc > 1) ? atoi(argv[1]): 0;
if (n == 10)
test_function("List time",10000000, test_list);
if (n == 20)
test_function("Array time", 100000000, test_array);
if (n == 40 || n == 42)
test_function("Dict time", 1000000, test_dict);
if (n == 41)
test_function("DictB time", 1000000, test_dict_big);
if (n == 50)
test_function("Sort time", 10000000, test_sort);
test("UT-HASH", numberof(table), table, argc, argv);
exit(0);
}
+4 -9
View File
@@ -31,17 +31,12 @@ static void test_hash(size_t n)
/********************************************************************************************/
const config_func_t table[] = {
{ 70,"XXHASH64", 100000000, test_hash_prepare, test_hash, test_hash_final}
};
int main(int argc, const char *argv[])
{
int n = (argc > 1) ? atoi(argv[1]) : 0;
if (n == 70) {
n = (argc > 2) ? atoi(argv[2]) : 100000000;
test_hash_prepare(n);
test_function("XXHASH64 time", n, test_hash);
test_hash_final();
}
test("XXHASH", numberof(table), table, argc, argv);
exit(0);
}
+304
View File
@@ -0,0 +1,304 @@
/*
* 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;
}
+81 -32
View File
@@ -1,7 +1,7 @@
/*
* M*LIB - common functions for bench module
*
* Copyright (c) 2017-2018, Patrick Pelissier
* 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:
@@ -25,35 +25,59 @@
#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 */
#include <windows.h>
static unsigned long long
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);
LARGE_INTEGER freq, val;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&val);
return (unsigned long long) (1000000. * (double) val.QuadPart / (double) freq.QuadPart);
}
#else
/* UNIX variant */
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/time.h>
static unsigned long long
static inline unsigned long long
cputime (void)
{
#if defined(MULTI_THREAD_MEASURE)
// Multi thread
// Multi thread: Uses real time
struct timeval tv;
gettimeofday (&tv, NULL);
return tv.tv_sec * 1000000ULL + tv.tv_usec;
#else
// Single thread
// Single thread: Uses process usage time
struct rusage rus;
getrusage (0, &rus);
return rus.ru_utime.tv_sec * 1000000ULL + rus.ru_utime.tv_usec;
@@ -62,41 +86,61 @@ cputime (void)
#endif
unsigned long g_result;
unsigned int randValue = 0;
// The result of the bench
extern unsigned long g_result;
static void rand_init(void)
// 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 unsigned int rand_get(void)
static inline unsigned int rand_get(void)
{
randValue = randValue * 31421U + 6927U;
return randValue;
}
static void test_function(const char str[], size_t n, void (*func)(size_t))
// 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;
printf ("%s %lu ms for n = %lu [r=%lu]\n", str, (unsigned long) end, (unsigned long) n, g_result);
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;
}
#if defined(_WIN32)
# include <windows.h>
#elif (defined(__APPLE__) && defined(__MACH__)) \
|| defined(__DragonFly__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__)
# include <sys/param.h>
# include <sys/sysctl.h>
# define USE_SYSCTL
#else
# include <unistd.h>
// 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)
@@ -120,4 +164,9 @@ static inline int get_cpu_count(void)
#endif
}
#ifdef __cplusplus
extern "C"
#endif
void compiler_barrier(void *p);
#endif
+2 -2
View File
@@ -1,7 +1,7 @@
/*
* MLIB - TEST module
*
* Copyright (c) 2017-2018, Patrick Pelissier
* 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:
@@ -59,7 +59,7 @@ static void find_max(void)
dict_int64_set_at (dict, get_rand(), get_rand());
n++;
if ((n & ((1<<20)-1)) == 0) {
printf ("n=%lu\n", n);
printf ("n=%zu\n", n);
}
}
dict_int64_clear(dict);
+178 -205
View File
@@ -3,50 +3,50 @@
//
// Original version Contributed by Jeremy Zerfas
// M*LIB port contributed by Patrick Pélissier
// gcc -O2 -march=native nucleotide.c -I../.. -std=c11 -lpthread -DNDEBUG
#define NDEBUG
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/time.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
// Define Open Addressing dictionnary. Need to define how to handle out of bound data.
static inline bool oor_equal_p(uint64_t k, unsigned char n)
// 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 oor_set(uint64_t *k, unsigned char n)
static inline void my_oor_set(uint64_t *k, unsigned char n)
{
*k = ~(uint64_t)n;
}
// Custom hash function.
static inline size_t my_hash(uint64_t key)
{
return ((key) ^ (key)>>7);
}
// Define a dictionnary of uint64_t --> uint32_t
DICT_OA_DEF2(dict_oligonucleotide,
uint64_t, M_OPEXTEND(M_DEFAULT_OPLIST, HASH(my_hash), OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)),
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_DEFAULT_OPLIST)
// Define oplist of dictionary
#define OLIGONUCLEOTIDE_OPLIST DICT_OPLIST(dict_oligonucleotide, M_OPEXTEND(M_DEFAULT_OPLIST, HASH(oor_hash), OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)), M_DEFAULT_OPLIST)
#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)
typedef struct {
uint64_t key;
uint32_t value;
} element;
// 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
@@ -55,143 +55,167 @@ typedef struct {
// 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;
// Function to use when sorting elements with qsort() later. Elements with
// larger values will come first and in cases of identical values then elements
// with smaller keys will come first.
static int element_Compare(const void *a, const void *b)
// 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)
{
const element * const left_Element = a;
const element * const right_Element = b;
// Sort based on element values.
if(left_Element->value < right_Element->value) return 1;
if(left_Element->value > right_Element->value) return -1;
// If we got here then both items have the same value so then sort based on
// key.
return left_Element->key > right_Element->key ? 1 : -1;
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));
}
}
}
}
// Generate frequencies for all oligonucleotides in polynucleotide that are of
// desired_Length_For_Oligonucleotides and then save it to output.
static void
generate_Frequencies_For_Desired_Length_Oligonucleotides(const char polynucleotide[],
const int polynucleotide_Length,
const int desired_Length_For_Oligonucleotides,
char * const output)
{
assert (2*desired_Length_For_Oligonucleotides <= 64);
dict_oligonucleotide_t hash_Table;
dict_oligonucleotide_init(hash_Table);
uint64_t key=0;
const uint64_t mask=(1ULL<<(2*desired_Length_For_Oligonucleotides))-1;
// 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_Table.
for(int i=0; i<desired_Length_For_Oligonucleotides-1; i++)
key=(key<<2 & mask) | polynucleotide[i];
// 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
// desired_Length_For_Oligonucleotides to hash_Table and update the count
// for each oligonucleotide.
for(int i=desired_Length_For_Oligonucleotides-1
; i<polynucleotide_Length; i++){
key=(key<<2 & mask) | polynucleotide[i];
uint32_t *p = dict_oligonucleotide_get(hash_Table, key);
if (p != NULL)
(*p) ++;
else {
dict_oligonucleotide_set_at(hash_Table, key, 1);
// 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);
}
}
}
// Create an array of elements from hash_Table.
int elements_Array_Size=dict_oligonucleotide_size(hash_Table), i=0;
element * elements_Array=malloc(elements_Array_Size*sizeof(element));
if (!elements_Array) abort();
for M_EACH(item, hash_Table, OLIGONUCLEOTIDE_OPLIST) {
elements_Array[i++]=((element){item->key, item->value});
}
// Clear the hash table
dict_oligonucleotide_clear(hash_Table);
// Sort elements_Array.
qsort(elements_Array, elements_Array_Size, sizeof(element), element_Compare);
// Print the frequencies for each oligonucleotide.
for(int output_Position=0, i=0; i<elements_Array_Size; i++) {
// Convert the key for the oligonucleotide to a string.
char oligonucleotide[desired_Length_For_Oligonucleotides+1];
for(int j=desired_Length_For_Oligonucleotides-1; j>-1; j--){
oligonucleotide[j]=NUCLEOTIDE_FOR_CODE(elements_Array[i].key);
elements_Array[i].key>>=2;
}
oligonucleotide[desired_Length_For_Oligonucleotides]='\0';
// Output the frequency for oligonucleotide to output.
output_Position+=snprintf(output+output_Position
, MAXIMUM_OUTPUT_LENGTH-output_Position, "%s %.3f\n", oligonucleotide
, 100.0f*elements_Array[i].value
/(polynucleotide_Length-desired_Length_For_Oligonucleotides+1));
}
free(elements_Array);
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
generate_Count_For_Oligonucleotide(const char * const polynucleotide,
const int polynucleotide_Length,
const char * const oligonucleotide,
char * const output)
static void compute_count(polynucleotide_t p, const char oligonucleotide[], char output[])
{
const int oligonucleotide_Length=strlen(oligonucleotide);
assert (2*oligonucleotide_Length <= 64);
const size_t oligonucleotide_Length = strlen(oligonucleotide);
dict_oligonucleotide_t hash_Table;
dict_oligonucleotide_init(hash_Table);
uint64_t key = 0;
const uint64_t mask=(1ULL<<(2*oligonucleotide_Length))-1;
// For the first several nucleotides we only need to append them to key in
// preparation for the insertion of complete oligonucleotides to hash_Table.
for(int i=0; i<oligonucleotide_Length-1; i++)
key=(key<<2 & mask) | polynucleotide[i];
// Add all the complete oligonucleotides of oligonucleotide_Length to
// hash_Table and update the count for each oligonucleotide.
for(int i=oligonucleotide_Length-1; i<polynucleotide_Length; i++){
key=(key<<2 & mask) | polynucleotide[i];
uint32_t *p = dict_oligonucleotide_get(hash_Table, key);
if (p != NULL)
(*p) ++;
else {
dict_oligonucleotide_set_at(hash_Table, key, 1);
}
}
compute_hash(hash_Table, p, oligonucleotide_Length);
// Generate the key for oligonucleotide.
key=0;
for(int i=0; i<oligonucleotide_Length; i++)
key=(key<<2) | CODE_FOR_NUCLEOTIDE(oligonucleotide[i]);
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 *p = dict_oligonucleotide_get(hash_Table, key);
uintmax_t count= p== NULL ? 0 : *p;
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);
@@ -199,94 +223,43 @@ generate_Count_For_Oligonucleotide(const char * const polynucleotide,
int main()
{
char buffer[MAXIMUM_OUTPUT_LENGTH];
worker_t worker;
// Initialize the different worker threads by auto-detecting the number of cores of the system
worker_init(worker, 0, 1, NULL);
worker_init(worker, -1, 0, NULL);
// Read the input
polynucleotide_t p, *ptr = &p;
polynucleotide_init_stream(p, stdin);
// Find the start of the third polynucleotide.
while(fgets(buffer, sizeof(buffer), stdin) && memcmp(">THREE", buffer
, sizeof(">THREE")-1));
// Start with 1 MB of storage for reading in the polynucleotide and grow
// geometrically.
int polynucleotide_Capacity=1048576;
int polynucleotide_Length=0;
char * polynucleotide=malloc(polynucleotide_Capacity);
if (!polynucleotide) abort();
// Start reading and encoding the third polynucleotide.
while(fgets(buffer, sizeof(buffer), stdin) && buffer[0]!='>'){
for(int i=0; buffer[i]!='\0'; i++)
if(buffer[i]!='\n')
polynucleotide[polynucleotide_Length++]
=CODE_FOR_NUCLEOTIDE(buffer[i]);
// Make sure we still have enough memory allocated for any potential
// nucleotides in the next line.
if(polynucleotide_Capacity-polynucleotide_Length<sizeof(buffer)) {
polynucleotide=realloc(polynucleotide, polynucleotide_Capacity*=2);
if (!polynucleotide) abort();
}
}
char output_Buffer[7][MAXIMUM_OUTPUT_LENGTH];
char (*output)[MAXIMUM_OUTPUT_LENGTH] = output_Buffer;
// Prepare outputs
char outputBuffer[MAXMUM_NUMBER_OUTPUT][MAXIMUM_OUTPUT_LENGTH];
char (*output)[MAXIMUM_OUTPUT_LENGTH] = outputBuffer;
// Do the following functions in parallel.
// Define a synchronization block
worker_sync_t block;
worker_start(block);
worker_sync_t block; // Define a synchronization block
worker_start(block, worker);
WORKER_SPAWN(worker, block, (polynucleotide, polynucleotide_Length, output), {
generate_Count_For_Oligonucleotide(polynucleotide,
polynucleotide_Length,
"GGTATTTTAATTTATAGT", output[6]);
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTATTTTAATTTATAGT", output[6]);
}, (/*no output*/));
WORKER_SPAWN(worker, block, (polynucleotide, polynucleotide_Length, output), {
generate_Count_For_Oligonucleotide(polynucleotide,
polynucleotide_Length,
"GGTATTTTAATT", output[5]);
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTATTTTAATT", output[5]);
}, (/*no output*/));
WORKER_SPAWN(worker, block, (polynucleotide, polynucleotide_Length, output), {
generate_Count_For_Oligonucleotide(polynucleotide,
polynucleotide_Length,
"GGTATT", output[4]);
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTATT", output[4]);
}, (/*no output*/));
WORKER_SPAWN(worker, block, (polynucleotide, polynucleotide_Length, output), {
generate_Count_For_Oligonucleotide(polynucleotide,
polynucleotide_Length,
"GGTA", output[3]);
WORKER_SPAWN(block, (ptr, output), {
compute_count(*ptr, "GGTA", output[3]);
}, (/*no output*/));
WORKER_SPAWN(worker, block, (polynucleotide, polynucleotide_Length, output), {
generate_Count_For_Oligonucleotide(polynucleotide,
polynucleotide_Length,
"GGT", output[2]);
}, (/*no output*/));
WORKER_SPAWN(worker, block, (polynucleotide, polynucleotide_Length, output), {
generate_Frequencies_For_Desired_Length_Oligonucleotides(polynucleotide,
polynucleotide_Length,
2,
output[1]);
}, (/*no output*/));
generate_Frequencies_For_Desired_Length_Oligonucleotides(polynucleotide,
polynucleotide_Length,
1,
output[0]);
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<7; i++)
printf("%s\n", output_Buffer[i]);
for(int i=0; i<MAXMUM_NUMBER_OUTPUT; i++)
printf("%s\n", outputBuffer[i]);
free(polynucleotide);
polynucleotide_clear(p);
worker_clear(worker);
return 0;
+53
View File
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,73 @@
#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
@@ -0,0 +1,53 @@
#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
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,34 @@
#include "../common.c"
#define M_USE_DICT_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;
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

+75
View File
@@ -0,0 +1,75 @@
API incompatibility
-------------------
V0.1.*: * First formal version of API
V0.2.*: * worker_start takes a 'worker_t' as an additional parameter
(This enables to perform a wait-on-event instead of a busy waiting).
* worker_spawn doesn't take into a 'worker_t' anymore.
* worker_init takes an int as numWorker instead of an unsigned int.
* RBTREE pop method has been renamed into _pop_at (as it takes a key parameter).
* SNAPSHOT_DEF has been removed. use SNAPSHOT_SPSC_DEF
* array's _set_at2 has been replaced by array's _get_at.
The interface is similar to dict _get_at, making the API cleaner and more generic.
_set_at2(a,i,x) ==> set(*_get_at(a,i),x)
* DICT_SET:
- Rename method _set_at as _push
Since there is no key, it is a push method, not a _set_at method.
- Rename DICT_SET_DEF2 as DICT_SET_DEF
since it only requires one argument.
- The method _ref returns a pointer to the data,
instead of a pointer to a single tuple like other DICT_SET interface.
- The format of the output to character string as changed.
* ALGO:
- Rename _contains as _contain_p
since it is a predicate '_p' and it shall be in infinitive form.
- Rename _map as _for_each (Standard name).
* M_PRINT_ARG & M_FPRINT_ARG don't put a final semicolon at the end
of their expansion anymore (cleaner and no longer needed with the
new available tools).
* For the TUPLE and the VARIANT
change name of _get_ ## field into _get_at_ ## fields
Since there is a name collision with other methods
if a field is named 'str'.
* Rename method _remove into _erase for dictionary & B+TREE (adding a compatibility layer) for API uniformization.
The provided _remove doesn't use an iterator but a 'key', incompatible with the one of array or list.
But is like the one provided by the priority queue.
V0.3.*: * Remove B+TREE _remove method as it has been deprecated (use _erase instead)
* Remove DICT _remove method as it has been deprecated (use _erase instead)
* Make _it_to_p method of B+TREE / RB-TREE as deprecated (uses _it_until_p instead ).
* Deprecated buffer options BUFFER_BLOCKING* and BUFFER_UNBLOCKING*
as the _push_blocking and _pop_blocking functions can do the same and are more versatil.
* Iteration over the items of a dictionnary/tree returns const iterators for access through
OPLIST (impact: algorithm & M_EACH) as the IT_REF operator is no longer exported.
The _it_ref method is still defined and can be used, so you can still modify the values
but it won't be automatically used anymore (as the keys CANNOT be modified).
(Previously it generates incorrect algorithm when used with m-dict).
V0.4.*: * The order of a list initialized using M_LET is reversed
to match what is done for ARRAY (and the C++ forward_list).
* Rename M_SKIP, M_KEEP & M_MID into M_SKIP_ARGS, M_KEEP_ARGS & M_MID_ARGS
due to conflict with glibc malloc.h (that defines M_KEEP for compatibility).
* Method write_string of m_serial expects a new argument (number of characters).
* Method _init_set2 of m-i-shared is removed.
* Operator _it_insert updates it_insertion iterator to reference the inserted element.
* Dereference Type of an iterator of a dict / B+Tree is suffixed by _itref_t instead of _type_t.
* 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.
+84
View File
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><!--This file was converted to xhtml by LibreOffice - see http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/xslt for the code.--><head profile="http://dublincore.org/documents/dcmi-terms/"><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/><title xml:lang="en-US">- no title specified</title><meta name="DCTERMS.title" content="" xml:lang="en-US"/><meta name="DCTERMS.language" content="en-US" scheme="DCTERMS.RFC4646"/><meta name="DCTERMS.source" content="http://xml.openoffice.org/odf2xhtml"/><meta name="DCTERMS.issued" content="2018-07-01T11:06:00.978729880" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.provenance" content="" xml:lang="en-US"/><meta name="DCTERMS.subject" content="," xml:lang="en-US"/><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en"/><link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" hreflang="en"/><link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en"/><link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en"/><style type="text/css">
@page { }
table { border-collapse:collapse; border-spacing:0; empty-cells:show }
td, th { vertical-align:top; font-size:10pt;}
h1, h2, h3, h4, h5, h6 { clear:both }
ol, ul { margin:0; padding:0;}
li { list-style: none; margin:0; padding:0;}
<!-- "li span.odfLiEnd" - IE 7 issue-->
li span. { clear: both; line-height:0; width:0; height:0; margin:0; padding:0; }
span.footnodeNumber { padding-right:1em; }
span.annotation_style_by_filter { font-size:95%; font-family:Arial; background-color:#fff000; margin:0; border:0; padding:0; }
* { margin:0;}
.ta1 { writing-mode:lr-tb; }
.Default { font-family:Liberation Sans; }
.ce100 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce101 { font-family:Liberation Sans; border-bottom-style:none; background-color:#ffff00; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce102 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#ffff00; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce103 { font-family:Liberation Sans; border-bottom-style:none; background-color:#ffff00; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; }
.ce104 { font-family:Liberation Sans; background-color:#e6e6e6; font-size:11pt; text-decoration:underline; font-weight:bold; }
.ce57 { font-family:Liberation Sans; background-color:transparent; font-size:11pt; text-decoration:none ! important; font-weight:bold; }
.ce58 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:transparent; border-left-style:none; border-right-style:none; border-top-style:none; font-size:11pt; text-decoration:none ! important; font-weight:bold; }
.ce59 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; font-size:11pt; text-decoration:underline; font-weight:bold; }
.ce60 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-style:none; font-size:11pt; text-decoration:none ! important; font-weight:bold; }
.ce61 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#e6e6e6; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-style:none; font-size:11pt; text-decoration:none ! important; font-weight:bold; }
.ce62 { font-family:Liberation Sans; background-color:#e6e6e6; font-size:11pt; text-decoration:none ! important; font-weight:bold; }
.ce63 { font-family:Liberation Sans; background-color:#e6e6e6; border-width:0,0621cm; border-style:solid; border-color:#000000; text-align:center ! important; margin-left:0cm; font-size:11pt; font-weight:bold; }
.ce64 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; font-weight:bold; }
.ce65 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; font-weight:bold; }
.ce66 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#e6e6e6; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; font-weight:bold; }
.ce67 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6ff; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; font-weight:bold; }
.ce68 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#e6e6ff; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; font-weight:bold; }
.ce69 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6ff; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; font-weight:bold; }
.ce70 { font-family:Liberation Sans; background-color:#e6e6e6; font-weight:bold; }
.ce71 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; font-size:11pt; text-decoration:underline; font-weight:bold; }
.ce72 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#e6e6e6; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; font-weight:bold; }
.ce73 { font-family:Liberation Sans; border-bottom-style:none; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; }
.ce74 { font-family:Liberation Sans; border-bottom-style:none; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce75 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce76 { font-family:Liberation Sans; border-bottom-style:none; background-color:transparent; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce77 { font-family:Liberation Sans; text-align:center ! important; margin-left:0cm; }
.ce78 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-style:none; border-right-style:none; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; font-size:11pt; text-decoration:underline; font-weight:bold; }
.ce79 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#e6e6e6; border-left-style:none; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; font-weight:bold; }
.ce80 { font-family:Liberation Sans; border-bottom-style:none; border-left-style:none; border-right-style:none; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; }
.ce81 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; border-left-style:none; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce82 { font-family:Liberation Sans; background-color:transparent; text-align:center ! important; margin-left:0cm; }
.ce83 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:transparent; border-left-style:none; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce84 { font-family:Liberation Sans; background-color:#ffff00; text-align:center ! important; margin-left:0cm; }
.ce85 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#ffff00; border-left-style:none; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce86 { font-family:Liberation Sans; border-bottom-style:none; background-color:#ffff00; border-left-style:none; border-right-style:none; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; }
.ce87 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; font-size:11pt; text-decoration:underline; font-weight:bold; }
.ce88 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#e6e6e6; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; font-weight:bold; }
.ce89 { font-family:Liberation Sans; border-bottom-style:none; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; }
.ce90 { font-family:Liberation Sans; border-bottom-style:none; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce91 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce92 { font-family:Liberation Sans; border-bottom-style:none; background-color:#ffff00; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce93 { font-family:Liberation Sans; border-bottom-style:none; background-color:#ffff00; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-style:none; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce94 { font-family:Liberation Sans; border-bottom-style:none; background-color:transparent; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce95 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:transparent; border-left-style:none; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.ce96 { font-family:Liberation Sans; border-bottom-style:none; background-color:#e6e6e6; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; font-size:11pt; text-decoration:none ! important; font-weight:bold; }
.ce97 { font-family:Liberation Sans; border-bottom-width:0,0621cm; border-bottom-style:solid; border-bottom-color:#000000; background-color:#e6e6e6; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; font-weight:bold; }
.ce98 { font-family:Liberation Sans; border-bottom-style:none; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-width:0,0621cm; border-top-style:solid; border-top-color:#000000; text-align:center ! important; margin-left:0cm; }
.ce99 { font-family:Liberation Sans; border-bottom-style:none; border-left-width:0,0621cm; border-left-style:solid; border-left-color:#000000; border-right-width:0,0621cm; border-right-style:solid; border-right-color:#000000; border-top-style:none; text-align:center ! important; margin-left:0cm; }
.co1 { width:3.399cm; }
.co10 { width:1.304cm; }
.co11 { width:1.942cm; }
.co12 { width:1.815cm; }
.co13 { width:1.348cm; }
.co14 { width:1.432cm; }
.co15 { width:2.258cm; }
.co2 { width:6.281cm; }
.co3 { width:1.475cm; }
.co4 { width:1.277cm; }
.co5 { width:1.602cm; }
.co6 { width:1.39cm; }
.co7 { width:1.686cm; }
.co8 { width:1.644cm; }
.co9 { width:2.452cm; }
.ro1 { height:0.487cm; }
.ro2 { height:0.885cm; }
.ro3 { height:0.452cm; }
<!-- ODF styles with no properties representable as CSS -->
{ }
</style></head><body dir="ltr" style="writing-mode:lr-tb; "><table border="0" cellspacing="0" cellpadding="0" class="ta1"><colgroup><col width="149"/><col width="274"/><col width="64"/><col width="56"/><col width="70"/><col width="61"/><col width="74"/><col width="72"/><col width="107"/><col width="57"/><col width="107"/><col width="107"/><col width="74"/><col width="85"/><col width="79"/><col width="79"/><col width="59"/><col width="61"/><col width="63"/><col width="99"/></colgroup><tr class="ro1"><td style="text-align:left;width:3.399cm; " class="ce57"> </td><td style="text-align:left;width:6.281cm; " class="ce57"> </td><td colspan="6" style="text-align:left;width:1.475cm; " class="ce71"><p>Sequence Containers</p></td><td colspan="4" style="text-align:left;width:2.452cm; " class="ce71"><p>Associative Containers</p></td><td style="text-align:left;width:1.686cm; " class="ce96"> </td><td colspan="6" style="text-align:left;width:1.942cm; " class="ce71"><p>Synchronization Containers</p></td><td style="text-align:left;width:2.258cm; " class="ce104"> </td></tr><tr class="ro2"><td style="text-align:left;width:3.399cm; " class="ce58"> </td><td style="text-align:left;width:6.281cm; " class="ce63"><p>Method</p></td><td style="text-align:left;width:1.475cm; " class="ce72"><p>ARRAY</p></td><td style="text-align:left;width:1.277cm; " class="ce79"><p>LIST</p></td><td style="text-align:left;width:1.602cm; " class="ce79"><p>DUALP</p><p>LIST</p></td><td style="text-align:left;width:1.39cm; " class="ce79"><p>I-LIST</p></td><td style="text-align:left;width:1.686cm; " class="ce79"><p>DEQUE</p></td><td style="text-align:left;width:1.644cm; " class="ce88"><p>BITSET</p></td><td style="text-align:left;width:2.452cm; " class="ce72"><p>B+TREE</p><p>DICT/SET</p></td><td style="text-align:left;width:1.304cm; " class="ce79"><p>R/B</p><p>TREE</p></td><td style="text-align:left;width:2.452cm; " class="ce79"><p>[S]HASH</p><p>DICT / SET</p></td><td style="text-align:left;width:2.452cm; " class="ce88"><p>OA DICT</p></td><td style="text-align:left;width:1.686cm; " class="ce97"><p>PRIO </p><p>QUEUE</p></td><td style="text-align:left;width:1.942cm; " class="ce72"><p>BUFFER</p></td><td style="text-align:left;width:1.815cm; " class="ce79"><p>QUEUE </p><p>MPMC</p></td><td style="text-align:left;width:1.815cm; " class="ce79"><p>QUEUE </p><p>SPSC</p></td><td style="text-align:left;width:1.348cm; " class="ce79"><p>SNAP</p><p>SPSC</p></td><td style="text-align:left;width:1.39cm; " class="ce79"><p>SNAP</p><p>SPMC</p></td><td style="text-align:left;width:1.432cm; " class="ce88"><p>SNAP </p><p>MPMC</p></td><td style="text-align:left;width:2.258cm; " class="ce70"> </td></tr><tr class="ro1"><td style="text-align:left;width:3.399cm; " class="ce59"><p>CONSTRUCTOR</p></td><td style="text-align:left;width:6.281cm; " class="ce64"><p>_init</p></td><td style="text-align:left;width:1.475cm; " class="ce73"><p>X</p></td><td style="text-align:left;width:1.277cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.602cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.39cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.686cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.644cm; " class="ce89"><p>X</p></td><td style="text-align:left;width:2.452cm; " class="ce73"><p>X</p></td><td style="text-align:left;width:1.304cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:2.452cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:2.452cm; " class="ce89"><p>X</p></td><td style="text-align:left;width:1.686cm; " class="ce98"><p>X</p></td><td style="text-align:left;width:1.942cm; " class="ce73"><p>X</p></td><td style="text-align:left;width:1.815cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.815cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.348cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.39cm; " class="ce80"><p>X</p></td><td style="text-align:left;width:1.432cm; " class="ce89"><p>X</p></td><td style="text-align:left;width:2.258cm; " class="Default"> </td></tr><tr class="ro1"><td style="text-align:left;width:3.399cm; " class="ce60"> </td><td style="text-align:left;width:6.281cm; " class="ce65"><p>_set</p></td><td style="text-align:left;width:1.475cm; " class="ce74"><p>X</p></td><td style="text-align:left;width:1.277cm; " class="ce77"><p>X</p></td><td style="text-align:left;width:1.602cm; " class="ce77"><p>X</p></td><td style="text-align:left;width:1.39cm; " class="ce77"> </td><td style="text-align:left;width:1.686cm; " class="ce77"><p>X</p></td><td style="text-align:left;width:1.644cm; " class="ce90"><p>X</p></td><td style="text-align:left;width:2.452cm; " class="ce74"><p>X</p></td><td style="text-align:left;width:1.304cm; " class="ce77"><p>X</p></td><td style="text-align:left;width:2.452cm; " class="ce77"><p>X</p></td><td style="text-align:left;width:2.452cm; " class="ce90"><p>X</p></td><td style="text-align:left;width:1.686cmLine truncated
BIN
View File
Binary file not shown.
+139 -23
View File
@@ -2,39 +2,155 @@ How to make a release?
======================
1) Check that all test pass on all primary systems.
Run 'make check' on all primary systems.
Run 'make check' or 'make checkall' on all primary systems.
No error shall be reported.
2) Check that no memory leak is reported by valgrind:
Run 'make valgrind' in tests folder on a system.
NOTE: valgrind seems completly lost in all the tests which spawn a lot of threads.
3) Check that no undefined behavior, nor data race, ... is reported by sanitizer:
2) Check that no undefined behavior, nor data race, ... is reported by sanitizer:
Run 'make sanitize' in tests folder on a system.
This needs at least GCC 7
4) Check that no new warning is reported by static analyser:
Run 'make scan-build' in tests folder on a system.
This needs at least clang 4.
Currently there is a false positive detected in m-shared:
"Argument to free() is offset by 8 bytes from the start of memory allocated by malloc()"
scan-build is not able to properly track that this case cannot open.
5) Check that coverage is reasonnable.
3) Check that coverage is reasonable.
Run 'make coverage' and analyze result.
6) Publish the release
4) Publish the release
In case of problem, open a problem report.
List of primary systems
=======================
* gcc 4.9 on linux/x86-64
* gcc 7 on linux/x86-64
* clang 3.5 on linux/x86-64
* clang 4 on linux/x86-64
* g++ 7 on linux/x86-64
List of automatically tested systems
====================================
* 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 6 on windows/x86-64
* 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 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"
since 'atomic' library is not automatically included for 32 bits systems.
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 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:
make CC="i586-mingw32msvc-gcc -std=c99 -DWINVER=0x600 -D_WIN32_WINNT=0x600" LOG_COMPILER=wine check
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 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.
The original issue in the tracker can then be closed with the issuer agreement.
This will have the following gains:
- no hard dependencies on any bug tracking infrastructure (can be migrated easily).
- a release will automatically contain all its open problem reports.
Once one issue of ISSUES.org is taken into account,
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
and expands all code in one line.
Different strategy for debugging the library itself are still possible:
1) Good old printf.
Add printf of interresting values in the debugged function.
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
cc -std=c99 -c -Wall test-file.i
The resulting executable can be debugged much more easily.
3) To debug the preprocessing itself, the Boot Wave library can be used
and in particular the [wave driver](https://www.boost.org/doc/libs/1_71_0/libs/wave/doc/wave_driver.html)
Add in the code the following pragmas around the code to debug:
#pragma wave trace(enable)
ARRAY_DEF (array_charp, char *)
#pragma wave trace(disable)
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
+453
View File
@@ -0,0 +1,453 @@
*Long term issues*
------------------
* TODO #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 = high bits of hash
pointer to object { key, hash, value }
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->
#+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
* TODO #25 : Support of error code model for error handling. :ENHANCEMENT:
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".
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.
This model should be applied at the container level only and not globally.
Different containers may need different levels of error handling.
4 combinaison to take into account:
==> ABORT on container / ABORT on used type: The current model
==> ABORT on container / RETCODE on used type: Needs to abort on reported error.
==> RETCODE on container / ABORT on used type: Nothing particular to note.
==> RETCODE on container / RETCODE on used type: Forward retcode to caller.
Find a way to make it while not making the code too complex
(try to keep as simple as possible).
Using a specialized oplist for such containers (_OPLIST_RETCODE)
using a specialized API for retcode:
API_RET_*: that expands to
if (func(args) == 0) goto handler_exit_failure;
Adding at the end of each service:
M_END_FUNCTION(cleanup_code) that expands to different cases:
M_END_FUNCTION_VALUE(cleanup_code, return_success, return_failure) that expands to different cases:
ABORT/ABORT:
handler_exit_success:
handler_exit_failure:
return;
ABORT/RETCODE:
handler_exit_success:
return;
handler_exit_failure:
RAISE_FATAL_ERROR
RETCODE/ABORT
handler_exit_success:
return SUCESS;
handler_exit_failure:
cleanup_code
return FAILURE;
RETCODE/RETCODE
handler_exit_success:
return SUCESS;
handler_exit_failure:
cleanup_code
return FAILURE;
If really needed, the macro can be avoided and code can be hand written.
Open points:
- How to handle warnings on unused labels?
- What about M_LET/ M_EACH?
* TODO #24 : New: Add MIN-MAX-HEAP container :ENHANCEMENT:
See https://en.wikipedia.org/wiki/Min-max_heap
as DPRIORITY_QUEUE_DEF ?
NOTE: Needs for such container?
* TODO #23: Strict MOVE semantic to clarify :ENHANCEMENT:
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
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
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:
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
other containers than the type shall be carefully moved using the provided
MOVE operator.
For example for tuple, it shall
- create an init_move operator if no one has disabled INIT_MOVE,
- export the init_move operator if at least one has exported a INIT_MOVE and no one has disabled INIT_MOVE.
** DO_INIT_MOVE operator
DO_INIT_MOVE macro is not 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).
==> Analyse limitation and possible constraint usages.
* TODO #20: New: Bucket priority queue :ENHANCEMENT:
Add a new kind of priority queue.
See https://en.wikipedia.org/wiki/Bucket_queue
Check if it will be better as intrusive or non-intrusive container.
To test if a bucket is empty or not, a bitfield can be used to check if
the bit associated to the bucket is set or not. To get the highest bucket
non empty, we can perform a CLZ of the bitset, which shall be much faster than
performing a linear search of the buckets (algorithm complexity is the same,
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.
* TODO #19: New: Intrusive Red Black Tree :ENHANCEMENT:
Add intrusive red black tree.
Look also for AVL tree (NOTE: Is there a performance difference between the two?)
* TODO #18: Missing methods :ENHANCEMENT:
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
* TODO #17: New: Ressource handler :ENHANCEMENT:
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
until 585 years).
The ressource handler shall make an association between a HANDLE 64 bits and:
- how much real owners claim to own the ressource
(the ressource is only owned by the ressource handler, however
it acts as a delegate of the real owner),
- how much users keep a pointer to the ressource.
- pointer to the resource itself.
This may be a better alternative than shared_ptr & weak_ptr:
- reduce fragmentation,
- no cycle dependencies,
- shared_ref & weak_ref becomes only HANDLE,
- all ressources can be freed in one pass.
Needs lock free dictionnary or at least concurrent dictionnary.
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.
* 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.
** First step: backoff methods :DONE:
** Second step: lock free node pool : :DONE:
Done as m-c-mempool header.
** Third step: Implement generic lock free list on top of it.
The ABA problem is already taken into account by the memory alloctor
provided that the lock free list doesn't try to be smart.
backoff has be used when using CAS.
Concurrent insertion / insertion and insertion / deletion and deletion / deletion shall be crefully analyzed when taken into account.
Questions:
- singly or doubly or dual push?
- needs to be logically deleted : needs a previous field
(NULL if not logically deleted) ? TBC
* 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:
Enhancement of the memory allocation scheme to find way to deal properly with advanced allocators:
- non-default alignment requirements for types,
- instance-based allocator (may need instance based variable access),
- expected life of created type (temporary or permanent),
- stack based allocator,
- global variable access for allocator,
- maximum allocation before failure.
Most of theses are already more or less supported. Examples shall be created to show how to deal with this:
- alignement shall be implemented with the attributes of <stdalign.h>
However I sill don't know how to implement "instance-based allocator" which is what is missing.
The problem is how to give to methods context local information store within the container itself.
Update:
API transformation support enables "instance-based allocator" to be made easily.
Needs some formal operator in the oplist to support it fully and an example.
Can be supported using another API extension, some more operators and forcing some names:
* API_N: call like FUNC(obj->extra_data, type)
'obj' is a forced named corresponding to an alias to an object in the function.
Operator needed:
- EXTRA_DATA: Add an extra-data field wihtin the container. Defines the type of data.
It is a kind of object inheritance where the container inherits some extra data from its base.
* TODO #12: New: Atomic shared pointer :ENHANCEMENT:
Add an extension to the SHARED_PTR API:
- New type atomic_shared_ptr
- name_init_atomic_set (&atomic_shared_ptr, shared_ptr);
- name_init_set_atomic (shared_ptr, &atomic_shared_ptr);
- name_init_atomic_set_atomic (&atomic_shared_ptr, &atomic_shared_ptr);
- name_atomic_set (&atomic_shared_ptr, shared_ptr);
- name_set_atomic (shared_ptr, &atomic_shared_ptr);
- name_atomic_set_atomic (&atomic_shared_ptr, &atomic_shared_ptr);
- name_atomic_clear
No _ref or direct _init: we need to init first a normal shared_ptr then the atomic (TBC)
** _atomic_set method:
It can be implemented by incrementing the non atomic shared pointer reference,
then performs a compare_and_swap to the data of the atomic shared pointer,
finally decrement and dec/free the swapped previous data of the atomic like a normal shared pointer.
All 3 steps are safe.
** _set_atomic method:
It needs to perform the following atomic operation : <read the pointer, deref pointer and increment the pointed value> I don't known how to do it properly.
See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4162.pdf
Proposition for _set_atomic we store temporary NULL to the atomic_ptr struct to request an exclusive access to the data (this looks like a lock and other operations need to handle NULL) :
#+BEGIN_SRC C
void shared_ptr_set_atomic(ptr a, atomic_ptr *ptr)
{
// Get exclusive access to the data
p = atomic_load(ptr);
do {
if (p == NULL) {
// TODO: exponential backoff
p = atomic_load(ptr);
continue;
}
} while (!atomic_compare_exchange_weak(ptr, &p, NULL));
// p has exclusive access to the pointer
p->data->cpt ++;
a->data = p->data;
atomic_exchange (ptr, p);
}
#+END_SRC
This prevents using NULL which obliges atomic shared pointer to point to a created object...
Other alternative solution is to use the bit 0 to mark the pointer as being updated, preventing other from using it (TBC only clear):
#+BEGIN_SRC C
void shared_ptr_set_atomic(ptr a, atomic_ptr *ptr)
{
// Get exclusive access to the data
p = atomic_load(ptr);
do {
if ( (p&1) != 0) {
// TODO: exponential backoff
p = atomic_load(ptr);
continue;
}
} while (!atomic_compare_exchange_weak(ptr, &p, p|1));
// Exclusive access (kind of lock).
p->data->cpt ++;
a->data = p->data;
atomic_set (ptr, p);
}
#+END_SRC
Other implementation seems to have it hard to be lock-free: cf. https://github.com/llvm-mirror/libcxx/commit/5fec82dc0db3623546038e4a86baa44f749e554f
* TODO #5: New: Concurrent dictionary Container :ENHANCEMENT:
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.
Create a static array of N dictionnary with N mutex. Then to access the data will perform :
- compute hash of object,
- access high bits of hash and select which dictionnary shall have the data,
- lock it,
- perform classic access to the data (check if the compiler can properly optimize the hash computation),
- unlock it.
The property of the hash shall allow a good dispersion of the data across multiple locks, reducing the constraints on the lock. This implementation could be build easily upon the already existent dictionary.
To test.
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.
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
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:
** DONE _push_bulk
Test the capacity of the queue and push as much as possible in the queue
with one check of the atomic structure.
** DONE _pop_bulk
Test the capacity of the queue and push as much as possible in the queue
with one check of the atomic structure.
** DONE _push_force:
If the capacity of the queue is full, pop one element and push it:
push always succeed and the queue always keep the youngest element.
* DONE #21: Generic Binary serialization :ENHANCEMENT:
Based on issue #26 of https://github.com/P-p-H-d/mlib/issues/26
Some kind of "binary serialization" on the model of get_str/parse_str
could be possible. It would be a great feature from the application
point-of-view: binary representation is more bandwidth-efficient if
used on network communications.
It will be good to have import/export methods to the
XML/JSON/MSGPACK/PROTOBUF/BINARY format.
However, adding all of them on by one in the M*LIB containers
doesn't seem satisfactory.
Instead, adding a generic interface for the serialization of data
that may be customized by the user to perform the import/export of
objects in whatever format they want into what they want (FILE/memory/...).
To simplify it, this interface could only support one kind of import/export
per compilation unit.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

+34 -5
View File
@@ -1,18 +1,47 @@
# 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=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
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
GMP_DIR=
CPPFLAGS=-I..
LDFLAGS=-pthread -lgmp
LDFLAGS=-pthread
RM=rm -f
.SUFFIXES: .c .exe
.c.exe:
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) `cat config` $< -o $@
all:
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
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
$(RM) config-test.c config-test.exe
clean:
$(RM) *.exe *.s *~ *.o ./a.dat
$(RM) *.exe *.s *~ *.o ./a.dat config
+68
View File
@@ -0,0 +1,68 @@
#include <stdio.h>
#include "m-array.h"
#include "m-algo.h"
/* Define a dynamic array of int */
ARRAY_DEF(vector_int, int)
/* Register the oplist of this dynamic array globally */
#define M_OPL_vector_int_t() ARRAY_OPLIST(vector_int)
/* Define some standards algorithms on this dynamic array */
ALGO_DEF(vector_int, vector_int_t)
/* Define a dynamic array of bool */
ARRAY_DEF(vector_bool, bool, M_BOOL_OPLIST)
/* 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 */
ALGO_DEF(vector_bool, vector_bool_t)
/* ID function */
static bool id(bool x) { return x ; }
int main(void)
{
// Define, init (& later clear) myvector & tmp as vector_int_t
M_LET(myvector, tmp, vector_int_t) {
// Fill myvector with 3 int equal to 20
vector_int_fill_n(myvector, 3, 20);
// Fill tmp with 3 int equal to 33
vector_int_fill_n(tmp, 3, 33);
// Append all tmp in myvector
vector_int_splice(myvector, tmp);
// Fill tmp with 2 int equal to 10
vector_int_fill_n(tmp, 2, 10);
// Append all tmp in myvector
vector_int_splice(myvector, tmp);
// Display the result
printf("myvector contains:");
// In C11, the for loop can be simplified as :
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
ALGO_FOR_EACH(myvector, vector_int_t, M_PRINT, " ");
#else
for M_EACH(it, myvector, vector_int_t) {
printf(" %d", *it);
}
#endif
printf("\n");
}
// Same thing but with booleans
M_LET(myvector, tmp, vector_bool_t) {
vector_bool_fill_n(myvector, 3, false);
vector_bool_fill_n(tmp, 3, true);
vector_bool_splice(myvector, tmp);
vector_bool_fill_n(tmp, 2, false);
vector_bool_splice(myvector, tmp);
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) );
}
return 0;
}
+42
View File
@@ -0,0 +1,42 @@
#include "m-dict.h"
#include "m-array.h"
#include "m-algo.h"
#include "m-string.h"
/* Define a dictionnary (or hash_map or undordered_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 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 */
#define start_with(pattern, item) \
string_start_with_str_p((item).key, (pattern))
/* Micro macro to get the value of a pair of (key, value) */
#define get_value(out, item) ((out) = (item).value)
int main(void)
{
int s;
// 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' */
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);
/* Sum theses values */
ALGO_REDUCE(s, keys, vector_int_t, sum);
printf("Sum of elements starting with 'b' is: %d\n", s);
}
return 0;
}
+38
View File
@@ -0,0 +1,38 @@
#include "m-algo.h"
#include "m-array.h"
#include "m-string.h"
/* Define an array of int */
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.
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;
// Compute the sum of theses integers.
ALGO_REDUCE(sum, v, vector_int_t, add);
// Compute the product of theses integers.
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);
printf ("sum: %d\n"
"product: %d\n"
"dash str: %s\n", sum, product, string_get_cstr(s));
}
return 0;
}
+619
View File
@@ -0,0 +1,619 @@
/* Include M*LIB header */
#include "m-array.h"
#include "m-string.h"
#include "m-tuple.h"
/* Provide several examples of different types usage with array,
with the oplist to use for each case.
Each time it creates and initializes an array,
fills it with some number,
computes its sum,
and returns it.
This is done for several basic C types:
- integers,
- floats,
- pointers,
- structures,
- tuples
*/
/* 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.
*/
ARRAY_DEF(r_bool, bool)
/* Basic usage of the type */
static int
test_bool(int n)
{
r_bool_t array;
r_bool_init(array);
for(int i = 0; i < n; i++) {
r_bool_push_back(array, i & 1);
}
int s = 0;
for(int i = 0; i < n; i++) {
s += *r_bool_get(array, i);
}
r_bool_clear(array);
return s;
}
/* Same with type char */
ARRAY_DEF(r_char, char)
static int
test_char(int n)
{
r_char_t array;
r_char_init(array);
for(int i = 0; i < n; i++) {
r_char_push_back(array, i & 255);
}
int s = 0;
for(int i = 0; i < n; i++) {
s += *r_char_get(array, i);
}
r_char_clear(array);
return s;
}
/* Same with type signed int. */
ARRAY_DEF(r_int, signed int)
static int
test_int(int n)
{
r_int_t array;
r_int_init(array);
for(int i = 0; i < n; i++) {
r_int_push_back(array, i);
}
int s = 0;
for(int i = 0; i < n; i++) {
s += *r_int_get(array, i);
}
r_int_clear(array);
return s;
}
/* Same with type signed int.
But with an explicit oplist.
This generates exactly the same code than r_int
*/
ARRAY_DEF(r_int2, signed int, M_DEFAULT_OPLIST)
static int
test_int2(int n)
{
r_int2_t array;
r_int2_init(array);
for(int i = 0; i < n; i++) {
r_int2_push_back(array, i);
}
int s = 0;
for(int i = 0; i < n; i++) {
s += *r_int2_get(array, i);
}
r_int2_clear(array);
return s;
}
/* Same with type unsigned long long */
ARRAY_DEF(r_ullong, unsigned long long)
static int
test_ullong(int n)
{
r_ullong_t array;
r_ullong_init(array);
for(int i = 0; i < n; i++) {
r_ullong_push_back(array, i);
}
int s = 0;
for(int i = 0; i < n; i++) {
s += *r_ullong_get(array, i);
}
r_ullong_clear(array);
return s;
}
/* Same with type float */
ARRAY_DEF(r_float, float)
static int
test_float(int n)
{
r_float_t array;
r_float_init(array);
for(int i = 0; i < n; i++) {
r_float_push_back(array, i/4.0);
}
float s = 0;
for(int i = 0; i < n; i++) {
s += *r_float_get(array, i);
}
r_float_clear(array);
return s;
}
/* Same with type double and an explicit oplist*/
ARRAY_DEF(r_double, double, M_DEFAULT_OPLIST)
static int
test_double(int n)
{
r_double_t array;
r_double_init(array);
for(int i = 0; i < n; i++) {
r_double_push_back(array, i/4.0);
}
float s = 0;
for(int i = 0; i < n; i++) {
s += *r_double_get(array, i);
}
r_double_clear(array);
return s;
}
/* Helper function strdup */
static char *my_strdup(const char *p)
{
size_t s = strlen(p);
char *d= malloc(s+1);
if(!d) abort();
strcpy(d, p);
return d;
}
/* Same with type const char *, representing a contant string.
We *** need *** an explicit oplist to tell M*LIB
to consider the type as a constant 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
string equality.
*/
ARRAY_DEF(r_cstring, const char *, M_CSTR_OPLIST)
static int
test_cstring(int n)
{
r_cstring_t array;
r_cstring_init(array);
for(int i = 0; i < n; i++) {
char buffer[10];
// Create a string from the integer
sprintf(buffer, "%d", i);
// We need to make an explicit copy of the string
// since it is not supported by the basic type.
char *p = my_strdup(buffer);
// Push the copy in the container.
r_cstring_push_back(array, p);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get back the string
const char *p = *r_cstring_get(array, i);
// Convert it to integer
int j = atoi(p);
s += j;
}
// We also need a special unalloc pass
// to free all constant strings we have allocated.
for(int i = 0; i < n; i++) {
const char *p = *r_cstring_get(array, i);
free((void*)(uintptr_t)p);
}
r_cstring_clear(array);
return s;
}
/* Same with type string_t of M*LIB, representing a variable 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
give it to array_def! */
ARRAY_DEF(r_string, string_t)
static int
test_string(int n)
{
r_string_t array;
string_t str;
r_string_init(array);
string_init (str);
for(int i = 0; i < n; i++) {
// create a string from an integer
string_printf(str, "%d", i);
// No need to make a copy in the container!
r_string_push_back(array, str);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get back the string and convert it back to an integer
int j = atoi(string_get_cstr(*r_string_get(array, i)));
s += j;
}
// No need to explicit dealloc !
string_clear(str);
r_string_clear(array);
return s;
}
/* Same with type string_t of M*LIB, representing a variable string
and its explicit oplist. And said above, it generates exactly the
same code. */
ARRAY_DEF(r_string2, string_t, STRING_OPLIST)
/* Same with type 'volatile unsigned int *'
The array stores pointers to another integer,
allocated somewhere else.
We need to tell M*LIB to handle the basic type
as pointers without caring for what the value of
the pointer is.
So here, we **need** to specify the oplist of the type
as M_PTR_OPLIST.
*/
ARRAY_DEF(r_vintptr, volatile unsigned int *, M_PTR_OPLIST)
static int
test_vintptr(int n)
{
r_vintptr_t array;
// Allocate a secondary table to store the value.
unsigned *tab = calloc(n, sizeof(volatile unsigned int));
if (!tab) abort();
r_vintptr_init(array);
for(int i = 0; i < n; i++) {
tab[i] = i*i - i;
// Push the pointer to this integer in the array
r_vintptr_push_back(array, &tab[i]);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get the pointer to the integer.
volatile unsigned *p = *r_vintptr_get(array, i);
s += *p;
}
r_vintptr_clear(array);
free(tab);
return s;
}
/* Same with a structure type.
We need to tell M*LIB to handle the basic type
as POD;
So here, we **need** to specify the oplist of the type
as M_POD_OPLIST.
*/
struct rock_me_out {
int n;
float other;
};
ARRAY_DEF(r_rockme, struct rock_me_out, M_POD_OPLIST)
static int
test_rockme(int n)
{
r_rockme_t array;
r_rockme_init(array);
for(int i = 0; i < n; i++) {
struct rock_me_out rock;
rock.n = i*i - i;
// Push the struct in the array
r_rockme_push_back(array, rock);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get the pointer to the struct
struct rock_me_out *p = r_rockme_get(array, i);
s += p->n;
}
r_rockme_clear(array);
return s;
}
/* Same with a structure type defined with [1]:
We need to tell M*LIB to handle the basic type
as a special array;
So here, we **need** to specify the oplist of the type
as M_A1_OPLIST.
*/
typedef struct rock_me_in {
int n;
float other;
} rock_me_in[1];
ARRAY_DEF(r_rockme2, rock_me_in, M_A1_OPLIST)
static int
test_rockme2(int n)
{
r_rockme2_t array;
r_rockme2_init(array);
for(int i = 0; i < n; i++) {
rock_me_in rock;
rock->n = i*i - i;
r_rockme2_push_back(array, rock);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get the pointer to the struct.
rock_me_in *p = r_rockme2_get(array, i);
s += (*p)->n;
}
r_rockme2_clear(array);
return s;
}
/* Same with a structure type defined with [1] and a global registeration.
We need to tell M*LIB to handle the basic type
as a special array.
To do so, 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.
Then we define the array, giving it only the type.
M*LIB will look at the global registered oplist of the type, we don't
need to give it explictly.
Global registeration makes easier code.
Registeration should be done when the type is defined.
*/
#define M_OPL_rock_me_in() M_A1_OPLIST
ARRAY_DEF(r_rockme2b, rock_me_in)
static int
test_rockme2b(int n)
{
r_rockme2b_t array;
r_rockme2b_init(array);
for(int i = 0; i < n; i++) {
rock_me_in rock;
rock->n = i*i - i;
r_rockme2b_push_back(array, rock);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get the pointer to the struct.
rock_me_in *p = r_rockme2b_get(array, i);
s += (*p)->n;
}
r_rockme2b_clear(array);
return s;
}
/* 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.
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.
*/
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))
static int
test_rockme3(int n)
{
r_rockme3_t array;
rock_you_t x;
r_rockme3_init(array);
rock_you_init(x);
for(int i = 0; i < n; i++) {
rock_you_set_n(x, i*i - i);
r_rockme3_push_back(array, x);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get the pointer to the structure containing the integer.
rock_you_t *p = r_rockme3_get(array, i);
s += (*p)->n;
}
r_rockme3_clear(array);
rock_you_clear(x);
return s;
}
/* 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.
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.
Then we define the array, giving it only the type.
M*LIB will look at the global registered oplist of the type, we don't
need to give it explictly.
Global registeration makes easier code.
*/
TUPLE_DEF2(rock_us, (n, int), (other, float))
#define M_OPL_rock_us_t() TUPLE_OPLIST(rock_us, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
ARRAY_DEF(r_rockme4, rock_us_t)
static int
test_rockme4(int n)
{
r_rockme4_t array;
rock_us_t x;
r_rockme4_init(array);
rock_us_init(x);
for(int i = 0; i < n; i++) {
rock_us_set_n(x, i*i - i);
r_rockme4_push_back(array, x);
}
int s = 0;
for(int i = 0; i < n; i++) {
// Get the pointer to the structure containing the integer.
rock_us_t *p = r_rockme4_get(array, i);
s += (*p)->n;
}
r_rockme4_clear(array);
rock_us_clear(x);
return s;
}
int main (int argc, const char *argv[])
{
int n = argc == 1 ? 10 : atoi(argv[1]);
int s;
s = test_bool(n);
printf ("S[bool] = %d\n", s);
s = test_char(n);
printf ("S[char] = %d\n", s);
s = test_int(n);
printf ("S[int] = %d\n", s);
s = test_int2(n);
printf ("S[int2] = %d\n", s);
s = test_ullong(n);
printf ("S[ullong] = %d\n", s);
s = test_float(n);
printf ("S[float] = %d\n", s);
s = test_double(n);
printf ("S[double] = %d\n", s);
s = test_cstring(n);
printf ("S[cstring] = %d\n", s);
s = test_string(n);
printf ("S[string] = %d\n", s);
s = test_vintptr(n);
printf ("S[vintptr] = %d\n", s);
s = test_rockme(n);
printf ("S[rockme] = %d\n", s);
s = test_rockme2(n);
printf ("S[rockme2] = %d\n", s);
s = test_rockme2b(n);
printf ("S[rockme2b] = %d\n", s);
s = test_rockme3(n);
printf ("S[rockme3] = %d\n", s);
s = test_rockme3(n);
printf ("S[rockme4] = %d\n", s);
exit(0);
}
+2 -2
View File
@@ -1,14 +1,14 @@
#include <stdlib.h>
#include "m-array.h"
// Let's define an array of 'int' named 'int'
// Let's define an array of 'int' named 'array_int'
ARRAY_DEF(array_int, int)
const int n = 100000;
int main(void)
{
// Declare and initilize the array
// Declare and initialize the array
array_int_t x;
array_int_init(x);
+13 -1
View File
@@ -1,9 +1,13 @@
#if HAVE_GMP
#include <gmp.h>
#include "m-array.h"
#include "m-algo.h"
/* Define an array of mpz_t */
ARRAY_DEF(array_mpz, mpz_t, M_CLASSIC_OPLIST(mpz))
/* Define some algorithm functions on array_mpz_t */
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){
@@ -19,14 +23,22 @@ int main(void)
mpz_init_set_ui(z, 1);
array_mpz_t a;
array_mpz_init(a);
array_mpz_push_back(a, z);
for(size_t i = 2 ; i < 1000; i++) {
mpz_mul_ui(z, z, i);
array_mpz_push_back(a, z);
}
/* z = sum (a[i]^2) */
/* Compute z = sum (a[i]^2) */
array_mpz_map_reduce (&z, a, my_mpz_inc, my_mpz_sqr);
gmp_printf ("Z=%Zd\n", z);
array_mpz_clear(a);
mpz_clear(z);
}
#else
// Nothing to do
int main(void) { return 0; }
#endif
+116
View File
@@ -0,0 +1,116 @@
#include "m-array.h"
#include "m-string.h"
/* This example show how to use complex structure with array
embedding another library */
/* This is a typical trivial library with its interface */
typedef struct lib_ext_struct {
int id;
// Other data may be added
} lib_ext_struct;
/* Method to create a duplicate of the object.
The new object is heap allocated */
static lib_ext_struct *lib_ext_struct_Duplicate(const lib_ext_struct *obj)
{
lib_ext_struct *p = malloc(sizeof(lib_ext_struct));
if (!p) abort();
p->id = obj->id;
return p;
}
/* Method to delete any object */
static void lib_ext_struct_Delete(lib_ext_struct *obj)
{
free(obj);
}
/* This is the complex structure */
typedef struct {
uint32_t id;
string_t type;
lib_ext_struct* properties;
} data_node;
/* This method shall initialize the object data_node to
the init state.
It takes as first argument the object to initialize,
and since it takes by reference through a pointer,
it is compatible with 'API_2' convention for oplist */
static void data_node_init(data_node *obj)
{
obj->id = 0;
string_init(obj->type);
obj->properties = NULL;
}
/* This method shall initialize the object data_node to
the same state as the 'src' object (creating a copy, a duplicate) .
It takes as first argument the object to initialize,
and as second argument the source object.
It takes both object by reference through pointers,
as such it is compatible with 'API_6' convention for oplist */
static void data_node_init_set(data_node *obj, const data_node *src)
{
obj->id = src->id;
string_init_set(obj->type, src->type);
if (src->properties)
obj->properties = lib_ext_struct_Duplicate(src->properties);
else
obj->properties = NULL;
}
/* This method shall set the object data_node to
the same state as the 'src' object (creating a copy, a duplicate) .
THe object was already initialized.
It takes as first argument the object to initialize,
and as second argument the source object.
It takes both object by reference through pointers,
as such it is compatible with 'API_6' convention for oplist */
static void data_node_set(data_node *obj, const data_node *src)
{
obj->id = src->id;
string_set(obj->type, src->type);
if (obj->properties)
lib_ext_struct_Delete(obj->properties);
if (src->properties)
obj->properties = lib_ext_struct_Duplicate(src->properties);
else
obj->properties = NULL;
}
/* This method shall clear the object data_node to
the cleared state (aka it shall free any resource).
It takes as first argument the object to initialize,
and since it takes by reference through a pointer,
it is compatible with 'API_2' convention for oplist */
static void data_node_clear(data_node *obj)
{
string_clear(obj->type);
if (obj->properties)
lib_ext_struct_Delete(obj->properties);
}
/* Create a dynamic array of 'data_node' named array_data_node_t
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.
*/
ARRAY_DEF(/* the array prefix */ array_data_node,
/* the object type */ data_node,
/* the object oplist */ (INIT(API_2(data_node_init)),
SET(API_6(data_node_set)),
INIT_SET(API_6(data_node_init_set)),
CLEAR(API_2(data_node_clear))))
/* Define a global array with the created type */
array_data_node_t global_array;
int main(void)
{
/* Call the created method */
array_data_node_init(global_array);
/* Do stuff... */
array_data_node_clear(global_array);
}
+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));
}
}
+65
View File
@@ -0,0 +1,65 @@
#include "m-bptree.h"
#include "m-string.h"
// Define a map int -> string named map_employee_id
// 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 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)
int main(void)
{
map_employee_id_t Employees;
map_employee_id_init(Employees);
// Assign the map with some data
map_employee_id_set_at(Employees, 17425, STRING_CTE("Mike"));
map_employee_id_set_at(Employees, 7147, STRING_CTE("Tango"));
map_employee_id_set_at(Employees, 841, STRING_CTE("Charlie"));
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"));
printf("Number of employees: %zu\n", map_employee_id_size(Employees));
// Iterate over the employee list
printf("\nList of employees (sorted by id):\n");
map_employee_id_it_t it;
for(map_employee_id_it(it, Employees); !map_employee_id_end_p(it); map_employee_id_next(it)) {
// Get a pointer to this employee from the iterator
const map_employee_id_itref_t *e = map_employee_id_cref(it);
// Print it
printf ("%d: %s\n", *(e->key_ptr), string_get_cstr(*(e->value_ptr)));
}
// Now, let's go using some macros!
// Let's create a reverse map
M_LET(Employees_r, map_employee_name_t) {
// Let's fill in the reverse map with each employee
// (using macro M_EACH)
for M_EACH(e, Employees, map_employee_id_t) {
map_employee_name_set_at(Employees_r, *(e->value_ptr), *(e->key_ptr));
}
// Iterate over the employee list
printf("\nList of employees (sorted by name):\n");
for M_EACH(e, Employees_r, map_employee_name_t) {
printf ("%d: %s\n", *(e->value_ptr), string_get_cstr(*(e->key_ptr)));
}
// Print
printf("\nElisabeth has id = %d\n", *map_employee_name_get(Employees_r, STRING_CTE("Elisabeth")));
} /* Employees_r is cleared beyond this point */
map_employee_id_clear(Employees);
return 0;
}
+36
View File
@@ -0,0 +1,36 @@
#include "m-core.h"
// Stubs defined for the example. Real code will use soundio library.
struct SoundIo { int x; };
struct SoundIoDevice { int x; };
struct SoundIoOutStream { int x; };
static struct SoundIo *soundio_create(void) { return (struct SoundIo *) malloc(sizeof(struct SoundIo)); }
static void soundio_destroy(struct SoundIo *s) { free(s); }
static struct SoundIoDevice *soundio_get_device(struct SoundIo *io, int def) { (void) io; (void) def; return (struct SoundIoDevice *) malloc(sizeof(struct SoundIoDevice)); }
static void soundio_device_unref(struct SoundIoDevice *s) { free(s); }
static struct SoundIoOutStream *soundio_outstream_create(struct SoundIoDevice *device) { (void) device ; return (struct SoundIoOutStream *) malloc(sizeof(struct SoundIoOutStream)); }
static void soundio_outstream_destroy(struct SoundIoOutStream *s) { free(s); }
static bool soundio_wait_events(struct SoundIo *s) { (void) s; return false; }
// End of stubs
int main(void)
{
int err = 1;
/* Example of using M_LET_IF macro to simplify writing error handling code.
The following code creates some object, test if the object creation succeeds, register the destructor, and print an error if something went wrong
*/
M_LET_IF( struct SoundIo *soundio = soundio_create(), soundio != 0 , soundio_destroy(soundio) , fprintf(stderr, "out of memory for soundio\n") )
M_LET_IF(struct SoundIoDevice *device = soundio_get_device(soundio, -1), device != 0, soundio_device_unref(device), fprintf(stderr, "out of memory for device\n"))
M_LET_IF(struct SoundIoOutStream *outstream = soundio_outstream_create(device), outstream != 0, soundio_outstream_destroy(outstream), fprintf(stderr, "out of memory for stream\n")) {
err = 0;
bool cont = true;
while (cont)
cont = soundio_wait_events(soundio);
}
return err;
}
+1 -1
View File
@@ -5,7 +5,7 @@
#include "m-string.h"
// Define a dictionnary of string --> int
// named 'str'
// named 'dict_str'
DICT_DEF2(dict_str, string_t, STRING_OPLIST, int, M_DEFAULT_OPLIST)
int main(void)
+2 -2
View File
@@ -15,7 +15,7 @@ int main(void) {
char *k = dict_m32_get(h, 10); // No 10 in h, so k == NULL
int is_missing = (k != NULL); // true
assert (is_missing);
dict_m32_remove(h, 5); // h is now empty
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)) {
struct dict_m32_pair_s *item = dict_m32_ref(it);
@@ -33,7 +33,7 @@ int main(void) {
char *k = dict_m32_get(h, 10); // k == NULL
int is_missing = (k != NULL); // true
assert (is_missing);
dict_m32_remove(h, 5); // h is now empty
dict_m32_erase(h, 5); // h is now empty
for M_EACH(item, h, M32_OPLIST) { // traverse each item
item->value = 1; // Set its value to 1
}
+7 -6
View File
@@ -5,8 +5,9 @@
#include "m-dict.h"
#include "m-string.h"
DICT_DEF2(dict_map, char, M_DEFAULT_OPLIST, int, M_DEFAULT_OPLIST)
// Define a dictionary (hashmap) from 'char' to 'int'
DICT_DEF2(dict_map, char, int)
int main(void)
{
dict_map_t mp;
@@ -50,11 +51,11 @@ int main(void)
printf("Enter the mapped string to be deleted: ");
string_fgets (str, stdin, STRING_READ_PURE_LINE);
s = atoi(string_get_cstr(str));
dict_map_remove(mp, s);
dict_map_erase(mp, s);
break;
case 3:
printf("Size of Map: %lu\n", (unsigned long) dict_map_size(mp) );
printf("Size of Map: %zu\n", dict_map_size(mp) );
break;
case 4:
@@ -81,7 +82,7 @@ int main(void)
}
break;
case 7:
case 6:
dict_map_clear(mp);
string_clear (str);
exit(0);
@@ -89,7 +90,7 @@ int main(void)
default:
printf("Wrong Choice\n");
break;
}
}
}
+14 -5
View File
@@ -5,14 +5,23 @@
/* program that reads text from standard-input,
and prints the total number of distinct words found in the text.
*/
DICT_SET_DEF2(dict_str, string_t, STRING_OPLIST)
/* Definition of a set (hashset) of unique string_t */
DICT_SET_DEF(dict_str, string_t, STRING_OPLIST)
int main(void)
{
// Define word as a string_t
M_LET(word, STRING_OPLIST)
M_LET(wordcount, DICT_SET_OPLIST(dict_str, STRING_OPLIST)) {
while (string_fget_word(word, " \t\n,.!;:?", stdin))
dict_str_set_at(wordcount, word);
printf ("Words: %lu\n", dict_str_size(wordcount));
// Define wordcount as a set of string_t
M_LET(wordcount, DICT_SET_OPLIST(dict_str, STRING_OPLIST)) {
// Read a word from the standard input
while (string_fget_word(word, " \t\n,.!;:?", stdin)) {
// Push this word in the set.
// Do nothing if it already exists.
dict_str_push(wordcount, word);
}
// Print the number of words of the standard input.
printf ("Words: %zu\n", dict_str_size(wordcount));
}
}
+56
View File
@@ -0,0 +1,56 @@
#include <stdio.h>
#include "m-string.h"
#include "m-array.h"
#include "m-dict.h"
// Define an array of size_t
ARRAY_DEF(array_size, size_t)
// Register the oplist of this array globaly
#define M_OPL_array_size_t() ARRAY_OPLIST(array_size)
// Define a dictionary (hashmap) of string_t to array of size_t
DICT_DEF2(map_pos, string_t, array_size_t)
// Register the oplist of this dictionary (hashmap)
#define M_OPL_map_pos_t() DICT_OPLIST(map_pos, STRING_OPLIST, ARRAY_OPLIST(array_size))
int main(int argc, const char *argv[])
{
if (argc != 2) {
printf("USAGE: %s filename\n", argv[0]);
exit(0);
}
// Define word as a string_t
M_LET(word, string_t)
// Define positions as a map of string_t-->array of size_t
M_LET(positions, map_pos_t) {
// Open the file
FILE *f = fopen(argv[1], "rt");
if (!f) {
fprintf(stderr, "ERROR: Cannot open %s.\n", argv[1]);
return 1;
}
// 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_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));
}
// Close the file
fclose(f);
// Print the words and where they are:
for M_EACH(pair, positions, map_pos_t) {
string_fputs(stdout, pair->key);
for M_EACH(pos, pair->value, array_size_t) {
printf(" %zu", *pos);
}
printf("\n");
}
} // All created objects are destroyed beyond this point
return 0;
}
+255
View File
@@ -0,0 +1,255 @@
#include <stdio.h>
#include <stdint.h>
#include "m-array.h"
#include "m-dict.h"
#include "m-string.h"
#include "m-algo.h"
/* Based on:
* Easy Perfect Minimal Hashing
* By Steve Hanov. Released to the public domain.
* http://stevehanov.ca/blog/index.php?id=119
*
* Based on:
* Edward A. Fox, Lenwood S. Heath, Qi Fan Chen and Amjad M. Daoud,
* "Practical minimal perfect hash functions for large databases", CACM, 35(1):105-121
*
* also a good reference:
* Compress, Hash, and Displace algorithm by Djamal Belazzougui,
* Fabiano C. Botelho, and Martin Dietzfelbinger
*/
/* 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)
// Define an array of integer to store the value and register it.
ARRAY_DEF(array_value, uint32_t) // Start from 1. 0 is 'None'
#define M_OPL_array_value_t() ARRAY_OPLIST(array_value)
// Define an array of integer to store the seed and register it.
ARRAY_DEF(array_seed, int32_t)
#define M_OPL_array_seed_t() ARRAY_OPLIST(array_seed)
// Define algorithms on array_seed
ALGO_DEF(array_seed, array_seed_t)
// Define an array of constant string that are ordered by their size.
ARRAY_DEF(array_cstr, const char *, M_CSTR_OPLIST)
// Register it globally but with a custom CMP operator
static inline int array_cstr_cmp(const array_cstr_t a, const array_cstr_t b) {
// We compare only the size
size_t sa = array_cstr_size(a);
size_t sb = array_cstr_size(b);
return (sa > sb) ? -1 : (sa < sb);
}
#define M_OPL_array_cstr_t() M_OPEXTEND(ARRAY_OPLIST(array_cstr, M_CSTR_OPLIST), CMP(array_cstr_cmp))
// Define an array of array of constant string, and some algo over this container
ARRAY_DEF(array_bucket, array_cstr_t)
#define M_OPL_array_bucket_t() ARRAY_OPLIST(array_bucket, M_OPL_array_cstr_t() )
ALGO_DEF(array_bucket, array_bucket_t)
// Define an array of string to save the input.
ARRAY_DEF(array_string, string_t)
#define M_OPL_array_string_t() ARRAY_OPLIST(array_string, M_OPL_string_t())
/* The algorithm may not converge on all inputs if the hash function
* doesn't randomly distribute the inputs:
* str1 != str2 ==> \exist seed \such_as hash(seed,str1) != hash(seed, str2)
* The first hash function below doesn't provide the needed property for
* inputs with two words 'a' and 'c'
* The second one is more robust but may still have this issue.
*/
static uint32_t hash(int32_t seed, const char str[])
{
#if 0
if (seed == 0) seed = 0x01000193;
while (*str) {
seed = ((seed * 0x01000193) ^ *str);
str++;
}
return seed;
#else
if (seed == 0) seed = 0x811C9DC5;
while (*str) {
seed = (seed ^ *str) * 16777619;
str++;
}
return seed ^ (seed >> 16);
#endif
}
// Step 1: place all key keys into buckets
static void
CreateMinimalPerfectHash1(array_seed_t seed, array_value_t value,
array_bucket_t bucket,
const dict_mph_t dict)
{
size_t size = dict_mph_size (dict);
array_value_resize(value, size);
array_seed_resize(seed, size);
array_bucket_resize(bucket, size);
for M_EACH(item, dict, dict_mph_t) {
size_t i = hash(0, item->key) % size;
array_cstr_push_back (*array_bucket_get (bucket, i), item->key);
}
}
// Step 2: Sort the buckets and process the ones with the most items first.
static void
CreateMinimalPerfectHash2(array_seed_t seed, array_value_t value,
array_bucket_t bucket,
const dict_mph_t dict)
{
size_t size = dict_mph_size (dict);
array_bucket_sort(bucket);
M_LET(slots, array_seed_t) {
for M_EACH(b, bucket, array_bucket_t) {
if (array_cstr_size(*b) <= 1)
break;
size_t d = 1;
/* Repeatedly try different values of d until we find a hash function
that places all items in the bucket into free slots.
This may loop forever on some inputs if the hash function is not good
enought. */
for(bool cont = true; cont ; ) {
cont = false;
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)){
d++;
cont = true;
break;
}
array_seed_push_back (slots, s);
}
}
// Fill in the seed & value with the computed value
array_seed_set_at(seed, hash(0, *array_cstr_get(*b, 0)) % size, d);
d = 0;
for M_EACH(it, *b, array_cstr_t) {
array_value_set_at(value,
*array_seed_get(slots, d),
*dict_mph_get(dict, *it));
d++;
}
}
}
}
/* Step 3:
* Only buckets with 1 item remain. Process them more quickly by directly
* placing them into a free slot. Use a negative value of d to indicate
* this.
*/
static void
CreateMinimalPerfectHash3(array_seed_t seed, array_value_t value,
array_bucket_t bucket,
const dict_mph_t dict)
{
size_t size = dict_mph_size (dict);
M_LET(freelist, array_seed_t) {
// Get a list of available slot
for(size_t i = 0; i < size; i++)
if (*array_value_get(value, i) == 0)
array_seed_push_back(freelist, i);
for M_EACH(b, bucket, array_bucket_t) {
if (array_cstr_size(*b) != 1)
continue;
int32_t slot;
array_seed_pop_back(&slot, freelist);
/*We subtract one to ensure it's negative even if the zeroeth slot was
used. */
array_seed_set_at (seed, hash(0, *array_cstr_get(*b, 0)) % size,
-slot-1);
array_value_set_at(value, slot, *dict_mph_get(dict, *array_cstr_get(*b, 0)));
}
}
}
static void
CreateMinimalPerfectHash(array_seed_t seed, array_value_t value,
const dict_mph_t dict)
{
M_LET(bucket, array_bucket_t) {
CreateMinimalPerfectHash1(seed, value, bucket, dict);
CreateMinimalPerfectHash2(seed, value, bucket, dict);
CreateMinimalPerfectHash3(seed, value, bucket, dict);
}
}
static void
dict_read_from_file(dict_mph_t dict, array_string_t arr, const char filename[])
{
FILE *f = fopen(filename, "rt");
if (!f) {
fprintf(stderr, "ERROR: Cannot open %s\n", filename);
exit(2);
}
uint32_t line = 1;
M_LET(str, string_t) {
while (!feof(f) && !ferror(f)) {
string_fgets(str, f, STRING_READ_PURE_LINE);
string_strim(str);
if (!string_empty_p(str)) {
// 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++;
}
}
}
fclose(f);
}
static uint32_t
perfect_hash_lockup(array_seed_t seed, array_value_t value,
const char key[])
{
int32_t s = *array_seed_get(seed, hash(0, key) % array_seed_size(seed));
if (s < 0)
return *array_value_get(value, -s-1);
else
return *array_value_get(value, hash(s, key) % array_value_size(value));
}
static void
test(array_seed_t seed, array_value_t value, dict_mph_t dict)
{
for M_EACH(item, dict, dict_mph_t) {
const char *key = item->key;
uint32_t v = perfect_hash_lockup(seed, value, key);
if (v != item->value) {
fprintf(stderr, "ERROR for %s: %u VS %u\n", key, v, item->value);
}
}
}
int main(int argc, const char *argv[])
{
// Create arr as array_string_t, dict as dist_mph_t and seed as array_seed_t
M_LET(arr, array_string_t) M_LET(dict, dict_mph_t) M_LET(seed, array_seed_t)
// and value as array_value_t
M_LET(value, array_value_t) {
const char *filename = (argc > 1) ? argv[1] :"/usr/share/dict/words";
dict_read_from_file(dict, arr, filename);
CreateMinimalPerfectHash(seed, value, dict);
test(seed, value, dict);
}
return 0;
}
+9 -4
View File
@@ -4,6 +4,7 @@
#include "m-array.h"
#include "m-string.h"
// Define an array of integer
ARRAY_DEF(array_int, int)
typedef struct {
@@ -25,7 +26,7 @@ static void tape_devance(tape_t tape) { if (tape->pos > 0) tape->pos--; }
typedef struct {
string_t code;
array_int_t bracket_map; // Should use map when possible.
array_int_t bracket_map;
} program_t[1];
static void program_init(program_t p, string_t text) {
@@ -47,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_set_at2 (p->bracket_map, left, right);
array_int_set_at2 (p->bracket_map, right, left);
*array_int_safe_get (p->bracket_map, left) = right;
*array_int_safe_get (p->bracket_map, right) = left;
}
pc++;
@@ -98,7 +99,11 @@ static void program_run(program_t p){
static void read_file(string_t str, const string_t filename) {
FILE *f = fopen(string_get_cstr(filename), "rt");
if (!f) abort();
if (!f) {
fprintf(stderr, "ERROR: Cannot open %s\n", string_get_cstr(filename));
exit(2);
}
// Read the full FILE in the string
string_fgets (str, f, STRING_READ_FILE);
fclose(f);
}
+9 -2
View File
@@ -1,3 +1,5 @@
#if HAVE_GMP
#include <stdio.h>
#include <gmp.h>
@@ -50,14 +52,19 @@ int main(void)
// Dictionary iterator are pair (key,value)
if (my_integer_n_p(p->value)) {
printf ("It is a long long, value = %lld\n",
*my_integer_get_n(p->value));
*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_get_z(p->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
+4 -2
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"
@@ -12,7 +12,9 @@ unsigned long long rand_seed;
#include "m-variant.h"
/* This example will show how to create JSON-like files.
This is a JSON **like** syntax, not exactly JSON format */
This is a JSON **like** syntax, not exactly JSON format.
For an example with JSON format, see https://github.com/P-p-H-d/mjsonlib
*/
/* First let's handle the OUT/IN functions of boolean */
static inline void boolean_out_str(FILE *f, bool b)
+94
View File
@@ -0,0 +1,94 @@
#include <stdio.h>
#include "m-tuple.h"
#include "m-array.h"
#include "m-string.h"
#include "m-list.h"
#include "m-buffer.h"
/* This example chains the structure in different ways in
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)
ARRAY_DEF(symbol_list, symbol_t)
#define M_OPL_symbol_list_t() ARRAY_OPLIST(symbol_list, M_OPL_symbol_t())
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)
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)
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() )
TUPLE_DEF2(my_triple_tuple, (name, string_t), (inner_tuple, my_tuple_t), (list, list_of_tuple_of_tuple_t) )
#define M_OPL_my_triple_tuple_t() TUPLE_OPLIST(my_triple_tuple, STRING_OPLIST, M_OPL_my_tuple_t(), M_OPL_list_of_tuple_of_tuple_t())
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())
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_DEF2(mlib_points, (first_ref, mlib_point_ptr, M_PTR_OPLIST),
(second_ref, mlib_point_ptr, M_PTR_OPLIST),
(third, mlib_point_t))
#define M_OPL_mlib_points_t() \
TUPLE_OPLIST(mlib_points, M_PTR_OPLIST, M_PTR_OPLIST, M_OPL_mlib_point_t())
static void let2(void)
{
// Initialize p1 as mlib_point_t with (4,4)
// and p2 as mlib_point_t with (5,5)
// and pair as mlib_point_t with default value
M_LET((p1, 4, 4), (p2, 5, 5), mlib_point_t) {
M_LET(pair, mlib_points_t) {
pair->first_ref = p1;
pair->second_ref = p2;
pair->third->x = pair->third->y = 6;
assert(pair->first_ref->x == 4);
p1->x = 10;
assert(pair->first_ref->x == 10);
assert(pair->third->x == 6);
}
}
}
static void let(void)
{
// Let's initialize all the declared types
M_LET(s, symbol_t)
M_LET(l, symbol_list_t)
M_LET(r,record_t)
M_LET(tup, my_tuple_t)
M_LET(l2, my_list_of_tuple_t)
M_LET(tuptup, my_tuple_of_tuple_t)
M_LET(ltuptup, list_of_tuple_of_tuple_t)
M_LET(tuptuptup, my_triple_tuple_t)
M_LET(junc, my_junction_t)
{
printf("Init ok\n");
}
}
int main(void)
{
let();
let2();
}
+31
View File
@@ -0,0 +1,31 @@
#include <stdio.h>
#include "m-array.h"
#include "m-string.h"
// Let's create an array of string_t and register it globaly
ARRAY_DEF(vector_string, string_t)
#define M_OPL_vector_string_t() ARRAY_OPLIST(vector_string, STRING_OPLIST)
int main(void)
{
// Let's define a new string named str
M_LET(str, string_t)
// Let's define msg as a vector_array_t
M_LET( (msg, STRING_CTE("Hello"), STRING_CTE("C"), STRING_CTE("World!"), STRING_CTE("Let's"), STRING_CTE("discover"), STRING_CTE("M*LIB!")), vector_string_t) {
// Iterate over all words of the array msg
for M_EACH(word, msg, vector_string_t) {
// Cat the current word into the target string
string_cat(str, *word);
// Also add a space character
string_push_back(str, ' ');
}
// Let's define another string and set it to a formatted value.
M_LET( (count, "\nTo display this it uses \"vector\" of %zu strings!", vector_string_size(msg)), string_t) {
string_cat(str, count);
}
// Print the result
printf("%s\n", string_get_cstr(str) );
}
return 0;
}
+10 -8
View File
@@ -4,6 +4,15 @@
#include "m-rbtree.h"
// Let's define one utility function.
void *xmalloc(size_t n);
void *xmalloc(size_t n)
{
void *p = malloc (n);
if (!p) abort();
return p;
}
// Let's define a new type.
typedef struct {
int key;
@@ -12,7 +21,7 @@ typedef struct {
#define SIZE 256
void *xmalloc(size_t n);
// Let's define the prototypes of the methods of this new type.
void my_type_init(my_type_t x);
void my_type_clear(my_type_t x);
void my_type_init_set(my_type_t x, const my_type_t y);
@@ -24,13 +33,6 @@ void my_type_out_str(FILE *f, const my_type_t x);
bool my_type_in_str(my_type_t x, FILE *f);
void my_type_rand(my_type_t x);
void *xmalloc(size_t n)
{
void *p = malloc (n);
if (!p) abort();
return p;
}
// Let's define its constructor
void my_type_init(my_type_t x)
{
+53
View File
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <string.h>
#include "m-string.h"
#define MAX_COLUMN 80
static void format(FILE *f)
{
string_t s;
string_init(s);
while (string_fgets(s, f, STRING_READ_PURE_LINE) == true)
{
size_t n = string_size(s);
if (n > 0 && string_get_char(s, n-1) == '\\' && n < MAX_COLUMN) {
string_left(s, n-1);
while (n < MAX_COLUMN-1) {
string_push_back(s, ' ');
n++;
}
string_push_back(s, '\\');
}
if (n >= MAX_COLUMN && string_get_char(s, n-1) == '\\') {
n--;
string_left(s, n);
while (n >= MAX_COLUMN-2 && string_get_char(s, n-1) == ' ') {
n--;
string_left(s, n);
}
string_push_back(s, ' ');
string_push_back(s, '\\');
}
printf("%s\n", string_get_cstr(s));
}
string_clear(s);
}
int main(int argc, const char *argv[])
{
if (argc < 2)
{
fprintf(stderr, "ERROR: Missing argument filename.\nUSAGE: %s filename.h\n", argv[0]);
exit(1);
}
FILE *f = fopen(argv[1], "rt");
if (!f) {
fprintf(stderr, "ERROR: Cannot open filename '%s' .h\n", argv[1]);
exit(2);
}
format(f);
fclose(f);
exit(0);
}
+97
View File
@@ -0,0 +1,97 @@
#include "m-array.h"
#include "m-string.h"
// Define an array of string_t. Since the oplist of string_t is registered globaly
// there is no need to give it to this definition.
ARRAY_DEF(str_array, string_t)
// First the verbose way and (nearly) macro free:
static void main_macrofree(void)
{
str_array_t tab_name;
str_array_init(tab_name);
// Push some elements in the array (long way)
str_array_push_back(tab_name, STRING_CTE("My"));
str_array_push_back(tab_name, STRING_CTE("CD"));
str_array_push_back(tab_name, STRING_CTE("IS"));
str_array_push_back(tab_name, STRING_CTE("OUT"));
// 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));
str_array_push_back(tab_name, format);
string_printf(format, "There is a capacty of %d", str_array_capacity(tab_name));
string_replace_all_str(format, "capacty", "capacity");
str_array_push_back(tab_name, format);
string_printf(format, "The third element is '%s'", string_get_cstr(*str_array_get(tab_name, 2)));
str_array_push_back(tab_name, format);
string_clear(format);
// Display the content of the array.
str_array_it_t it;
int i = 0;
for (str_array_it(it, tab_name) ; !str_array_end_p(it); str_array_next(it)) {
printf("item[%d] = '%s'\n", i, string_get_cstr(*str_array_cref(it)) );
i++;
}
// Clear the array
str_array_clear(tab_name);
}
// Then the short version with macros.
// For this we need to register the oplist of the array of string globally.
#define M_OPL_str_array_t() ARRAY_OPLIST(str_array, STRING_OPLIST)
static void main_macro(void)
{
// Define and fill an array of string with some elements in it:
M_LET( (tab_name, STRING_CTE("My"), STRING_CTE("CD"), STRING_CTE("IS"), STRING_CTE("OUT")), str_array_t) {
// 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));
str_array_push_back(tab_name, format);
string_printf(format, "There is a capacty of %d", str_array_capacity(tab_name));
string_replace_all_str(format, "capacty", "capacity");
str_array_push_back(tab_name, format);
string_printf(format, "The third element is '%s'", string_get_cstr(*str_array_get(tab_name, 2)));
str_array_push_back(tab_name, format);
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
// 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("-%zu.txt", str_array_size(tab_name) ));
str_array_push_back(tab_name, format);
#endif
} // beyond this point format is cleared
// Display the content of the array.
int i = 0;
for M_EACH(item, tab_name, str_array_t) {
printf("item[%d] = '%s'\n", i, string_get_cstr(*item) );
i++;
}
} // beyond this point tab_name is cleared
}
int main(void)
{
printf("Version macrofree:\n");
main_macrofree();
printf("Version macro:\n");
main_macro();
return 0;
}
+44
View File
@@ -0,0 +1,44 @@
#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_DEFAULT_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:
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) {
#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
}
}
}
}
+37
View File
@@ -0,0 +1,37 @@
/* Based on https://en.cppreference.com/w/cpp/algorithm/for_each
Need to be built in C11 mode */
#include <stdio.h>
#include "m-array.h"
#include "m-algo.h"
/* Define a dynamic array of int */
ARRAY_DEF(vector_int, int)
#define M_OPL_vector_int_t() ARRAY_OPLIST(vector_int)
/* Define operator increment on int */
#define INC(n) (n)++
int main(void)
{
M_LET( (nums, 3, 4, 2, 8, 15, 267), vector_int_t) {
// Print the array before
printf ("before:");
ALGO_FOR_EACH(nums, vector_int_t, M_PRINT, " ");
printf ("\n");
// Increment each element of the array
ALGO_FOR_EACH(nums, vector_int_t, INC);
// Print the array after
printf ("after: ");
ALGO_FOR_EACH(nums, vector_int_t, M_PRINT, " ");
printf ("\n");
// Sum the elements of the array
int sum = 0;
ALGO_REDUCE(sum, nums, vector_int_t, add);
M_PRINT("sum = ", sum, "\n");
}
return 0;
}
+89
View File
@@ -0,0 +1,89 @@
#include "m-tuple.h"
#include "m-array.h"
#include "m-algo.h"
#include "m-funcobj.h"
#include "m-serial-json.h"
#include "m-string.h"
/* Define the employee class */
TUPLE_DEF2(employee,
(name, string_t),
(age, int),
(idnum, int))
/* Register globaly the employee_t oplist */
#define M_OPL_employee_t() TUPLE_OPLIST(employee, STRING_OPLIST, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
/* 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.
* 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 */,
vector_employee_cmp_obj /* name of the interface */,
(a, b) /* name of the input parameters of the function like object. The type are inherited from the interface. */, {
/* code of the function object */
if (string_equal_str_p(self->sort_field, "name"))
return string_cmp(a->name, b->name);
else if (string_equal_str_p(self->sort_field, "age"))
return a->age < b->age ? -1 : a->age > b->age;
else
return a->idnum < b->idnum ? -1 : a->idnum > b->idnum;
},
/* Additional fields stored in the function object */
(sort_field, string_t) )
#define M_OPL_compare_by_t() FUNC_OBJ_INS_OPLIST(compare_by, STRING_OPLIST)
// Let's read an array of person from the given JSON file
static void read(vector_employee_t base, const char filename[])
{
m_serial_return_code_t ret;
// Open the file
FILE *f = fopen(filename, "rt");
if (!f) {
// Handle errors
fprintf(stderr, "ERROR: Cannot open file '%s'.\n", filename);
exit(2);
}
// Initialize the JSON serializer with this file
M_LET( (in,f), m_serial_json_read_t)
// Read the JSON file and fill in 'base' with it.
ret = vector_employee_in_serial(base, in);
// Let's handle serialization error
if (ret != M_SERIAL_OK_DONE) {
fprintf(stderr, "ERROR: Cannot read JSON data from file '%s'.\nParsing stops at:\n", filename);
while (!feof(f)) { fputc(fgetc(f), stdout); }
fclose(f);
exit(2);
}
// Close the FILE
fclose(f);
}
int main(void)
{
M_LET(emps, vector_employee_t) {
/* Code to populate database from JSON */
read(emps, "ex11-algo02.json");
// 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));
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));
M_PRINT("Employees sorted by name are: ", (emps, vector_employee_t), "\n" );
// End
}
return 0;
}
+9
View File
@@ -0,0 +1,9 @@
[
{ "name": "John Doe", "age": 32, "idnum": 14528},
{ "name": "Clint Smith", "age": 31, "idnum": 14529},
{ "name": "Linda Cameron", "age": 20, "idnum": 14527},
{ "name": "Cameron Carrey", "age": 25, "idnum": 14526},
{ "name": "Marty Brown", "age": 26, "idnum": 14525},
{ "name": "Donald Cow", "age": 45, "idnum": 14520}
]
+60
View File
@@ -0,0 +1,60 @@
#include "m-serial-json.h"
#include "m-tuple.h"
#include "m-array.h"
// Let's define a 'person' composed of several fields.
TUPLE_DEF2(person,
(surname, string_t),
(age, int),
(present, bool)
)
// Register the oplist of this tuple globaly
#define M_OPL_person_t() TUPLE_OPLIST(person, M_DEFAULT_OPLIST, STRING_OPLIST, M_DEFAULT_OPLIST )
// Let's define an array of person
ARRAY_DEF(base, person_t)
// Register the oplist of this array globaly
#define M_OPL_base_t() ARRAY_OPLIST(base, M_OPL_person_t())
// Let's read an array of person from the given JSON file
static void read(base_t base, const char filename[])
{
m_serial_read_t in;
m_serial_return_code_t ret;
// Open the file
FILE *f = fopen(filename, "rt");
if (!f) {
fprintf(stderr, "ERROR: Cannot open file '%s'.\n", filename);
exit(2);
}
// Initialize the serializer with the file
m_serial_json_read_init(in, f);
// Read the array
ret = base_in_serial(base, in);
if (ret != M_SERIAL_OK_DONE) {
fprintf(stderr, "ERROR: Cannot read JSON data from file '%s'.\n", filename);
exit(2);
}
// Let's close & clear all
m_serial_json_read_clear(in);
fclose(f);
}
int main(void)
{
// Let's have base as a base_t
M_LET(base, base_t) {
// Read the JSON file and fill-in base
read(base, "ex11-json01.json");
// Print the contents of base:
printf ("List of presents:\n");
for M_EACH(el, base, base_t) {
if ((*el)->present) {
printf("%s\n", string_get_cstr((*el)->surname));
}
}
}
exit(0);
}
+7
View File
@@ -0,0 +1,7 @@
[
{ "surname": "Angel", "age": 1, "present": false},
{ "surname": "Snake", "age": 2, "present": true},
{ "surname": "BallOfBase", "age": 5, "present": true}
]
+45
View File
@@ -0,0 +1,45 @@
#include <stdio.h>
#include "m-array.h"
#include "m-tuple.h"
#include "m-dict.h"
#include "m-string.h"
// Let's define a tuple composed of (offset, value) and register it
TUPLE_DEF2(symbol, (offset, long), (value, long))
#define M_OPL_symbol_t() TUPLE_OPLIST(symbol, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
// Let's define an array of such tuple and register it
ARRAY_DEF(array_symbol, symbol_t)
#define M_OPL_array_symbol_t() ARRAY_OPLIST(array_symbol, M_OPL_symbol_t())
// Let's define a dictionnary associating a string_t to such an array and register it
DICT_DEF2(sections, string_t, array_symbol_t)
#define M_OPL_sections_t() DICT_OPLIST(sections, STRING_OPLIST, M_OPL_array_symbol_t())
int main(int argc, const char *argv[])
{
if (argc < 2) abort();
FILE *f = fopen(argv[1], "rt");
if (!f) {
fprintf(stderr, "ERROR: Cannot open %s\n", argv[1]);
return 2;
}
// Create & initialize sc as sections_t
M_LET(sc, sections_t) {
// Read the section from the FILE
sections_in_str(sc, f);
// Get the section named .text
array_symbol_t *a = sections_get(sc, STRING_CTE(".text"));
if (a == NULL) {
printf("There is no .text section.");
} else {
// Print its content
printf("Section .text is :");
array_symbol_out_str(stdout, *a);
printf("\n");
}
}
return 0;
}
+88
View File
@@ -0,0 +1,88 @@
/* Based on the example of STC https://github.com/tylov/STC */
#include "m-dict.h"
#include "m-array.h"
#include "m-deque.h"
#include "m-list.h"
#include "m-rbtree.h"
#include "m-algo.h"
#include "m-tuple.h"
// NOTE: After each definition of a container, we register its oplist
// It is not mandatory, but it makes the code easier to write and read.
// Define a basic structure (POD structure) using a tuple to get the default functions
TUPLE_DEF2(Point, (x, float), (y, float))
#define M_OPL_Point_t() TUPLE_OPLIST(Point, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
// NOTE: array, list, deque don't have a native find function.
// We'll use the algorithm header to create a find function for such containers.
// Define a set of int & register its oplist
DICT_SET_DEF(cset_i, int)
#define M_OPL_cset_i_t() DICT_SET_OPLIST(cset_i, M_DEFAULT_OPLIST)
// Define an array of Point, register its oplist & include some basic algorithms
ARRAY_DEF(cvec_p, Point_t)
#define M_OPL_cvec_p_t() ARRAY_OPLIST(cvec_p, M_OPL_Point_t())
ALGO_DEF(cvec_p, cvec_p_t)
// Define a deque of int, including some basic algorithms
DEQUE_DEF(cdeq_i, int)
#define M_OPL_cdeq_i_t() DEQUE_OPLIST(cdeq_i, M_DEFAULT_OPLIST)
ALGO_DEF(cdeq_i, cdeq_i_t)
// Define a backward list, including some basic algorithms
LIST_DEF(clist_i, int)
#define M_OPL_clist_i_t() LIST_OPLIST(clist_i, M_DEFAULT_OPLIST)
ALGO_DEF(clist_i, clist_i_t)
// Define an unordered map of int to int
DICT_DEF2(csmap_i, int, int)
#define M_OPL_csmap_i_t() DICT_OPLIST(csmap_i, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
int main(void)
{
// Define, init & set the different containers.
M_LET( (set, 10, 20, 30), cset_i_t)
M_LET( (vec, (10, 1), (20, 2), (30, 3) ), cvec_p_t)
M_LET( (deq, 10, 20, 30), cdeq_i_t)
M_LET( (lst, 10, 20, 30), clist_i_t)
M_LET( (map, (20, 2), (10, 1), (30,3) ), csmap_i_t) {
// add one more element to each container
cset_i_push(set, 40);
cvec_p_push_back(vec, (Point_t) {{40, 4}} );
cdeq_i_push_front(deq, 5);
clist_i_push_back(lst, 5);
csmap_i_set_at(map, 40, 4);
M_PRINT("vec= ", (vec, cvec_p_t));
// Find an element (either native or through the algo header)
int *i1 = cset_i_get(set, 20);
cvec_p_it_t i2; cvec_p_find(i2, vec, (Point_t) {{20, 2}});
cdeq_i_it_t i3; cdeq_i_find(i3, deq, 20);
clist_i_it_t i4; clist_i_find(i4, lst, 20);
int *i5 = csmap_i_get(map, 20);
printf("\nFound: %d, (%g, %g), %d, %d, [%d: %d]\n",
*i1,
(*cvec_p_ref(i2))->x, (*cvec_p_ref(i2))->y,
*cdeq_i_ref(i3),
*clist_i_ref(i4),
20, *i5);
// Erase the elements found (through key or through iterators)
cset_i_erase(set, *i1);
cvec_p_remove(vec, i2);
cdeq_i_remove(deq, i3);
clist_i_remove(lst, i4);
csmap_i_erase(map, *i5);
// Display everything in one call by using the registered print functions of the different types.
M_PRINT("After erasing elements found:\n",
"set: ", (set, cset_i_t), "\n",
"vec: ", (vec, cvec_p_t), "\n",
"deq: ", (deq, cdeq_i_t), "\n",
"map: ", (map, csmap_i_t), "\n");
}
}
+1125 -530
View File
File diff suppressed because it is too large. Load diff
+1068 -783
View File
File diff suppressed because it is too large. Load diff
+148 -74
View File
@@ -1,7 +1,7 @@
/*
* M*LIB - Thin stdatomic wrapper for C++ compatibility
*
* Copyright (c) 2017-2018, Patrick Pelissier
* 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:
@@ -22,18 +22,21 @@
* (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 __M_ATOMIC_H
#define __M_ATOMIC_H
#ifndef MSTARLIB_ATOMIC_H
#define MSTARLIB_ATOMIC_H
/* NOTE: Due to the C++ not having recognized stdatomic.h officialy,
it is hard to use this header directly with a C++ compiler like
g++ or MSVC.
(See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932 ).
clang has no issue with this header.
GCC 4.9 doesn't have a working implementation of 'atomic'
it is hard to use this header directly with a C++ compiler.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932
clang++ has no issue with this header but if someone includes
atomic from C++, there is incompatibility between atomic & stdatomic.
Moreover some compilers lack a working stdatomic header.
GCC 4.9 doesn't have a working implementation of 'atomic'.
APPLE Clang defines __GNUC__ to be only 4 despite having full support
for atomic.
*/
#if defined(__cplusplus) && __cplusplus >= 201103L \
&& !defined(__clang__) && !(defined(__GNUC__) && __GNUC__ < 5)
#if defined(__cplusplus) && __cplusplus >= 201103L \
&& !(defined(__GNUC__) && __GNUC__ < 5 && !defined(__APPLE__))
/* NOTE: This is what the stdatomic.h header shall do in C++ mode. */
#include <atomic>
@@ -89,42 +92,91 @@ using std::atomic_flag_test_and_set_explicit;
using std::atomic_flag_clear;
using std::atomic_flag_clear_explicit;
using std::memory_order_relaxed;
using std::memory_order_consume;
using std::memory_order_acquire;
using std::memory_order_release;
using std::memory_order_acq_rel;
using std::memory_order_seq_cst;
/* CLANG provides a warning on defining _Atomic as it sees it
* as a reserved system macro. It is true. However, the goal of this
* header is to provide stdatomic semantic, so it needs to define
* _Atomic macro.
*
* So, this warning has to be ignored.
*
* It cannot use M_BEGIN_PROTECTED_CODE as this header is normally
* independent of m-core.h
*/
#if defined(__clang__) && __clang_major__ >= 4
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored \"-Wreserved-id-macro\"")
#endif
#define _Atomic(T) std::atomic< T >
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
|| ( defined(__GNUC__) && !defined(__clang__) && !defined(__cplusplus) && (__GNUC__*100 + __GNUC_MINOR__) >= 409) \
|| (defined(__clang__) && __clang_major__ >= 4)
#if defined(__clang__) && __clang_major__ >= 4
_Pragma("clang diagnostic pop")
#endif
/* C11 with working stdatomic
STDATOMIC doesn't work with C++ except for clang but is incompatible with atomic.
GCC < 4.9 doesn't provide a compliant stdatomic.h
CLANG 3.5 has issues with GCC's stdatomic.h and doesn't provide its own
ICC < 18 doesn't provide a compliant stdatomic.h
*/
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) ) \
|| (defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__cplusplus) && (__GNUC__*100 + __GNUC_MINOR__) >= 409) \
|| (defined(__clang__) && (__clang_major__ * 100 + __clang_minor__) >= 308) \
|| (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1800)
/* CLANG 3.5 has issues with GCC's stdatomic.h
and doesn't provide its own stdatomic.h */
#include <stdatomic.h>
#else
/* MSYS2 has a conflict between cdefs.h which defines a _Atomic macro (if not C11)
not compatible with the used stdatomic.h (from GCC).
Provide a configurable mechanism to undef it with auto-detection of msys2 / gcc */
#ifndef M_USE_UNDEF_ATOMIC
# if defined(__MSYS__) && defined(__GNUC__) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L)
# define M_USE_UNDEF_ATOMIC 1
# endif
#endif
#if defined(M_USE_UNDEF_ATOMIC) && M_USE_UNDEF_ATOMIC == 1
# undef _Atomic
#endif
/* Non working atomic.h, nor working stdatomic.h found.
/* Non working C++ atomic header, nor working stdatomic.h found.
Write a compatible layer using mutex as slin as possible.
Supports only up to 64-bits atomic (sizeof long long to be more precise).
The locks are never properly cleared and remain active until
the end of the program.
We also assume that the call to the atomic_* interface is "clean".
We also assume that the call to the atomic_* interface is "macro clean".
*/
#include "m-mutex.h"
#else
/* The structure is quite large:
__val : value of the atomic type,
__zero : zero value of the atomic type (constant),
__previous: temporary value used within the mutex lock,
__lock : the mutex lock.
#include "m-mutex.h"
#include "m-core.h"
M_BEGIN_PROTECTED_CODE
/* _Atomic qualifier for a type (emulation).
The structure is quite large:
_val : value of the atomic type,
_zero : zero value of the atomic type (constant),
_previous: temporary value used within the mutex lock,
_lock : the mutex lock.
Support up to sizeof (long long) type.
*/
#define _Atomic(T) \
struct { \
volatile T __val; \
T __zero; \
T __previous; \
m_mutex_t __lock; \
#define _Atomic(T) \
struct { \
T volatile _val; \
T _zero; \
T _previous; \
m_mutex_t _lock; \
}
/* Even memory order is defined, only the strongest constraint is used */
/* Define the supported memory order.
Even if memory order is defined, only the strongest constraint is used */
typedef enum {
memory_order_relaxed,
memory_order_consume,
@@ -152,7 +204,7 @@ typedef _Atomic(size_t) atomic_size_t;
typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
/* Define the minimum size supported by the architecture
for atomic read or write.
for an atomic read or write.
This can help a lot since it avoids locking for atomic_load and
atomic_store.
*/
@@ -165,77 +217,97 @@ typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
#endif
/* Detect if stdint.h was included */
#if (defined (INTMAX_C) && defined (UINTMAX_C) && !defined(__cplusplus)) || \
defined (_STDINT_H) || defined (_STDINT_H_) || defined (_STDINT) || \
#if (defined (INTMAX_C) && defined (UINTMAX_C) && !defined(__cplusplus)) || \
defined (_STDINT_H) || defined (_STDINT_H_) || defined (_STDINT) || \
defined (_SYS_STDINT_H_)
/* Define additional atomic types */
typedef _Atomic(intmax_t) atomic_intmax_t;
typedef _Atomic(uintmax_t) atomic_uintmax_t;
#endif
/* Unlock the mutex and return the given value */
/* (INTERNAL) Unlock the mutex and return the given value */
static inline long long atomic_fetch_unlock (m_mutex_t *lock, long long val)
{
m_mutex_unlock (*lock);
return val;
}
/* This is the heart of the wrapper:
/* (INTERNAL) This is the heart of the wrapper:
lock the atomic value, read it and returns the value.
In order to avoid any compiler extension, we need to transform the
atomic type into 'long long' then convert it back to its value.
This is because __previous can't be read after the lock, and we can't
This is because _previous can't be read after the lock, and we can't
generate temporary variable within a macro.
The trick is computing _val - _zero within the lock, then
returns retvalue + _zero after the lock.
returns retvalue + _zero after the release of the lock.
*/
#define atomic_fetch_op(ptr, val, op) \
(m_mutex_lock((ptr)->__lock), \
(ptr)->__previous = (ptr)->__val, \
(ptr)->__val op (val), \
atomic_fetch_unlock(&(ptr)->__lock, (ptr)->__previous-(ptr)->__zero)+(ptr)->__zero)
#define atomic_fetch_op(ptr, val, op) \
(m_mutex_lock((ptr)->_lock), \
(ptr)->_previous = (ptr)->_val, \
(ptr)->_val op (val), \
atomic_fetch_unlock(&(ptr)->_lock, (long long)((ptr)->_previous-(ptr)->_zero))+(ptr)->_zero)
/* Perform an atomic add (EMULATION) */
#define atomic_fetch_add(ptr, val) atomic_fetch_op(ptr, val, +=)
/* Perform an atomic sub (EMULATION) */
#define atomic_fetch_sub(ptr, val) atomic_fetch_op(ptr, val, -=)
/* Perform an atomic or (EMULATION) */
#define atomic_fetch_or(ptr, val) atomic_fetch_op(ptr, val, |=)
/* Perform an atomic xor (EMULATION) */
#define atomic_fetch_xor(ptr, val) atomic_fetch_op(ptr, val, ^=)
/* Perform an atomic and (EMULATION) */
#define atomic_fetch_and(ptr, val) atomic_fetch_op(ptr, val, &=)
/* Perform an atomic exchange (EMULATION) */
#define atomic_exchange(ptr, val) atomic_fetch_op(ptr, val, =)
/* Initialize an atomic GLOBAL variable */
#define ATOMIC_VAR_INIT(val) { val, 0, 0, M_MUTEXI_INIT_VALUE }
#define atomic_init(ptr, val) \
(m_mutex_init((ptr)->__lock), (ptr)->__val = val, (ptr)->__zero = 0)
/* Initialize an atomic variable */
#define atomic_init(ptr, val) \
(m_mutex_init((ptr)->_lock), (ptr)->_val = val, (ptr)->_zero = 0)
#define atomic_load_lock(ptr) \
(m_mutex_lock((ptr)->__lock), \
(ptr)->__previous = (ptr)->__val, \
atomic_fetch_unlock(&(ptr)->__lock, (ptr)->__previous-(ptr)->__zero)+(ptr)->__zero)
/* (INTERNAL) Load an atomic variable within a lock
(needed for variable greater than CPU atomic size) */
#define atomic_load_lock(ptr) \
(m_mutex_lock((ptr)->_lock), \
(ptr)->_previous = (ptr)->_val, \
atomic_fetch_unlock(&(ptr)->_lock, (long long) ((ptr)->_previous-(ptr)->_zero))+(ptr)->_zero)
#define atomic_store_lock(ptr, val) \
(m_mutex_lock((ptr)->__lock), \
(ptr)->__val = (val), \
m_mutex_unlock((ptr)->__lock))
/* (INTERNAL) Store an atomic variable within a lock
(needed for variable greater than CPU atomic size) */
#define atomic_store_lock(ptr, val) \
(m_mutex_lock((ptr)->_lock), \
(ptr)->_val = (val), \
m_mutex_unlock((ptr)->_lock))
#define atomic_load(ptr) \
( sizeof ((ptr)->__val) <= ATOMICI_MIN_RW_SIZE \
? (ptr)->__val \
/* Atomic load of a variable (EMULATION)
If the atomic type size is not greater than the CPU atomic size,
we can perform a direct read of the variable (much faster) */
#define atomic_load(ptr) \
( sizeof ((ptr)->_val) <= ATOMICI_MIN_RW_SIZE \
? (ptr)->_val \
: atomic_load_lock(ptr))
#define atomic_store(ptr, val) do { \
if ( sizeof ((ptr)->__val) <= ATOMICI_MIN_RW_SIZE) { \
(ptr)->__val = (val); \
} else { \
long long _offset = (val) - (ptr)->__zero; \
atomic_store_lock(ptr, (ptr)->__zero + _offset); \
} \
/* Atomic store of a variable (EMULATION)
If the atomic type size is not greater than the CPU atomic size,
we can perform a direct write of the variable (much faster) */
#define atomic_store(ptr, val) do { \
if ( sizeof ((ptr)->_val) <= ATOMICI_MIN_RW_SIZE) { \
(ptr)->_val = (val); \
} else { \
long long _offset = (long long) ((val) - (ptr)->_zero); \
atomic_store_lock(ptr, (ptr)->_zero + _offset); \
} \
} while (0)
#define atomic_compare_exchange_strong(ptr, exp, val) \
(m_mutex_lock((ptr)->__lock), \
atomic_fetch_unlock(&(ptr)->__lock, \
(ptr)->__val == *(exp) \
? ((ptr)->__val = (val), true) \
: (*(exp) = (ptr)->__val, false)))
/* Perform a CAS (Compare and swap) operation (EMULATION) */
#define atomic_compare_exchange_strong(ptr, exp, val) \
(m_mutex_lock((ptr)->_lock), \
atomic_fetch_unlock(&(ptr)->_lock, \
(ptr)->_val == *(exp) \
? ((ptr)->_val = (val), true) \
: (*(exp) = (ptr)->_val, false)))
#define atomic_fetch_add_explicit(ptr, val, mem) atomic_fetch_op(ptr, val, +=)
@@ -250,11 +322,13 @@ static inline long long atomic_fetch_unlock (m_mutex_t *lock, long long val)
#define atomic_thread_fence(mem) (void) 0
#define atomic_signal_fence(mem) (void) 0
#define atomic_is_lock_free(ptr) false
#define atomic_compare_exchange_strong_explicit(ptr, exp, val, mem) atomic_compare_exchange_strong(ptr, exp, val)
#define atomic_compare_exchange_weak_explicit(ptr, exp, val, mem) atomic_compare_exchange_strong(ptr, exp, val)
#define atomic_compare_exchange_weak(ptr, exp, val) atomic_compare_exchange_strong(ptr, exp, val)
#define atomic_compare_exchange_strong_explicit(ptr, exp, val, mem1, mem2) atomic_compare_exchange_strong(ptr, exp, val)
#define atomic_compare_exchange_weak_explicit(ptr, exp, val, mem1, mem2) atomic_compare_exchange_strong(ptr, exp, val)
#define atomic_compare_exchange_weak(ptr, exp, val) atomic_compare_exchange_strong(ptr, exp, val)
/* TODO: Missing atomic_flag. Problem: it needs to be lock free! */
/* TODO: Missing atomic_flag. Problem: it is supposed to be lock free! */
M_END_PROTECTED_CODE
#endif
+464 -259
View File
File diff suppressed because it is too large. Load diff
+1482
View File
File diff suppressed because it is too large. Load diff
+1191 -656
View File
File diff suppressed because it is too large. Load diff
+831
View File
@@ -0,0 +1,831 @@
/*
* M*LIB - Concurrent memory pool allocator
*
* 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 MSTARLIB_CONCURRENT_MEMPOOL_H
#define MSTARLIB_CONCURRENT_MEMPOOL_H
#include "m-core.h"
#include "m-atomic.h"
#include "m-genint.h"
M_BEGIN_PROTECTED_CODE
/* Minimum number of nodes per group of nodes */
#define M_CMEMP00L_MIN_NODE_PER_GROUP 16
#define C_MEMPOOL_DEF(name, type_t) \
M_BEGIN_PROTECTED_CODE \
M_CMEMP00L_DEF_SINGLY_LIST(name, type_t) \
M_CMEMP00L_DEF_LF_QUEUE(name, type_t) \
M_CMEMP00L_DEF_LFMP_THREAD_MEMPOOL(name, type_t) \
M_CMEMP00L_DEF_SYSTEM_ALLOC(name, type_t) \
M_CMEMP00L_DEF_LF_MEMPOOL(name, type_t) \
M_END_PROTECTED_CODE
/* Classic internal Singly List without allocation */
#define M_CMEMP00L_DEF_SINGLY_LIST(name, type_t) \
\
typedef struct M_C(name, _slist_node_s) { \
struct M_C(name, _slist_node_s) *next; \
type_t data; \
} M_C(name, _slist_node_ct); \
\
typedef struct M_C(name, _slist_node_s) *M_C(name, _slist_ct)[1]; \
\
static inline void \
M_C(name, _slist_init)(M_C(name, _slist_ct) list) \
{ \
*list = NULL; \
} \
\
static inline void \
M_C(name, _slist_push)(M_C(name, _slist_ct) list, \
M_C(name, _slist_node_ct) *node) \
{ \
node->next = *list; \
*list = node; \
} \
\
static inline M_C(name, _slist_node_ct) * \
M_C(name, _slist_pop)(M_C(name, _slist_ct) list) \
{ \
M_ASSERT (*list != NULL); \
M_C(name, _slist_node_ct) *node = *list; \
*list = node->next; \
M_IF_DEBUG(node->next = NULL;) \
return node; \
} \
\
static inline bool \
M_C(name, _slist_empty_p)(M_C(name, _slist_ct) list) \
{ \
return *list == NULL; \
} \
\
static inline void \
M_C(name, _slist_move)(M_C(name, _slist_ct) list, \
M_C(name, _slist_ct) src) \
{ \
*list = *src; \
*src = NULL; \
} \
\
static inline void \
M_C(name, _slist_clear)(M_C(name, _slist_ct) list) \
{ \
M_C(name, _slist_node_ct) *it = *list, *next; \
while (it) { \
next = it->next; \
M_MEMORY_DEL(it); \
it = next; \
} \
*list = NULL; \
} \
/* Lock Free free queue list (not generic one) of lists without allocation
Based on Michael & Scott Lock Free Queue List algorithm.
Each list is considered empty if there is only one node within.
This LF Queue List doesn't try to prevent the ABA problem. It is up to the
caller to avoid recycling the nodes too fast.
Each list has its own unique NIL ptr in order to avoid issues when
migrating a node from a Q to another: in the following scenario,
- Thread 1 performs a PUSH of N in Q1 with Q1 empty (only node is NA)
NA.next is NIL.
- Thread 1 is interrupted just before the CAS on NA.next
- Thread 2 performs a sucessfull push of NB in Q1. NA.next is set to NB.
- Thread 2 performs a sucessfull pop of NA in Q1
- Thread 2 performs a sucessfull push of NA in Q2. NA.next is set to NIL.
- Thread 1 is restored and will succeed as NA.next is once again NIL.
In order to prevent the last CAS to succeed, each queue uses its own NIL pointer.
It is a derived problem of the ABA problem.
*/
/* TODO: Optimize alignement to reduce memory consumption. NIL object can use []
to reduce memory consumption too (non compatible with C++ ...) */
#define M_CMEMP00L_DEF_LF_QUEUE(name, type_t) \
\
typedef struct M_C(name, _lf_node_s) { \
M_ATTR_EXTENSION _Atomic(struct M_C(name, _lf_node_s) *) next; \
m_gc_atomic_ticket_ct cpt; \
M_C(name, _slist_ct) list; \
} M_C(name, _lf_node_t); \
\
typedef struct M_C(name, _lflist_s) { \
M_ATTR_EXTENSION _Atomic(M_C(name, _lf_node_t) *) head; \
char align1[M_ALIGN_FOR_CACHELINE_EXCLUSION]; \
M_ATTR_EXTENSION _Atomic(M_C(name, _lf_node_t) *) tail; \
char align2[M_ALIGN_FOR_CACHELINE_EXCLUSION]; \
M_C(name, _lf_node_t) nil; \
} M_C(name, _lflist_ct)[1]; \
\
static inline void \
M_C(name, _lflist_init)(M_C(name, _lflist_ct) list, \
M_C(name, _lf_node_t) *node) \
{ \
atomic_init(&list->head, node); \
atomic_init(&list->tail, node); \
atomic_store_explicit(&node->next, &list->nil, memory_order_relaxed); \
} \
\
static inline bool \
M_C(name, _lflist_empty_p)(M_C(name, _lflist_ct) list) \
{ \
return atomic_load(&list->tail) == atomic_load(&list->head); \
} \
\
static inline void \
M_C(name, _lflist_push)(M_C(name, _lflist_ct) list, \
M_C(name, _lf_node_t) *node, m_core_backoff_ct bkoff) \
{ \
M_C(name, _lf_node_t) *tail; \
M_C(name, _lf_node_t) *next; \
\
atomic_store_explicit(&node->next, &list->nil, memory_order_relaxed); \
m_core_backoff_reset(bkoff); \
while (true) { \
tail = atomic_load(&list->tail); \
next = atomic_load_explicit(&tail->next, memory_order_acquire); \
if (M_UNLIKELY(next != &list->nil)) { \
/* Tail was not pointing to the last node \
Try to swing Tail to the next node */ \
atomic_compare_exchange_weak_explicit(&list->tail, \
&tail, next, \
memory_order_release, \
memory_order_relaxed); \
} else { \
/* Try to link node at the end of the linked list */ \
if (atomic_compare_exchange_strong_explicit(&tail->next, \
&next, node, \
memory_order_release, \
memory_order_relaxed)) \
break; \
m_core_backoff_wait(bkoff); \
} \
} \
/* Enqueue is done. Try to swing Tail to the inserted node \
If it fails, someone else will do it or has already did it. */ \
atomic_compare_exchange_strong_explicit(&list->tail, &tail, node, \
memory_order_acq_rel, \
memory_order_relaxed); \
} \
\
static inline M_C(name, _lf_node_t) * \
M_C(name, _lflist_pop)(M_C(name, _lflist_ct) list, m_core_backoff_ct bkoff) \
{ \
M_C(name, _lf_node_t) *head; \
M_C(name, _lf_node_t) *tail; \
M_C(name, _lf_node_t) *next; \
\
/* Reinitialize backoff */ \
m_core_backoff_reset(bkoff); \
while (true) { \
head = atomic_load(&list->head); \
tail = atomic_load(&list->tail); \
next = atomic_load(&head->next); \
/* Are head, tail, and next consistent?*/ \
if (M_LIKELY(head == \
atomic_load_explicit(&list->head, memory_order_relaxed))) \
{ \
/* Is queue empty or Tail falling behind? */ \
if (head == tail) { \
/* Is queue empty? */ \
if (next == &list->nil) \
return NULL; \
/* Tail is falling behind. Try to advance it */ \
atomic_compare_exchange_strong_explicit(&list->tail, &tail, \
next, \
memory_order_release, \
memory_order_relaxed); \
} else { \
/* Try to swing Head to the next node */ \
if (atomic_compare_exchange_strong_explicit(&list->head, \
&head, next, \
memory_order_release, \
memory_order_relaxed)) { \
break; \
} \
/* Failure: perform a random exponential backoff */ \
m_core_backoff_wait(bkoff); \
} \
} \
} \
/* dequeue returns an element that becomes the new dummy element (the new head), \
and the former dummy element (the former head) is removed: \
Since we want a link of free list, and we don't care about the content itsef, \
provided that the node we return is older than the one we should return, \
Therefore, we return the previous dummy head. \
As such, it is not the original MSqueue algorithm. */ \
M_IF_DEBUG(atomic_store(&head->next, (M_C(name, _lf_node_t) *) 0);) \
return head; \
} \
\
/* Dequeue a node if the node is old enough */ \
static inline M_C(name, _lf_node_t) * \
M_C(name, _lflist_pop_if)(M_C(name, _lflist_ct) list, \
m_gc_ticket_ct age, m_core_backoff_ct bkoff) \
{ \
M_C(name, _lf_node_t) *head; \
M_C(name, _lf_node_t) *tail; \
M_C(name, _lf_node_t) *next; \
\
m_core_backoff_reset(bkoff); \
while (true) { \
head = atomic_load(&list->head); \
tail = atomic_load(&list->tail); \
next = atomic_load(&head->next); \
if (M_LIKELY(head == atomic_load_explicit(&list->head, memory_order_relaxed))) \
{ \
if (head == tail) { \
if (next == &list->nil) \
return NULL; \
atomic_compare_exchange_strong_explicit(&list->tail, &tail, next, \
memory_order_release, \
memory_order_relaxed); \
} else { \
/* Test if the node is old enought to be popped */ \
if (atomic_load_explicit(&next->cpt, memory_order_relaxed) >= age) \
return NULL; \
/* Try to swing Head to the next node */ \
if (atomic_compare_exchange_strong_explicit(&list->head, \
&head, next, \
memory_order_release, \
memory_order_relaxed)) { \
break; \
} \
m_core_backoff_wait(bkoff); \
} \
} \
} \
M_IF_DEBUG(atomic_store(&head->next, (M_C(name, _lf_node_t) *) 0);) \
return head; \
} \
\
static inline void \
M_C(name, _lflist_clear)(M_C(name, _lflist_ct) list) \
{ \
m_core_backoff_ct bkoff; \
m_core_backoff_init(bkoff); \
while (true) { \
M_C(name, _lf_node_t) *node = M_C(name, _lflist_pop)(list, bkoff); \
if (node == NULL) break; \
M_C(name, _lf_node_t) *next = atomic_load_explicit(&node->next, \
memory_order_relaxed); \
M_C(name, _slist_clear)(node->list); \
M_MEMORY_DEL(node); \
node = next; \
} \
/* Dummy node to free too */ \
M_C(name, _lf_node_t) *dummy; \
dummy = atomic_load_explicit(&list->head, memory_order_relaxed); \
M_C(name, _slist_clear)(dummy->list); \
M_MEMORY_DEL(dummy); \
} \
/* System node allocator: request memory to the system.
As such it is a non Lock-Free path. */
#define M_CMEMP00L_DEF_SYSTEM_ALLOC(name, type_t) \
\
static inline M_C(name, _lf_node_t) * \
M_C(name, _alloc_node)(unsigned int initial) \
{ \
M_C(name, _lf_node_t) * node; \
node = M_MEMORY_ALLOC(M_C(name, _lf_node_t)); \
if (M_UNLIKELY(node == NULL)) { \
M_MEMORY_FULL(sizeof(M_C(name, _lf_node_t))); \
return NULL; \
} \
atomic_init(&node->next, (M_C(name, _lf_node_t) *) 0); \
atomic_init(&node->cpt, 0UL); \
M_C(name, _slist_init)(node->list); \
for(unsigned i = 0; i < initial; i++) { \
M_C(name, _slist_node_ct) *n; \
n = M_MEMORY_ALLOC(M_C(name, _slist_node_ct)); \
if (M_UNLIKELY(n == NULL)) { \
M_MEMORY_FULL(sizeof(M_C(name, _lf_node_t))); \
return NULL; \
} \
M_C(name, _slist_push)(node->list, n); \
} \
return node; \
} \
/* Concurrent Memory pool
The data structure is the following.
Each thread has its own pool of nodes (local) that only it can
access (it is a singly list). If there is no longer any node in this
pool, it requests a new pool to the lock free queue of pool (group of
nodes). If it fails, it requests a new pool to the system allocator
(and from there it is no longer lock free).
This memory pool can only be lock free if the initial state is
sufficiently dimensionned to avoid calling the system allocator during
the normal processing.
Then each thread pushs its deleted node into another pool of nodes,
where the node is logically deleted (no contain of the node is destroyed
at this point and the node can be freely accessed by other threads).
Once the thread mempool is put to sleep, the age of the pool of logical
deleted nodes is computed and this pool is move to the Lock Free Queue
List of pools to be reclaimed. Then A Garbage Collector is performed
on this Lock Free Queue list to reclaim all pools thare are sufficiently
aged (taking into account the grace period of the pool) to be moved back
to the Lock Free Queue of the free pools.
Each pool of nodes can be in the following state:
* FREE state if it is present in the Lock Free Queue of free pools.
* EMPTY state if it is present in the Lock Free Queue of empty pools
which means that the nodes present in it has been USED directly by a thread,
* TO_BE_RECLAIMED state if it is present in the Lock Free Queue of TBR pools
A pool of nodes will go to the following state:
FREE --> EMPTY --> TO_BE_RECLAIMED
^ |
+----------------------+
The ABA problem is taken into account as a node cannot be reused in the
same queue without performing a full cycle of its state. Moreover
it can only move from TO_BE_RECLAIMED to FREE if and only if a grace
period is finished (and then we are sure that no thread references any
older node).
Each thread has its own backoff structure (with local pseudo-random
generator).
The grace period is detected through a global age counter (ticket)
that is incremented each time a thread is awaken / sleep.
Each thread has its own age that is set to the global ticket on sleep/awaken.
The age of the pool to be reclaimed is also set to this global age counter.
To ensure that the grace period is finished, it tests if all threads
are younger than the age of the pool to be reclaimed.
From a performance point of view, this puts a bottleneck on the global
age counter that is shared and incremented by all threads. However,
the sleep/awaken operations are much less frequent than other operations.
Thus, it shall not have a huge impact on the performance if the user
code is intelligent with the sleep/awaken operations.
As such it won't support more than ULONG_MAX sleep for all threads.
*/
#define M_CMEMP00L_DEF_LFMP_THREAD_MEMPOOL(name, type_t) \
\
typedef struct M_C(name, _lfmp_thread_s) { \
M_C(name, _slist_ct) free; \
M_C(name, _slist_ct) to_be_reclaimed; \
M_CACHELINE_ALIGN(align1, M_C(name, _slist_ct), M_C(name, _slist_ct)); \
} M_C(name, _lfmp_thread_ct); \
\
static inline void \
M_C(name, _lfmp_thread_init)(M_C(name, _lfmp_thread_ct) *t) \
{ \
M_C(name, _slist_init)(t->free); \
M_C(name, _slist_init)(t->to_be_reclaimed); \
} \
\
static inline void \
M_C(name, _lfmp_thread_clear)(M_C(name, _lfmp_thread_ct) *t) \
{ \
M_ASSERT(M_C(name, _slist_empty_p)(t->to_be_reclaimed)); \
M_C(name, _slist_clear)(t->free); \
M_C(name, _slist_clear)(t->to_be_reclaimed); \
} \
/* NOTE: once a node is deleted, its data are kept readable until the future GC */
#define M_CMEMP00L_DEF_LF_MEMPOOL(name, type_t) \
\
typedef struct M_C(name, _s) { \
unsigned initial; \
M_C(name, _lfmp_thread_ct) *thread_data; \
M_C(name, _lflist_ct) free; \
M_C(name, _lflist_ct) to_be_reclaimed; \
M_C(name, _lflist_ct) empty; \
m_gM_CMEMP00L_list_ct mempool_node; \
struct m_gc_s *gc_mem; \
} M_C(name, _t)[1]; \
\
/* Garbage collect of the nodes of the mempool on sleep */ \
static inline void \
M_C3(m_cmemp00l_,name,_gc_on_sleep)(m_gc_t gc_mem, m_gM_CMEMP00L_list_ct *data, \
m_gc_tid_t id, m_gc_ticket_ct ticket, m_gc_ticket_ct min_ticket) \
{ \
/* Get back the mempool from the node */ \
struct M_C(name, _s) *mempool = \
M_TYPE_FROM_FIELD(struct M_C(name, _s), data, m_gM_CMEMP00L_list_ct, mempool_node); \
\
/* Move the local nodes of the mempool to be reclaimed to the thread into the global pool */ \
if (!M_C(name, _slist_empty_p)(mempool->thread_data[id].to_be_reclaimed)) { \
M_C(name, _lf_node_t) *node; \
/* Get a new empty group of nodes */ \
node = M_C(name, _lflist_pop)(mempool->empty, gc_mem->thread_data[id].bkoff); \
if (M_UNLIKELY (node == NULL)) { \
/* Fail to get an empty group of node. \
Alloc a new one from the system */ \
node = M_C(name, _alloc_node)(0); \
M_ASSERT(node != NULL); \
} \
M_ASSERT(M_C(name, _slist_empty_p)(node->list)); \
M_C(name, _slist_move)(node->list, mempool->thread_data[id].to_be_reclaimed); \
atomic_store_explicit(&node->cpt, ticket, memory_order_relaxed); \
M_C(name, _lflist_push)(mempool->to_be_reclaimed, node, gc_mem->thread_data[id].bkoff); \
} \
\
/* Perform a GC of the freelist of nodes */ \
while (true) { \
M_C(name, _lf_node_t) *node; \
node = M_C(name, _lflist_pop_if)(mempool->to_be_reclaimed, \
min_ticket, gc_mem->thread_data[id].bkoff); \
if (node == NULL) break; \
M_C(name, _lflist_push)(mempool->free, node, gc_mem->thread_data[id].bkoff); \
} \
} \
\
static inline void \
M_C(name, _init)(M_C(name, _t) mem, m_gc_t gc_mem, \
unsigned init_node_count, unsigned init_group_count) \
{ \
const size_t max_thread = gc_mem->max_thread; \
/* Initialize the thread data of the mempool */ \
mem->thread_data = M_MEMORY_REALLOC(M_C(name, _lfmp_thread_ct), NULL, max_thread); \
if (mem->thread_data == NULL) { \
M_MEMORY_FULL(max_thread * sizeof(M_C(name, _lfmp_thread_ct))); \
return; \
} \
for(unsigned i = 0; i < max_thread;i++) { \
M_C(name, _lfmp_thread_init)(&mem->thread_data[i]); \
} \
/* Preallocate some group of nodes for the mempool */ \
mem->initial = M_MAX(M_CMEMP00L_MIN_NODE_PER_GROUP, init_node_count); \
M_C(name, _lflist_init)(mem->free, M_C(name, _alloc_node)(init_node_count)); \
M_C(name, _lflist_init)(mem->to_be_reclaimed, M_C(name, _alloc_node)(init_node_count)); \
M_C(name, _lflist_init)(mem->empty, M_C(name, _alloc_node)(0)); \
for(unsigned i = 1; i < init_group_count; i++) { \
M_C(name, _lflist_push)(mem->free, M_C(name, _alloc_node)(init_node_count), \
gc_mem->thread_data[0].bkoff); \
M_C(name, _lflist_push)(mem->empty, M_C(name, _alloc_node)(0), \
gc_mem->thread_data[0].bkoff); \
} \
/* Register the mempool in the GC */ \
mem->mempool_node.gc_on_sleep = M_C3(m_cmemp00l_,name,_gc_on_sleep); \
mem->mempool_node.next = gc_mem->mempool_list; \
gc_mem->mempool_list = &mem->mempool_node; \
mem->gc_mem = gc_mem; \
} \
\
static inline void \
M_C(name, _clear)(M_C(name, _t) mem) \
{ \
const unsigned max_thread = mem->gc_mem->max_thread; \
for(unsigned i = 0; i < max_thread;i++) { \
M_C(name, _lfmp_thread_clear)(&mem->thread_data[i]); \
} \
M_MEMORY_FREE(mem->thread_data); \
mem->thread_data = NULL; \
M_C(name, _lflist_clear)(mem->empty); \
M_C(name, _lflist_clear)(mem->free); \
M_ASSERT(M_C(name, _lflist_empty_p)(mem->to_be_reclaimed)); \
M_C(name, _lflist_clear)(mem->to_be_reclaimed); \
/* TODO: Unregister from the GC? */ \
} \
\
static inline type_t * \
M_C(name, _new)(M_C(name, _t) mem, m_gc_tid_t id) \
{ \
M_C(name, _slist_node_ct) *snode; \
M_C(name, _lf_node_t) *node; \
while (true) { \
/* Fast & likely path where we access the thread pool of nodes */ \
if (M_LIKELY(!M_C(name, _slist_empty_p)(mem->thread_data[id].free))) { \
snode = M_C(name, _slist_pop)(mem->thread_data[id].free); \
return &snode->data; \
} \
/* Request a group node to the freelist of groups */ \
node = M_C(name, _lflist_pop)(mem->free, mem->gc_mem->thread_data[id].bkoff); \
if (M_UNLIKELY (node == NULL)) { \
/* Request a new group to the system. Non Lock Free path */ \
M_ASSERT(mem->initial > 0); \
node = M_C(name, _alloc_node)(mem->initial); \
M_ASSERT(node != NULL); \
M_ASSERT(!M_C(name, _slist_empty_p)(node->list)); \
} \
M_C(name, _slist_move)(mem->thread_data[id].free, node->list); \
/* Push back the empty group */ \
M_ASSERT (M_C(name, _slist_empty_p)(node->list)); \
M_C(name, _lflist_push)(mem->empty, node, mem->gc_mem->thread_data[id].bkoff); \
} \
} \
\
static inline void \
M_C(name, _del)(M_C(name, _t) mem, type_t *d, m_gc_tid_t id) \
{ \
M_C(name, _slist_node_ct) *snode; \
M_ASSERT( d != NULL); \
snode = M_TYPE_FROM_FIELD(M_C(name, _slist_node_ct), d, type_t, data); \
M_C(name, _slist_push)(mem->thread_data[id].to_be_reclaimed, snode); \
} \
/***********************************************************************/
/* Define the ID of a thread */
typedef unsigned int m_gc_tid_t;
/* Define the age of a node */
/* TODO: Compute if sufficient (worst cast ULONG_MAX is 32 bits) */
typedef unsigned long m_gc_ticket_ct;
typedef atomic_ulong m_gc_atomic_ticket_ct;
/* Define the Linked List of mempools that are registered in the GC */
struct m_gc_s;
typedef struct m_gM_CMEMP00L_list_s {
struct m_gM_CMEMP00L_list_s *next;
void (*gc_on_sleep)(struct m_gc_s *gc_mem,
struct m_gM_CMEMP00L_list_s *data, m_gc_tid_t id,
m_gc_ticket_ct ticket, m_gc_ticket_ct min_ticket);
void *data;
} m_gM_CMEMP00L_list_ct;
/* Define the Garbage collector thread data */
typedef struct m_gc_lfmp_thread_s {
m_gc_atomic_ticket_ct ticket;
m_core_backoff_ct bkoff;
M_CACHELINE_ALIGN(align1, atomic_ulong, m_core_backoff_ct);
} m_gc_lfmp_thread_ct;
/* Define the Garbage collector coordinator */
typedef struct m_gc_s {
m_gc_atomic_ticket_ct ticket;
m_gc_tid_t max_thread;
genint_t thread_alloc;
m_gc_lfmp_thread_ct *thread_data;
m_gM_CMEMP00L_list_ct *mempool_list;
} m_gc_t[1];
static inline void
m_gc_init(m_gc_t gc_mem, size_t max_thread)
{
M_ASSERT(gc_mem != NULL);
M_ASSERT(max_thread > 0 && max_thread < INT_MAX);
atomic_init(&gc_mem->ticket, 0UL);
genint_init(gc_mem->thread_alloc, (unsigned int) max_thread);
gc_mem->thread_data = M_MEMORY_REALLOC(m_gc_lfmp_thread_ct, NULL, max_thread);
if (gc_mem->thread_data == NULL) {
M_MEMORY_FULL(max_thread * sizeof(m_gc_lfmp_thread_ct));
return;
}
for(unsigned i = 0; i < max_thread;i++) {
atomic_init(&gc_mem->thread_data[i].ticket, ULONG_MAX);
m_core_backoff_init(gc_mem->thread_data[i].bkoff);
}
gc_mem->max_thread = (unsigned int) max_thread;
gc_mem->mempool_list = NULL;
}
static inline void
m_gc_clear(m_gc_t gc_mem)
{
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
for(m_gc_tid_t i = 0; i < gc_mem->max_thread;i++) {
m_core_backoff_clear(gc_mem->thread_data[i].bkoff);
}
M_MEMORY_FREE(gc_mem->thread_data);
gc_mem->thread_data = NULL;
genint_clear(gc_mem->thread_alloc);
}
static inline m_gc_tid_t
m_gc_attach_thread(m_gc_t gc_mem)
{
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
unsigned id = genint_pop(gc_mem->thread_alloc);
return M_ASSIGN_CAST(m_gc_tid_t, id);
}
static inline void
m_gc_detach_thread(m_gc_t gc_mem, m_gc_tid_t id)
{
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
M_ASSERT(id < gc_mem->max_thread);
M_ASSERT(atomic_load(&gc_mem->thread_data[id].ticket) == ULONG_MAX);
genint_push(gc_mem->thread_alloc, id);
}
static inline void
m_gc_awake(m_gc_t gc_mem, m_gc_tid_t id)
{
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
M_ASSERT(id < gc_mem->max_thread);
M_ASSERT(atomic_load(&gc_mem->thread_data[id].ticket) == ULONG_MAX);
m_gc_ticket_ct t = atomic_fetch_add(&gc_mem->ticket, 1UL) + 1;
atomic_store(&gc_mem->thread_data[id].ticket, t);
}
static inline m_gc_ticket_ct
m_cmemp00l_gc_min_ticket(m_gc_t gc_mem)
{
m_gc_ticket_ct min = atomic_load(&gc_mem->thread_data[0].ticket);
for(m_gc_tid_t i = 1; i < gc_mem->max_thread; i++) {
m_gc_ticket_ct t = atomic_load(&gc_mem->thread_data[i].ticket);
min = M_MIN(t, min);
}
return min;
}
static inline void
m_gc_sleep(m_gc_t gc_mem, m_gc_tid_t id)
{
/* Increase life time of the thread */
m_gc_ticket_ct t = atomic_fetch_add(&gc_mem->ticket, 1UL);
atomic_store(&gc_mem->thread_data[id].ticket, t+1);
const m_gc_ticket_ct min_ticket = m_cmemp00l_gc_min_ticket(gc_mem);
/* Iterate over all registered mempools */
m_gM_CMEMP00L_list_ct *it = gc_mem->mempool_list;
while (it) {
/* Perform a garbage collect of the mempool */
it->gc_on_sleep(gc_mem, it, id, t, min_ticket);
/* Next mempool to scan for GC */
it = it->next;
}
/* Sleep the thread */
atomic_store(&gc_mem->thread_data[id].ticket, ULONG_MAX);
}
/***********************************************************************/
/* */
/* Variable Length Array MEMPOOL */
/* */
/***********************************************************************/
M_CMEMP00L_DEF_SINGLY_LIST(m_vlapool, char)
M_CMEMP00L_DEF_LF_QUEUE(m_vlapool, char)
M_CMEMP00L_DEF_SYSTEM_ALLOC(m_vlapool, char)
typedef struct m_vlapool_lfmp_thread_s {
m_vlapool_slist_ct to_be_reclaimed;
M_CACHELINE_ALIGN(align1, m_vlapool_slist_ct);
} m_vlapool_lfmp_thread_ct;
static inline void
m_vlapool_lfmp_thread_init(m_vlapool_lfmp_thread_ct *t)
{
m_vlapool_slist_init(t->to_be_reclaimed);
}
static inline void
m_vlapool_lfmp_thread_clear(m_vlapool_lfmp_thread_ct *t)
{
M_ASSERT(m_vlapool_slist_empty_p(t->to_be_reclaimed));
m_vlapool_slist_clear(t->to_be_reclaimed);
}
typedef struct m_vlapool_s {
m_vlapool_lflist_ct to_be_reclaimed;
m_vlapool_lflist_ct empty;
m_vlapool_lfmp_thread_ct *thread_data;
m_gM_CMEMP00L_list_ct mvla_node;
struct m_gc_s *gc_mem;
} m_vlapool_t[1];
/* Garbage collect of the nodes of the vla mempool on sleep */
static inline void
m_cmemp00l_vlapool_on_sleep(m_gc_t gc_mem, m_gM_CMEMP00L_list_ct *data,
m_gc_tid_t id, m_gc_ticket_ct ticket, m_gc_ticket_ct min_ticket)
{
/* Get back the mempool from the node */
struct m_vlapool_s *vlapool =
M_TYPE_FROM_FIELD(struct m_vlapool_s, data, m_gM_CMEMP00L_list_ct, mvla_node);
/* Move the local nodes of the vlapool to be reclaimed to the thread into the global pool */
if (!m_vlapool_slist_empty_p(vlapool->thread_data[id].to_be_reclaimed)) {
m_vlapool_lf_node_t *node;
/* Get a new empty group of nodes */
node = m_vlapool_lflist_pop(vlapool->empty, gc_mem->thread_data[id].bkoff);
if (M_UNLIKELY (node == NULL)) {
/* Fail to get an empty group of node.
Alloc a new one from the system */
node = m_vlapool_alloc_node(0);
M_ASSERT(node != NULL);
}
M_ASSERT(m_vlapool_slist_empty_p(node->list));
m_vlapool_slist_move(node->list, vlapool->thread_data[id].to_be_reclaimed);
atomic_store_explicit(&node->cpt, ticket, memory_order_relaxed);
m_vlapool_lflist_push(vlapool->to_be_reclaimed, node, gc_mem->thread_data[id].bkoff);
}
/* Perform a GC of the freelist of nodes */
while (true) {
m_vlapool_lf_node_t *node;
node = m_vlapool_lflist_pop_if(vlapool->to_be_reclaimed,
min_ticket, gc_mem->thread_data[id].bkoff);
if (node == NULL) break;
// No reuse of VLA nodes. Free physically the node back to the system
m_vlapool_slist_clear(node->list);
// Add back the empty group of nodes
m_vlapool_slist_init(node->list);
m_vlapool_lflist_push(vlapool->empty, node, gc_mem->thread_data[id].bkoff);
}
}
static inline void
m_vlapool_init(m_vlapool_t mem, m_gc_t gc_mem)
{
const size_t max_thread = gc_mem->max_thread;
/* Initialize the thread data of the vlapool */
mem->thread_data = M_MEMORY_REALLOC(m_vlapool_lfmp_thread_ct, NULL, max_thread);
if (mem->thread_data == NULL) {
M_MEMORY_FULL(max_thread * sizeof(m_vlapool_lfmp_thread_ct));
return;
}
for(unsigned i = 0; i < max_thread;i++) {
m_vlapool_lfmp_thread_init(&mem->thread_data[i]);
}
/* Initialize the lists */
m_vlapool_lflist_init(mem->to_be_reclaimed, m_vlapool_alloc_node(0));
m_vlapool_lflist_init(mem->empty, m_vlapool_alloc_node(0));
/* Register the mempool in the GC */
mem->mvla_node.gc_on_sleep = m_cmemp00l_vlapool_on_sleep;
mem->mvla_node.next = gc_mem->mempool_list;
gc_mem->mempool_list = &mem->mvla_node;
mem->gc_mem = gc_mem;
}
static inline void
m_vlapool_clear(m_vlapool_t mem)
{
const unsigned max_thread = mem->gc_mem->max_thread;
for(unsigned i = 0; i < max_thread;i++) {
m_vlapool_lfmp_thread_clear(&mem->thread_data[i]);
}
M_MEMORY_FREE(mem->thread_data);
mem->thread_data = NULL;
m_vlapool_lflist_clear(mem->empty);
M_ASSERT(m_vlapool_lflist_empty_p(mem->to_be_reclaimed));
m_vlapool_lflist_clear(mem->to_be_reclaimed);
/* TODO: Unregister from the GC? */
}
static inline void *
m_vlapool_new(m_vlapool_t mem, m_gc_tid_t id, size_t size)
{
M_ASSERT(mem != NULL && mem->gc_mem != NULL);
M_ASSERT(id < mem->gc_mem->max_thread);
M_ASSERT( atomic_load(&mem->gc_mem->thread_data[id].ticket) != ULONG_MAX);
// Nothing to do with theses parameters yet
(void) mem;
(void) id;
// Ensure the size is big enough to also represent a node
size += offsetof(struct m_vlapool_slist_node_s, data);
// Simply wrap around a system call to get the memory
char *ptr = M_MEMORY_REALLOC(char, NULL, size);
return (ptr == NULL) ? NULL : M_ASSIGN_CAST(void *, ptr + offsetof(struct m_vlapool_slist_node_s, data));
}
static inline void
m_vlapool_del(m_vlapool_t mem, void *d, m_gc_tid_t id)
{
M_ASSERT(mem != NULL && mem->gc_mem != NULL);
M_ASSERT(id < mem->gc_mem->max_thread);
M_ASSERT(atomic_load(&mem->gc_mem->thread_data[id].ticket) != ULONG_MAX);
M_ASSERT(d != NULL);
// Get back the pointer to a struct m_vlapool_slist_node_s.
d = M_ASSIGN_CAST(void *, M_ASSIGN_CAST(char *, d) - offsetof(struct m_vlapool_slist_node_s, data));
m_vlapool_slist_node_ct *snode = M_ASSIGN_CAST(m_vlapool_slist_node_ct *, d);
// Push the logicaly free memory into the list of the nodes to be reclaimed.
m_vlapool_slist_push(mem->thread_data[id].to_be_reclaimed, snode);
}
M_END_PROTECTED_CODE
#endif
+909
View File
@@ -0,0 +1,909 @@
/*
* M*LIB - Basic Protected Concurrent module over container.
*
* 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 MSTARLIB_CONCURRENT_H
#define MSTARLIB_CONCURRENT_H
#include "m-core.h"
#include "m-mutex.h"
#include "m-atomic.h"
/* Define a protected concurrent container and its associated functions
based on the given container.
USAGE: CONCURRENT_DEF(name, type [, oplist_of_the_type]) */
#define CONCURRENT_DEF(name, ...) \
CONCURRENT_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a protected concurrent container and its associated functions
based on the given container as the given name name_t
USAGE: CONCURRENT_DEF_AS(name, name_t, type [, oplist_of_the_type]) */
#define CONCURRENT_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \
M_C0NCURRENT_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
(name, __VA_ARGS__, name_t ))) \
M_END_PROTECTED_CODE
/* Define a protected concurrent container and its associated functions
based on its given container. Operations that perform only read of the container
can be done in parallel.
USAGE: CONCURRENT_RP_DEF(name, type [, oplist_of_the_type]) */
#define CONCURRENT_RP_DEF(name, ...) \
CONCURRENT_RP_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a protected concurrent container and its associated functions
as the given name name_t
based on its given container. Operations that perform only read of the container
can be done in parallel.
USAGE: CONCURRENT_RP_DEF_AS(name, name_t, type [, oplist_of_the_type]) */
#define CONCURRENT_RP_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \
M_C0NCURRENT_RP_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
(name, __VA_ARGS__, name_t ))) \
M_END_PROTECTED_CODE
/* Define the oplist of a protected concurrent container given its name and its oplist.
USAGE: CONCURRENT_OPLIST(name[, oplist of the type]) */
#define CONCURRENT_OPLIST(...) \
M_C0NCURRENT_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ )))
/********************************** INTERNAL ************************************/
/* Deferred evaluation for the oplist definition,
so that all arguments are evaluated before further expansion */
#define M_C0NCURRENT_OPLIST_P1(arg) M_C0NCURRENT_OPLIST_P2 arg
/* Validation of the given oplist */
#define M_C0NCURRENT_OPLIST_P2(name, oplist) \
M_IF_OPLIST(oplist)(M_C0NCURRENT_OPLIST_P3, M_C0NCURRENT_OPLIST_FAILURE)(name, oplist)
/* Prepare a clean compilation failure */
#define M_C0NCURRENT_OPLIST_FAILURE(name, oplist) \
((M_LIB_ERROR(ARGUMENT_OF_CONCURRENT_OPLIST_IS_NOT_AN_OPLIST, name, oplist)))
/* OPLIST definition
GET_KEY is not present as its interface is not compatible with a concurrent
container (_get returns a pointer to an internal data, data that may be
destroyed by another thread).
*/
#define M_C0NCURRENT_OPLIST_P3(name, oplist) \
(M_IF_METHOD(INIT, oplist)(INIT(M_C(name, _init)),) \
,M_IF_METHOD(INIT_SET, oplist)(INIT_SET(M_C(name, _init_set)),) \
,M_IF_METHOD(SET, oplist)(SET(M_C(name, _set)),) \
,M_IF_METHOD(CLEAR, oplist)(CLEAR(M_C(name, _clear)),) \
,M_IF_METHOD(INIT_MOVE, oplist)(INIT_MOVE(M_C(name, _init_move)),) \
,M_IF_METHOD(MOVE, oplist)(MOVE(M_C(name, _move)),) \
,M_IF_METHOD(SWAP,oplist)(SWAP(M_C(name, _swap)),) \
,NAME(name) \
,TYPE(M_C(name,_ct)) \
,SUBTYPE(M_C(name, _subtype_ct)) \
,OPLIST(oplist) \
,M_IF_METHOD(EMPTY_P, oplist)(EMPTY_P(M_C(name,_empty_p)),) \
,M_IF_METHOD(GET_SIZE, oplist)(GET_SIZE(M_C(name,_size)),) \
,M_IF_METHOD(RESET, oplist)(RESET(M_C(name,_reset)),) \
,M_IF_METHOD(KEY_TYPE, oplist)(KEY_TYPE(M_GET_KEY_TYPE oplist),) \
,M_IF_METHOD(VALUE_TYPE, oplist)(VALUE_TYPE(M_GET_VALUE_TYPE oplist),) \
,M_IF_METHOD(KEY_TYPE, oplist)(KEY_OPLIST(M_GET_KEY_OPLIST oplist),) \
,M_IF_METHOD(VALUE_TYPE, oplist)(VALUE_OPLIST(M_GET_VALUE_OPLIST oplist), ) \
,M_IF_METHOD(SET_KEY, oplist)(SET_KEY(M_C(name, _set_at)),) \
,M_IF_METHOD(ERASE_KEY, oplist)(ERASE_KEY(M_C(name, _erase)),) \
,M_IF_METHOD(PUSH, oplist)(PUSH(M_C(name,_push)),) \
,M_IF_METHOD(POP, oplist)(POP(M_C(name,_pop)),) \
,M_IF_METHOD(PUSH_MOVE, oplist)(PUSH_MOVE(M_C(name,_push_move)),) \
,M_IF_METHOD(POP_MOVE, oplist)(POP_MOVE(M_C(name,_pop_move)),) \
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \
,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \
,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \
,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \
,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),) \
,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),) \
,M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \
,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \
,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \
,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \
)
/* Internal contract
NOTE: Can't check too much without locking the container itself
*/
#define M_C0NCURRENT_CONTRACT(c) do { \
M_ASSERT ((c) != NULL); \
M_ASSERT ( (c)->self == (c)); \
} while (0)
/* Deferred evaluation for the concurrent definition,
so that all arguments are evaluated before further expansion */
#define M_C0NCURRENT_DEF_P1(arg) M_C0NCURRENT_DEF_P2 arg
/* Validate the value oplist before going further */
#define M_C0NCURRENT_DEF_P2(name, type, oplist, concurrent_t) \
M_IF_OPLIST(oplist)(M_C0NCURRENT_DEF_P3, M_C0NCURRENT_DEF_FAILURE)(name, type, oplist, concurrent_t)
/* Stop processing with a compilation failure */
#define M_C0NCURRENT_DEF_FAILURE(name, type, oplist, concurrent_t) \
M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(CONCURRENT_DEF): the given argument is not a valid oplist: " M_AS_STR(oplist))
/* Internal concurrent definition
- name: prefix to be used
- type: type of the sub container
- oplist: oplist of the type of the sub container
- concurrent_t: alias for M_C(name, _t) [ type of the container ]
*/
#define M_C0NCURRENT_DEF_P3(name, type, oplist, concurrent_t) \
\
/* Define a concurrent container using a lock */ \
typedef struct M_C(name, _s) { \
struct M_C(name, _s) *self; \
m_mutex_t lock; \
m_cond_t there_is_data; /* condition raised when there is data */ \
type data; \
} concurrent_t[1]; \
\
/* Define alias for pointer types */ \
typedef struct M_C(name, _s) *M_C(name, _ptr); \
typedef const struct M_C(name, _s) *M_C(name, _srcptr); \
\
/* Internal types for oplist */ \
typedef concurrent_t M_C(name, _ct); \
typedef type M_C(name, _subtype_ct); \
\
/* Don't define iterator as it cannot be reliable in a concurrent type */ \
M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \
\
/* Define the internal services used for the lock strategy */ \
\
/* Initial the fields of the concurrent object not associated to the \
sub-container. */ \
static inline void \
M_C(name, _internal_init)(concurrent_t out) \
{ \
m_mutex_init(out->lock); \
m_cond_init(out->there_is_data); \
out->self = out; \
M_C0NCURRENT_CONTRACT(out); \
} \
\
/* Clear the fields of the concurrent object not associated to the \
sub-container. */ \
static inline void \
M_C(name, _internal_clear)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_clear(out->lock); \
m_cond_clear(out->there_is_data); \
out->self = NULL; \
} \
\
/* Get the read lock. Multiple threads can get it, but only for reading. \
write lock is exclusive. \
NOTE: This instance doesn't implement the read/write strategy, \
and only get the lock */ \
static inline void \
M_C(name, _read_lock)(const concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_lock (out->self->lock); \
} \
\
/* Free the read lock. See above. \
NOTE: This instance doesn't implement the read/write strategy, \
and only get the lock */ \
static inline void \
M_C(name, _read_unlock)(const concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_unlock (out->self->lock); \
} \
\
/* Wait for a thread pushing some data in the container. \
CONSTRAINT: the read lock shall be get before calling this service */ \
static inline void \
M_C(name, _read_wait)(const concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_cond_wait(out->self->there_is_data, out->self->lock); \
} \
\
/* Get the write lock. Only one threads can get it, and no other threads \
can get the read lock too. \
NOTE: This instance doesn't implement the read/write strategy, \
and only get the lock */ \
static inline void \
M_C(name, _write_lock)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_lock (out->lock); \
} \
\
/* Free the write lock. \
NOTE: This instance doesn't implement the read/write strategy, \
and only get the lock */ \
static inline void \
M_C(name, _write_unlock)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_unlock (out->lock); \
} \
\
/* Wait for a thread pushing some data in the container. \
CONSTRAINT: the write lock shall be get before calling this service */ \
static inline void \
M_C(name, _write_wait)(const concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_cond_wait(out->self->there_is_data, out->self->lock); \
} \
\
/* Wait to all threads that some data are available in the container. \
CONSTRAINT: the write lock shall be get before calling this service */ \
static inline void \
M_C(name, _write_signal)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
/* We need to signal this to ALL waiting threads as multiple threads \
may wait on a some data of this container. */ \
m_cond_broadcast(out->there_is_data); \
} \
\
M_C0NCURRENT_DEF_FUNC_P3(name, type, oplist, concurrent_t)
/* Internal definition of the functions commons to concurrent and rp-concurrent
- name: prefix to be used
- type: type of the sub container
- oplist: oplist of the type of the sub container
- concurrent_t: alias for M_C(name, _t) [ type of the container ]
A function is defined only if the underlying container exports the needed
services. It is usually one service declared per service exported.
*/
#define M_C0NCURRENT_DEF_FUNC_P3(name, type, oplist, concurrent_t) \
\
M_IF_METHOD(INIT, oplist)( \
static inline void \
M_C(name, _init)(concurrent_t out) \
{ \
M_C(name, _internal_init)(out); \
M_CALL_INIT(oplist, out->data); \
M_C0NCURRENT_CONTRACT(out); \
} \
,) \
\
M_IF_METHOD(INIT_SET, oplist)( \
static inline void \
M_C(name, _init_set)(concurrent_t out, concurrent_t const src) \
{ \
M_C0NCURRENT_CONTRACT(src); \
M_ASSERT (out != src); \
M_C(name, _internal_init)(out); \
M_C(name, _read_lock)(src); \
M_CALL_INIT_SET(oplist, out->data, src->data); \
M_C(name, _read_unlock)(src); \
M_C0NCURRENT_CONTRACT(out); \
} \
,) \
\
M_IF_METHOD(SET, oplist)( \
static inline void \
M_C(name, _set)(concurrent_t out, concurrent_t const src) \
{ \
M_C0NCURRENT_CONTRACT(out); \
if (M_UNLIKELY (out == src)) return; \
/* Need to order the locks in a total way to avoid lock deadlock. \
Indeed, two call to _set can be done in two threads with : \
T1: A := B \
T2: B := A \
If we lock first the mutex of out, then the src, it could be possible \
in the previous scenario that both mutexs are locked: T1 has locked A \
and T2 has locked B, and T1 is waiting for locking B, and T2 is waiting \
for locking A, resulting in a deadlock. \
To avoid this problem, we **always** lock the mutex which address is \
the lowest. */ \
if (out < src) { \
M_C(name, _write_lock)(out); \
M_C(name, _read_lock)(src); \
} else { \
M_C(name, _read_lock)(src); \
M_C(name, _write_lock)(out); \
} \
M_CALL_SET(oplist, out->data, src->data); \
if (out < src) { \
M_C(name, _read_lock)(src); \
M_C(name, _write_unlock)(out); \
} else { \
M_C(name, _write_unlock)(out); \
M_C(name, _read_unlock)(src); \
} \
M_C0NCURRENT_CONTRACT(out); \
} \
,) \
\
M_IF_METHOD(CLEAR, oplist)( \
static inline void \
M_C(name, _clear)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
/* No need to lock. A clear is supposed to be called when all operations \
of the container in other threads are terminated */ \
M_CALL_CLEAR(oplist, out->data); \
M_C(name, _internal_clear)(out); \
} \
,) \
\
M_IF_METHOD(INIT_MOVE, oplist)( \
static inline void \
M_C(name, _init_move)(concurrent_t out, concurrent_t src) \
{ \
M_C0NCURRENT_CONTRACT(src); \
M_ASSERT (out != src); \
/* No need to lock 'src' ? */ \
M_C(name, _internal_init)(out); \
M_CALL_INIT_MOVE(oplist, out->data, src->data); \
M_C(name, _internal_clear)(src); \
M_C0NCURRENT_CONTRACT(out); \
} \
,) \
\
M_IF_METHOD(MOVE, oplist)( \
static inline void \
M_C(name, _move)(concurrent_t out, concurrent_t src) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C0NCURRENT_CONTRACT(src); \
/* No need to lock 'src' ? */ \
M_C(name, _write_lock)(out); \
M_CALL_MOVE(oplist, out->data, src->data); \
M_C(name, _write_unlock)(out); \
M_C(name, _internal_clear)(src); \
M_C0NCURRENT_CONTRACT(out); \
} \
,) \
\
M_IF_METHOD(SWAP, oplist)( \
static inline void \
M_C(name, _swap)(concurrent_t out, concurrent_t src) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C0NCURRENT_CONTRACT(src); \
if (M_UNLIKELY (out == src)) return; \
/* See comment above */ \
if (out < src) { \
M_C(name, _write_lock)(out); \
M_C(name, _write_lock)(src); \
} else { \
M_C(name, _write_lock)(src); \
M_C(name, _write_lock)(out); \
} \
M_CALL_SWAP(oplist, out->data, src->data); \
if (out < src) { \
M_C(name, _write_unlock)(src); \
M_C(name, _write_unlock)(out); \
} else { \
M_C(name, _write_unlock)(out); \
M_C(name, _write_unlock)(src); \
} \
} \
,) \
\
M_IF_METHOD(RESET, oplist)( \
static inline void \
M_C(name, _reset)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
M_CALL_RESET(oplist, out->data); \
M_C(name, _write_unlock)(out); \
} \
static inline void M_ATTR_DEPRECATED \
M_C(name, _clean)(concurrent_t out) \
{ \
M_C(name,_reset)(out); \
} \
,) \
\
M_IF_METHOD(EMPTY_P, oplist)( \
static inline bool \
M_C(name, _empty_p)(concurrent_t const out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _read_lock)(out); \
bool b = M_CALL_EMPTY_P(oplist, out->data); \
M_C(name, _read_unlock)(out); \
return b; \
} \
,) \
\
M_IF_METHOD(GET_SIZE, oplist)( \
static inline size_t \
M_C(name, _size)(concurrent_t const out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _read_lock)(out); \
size_t r = M_CALL_GET_SIZE(oplist, out->data); \
M_C(name, _read_unlock)(out); \
return r; \
} \
,) \
\
M_IF_METHOD(SET_KEY, oplist)( \
static inline void \
M_C(name, _set_at)(concurrent_t out, M_GET_KEY_TYPE oplist const key, M_GET_VALUE_TYPE oplist const data) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
M_CALL_SET_KEY(oplist, out->data, key, data); \
M_C(name, _write_signal)(out); \
M_C(name, _write_unlock)(out); \
} \
,) \
\
M_IF_METHOD(GET_KEY, oplist)( \
static inline bool \
M_C(name, _get_copy)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_ASSERT (out_data != NULL); \
M_C(name, _read_lock)(out); \
M_GET_VALUE_TYPE oplist *p = M_CALL_GET_KEY(oplist, out->data, key); \
if (p != NULL) { \
M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \
} \
M_C(name, _read_unlock)(out); \
return p != NULL; \
} \
,) \
\
M_IF_METHOD(SAFE_GET_KEY, oplist)( \
static inline void \
M_C(name, _safe_get_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_ASSERT (out_data != NULL); \
M_C(name, _write_lock)(out); \
M_GET_VALUE_TYPE oplist *p = M_CALL_SAFE_GET_KEY(oplist, out->data, key); \
M_ASSERT (p != NULL); \
M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \
M_C(name, _write_unlock)(out); \
} \
static inline M_ATTR_DEPRECATED void \
M_C(name, _get_at_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \
{ \
M_C(name, _safe_get_copy)(out_data, out, key); \
} \
,) \
\
M_IF_METHOD(ERASE_KEY, oplist)( \
static inline bool \
M_C(name, _erase)(concurrent_t out, M_GET_KEY_TYPE oplist const key) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
bool b = M_CALL_ERASE_KEY(oplist, out->data, key); \
/* We suppose that the container has 'infinite' capacity, so \
we won't signal that a free space has been created */ \
M_C(name, _write_unlock)(out); \
return b; \
} \
,) \
\
M_IF_METHOD(PUSH, oplist)( \
static inline void \
M_C(name, _push)(concurrent_t out, M_GET_SUBTYPE oplist const data) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
M_CALL_PUSH(oplist, out->data, data); \
M_C(name, _write_signal)(out); \
M_C(name, _write_unlock)(out); \
} \
,) \
\
M_IF_METHOD(POP, oplist)( \
static inline void \
M_C(name, _pop)(M_GET_SUBTYPE oplist *p, concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
M_CALL_POP(oplist, p, out->data); \
/* See comment above */ \
M_C(name, _write_unlock)(out); \
} \
,) \
\
M_IF_METHOD(PUSH_MOVE, oplist)( \
static inline void \
M_C(name, _push_move)(concurrent_t out, M_GET_SUBTYPE oplist *data) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
M_CALL_PUSH_MOVE(oplist, out->data, data); \
M_C(name, _write_signal)(out); \
M_C(name, _write_unlock)(out); \
} \
,) \
\
M_IF_METHOD(POP_MOVE, oplist)( \
static inline void \
M_C(name, _pop_move)(M_GET_SUBTYPE oplist *p, concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
M_CALL_POP_MOVE(oplist, p, out->data); \
/* See comment above */ \
M_C(name, _write_unlock)(out); \
} \
,) \
\
M_IF_METHOD(GET_STR, oplist)( \
static inline void \
M_C(name, _get_str)(string_t str, concurrent_t const out, bool a) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _read_lock)(out); \
M_CALL_GET_STR(oplist, str, out->data, a); \
M_C(name, _read_unlock)(out); \
} \
,) \
\
M_IF_METHOD(OUT_STR, oplist)( \
static inline void \
M_C(name, _out_str)(FILE *f, concurrent_t const out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _read_lock)(out); \
M_CALL_OUT_STR(oplist, f, out->data); \
M_C(name, _read_unlock)(out); \
} \
,) \
\
M_IF_METHOD(PARSE_STR, oplist)( \
static inline bool \
M_C(name, _parse_str)(concurrent_t out, const char str[], const char **e) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
bool b = M_CALL_PARSE_STR(oplist, out->data, str, e); \
M_C(name, _write_signal)(out); \
M_C(name, _write_unlock)(out); \
return b; \
} \
,) \
\
M_IF_METHOD(IN_STR, oplist)( \
static inline bool \
M_C(name, _in_str)(concurrent_t out, FILE *f) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
bool b = M_CALL_IN_STR(oplist, out->data, f); \
M_C(name, _write_signal)(out); \
M_C(name, _write_unlock)(out); \
return b; \
} \
,) \
\
M_IF_METHOD(OUT_SERIAL, oplist)( \
static inline m_serial_return_code_t \
M_C(name, _out_serial)(m_serial_write_t f, concurrent_t const out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _read_lock)(out); \
m_serial_return_code_t r = M_CALL_OUT_SERIAL(oplist, f, out->data); \
M_C(name, _read_unlock)(out); \
return r; \
} \
,) \
\
M_IF_METHOD(IN_SERIAL, oplist)( \
static inline m_serial_return_code_t \
M_C(name, _in_serial)(concurrent_t out, m_serial_read_t f) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _write_lock)(out); \
m_serial_return_code_t r = M_CALL_IN_SERIAL(oplist, out->data, f); \
M_C(name, _write_signal)(out); \
M_C(name, _write_unlock)(out); \
return r; \
} \
,) \
\
M_IF_METHOD(EQUAL, oplist)( \
static inline bool \
M_C(name, _equal_p)(concurrent_t const out1, concurrent_t const out2) \
{ \
M_C0NCURRENT_CONTRACT(out1); \
M_C0NCURRENT_CONTRACT(out2); \
if (M_UNLIKELY (out1 == out2)) return true; \
/* See comment above on mutal mutexs */ \
if (out1 < out2) { \
M_C(name, _read_lock)(out1); \
M_C(name, _read_lock)(out2); \
} else { \
M_C(name, _read_lock)(out2); \
M_C(name, _read_lock)(out1); \
} \
bool b = M_CALL_EQUAL(oplist, out1->data, out2->data); \
if (out1 < out2) { \
M_C(name, _read_unlock)(out2); \
M_C(name, _read_unlock)(out1); \
} else { \
M_C(name, _read_unlock)(out1); \
M_C(name, _read_unlock)(out2); \
} \
return b; \
} \
,) \
\
M_IF_METHOD(GET_KEY, oplist)( \
static inline bool \
M_C(name, _get_blocking)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key, bool blocking) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_ASSERT (out_data != NULL); \
bool ret = false; \
M_C(name, _read_lock)(out); \
while (true) { \
M_GET_VALUE_TYPE oplist *p = M_CALL_GET_KEY(oplist, out->data, key); \
if (p != NULL) { \
M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \
ret = true; \
break; \
} \
if (blocking == false) break; \
/* No data: wait for a write to signal some data */ \
M_C(name, _read_wait)(out); \
} \
M_C(name, _read_unlock)(out); \
return ret; \
} \
,) \
\
M_IF_METHOD2(POP, EMPTY_P, oplist)( \
static inline bool \
M_C(name, _pop_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_ASSERT (p != NULL); \
bool ret = false; \
M_C(name, _write_lock)(out); \
while (true) { \
if (!M_CALL_EMPTY_P(oplist, out->data)) { \
M_CALL_POP(oplist, p, out->data); \
ret = true; \
break; \
} \
if (blocking == false) break; \
/* No data: wait for a write to signal some data */ \
M_C(name, _write_wait)(out); \
} \
M_C(name, _write_unlock)(out); \
return ret; \
} \
,) \
\
M_IF_METHOD2(POP_MOVE, EMPTY_P, oplist)( \
static inline bool \
M_C(name, _pop_move_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_ASSERT (p != NULL); \
bool ret = false; \
M_C(name, _write_lock)(out); \
while (true) { \
if (!M_CALL_EMPTY_P(oplist, out->data)) { \
M_CALL_POP_MOVE(oplist, p, out->data); \
ret = true; \
break; \
} \
if (blocking == false) break; \
/* No data: wait for a write to signal some data */ \
M_C(name, _write_wait)(out); \
} \
M_C(name, _write_unlock)(out); \
return ret; \
} \
,) \
\
M_IF_METHOD(HASH, oplist)( \
static inline size_t \
M_C(name, _hash)(concurrent_t const out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
M_C(name, _read_lock)(out); \
size_t h = M_CALL_HASH(oplist, out->data); \
M_C(name, _read_unlock)(out); \
/* The hash is unchanged by the concurrent container */ \
return h; \
} \
,) \
/* Deferred evaluation for the RP concurrent definition,
so that all arguments are evaluated before further expansion */
#define M_C0NCURRENT_RP_DEF_P1(arg) M_C0NCURRENT_RP_DEF_P2 arg
/* Validate the value oplist before going further */
#define M_C0NCURRENT_RP_DEF_P2(name, type, oplist, concurrent_t) \
M_IF_OPLIST(oplist)(M_C0NCURRENT_RP_DEF_P3, M_C0NCURRENT_RP_DEF_FAILURE)(name, type, oplist, concurrent_t)
/* Stop processing with a compilation failure */
#define M_C0NCURRENT_RP_DEF_FAILURE(name, type, oplist, concurrent_t) \
M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(CONCURRENT_RP_DEF): the given argument is not a valid oplist: " M_AS_STR(oplist))
/* Internal RP concurrent definition
- name: prefix to be used
- type: type of the sub container
- oplist: oplist of the type of the sub container
- concurrent_t: alias for M_C(name, _t) [ type of the container ]
*/
#define M_C0NCURRENT_RP_DEF_P3(name, type, oplist, concurrent_t) \
\
typedef struct M_C(name, _s) { \
struct M_C(name, _s) *self; \
m_mutex_t lock; \
m_cond_t rw_done; \
size_t read_count; \
bool writer_waiting; \
m_cond_t there_is_data; /* condition raised when there is data */ \
type data; \
} concurrent_t[1]; \
\
typedef struct M_C(name, _s) *M_C(name, _ptr); \
typedef const struct M_C(name, _s) *M_C(name, _srcptr); \
\
typedef type M_C(name, _subtype_ct); \
\
/* Define the internal services for the lock strategy */ \
static inline void \
M_C(name, _internal_init)(concurrent_t out) \
{ \
m_mutex_init(out->lock); \
m_cond_init(out->rw_done); \
m_cond_init(out->there_is_data); \
out->self = out; \
out->read_count = 0; \
out->writer_waiting = false; \
M_C0NCURRENT_CONTRACT(out); \
} \
\
static inline void \
M_C(name, _internal_clear)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_clear(out->lock); \
m_cond_clear(out->rw_done); \
m_cond_clear(out->there_is_data); \
out->self = NULL; \
} \
\
static inline void \
M_C(name, _read_lock)(const concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
struct M_C(name, _s) *self = out->self; \
m_mutex_lock (self->lock); \
while (self->writer_waiting == true) { \
m_cond_wait(self->rw_done, self->lock); \
} \
self->read_count ++; \
m_mutex_unlock (self->lock); \
} \
\
static inline void \
M_C(name, _read_unlock)(const concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
struct M_C(name, _s) *self = out->self; \
m_mutex_lock (self->lock); \
self->read_count --; \
if (self->read_count == 0) { \
m_cond_broadcast (self->rw_done); \
} \
m_mutex_unlock (self->lock); \
} \
\
static inline void \
M_C(name, _write_lock)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_lock (out->lock); \
while (out->writer_waiting == true) { \
m_cond_wait(out->rw_done, out->lock); \
} \
out->writer_waiting = true; \
while (out->read_count > 0) { \
m_cond_wait(out->rw_done, out->lock); \
} \
m_mutex_unlock (out->lock); \
} \
\
static inline void \
M_C(name, _write_unlock)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_lock (out->lock); \
out->writer_waiting = false; \
m_cond_broadcast (out->rw_done); \
m_mutex_unlock (out->lock); \
} \
\
static inline void \
M_C(name, _read_wait)(const concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
struct M_C(name, _s) *self = out->self; \
M_ASSERT (self == out); \
m_mutex_lock (out->self->lock); \
self->read_count --; \
if (self->read_count == 0) { \
m_cond_broadcast (self->rw_done); \
} \
m_cond_wait(self->there_is_data, self->lock); \
while (self->writer_waiting == true) { \
m_cond_wait(self->rw_done, self->lock); \
} \
self->read_count ++; \
m_mutex_unlock (out->self->lock); \
} \
\
static inline void \
M_C(name, _write_wait)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_lock (out->lock); \
out->writer_waiting = false; \
m_cond_broadcast (out->rw_done); \
m_cond_wait(out->there_is_data, out->lock); \
while (out->writer_waiting == true) { \
m_cond_wait(out->rw_done, out->lock); \
} \
out->writer_waiting = true; \
while (out->read_count > 0) { \
m_cond_wait(out->rw_done, out->lock); \
} \
m_mutex_unlock (out->lock); \
} \
\
static inline void \
M_C(name, _write_signal)(concurrent_t out) \
{ \
M_C0NCURRENT_CONTRACT(out); \
m_mutex_lock (out->lock); \
m_cond_broadcast(out->there_is_data); \
m_mutex_unlock (out->lock); \
} \
\
M_C0NCURRENT_DEF_FUNC_P3(name, type, oplist, concurrent_t)
#endif
+2575 -445
View File
File diff suppressed because it is too large. Load diff
+1065 -735
View File
File diff suppressed because it is too large. Load diff
+1904 -1186
View File
File diff suppressed because it is too large. Load diff
Loaded 100 of 167 files, more files were not shown because too many files have changed in this diff. Show more