From a16a71084b4a3493886409bd4ae67a603b25d5fc Mon Sep 17 00:00:00 2001 From: sauron Date: Sun, 14 Sep 2025 18:37:25 +0900 Subject: [PATCH] commit 2025-09-14 18:37 is testing ZtCBody::Fetch() in ZCppMain/ZtCObjList.H --- ZCppMain/ZtCObjList.H | 237 ++++++++++++++++++++++++++++++++++++++-- ZCppMain/ZtCSimList.H | 6 + ZCppMainTest/ZtCObjList_000.cpp | 26 +++++ 3 files changed, 261 insertions(+), 8 deletions(-) diff --git a/ZCppMain/ZtCObjList.H b/ZCppMain/ZtCObjList.H index 2f1fd0c..92a6669 100644 --- a/ZCppMain/ZtCObjList.H +++ b/ZCppMain/ZtCObjList.H @@ -212,8 +212,7 @@ namespace ZNsMain } else if( AL_FarNum < ml_UseSize) // ( (AL_FarNum<0 ? -AL_FarNum : AL_FarNum)+1 <= ml_UseSize) { - ml_UseSize -= AL_FarNum+1 ; - + ml_UseSize -= AL_FarNum+1 ; **mp_NoUseHead = **AP_LinkOrgin ; APR_HeadCopy = mp_NoUseHead ; @@ -357,8 +356,6 @@ namespace ZNsMain if(VP_TempLink==APR_TailLink) { - DeleteHeap(); - // Add extra codes for memory over return; @@ -558,6 +555,23 @@ namespace ZNsMain }/* ~ZtCBody()*/ + ZtCBody(const ZtCBody& rhs) + { + ml_AllSize = + ml_UseSize = 0 ; + + mp_NoUseHead = + mp_NoUseTail = 0 ; + }/* + ZtCBody(const ZtCBody& rhs)*/ + + + ZtCBody& operator=(const ZtCBody& rhs) + { + return *this; + }/* + ZtCBody& operator=(const ZtCBody& rhs)*/ + void DeleteHeap() { @@ -584,6 +598,127 @@ namespace ZNsMain void DeleteHeap()*/ + TypeSize DeleteHeap(TypeSize AI_DelCnt) + { + if(ml_UseSize<1) return 0; + if(AI_DelCnt <1) return 0; + if(AI_DelCnt > size()) + { + AI_DelCnt=size(); DeleteHeap(); return AI_DelCnt; + }/* + if(AI_DelCnt > size())*/ + + + TypeSize VI_DelCntCopy = AI_DelCnt ; + ZCLink* VP_DelLink = mp_NoUseHead ; + + do /*+++++++++++++++++++++++++++*/ + { + mp_NoUseHead = + mp_NoUseHead->GetNextPtr() ; + + delete VP_DelLink; + + VP_DelLink = mp_NoUseHead ; + } + while(--VI_DelCntCopy>0); /*+++++++*/ + + ml_AllSize -= AI_DelCnt; + ml_UseSize -= AI_DelCnt; + + return AI_DelCnt; + }/* + TypeSize DeleteHeap(TypeSize AI_DelCnt)*/ + + + void AddHeap(TypeSize AI_AddCnt) + { + if(AI_AddCnt<1) return; + + if(size() < 1) + { + MakeLink + (AI_AddCnt, RR(mp_NoUseHead), RR(mp_NoUseTail)); + } + else + { + ZCLink* VP_MakeHead = 0; + ZCLink* VP_MakeTail = 0; + + MakeLink + (AI_AddCnt, RR(VP_MakeHead), RR(VP_MakeTail)); + + ZCLink::JoinLink(mp_NoUseTail, VP_MakeHead); + + mp_NoUseTail = VP_MakeTail ; + }/* + else*/ + + ml_UseSize += AI_AddCnt; + }/* + void AddHeap(TypeSize AI_AddCnt)*/ + + + void Fetch(ZtCBody& rhs) + { + if(this==&rhs ) return; + if(rhs.size()<1) return; + + RecvFreeIn //////////////////////// + ( + rhs.ml_UseSize , + rhs.mp_NoUseHead, + rhs.mp_NoUseTail + ); + /////////////////////////////////// + + this->ml_AllSize += rhs.ml_UseSize; + rhs. ml_AllSize -= rhs.ml_UseSize; + rhs. ml_UseSize = 0 ; + + rhs. mp_NoUseHead = 0 ; + rhs. mp_NoUseTail = 0 ; + }/* + void Fetch(ZtCBody& rhs)*/ + + + TypeSize Fetch(ZtCBody& rhs, TypeSize AI_FetchSize) + { + // rhs 의 앞에서 AI_FetchSize 개를 가져온다. + + if(this==&rhs ) return 0; + if(AI_FetchSize<1 ) return 0; + if(rhs.size() <1 ) return 0; + + if(AI_FetchSize>= rhs.size()) + { + AI_FetchSize = rhs.size(); + + Fetch(rhs); return AI_FetchSize; + }/* + if(AI_FetchSize>= rhs.size())*/ + + + ZCLink* VP_RhsCutTail = + rhs.mp_NoUseHead->GetNextPrevPtr(AI_FetchSize-1); + ZCLink* VP_RhsNewHead = VP_RhsCutTail->GetNextPtr( ); + + RecvFreeIn ////////////////////////////////////////// + ( + AI_FetchSize, rhs.mp_NoUseHead, VP_RhsCutTail + ); + ///////////////////////////////////////////////////// + + this->ml_AllSize += AI_FetchSize ; + rhs. ml_AllSize -= AI_FetchSize ; + rhs. ml_UseSize -= AI_FetchSize ; + rhs. mp_NoUseHead = VP_RhsNewHead; + + return AI_FetchSize; + }/* + TypeSize Fetch(ZtCBody& rhs, TypeSize AI_FetchSize)*/ + + TypeSize GetUseHeapSize() const { return ml_UseSize; @@ -1380,8 +1515,12 @@ namespace ZNsMain bool IsEmpty() const*/ - TypeSize GetSize() const{return ml_Size;} - TypeSize size () const{return ml_Size;} + TypeSize GetSize () const{return ml_Size;} + TypeSize size () const{return ml_Size;} + TypeSize capacity() const{return mo_FreeObjt.capacity();} + + TypeSize GetFreeSize() const + { return mo_FreeObjt.size(); } ZCLink* GetHeadLinkPtr(){return mp_HeadLink;} ZCLink* GetTailLinkPtr() @@ -2421,7 +2560,7 @@ namespace ZNsMain template - /*###########*/ + void IterElemRef ( TFunctor AO_Functor, TTypeHelp1& AR_TypeHelp1, TTypeHelp2& AR_TypeHelp2 @@ -2442,7 +2581,7 @@ namespace ZNsMain __for0(TypeSize, i, ml_Size)*/ }/* template - ############### + void IterElemRef ( TFunctor AO_Functor, TTypeHelp1& AR_TypeHelp1, TTypeHelp2& AR_TypeHelp2 @@ -2450,6 +2589,88 @@ namespace ZNsMain /*#############################################################################*/ + template void IterElemRev(TFunctor AO_Functor) + { + // 끝에서부터 순회한다. + + if(size()<1) return; ZCLink* + VP_LoopLink = mp_HeadLink->mp_PrevLink; + + __for0(TypeSize, i, ml_Size) + { + ZtCTypeData:: + GetObjRef(AO_Functor)( VP_LoopLink->mo_Data ); + + VP_LoopLink = VP_LoopLink->mp_PrevLink ; + }/* + __for0(TypeSize, i, ml_Size)*/ + }/* + template void IterElemRev(TFunctor AO_Functor) */ + + template + void IterElemRev(TFunctor AO_Functor, TTypeHelp AO_TypeHelp) + { + if(size()<1) return; + + typedef ZNsMain::ZtCCheckRef ZCCheckRef; + + ZCLink* VP_LoopLink = mp_HeadLink->mp_PrevLink ; + + __for0(TypeSize, i, ml_Size) + { + ZtCTypeData::GetObjRef(AO_Functor) + ( + VP_LoopLink->mo_Data, ZCCheckRef::PassData(AO_TypeHelp) + ); + //////////////////////////////////////////// + + VP_LoopLink = VP_LoopLink->mp_PrevLink ; + }/* + __for0(TypeSize, i, ml_Size)*/ + }/* + template + void IterElemRev(TFunctor AO_Functor, TTypeHelp AO_TypeHelp) */ + + + template + + void IterElemRev + ( + TFunctor AO_Functor, TTypeHelp1 AO_TypeHelp1, TTypeHelp2 AO_TypeHelp2 + ) + /*#############################################################################*/ + { + if(size()<1) return; + + typedef ZNsMain::ZtCCheckRef ZCCheckRef1; + typedef ZNsMain::ZtCCheckRef ZCCheckRef2; + + ZCLink* VP_LoopLink = mp_HeadLink->mp_PrevLink ; + + __for0(TypeSize, i, ml_Size) + { + ZtCTypeData::GetObjRef(AO_Functor) + ( + VP_LoopLink->mo_Data + , ZCCheckRef1::PassData(AO_TypeHelp1) + , ZCCheckRef2::PassData(AO_TypeHelp2) + ); + //////////////////////////////////////////// + + VP_LoopLink = VP_LoopLink->mp_PrevLink ; + }/* + __for0(TypeSize, i, ml_Size)*/ + }/* + template + + void IterElemRev + ( + TFunctor AO_Functor, TTypeHelp1 AO_TypeHelp1, TTypeHelp2 AO_TypeHelp2 + ) + ###############################################################################*/ + + + /*/////////////////////////////////////////////////////////////////////////// ■ IterElement() 예제. diff --git a/ZCppMain/ZtCSimList.H b/ZCppMain/ZtCSimList.H index c62c081..2565af9 100644 --- a/ZCppMain/ZtCSimList.H +++ b/ZCppMain/ZtCSimList.H @@ -1935,6 +1935,12 @@ namespace ZNsMain }/* inline TTypSize size() const*/ + inline TTypSize capacity() const + { + return mo_FreeObjt.capacity(); + }/* + inline TTypSize capacity() const*/ + inline bool IsEmpty() const { diff --git a/ZCppMainTest/ZtCObjList_000.cpp b/ZCppMainTest/ZtCObjList_000.cpp index e535b69..dc69097 100644 --- a/ZCppMainTest/ZtCObjList_000.cpp +++ b/ZCppMainTest/ZtCObjList_000.cpp @@ -58,6 +58,10 @@ namespace ZNsMain { VO_ListOfStr1.IterElement(&ShowDataInNode); } + cout<<"# 1th IterElemRev ####" <