更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_rbtree.h 文件参考

浏览源代码.

结构体

struct  TagRbNode
 
struct  TagRbTree
 
struct  TagRbWalk
 记录步数 更多...
 

类型定义

typedef struct TagRbNode LosRbNode
 
typedef ULONG_T(* pfRBCmpKeyFn) (const VOID *, const VOID *)
 
typedef ULONG_T(* pfRBFreeFn) (LosRbNode *)
 
typedef VOID *(* pfRBGetKeyFn) (LosRbNode *)
 
typedef struct TagRbTree LosRbTree
 
typedef struct TagRbWalk LosRbWalk
 记录步数 更多...
 

函数

VOID * LOS_RbFirstNode (LosRbTree *pstTree)
 
VOID * LOS_RbSuccessorNode (LosRbTree *pstTree, VOID *pstData)
 
VOID LOS_RbInitTree (LosRbTree *pstTree, pfRBCmpKeyFn pfCmpKey, pfRBFreeFn pfFree, pfRBGetKeyFn pfGetKey)
 
VOID LOS_RbDestroyTree (LosRbTree *pstTree)
 
LosRbNodeLOS_RbGetNextNode (LosRbTree *pstTree, VOID *pKey)
 
ULONG_T LOS_RbGetNode (LosRbTree *pstTree, VOID *pKey, LosRbNode **ppstNode)
 
VOID LOS_RbDelNode (LosRbTree *pstTree, LosRbNode *pstNode)
 
ULONG_T LOS_RbAddNode (LosRbTree *pstTree, LosRbNode *pstNew)
 
LosRbWalkLOS_RbCreateWalk (LosRbTree *pstTree)
 
VOID * LOS_RbWalkNext (LosRbWalk *pstWalk)
 
VOID LOS_RbDeleteWalk (LosRbWalk *pstWalk)
 

类型定义说明

◆ LosRbNode

typedef struct TagRbNode LosRbNode

◆ LosRbTree

typedef struct TagRbTree LosRbTree

◆ LosRbWalk

typedef struct TagRbWalk LosRbWalk

记录步数

◆ pfRBCmpKeyFn

typedef ULONG_T(* pfRBCmpKeyFn) (const VOID *, const VOID *)

在文件 los_rbtree.h58 行定义.

◆ pfRBFreeFn

typedef ULONG_T(* pfRBFreeFn) (LosRbNode *)

在文件 los_rbtree.h59 行定义.

◆ pfRBGetKeyFn

typedef VOID *(* pfRBGetKeyFn) (LosRbNode *)

在文件 los_rbtree.h60 行定义.

函数说明

◆ LOS_RbAddNode()

ULONG_T LOS_RbAddNode ( LosRbTree pstTree,
LosRbNode pstNew 
)

在文件 los_rbtree.c705 行定义.

706{
707 ULONG_T ulSearchNode;
708 VOID *pNodeKey = NULL;
709 LosRbNode *pstX = NULL;
710
711 if ((NULL == pstTree) || (NULL == pstNew)) {
712 return FALSE;
713 }
714 if ((NULL == pstTree->pfGetKey) || (NULL == pstTree->pfCmpKey)) {
715 return FALSE;
716 }
717
718 pNodeKey = pstTree->pfGetKey(pstNew);
719 ulSearchNode = LOS_RbGetNode(pstTree, pNodeKey, &pstX);
720 if (TRUE == ulSearchNode) {
721 return FALSE;
722 }
723
724 if (NULL == pstX) {
725 return FALSE;
726 }
727
728 LOS_RbInsertOneNodeProcess(pstTree, pstX, pstNew);
729
730 return TRUE;
731}
VOID LOS_RbInsertOneNodeProcess(LosRbTree *pstTree, LosRbNode *pstParent, LosRbNode *pstNew)
Definition: los_rbtree.c:497
ULONG_T LOS_RbGetNode(LosRbTree *pstTree, VOID *pKey, LosRbNode **ppstNode)
Definition: los_rbtree.c:656
unsigned int ULONG_T
Definition: los_typedef.h:214
pfRBCmpKeyFn pfCmpKey
Definition: los_rbtree.h:68
pfRBGetKeyFn pfGetKey
Definition: los_rbtree.h:70
函数调用图:
这是这个函数的调用关系图:

◆ LOS_RbCreateWalk()

LosRbWalk * LOS_RbCreateWalk ( LosRbTree pstTree)

在文件 los_rbtree.c435 行定义.

