4141// --------------------------------------------- INTERNAL INCLUDES ----------------------------------------------
4242// The internal includes are placed here after the config header is included and CANARD_ASSERT is defined.
4343#define CAVL2_T struct CanardTreeNode
44- #include <cavl2.h>
44+ #define CAVL2_ASSERT (x ) CANARD_ASSERT(x)
45+ #include <../lib/cavl2/cavl2.h>
4546
4647// --------------------------------------------- COMMON DEFINITIONS ---------------------------------------------
4748
7677#define MUTABLE_CONTAINER_OF (type , ptr , member ) \
7778 ((type*) (((ptr) == NULL) ? NULL : (void*) (((char*) (ptr)) - offsetof(type, member))))
7879
79- /// Used for inserting new items into AVL trees.
80- CANARD_PRIVATE struct CanardTreeNode * avlTrivialFactory (void * const user_reference )
81- {
82- return (struct CanardTreeNode * ) user_reference ;
83- }
84-
8580// --------------------------------------------- TRANSFER CRC ---------------------------------------------
8681
8782typedef uint16_t TransferCRC ;
@@ -340,8 +335,8 @@ CANARD_PRIVATE struct CanardTxQueueItem* txAllocateQueueItem(struct CanardTxQueu
340335/// Frames with identical CAN ID that are added later always compare greater than their counterparts with same CAN ID.
341336/// This ensures that CAN frames with the same CAN ID are transmitted in the FIFO order.
342337/// Frames that should be transmitted earlier compare smaller (i.e., put on the left side of the tree).
343- CANARD_PRIVATE ptrdiff_t txAVLPriorityPredicate ( //
344- const void * user_reference , // NOSONAR Cavl API requires pointer to non-const.
338+ CANARD_PRIVATE ptrdiff_t txAVLPriorityPredicate ( //
339+ const void * const user_reference ,
345340 const struct CanardTreeNode * const node )
346341{
347342 typedef struct CanardTxQueueItem TxItem ;
@@ -405,7 +400,7 @@ CANARD_PRIVATE int32_t txPushSingleFrame(struct CanardTxQueue* const que,
405400 & tqi -> priority_base ,
406401 & txAVLPriorityPredicate ,
407402 & tqi -> priority_base ,
408- & avlTrivialFactory );
403+ & cavl2_trivial_factory );
409404 (void ) priority_queue_res ;
410405 CANARD_ASSERT (priority_queue_res == & tqi -> priority_base );
411406
@@ -414,7 +409,7 @@ CANARD_PRIVATE int32_t txPushSingleFrame(struct CanardTxQueue* const que,
414409 & tqi -> deadline_base ,
415410 & txAVLDeadlinePredicate ,
416411 & tqi -> deadline_base ,
417- & avlTrivialFactory );
412+ & cavl2_trivial_factory );
418413 (void ) deadline_queue_res ;
419414 CANARD_ASSERT (deadline_queue_res == & tqi -> deadline_base );
420415
@@ -562,7 +557,7 @@ CANARD_PRIVATE int32_t txPushMultiFrame(struct CanardTxQueue* const que,
562557 & next -> priority_base ,
563558 & txAVLPriorityPredicate ,
564559 & next -> priority_base ,
565- & avlTrivialFactory );
560+ & cavl2_trivial_factory );
566561 (void ) priority_queue_res ;
567562 CANARD_ASSERT (priority_queue_res == & next -> priority_base );
568563 CANARD_ASSERT (que -> priority_root != NULL );
@@ -571,7 +566,7 @@ CANARD_PRIVATE int32_t txPushMultiFrame(struct CanardTxQueue* const que,
571566 & next -> deadline_base ,
572567 & txAVLDeadlinePredicate ,
573568 & next -> deadline_base ,
574- & avlTrivialFactory );
569+ & cavl2_trivial_factory );
575570 (void ) deadline_queue_res ;
576571 CANARD_ASSERT (deadline_queue_res == & next -> deadline_base );
577572 CANARD_ASSERT (que -> deadline_root != NULL );
@@ -1353,12 +1348,9 @@ int8_t canardRxAccept(struct CanardInstance* const ins,
13531348 // This is the reason the function has a logarithmic time complexity of the number of subscriptions.
13541349 // Note also that this one of the two variable-complexity operations in the RX pipeline; the other one
13551350 // is memcpy(). Excepting these two cases, the entire RX pipeline contains neither loops nor recursion.
1356- struct CanardTreeNode * const sub_node =
1357- cavl2_find_or_insert (& ins -> rx_subscriptions [(size_t ) model .transfer_kind ],
1358- & model .port_id ,
1359- & rxSubscriptionPredicateOnPortID ,
1360- ins ,
1361- NULL );
1351+ struct CanardTreeNode * const sub_node = cavl2_find (ins -> rx_subscriptions [(size_t ) model .transfer_kind ],
1352+ & model .port_id ,
1353+ & rxSubscriptionPredicateOnPortID );
13621354 struct CanardRxSubscription * const sub =
13631355 MUTABLE_CONTAINER_OF (struct CanardRxSubscription , sub_node , base );
13641356 if (out_subscription != NULL )
@@ -1420,7 +1412,7 @@ int8_t canardRxSubscribe(struct CanardInstance* const ins,
14201412 & out_subscription -> base ,
14211413 & rxSubscriptionPredicateOnStruct ,
14221414 out_subscription ,
1423- & avlTrivialFactory );
1415+ & cavl2_trivial_factory );
14241416 (void ) res ;
14251417 CANARD_ASSERT (res == & out_subscription -> base );
14261418 out = (out > 0 ) ? 0 : 1 ;
@@ -1439,12 +1431,8 @@ int8_t canardRxUnsubscribe(struct CanardInstance* const ins,
14391431 {
14401432 CanardPortID port_id_mutable = port_id ;
14411433
1442- struct CanardTreeNode * const sub_node = cavl2_find_or_insert ( //
1443- & ins -> rx_subscriptions [tk ],
1444- & port_id_mutable ,
1445- & rxSubscriptionPredicateOnPortID ,
1446- NULL ,
1447- NULL );
1434+ struct CanardTreeNode * const sub_node =
1435+ cavl2_find (ins -> rx_subscriptions [tk ], & port_id_mutable , & rxSubscriptionPredicateOnPortID );
14481436 if (sub_node != NULL )
14491437 {
14501438 struct CanardRxSubscription * const sub = MUTABLE_CONTAINER_OF (struct CanardRxSubscription , sub_node , base );
@@ -1483,11 +1471,8 @@ int8_t canardRxGetSubscription(struct CanardInstance* const ins,
14831471 {
14841472 CanardPortID port_id_mutable = port_id ;
14851473
1486- struct CanardTreeNode * const sub_node = cavl2_find_or_insert (& ins -> rx_subscriptions [tk ],
1487- & port_id_mutable ,
1488- & rxSubscriptionPredicateOnPortID ,
1489- NULL ,
1490- NULL );
1474+ struct CanardTreeNode * const sub_node =
1475+ cavl2_find (ins -> rx_subscriptions [tk ], & port_id_mutable , & rxSubscriptionPredicateOnPortID );
14911476 if (sub_node != NULL )
14921477 {
14931478 struct CanardRxSubscription * const sub = MUTABLE_CONTAINER_OF (struct CanardRxSubscription , sub_node , base );
0 commit comments