436{
437 LosRbNode *pstNode = NULL;
438 LosRbWalk *pstWalk = NULL;
439
440 if (NULL == pstTree) {
441 return NULL;
442 }
443
444 pstNode = LOS_RbFirstNode(pstTree);
445 if (NULL == pstNode) {
446 return NULL;
447 }
448
449 pstWalk = (LosRbWalk *)LOS_MemAlloc(m_aucSysMem0, sizeof(LosRbWalk));
450 if (NULL == pstWalk) {
451 return NULL;
452 }
453
454 LOS_ListAdd(&pstTree->stWalkHead, &pstWalk->stLink);
455 pstWalk->pstCurrNode = pstNode;
456 pstWalk->pstTree = pstTree;
457 return pstWalk;
458}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a new node to a doubly linked list.
Definition: los_list.h:217
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
Definition: los_memory.c:107
VOID * LOS_RbFirstNode(LosRbTree *pstTree)
Definition: los_rbtree.c:562
LOS_DL_LIST stWalkHead
Definition: los_rbtree.h:65
记录步数
Definition: los_rbtree.h:73
LosRbNode * pstCurrNode
Definition: los_rbtree.h:75
struct TagRbTree * pstTree
Definition: los_rbtree.h:76
LOS_DL_LIST stLink
Definition: los_rbtree.h:74
函数调用图:

◆ LOS_RbDeleteWalk()

VOID LOS_RbDeleteWalk ( LosRbWalk pstWalk)

在文件 los_rbtree.c481 行定义.

482{
483 if (NULL == pstWalk) {
484 return;
485 }
486
487 if (LOS_DL_LIST_IS_ON_QUEUE(&pstWalk->stLink)) {
488 LOS_ListDelete(&pstWalk->stLink);
489 }
490 pstWalk->pstCurrNode = NULL;
491 pstWalk->pstTree = NULL;
492 LOS_MemFree(m_aucSysMem0, pstWalk);
493
494 return;
495}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
Definition: los_list.h:292
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
函数调用图:

◆ LOS_RbDelNode()

VOID LOS_RbDelNode ( LosRbTree pstTree,
LosRbNode pstNode 
)

在文件 los_rbtree.c700 行定义.

701{
702 OsRbDeleteNode(pstTree, pstNode);
703}
STATIC VOID OsRbDeleteNode(LosRbTree *pstTree, VOID *pstData)
Definition: los_rbtree.c:257
函数调用图:
这是这个函数的调用关系图:

◆ LOS_RbDestroyTree()

VOID LOS_RbDestroyTree ( LosRbTree pstTree)

在文件 los_rbtree.c539 行定义.

540{
541 LosRbNode *pstNode = NULL;
542
543 if (NULL == pstTree) {
544 return;
545 }
546 if (NULL == pstTree->pfFree) {
547 return;
548 }
549
550 RB_WALK(pstTree, pstNode, pstWalk)
551 {
552 OsRbDeleteNode(pstTree, pstNode);
553 (VOID)pstTree->pfFree(pstNode);
554 }
555 RB_WALK_END(pstTree, pstNode, pstWalk);
556
557 OsRbClearTree(pstTree);
558
559 return;
560}
STATIC VOID OsRbClearTree(LosRbTree *pstTree)
Definition: los_rbtree.c:413
pfRBFreeFn pfFree
Definition: los_rbtree.h:69
函数调用图:

◆ LOS_RbFirstNode()

VOID * LOS_RbFirstNode ( LosRbTree pstTree)

在文件 los_rbtree.c562 行定义.

563{
564 LosRbNode *pstNode = NULL;
565 LosRbNode *pstNilT = NULL;
566
567 if (NULL == pstTree) {
568 return NULL;
569 }
570
571 pstNode = pstTree->pstRoot;
572 if (pstNode == NULL) {
573 return NULL;
574 }
575 pstNilT = &(pstTree->stNilT);
576
577 if (pstNilT == pstNode) {
578 return NULL;
579 }
580
581 while (pstNilT != pstNode->pstLeft) {
582 pstNode = pstNode->pstLeft;
583 }
584
585 return pstNode;
586}
struct TagRbNode * pstLeft
左孩子是谁 ?
Definition: los_rbtree.h:54
LosRbNode stNilT
Definition: los_rbtree.h:64
LosRbNode * pstRoot
Definition: los_rbtree.h:63
这是这个函数的调用关系图:

◆ LOS_RbGetNextNode()

LosRbNode * LOS_RbGetNextNode ( LosRbTree pstTree,
VOID *  pKey 
)

在文件 los_rbtree.c631 行定义.

632{
633 LosRbNode *pNode = NULL;
634
635 if (TRUE == LOS_RbGetNode(pstTree, pKey, &pNode)) {
636 return LOS_RbSuccessorNode(pstTree, pNode);
637 } else if ((NULL == pNode) || (&pstTree->stNilT == pNode)) {
638 return NULL;
639 } else if (RB_BIGGER == pstTree->pfCmpKey(pKey, pstTree->pfGetKey(pNode))) {
640 while (NULL != pNode) {
641 pNode = LOS_RbSuccessorNode(pstTree, pNode);
642 if (NULL == pNode) {
643 return NULL;
644 }
645
646 if (RB_SMALLER == pstTree->pfCmpKey(pKey, pstTree->pfGetKey(pNode))) {
647 break;
648 }
649 }
650 return pNode;
651 } else {
652 return pNode;
653 }
654}
VOID * LOS_RbSuccessorNode(LosRbTree *pstTree, VOID *pstData)
Definition: los_rbtree.c:588
函数调用图:

◆ LOS_RbGetNode()

ULONG_T LOS_RbGetNode ( LosRbTree pstTree,
VOID *  pKey,
LosRbNode **  ppstNode 
)

在文件 los_rbtree.c656 行定义.

657{
658 LosRbNode *pstNilT = NULL;
659 LosRbNode *pstX = NULL;
660 LosRbNode *pstY = NULL;
661 VOID *pNodeKey = NULL;
662 ULONG_T ulCmpResult;
663
664 if ((NULL == pstTree) || (NULL == pKey) || (NULL == ppstNode)) {
665 if (NULL != ppstNode) {
666 *ppstNode = NULL;
667 }
668 return FALSE;
669 }
670 if ((NULL == pstTree->pfGetKey) || (NULL == pstTree->pfCmpKey)) {
671 *ppstNode = NULL;
672 return FALSE;
673 }
674
675 pstNilT = &pstTree->stNilT;
676 pstY = pstTree->pstRoot;
677 pstX = pstY;
678
679 while (pstX != pstNilT) {
680 pNodeKey = pstTree->pfGetKey(pstX);
681
682 ulCmpResult = pstTree->pfCmpKey(pKey, pNodeKey);
683 if (RB_EQUAL == ulCmpResult) {
684 *ppstNode = pstX;
685 return TRUE;
686 }
687 if (RB_SMALLER == ulCmpResult) {
688 pstY = pstX;
689 pstX = pstX->pstLeft;
690 } else {
691 pstY = pstX;
692 pstX = pstX->pstRight;
693 }
694 }
695
696 *ppstNode = pstY;
697 return FALSE;
698}
struct TagRbNode * pstRight
右孩子是谁 ?
Definition: los_rbtree.h:53
这是这个函数的调用关系图:

◆ LOS_RbInitTree()

VOID LOS_RbInitTree ( LosRbTree pstTree,
pfRBCmpKeyFn  pfCmpKey,
pfRBFreeFn  pfFree,
pfRBGetKeyFn  pfGetKey 
)

在文件 los_rbtree.c524 行定义.

525{
526 if (NULL == pstTree) {
527 return;
528 }
529
530 OsRbInitTree(pstTree);
531
532 pstTree->pfCmpKey = pfCmpKey;
533 pstTree->pfFree = pfFree;
534 pstTree->pfGetKey = pfGetKey;
535
536 return;
537}
STATIC VOID OsRbInitTree(LosRbTree *pstTree)
Definition: los_rbtree.c:392
函数调用图:
这是这个函数的调用关系图:

◆ LOS_RbSuccessorNode()

VOID * LOS_RbSuccessorNode ( LosRbTree pstTree,
VOID *  pstData 
)

在文件 los_rbtree.c588 行定义.

589{
590 LosRbNode *pstY = NULL;
591 LosRbNode *pstNilT = NULL;
592 LosRbNode *pstNode = NULL;
593
594 if (NULL == pstTree) {
595 return NULL;
596 }
597
598 pstNode = (LosRbNode *)pstData;
599
600 if (NULL == pstNode) {
601 return NULL;
602 }
603
604 /* NilT is forbidden. */
605 if (!RB_IS_NOT_NILT(pstNode)) {
606 return NULL;
607 }
608
609 /* if we arrive here, pstTree is no NULL */
610 pstNilT = &(pstTree->stNilT);
611
612 if (pstNilT != pstNode->pstRight) {
613 pstNode = pstNode->pstRight;
614 while (pstNilT != pstNode->pstLeft) {
615 pstNode = pstNode->pstLeft;
616 }
617
618 return pstNode;
619 }
620
621 pstY = pstNode->pstParent;
622
623 while ((pstNilT != pstY) && (pstNode == pstY->pstRight)) {
624 pstNode = pstY;
625 pstY = pstY->pstParent;
626 }
627
628 return ((pstNilT == pstY) ? NULL : pstY);
629}
struct TagRbNode * pstParent
爸爸是谁 ?
Definition: los_rbtree.h:52
这是这个函数的调用关系图:

◆ LOS_RbWalkNext()

VOID * LOS_RbWalkNext ( LosRbWalk pstWalk)

在文件 los_rbtree.c460 行定义.

461{
462 LosRbNode *pstNode = NULL;
463
464 /*
465 * Here, in the previous code, we didn't check pstCurrNode
466 * pstTree, but in some circumstance, we will delete a tree
467 * (by calling function RB_ClearTree), meanwhile, we will
468 * evaluate pstCurrNode and pstTree to NULL, but at present,
469 * if we are walking groups and ports, then we will call this
470 * function(LOS_RbWalkNext), but the tree has been deleted already
471 */
472 if ((NULL == pstWalk) || (NULL == pstWalk->pstCurrNode) || (NULL == pstWalk->pstTree)) {
473 return NULL;
474 }
475
476 pstNode = pstWalk->pstCurrNode;
477 pstWalk->pstCurrNode = LOS_RbSuccessorNode(pstWalk->pstTree, pstNode);
478 return pstNode;
479}
函数调用图: