Re: [twsocket] Converting a cache to AVL tree
Yes it is indeed faster! Hard to measure but in the old version, during deletion it used to take n/2 time. n is the number of files which could reach up to 100K! Best Regards, SZ On Wed, Dec 7, 2011 at 17:57, Arno Garrels wrote: > Fastream Technologies wrote: > > > It seems to work perfectly now with your advice! See: > > www.iqproxyserver.comis being served with the beta version using ICS > > TCacheTree. > > Performance increased? > > > Thanks a lot, > > You are welcome. > > -- > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > It seems to work perfectly now with your advice! See: > www.iqproxyserver.comis being served with the beta version using ICS > TCacheTree. Performance increased? > Thanks a lot, You are welcome. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Hello Arno, It seems to work perfectly now with your advice! See: www.iqproxyserver.comis being served with the beta version using ICS TCacheTree. Thanks a lot, SZ On Tue, Dec 6, 2011 at 18:56, Arno Garrels wrote: > Fastream Technologies wrote: > > FLastInsertedNode := CacheNode; // Fastream > > Not a good idea since the reference may change or the node > be removed. > > -- > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > FLastInsertedNode := CacheNode; // Fastream Not a good idea since the reference may change or the node be removed. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
- Original Message - From: "Fastream Technologies" To: "ICS support mailing" Sent: Tuesday, December 06, 2011 4:40 PM Subject: Re: [twsocket] Converting a cache to AVL tree >I still get occasional AVs in shut down. It is in cacheNode deletion. This > is the code: Please populate a StringList with the to be deleted Keys and use RemoveKey(Key) rather than Remove(node); -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
I still get occasional AVs in shut down. It is in cacheNode deletion. This is the code: bool __fastcall ProxyCache::deleteFileFromDiskCacheWRTIndex(DiskFileCache *bufferFileCache, bool alreadyMarkedAsToDelete) { if(!bufferFileCache) return false; if(bufferFileCache->cacheTreeNode) { bufferFileCache->cacheTreeNode->Data = NULL; diskFileCacheIndex->Remove(bufferFileCache->cacheTreeNode); << RANDOM AV HERE! bufferFileCache->cacheTreeNode = NULL; } cacheCurrentDiskSize -= bufferFileCache->getAndZeroSize(); if(!bufferFileCache->getWriteLock() && !bufferFileCache->getIsReadLock()) { bufferFileCache->saveHeaderDataToIniFile(true); delete bufferFileCache; return true; } else { if(!alreadyMarkedAsToDelete) bufferFileCache->setDeleteFileASAP(); return false; } } //-- What I guess is multiple DiskFileCache's are assigned the same cacheNode and it is being deleted twice but not sure. This TCacheTree is not that flexible as it seems... Best Regards, SZ On Tue, Dec 6, 2011 at 17:35, Fastream Technologies wrote: > Hi Arno, > > procedure TCacheTree.Insert( > Key : String; > Data : Pointer; > Len : Integer; > TimeStamp : TDateTime = MinDT; > Expires : TDateTime = MinDT; > UpdateTime: Boolean = True; > UpdateData: Boolean = True); > var > CacheNode, > ResNode : TCacheNode; > NewIdx, > ResIdx : TCacheIdxNode; > Found : Boolean; > begin > CacheNode := TCacheNode.Create(Key, Data, Len); > FFoundNode := nil; > ResNode := TCacheNode(SearchAndInsert(CacheNode, Found)); > if not Found then // Primary key not found = new cache Node added > begin > NewIdx := TCacheIdxNode.Create(CacheNode, TimeStamp, Expires); > ResIdx := TCacheIdxNode(FSecIdxTree.SearchAndInsert(NewIdx, > Found)); > if not Found then // New TimeStamp inserted > CacheNode.FIdxRef := NewIdx > else begin // TimeStamp exists, add a duplicate > if not Assigned(ResIdx.FDups) then > begin > ResIdx.FDups := TSecIdxDuplicates.Create; > ResIdx.FDups.InsertEnd(ResIdx); > end; > ResIdx.FDups.InsertEnd(NewIdx); > CacheNode.FIdxRef := NewIdx; > end; > FLastInsertedNode := CacheNode; // Fastream > end > else begin // Primary key found - update data and secondary index > if UpdateData then > begin > // Old data needs to be freed > TriggerFreeData(ResNode.FData, ResNode.FLen); > // Update Data > ResNode.FData := Data; > ResNode.FLen := Len; > end; > if UpdateTime then > begin > //Update TimeStamp (delete and new) > FSecIdxTree.Remove(ResNode.FIdxRef); > NewIdx := TCacheIdxNode.Create(ResNode, TimeStamp, Expires); > ResIdx := TCacheIdxNode(FSecIdxTree.SearchAndInsert(NewIdx, > Found)); > if not Found then > ResNode.FIdxRef := NewIdx > else begin // Time value exists, create a duplicate > if not Assigned(ResIdx.FDups) then > begin > ResIdx.FDups := TSecIdxDuplicates.Create; > ResIdx.FDups.InsertEnd(ResIdx); > end; > ResIdx.FDups.InsertEnd(NewIdx); > ResNode.FIdxRef := NewIdx > end; > end; > FLastInsertedNode := ResNode; // Fastream > // not new > FreeAndNil(CacheNode); > end; > end; > > I think this is better to get the last insertion node. > > Best Regards, > > SZ > On Tue, Dec 6, 2011 at 11:03, Arno Garrels wrote: > >> Fastream Technologies wrote: >> >TCacheNode = class(TAvlTreeNode) >> >private >> >FKey : String; >> >FData: Pointer; >> >FLen : Integer; >> >FIdxRef : TCacheIdxNode; >> >public >> >constructor Create(Key: String; Data: Pointer; Len: Integer); >> >destructor Destroy; override; >> >propertyKey: String read FKey; >> >propertyData: Pointer read FData write FData; // could you >> > add this "write FData"?? Fastream >> >propertyLen: Integer read FLen; >> >propertyIdxRef: TCacheIdxNode read FIdxRef; >> >end; >> >> Done. >> >> -- >> Arno Garrels >> -- >> To unsubscribe or change your settings for TWSocket mailing list >> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket >> Visit our website at http://www.overbyte.be >> > > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Hi Arno, procedure TCacheTree.Insert( Key : String; Data : Pointer; Len : Integer; TimeStamp : TDateTime = MinDT; Expires : TDateTime = MinDT; UpdateTime: Boolean = True; UpdateData: Boolean = True); var CacheNode, ResNode : TCacheNode; NewIdx, ResIdx : TCacheIdxNode; Found : Boolean; begin CacheNode := TCacheNode.Create(Key, Data, Len); FFoundNode := nil; ResNode := TCacheNode(SearchAndInsert(CacheNode, Found)); if not Found then // Primary key not found = new cache Node added begin NewIdx := TCacheIdxNode.Create(CacheNode, TimeStamp, Expires); ResIdx := TCacheIdxNode(FSecIdxTree.SearchAndInsert(NewIdx, Found)); if not Found then // New TimeStamp inserted CacheNode.FIdxRef := NewIdx else begin // TimeStamp exists, add a duplicate if not Assigned(ResIdx.FDups) then begin ResIdx.FDups := TSecIdxDuplicates.Create; ResIdx.FDups.InsertEnd(ResIdx); end; ResIdx.FDups.InsertEnd(NewIdx); CacheNode.FIdxRef := NewIdx; end; FLastInsertedNode := CacheNode; // Fastream end else begin // Primary key found - update data and secondary index if UpdateData then begin // Old data needs to be freed TriggerFreeData(ResNode.FData, ResNode.FLen); // Update Data ResNode.FData := Data; ResNode.FLen := Len; end; if UpdateTime then begin //Update TimeStamp (delete and new) FSecIdxTree.Remove(ResNode.FIdxRef); NewIdx := TCacheIdxNode.Create(ResNode, TimeStamp, Expires); ResIdx := TCacheIdxNode(FSecIdxTree.SearchAndInsert(NewIdx, Found)); if not Found then ResNode.FIdxRef := NewIdx else begin // Time value exists, create a duplicate if not Assigned(ResIdx.FDups) then begin ResIdx.FDups := TSecIdxDuplicates.Create; ResIdx.FDups.InsertEnd(ResIdx); end; ResIdx.FDups.InsertEnd(NewIdx); ResNode.FIdxRef := NewIdx end; end; FLastInsertedNode := ResNode; // Fastream // not new FreeAndNil(CacheNode); end; end; I think this is better to get the last insertion node. Best Regards, SZ On Tue, Dec 6, 2011 at 11:03, Arno Garrels wrote: > Fastream Technologies wrote: > >TCacheNode = class(TAvlTreeNode) > >private > >FKey : String; > >FData: Pointer; > >FLen : Integer; > >FIdxRef : TCacheIdxNode; > >public > >constructor Create(Key: String; Data: Pointer; Len: Integer); > >destructor Destroy; override; > >propertyKey: String read FKey; > >propertyData: Pointer read FData write FData; // could you > > add this "write FData"?? Fastream > >propertyLen: Integer read FLen; > >propertyIdxRef: TCacheIdxNode read FIdxRef; > >end; > > Done. > > -- > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: >TCacheNode = class(TAvlTreeNode) >private >FKey : String; >FData: Pointer; >FLen : Integer; >FIdxRef : TCacheIdxNode; >public >constructor Create(Key: String; Data: Pointer; Len: Integer); >destructor Destroy; override; >propertyKey: String read FKey; >propertyData: Pointer read FData write FData; // could you > add this "write FData"?? Fastream >propertyLen: Integer read FLen; >propertyIdxRef: TCacheIdxNode read FIdxRef; >end; Done. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
TCacheNode = class(TAvlTreeNode) private FKey : String; FData: Pointer; FLen : Integer; FIdxRef : TCacheIdxNode; public constructor Create(Key: String; Data: Pointer; Len: Integer); destructor Destroy; override; propertyKey: String read FKey; propertyData: Pointer read FData write FData; // could you add this "write FData"?? Fastream propertyLen: Integer read FLen; propertyIdxRef: TCacheIdxNode read FIdxRef; end; Best Regards, SZ On Mon, Dec 5, 2011 at 18:05, Arno Garrels wrote: > Arno Garrels wrote: > > Fastream Technologies wrote: > >> FYI, this is the code: > >> > >> RAMFileCacheIndex->OnList = CacheTreeOnListForRAM; > >> RAMFileCacheIndex->ListTree(); > >> > >> for(int i = RAMFileCacheIndexList->Count - 1; i >= 0; --i) > >> > >> > deleteFileFromRAMCacheWRTIndex((RAMFileCache*)RAMFileCacheIndexList->Items[i], > >> false); (basically deletes the data > >> > >> RAMFileCacheIndexList->Clear(); > >> ... > >> > >> void __fastcall ProxyCache::CacheTreeOnListForRAM(TObject *Sender, > >> const > >> String Key, TDateTime TimeStamp, Pointer Data, int Len, TDateTime > >> Expires, > >> bool &Cancel) > >> { > >> RAMFileCacheIndexList->Add(Data); > >> } > >> > //--- > > > > If you do not override DoListNode you have to use a TStringList in > > CacheTreeOnListForRAM and add the key. > > After ListTree() call RemoveKey() on each list item, and of course > > you should have OnFreeData assigned and free your Data there, be it > > objects or other pointers to allocated memory. > > And if you choose to free Data explicitly somewhere else you should > set Data to NULL/nil because otherwise you might attempt to free it a > second time from OnFreeData, if Data is NULL OnFreeData won't be > triggered for a node. > > -- > Arno Garrels > > > > > > -- > > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Arno Garrels wrote: > Fastream Technologies wrote: >> FYI, this is the code: >> >> RAMFileCacheIndex->OnList = CacheTreeOnListForRAM; >> RAMFileCacheIndex->ListTree(); >> >> for(int i = RAMFileCacheIndexList->Count - 1; i >= 0; --i) >> >> deleteFileFromRAMCacheWRTIndex((RAMFileCache*)RAMFileCacheIndexList->Items[i], >> false); (basically deletes the data >> >> RAMFileCacheIndexList->Clear(); >> ... >> >> void __fastcall ProxyCache::CacheTreeOnListForRAM(TObject *Sender, >> const >> String Key, TDateTime TimeStamp, Pointer Data, int Len, TDateTime >> Expires, >> bool &Cancel) >> { >> RAMFileCacheIndexList->Add(Data); >> } >> //--- > > If you do not override DoListNode you have to use a TStringList in > CacheTreeOnListForRAM and add the key. > After ListTree() call RemoveKey() on each list item, and of course > you should have OnFreeData assigned and free your Data there, be it > objects or other pointers to allocated memory. And if you choose to free Data explicitly somewhere else you should set Data to NULL/nil because otherwise you might attempt to free it a second time from OnFreeData, if Data is NULL OnFreeData won't be triggered for a node. -- Arno Garrels > > -- > Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > FYI, this is the code: > > RAMFileCacheIndex->OnList = CacheTreeOnListForRAM; > RAMFileCacheIndex->ListTree(); > > for(int i = RAMFileCacheIndexList->Count - 1; i >= 0; --i) > > deleteFileFromRAMCacheWRTIndex((RAMFileCache*)RAMFileCacheIndexList->Items[i], > false); (basically deletes the data > > RAMFileCacheIndexList->Clear(); > ... > > void __fastcall ProxyCache::CacheTreeOnListForRAM(TObject *Sender, > const > String Key, TDateTime TimeStamp, Pointer Data, int Len, TDateTime > Expires, > bool &Cancel) > { > RAMFileCacheIndexList->Add(Data); > } > //--- If you do not override DoListNode you have to use a TStringList in CacheTreeOnListForRAM and add the key. After ListTree() call RemoveKey() on each list item, and of course you should have OnFreeData assigned and free your Data there, be it objects or other pointers to allocated memory. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > Ok, let's go step by step: How do I get the TCacheNode of the last > inserted one? Not possible, you only can get the oldest, why do you need that? I could easily add property Latest which should be the Last in the secondary tree with the TimeStamps. It is not possible to iterate over or list the secondary tree. > First() or Last()? None of both. First represents the most left and Last the most right node with the smallest key in First and greatest in Last. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Hi again, I think the problem is in the delete routine: bool __fastcall ProxyCache::deleteFileFromRAMCacheWRTIndex(RAMFileCache *bufferFileCache, bool alreadyMarkedAsToDelete) { if(!bufferFileCache) return false; if(bufferFileCache->cacheTreeNode) { RAMFileCacheIndex->Remove(bufferFileCache->cacheTreeNode); bufferFileCache->cacheTreeNode = NULL; } cacheCurrentRAMSize -= bufferFileCache->getAndZeroSize(); // first time it subtracts and then returns 0 if(!bufferFileCache->getWriteLock() && !bufferFileCache->getIsReadLock()) { delete bufferFileCache; return true; } else { if(!alreadyMarkedAsToDelete) bufferFileCache->setDeleteFileASAP(); return false; } } //-- if(bufferFileCache->cacheTreeNode) { RAMFileCacheIndex->Remove(bufferFileCache->cacheTreeNode); bufferFileCache->cacheTreeNode = NULL; } When this is entered, the data pointer or the bufferfilecache is NOT deleted by the tree, right? Also my question is pending, how do I get the tcachenode of the lastly inserted/updated data?? Best Regards, SZ On Mon, Dec 5, 2011 at 17:08, Fastream Technologies wrote: > Both of these do not work. Must I pass Now() while updating? I am just > passing the old timestamp! > Regards, > > SZ > On Mon, Dec 5, 2011 at 16:51, Fastream Technologies wrote: > >> Ok, let's go step by step: How do I get the TCacheNode of the last >> inserted one? First() or Last()? >> SZ >> On Mon, Dec 5, 2011 at 16:38, Fastream Technologies >> wrote: >> >>> FYI, this is the code: >>> >>>RAMFileCacheIndex->OnList = CacheTreeOnListForRAM; >>> RAMFileCacheIndex->ListTree(); >>> >>> for(int i = RAMFileCacheIndexList->Count - 1; i >= 0; --i) >>> >>> deleteFileFromRAMCacheWRTIndex((RAMFileCache*)RAMFileCacheIndexList->Items[i], >>> false); (basically deletes the data >>> >>> RAMFileCacheIndexList->Clear(); >>> ... >>> >>> void __fastcall ProxyCache::CacheTreeOnListForRAM(TObject *Sender, const >>> String Key, TDateTime TimeStamp, Pointer Data, int Len, TDateTime Expires, >>> bool &Cancel) >>> { >>> RAMFileCacheIndexList->Add(Data); >>> } >>> >>> //--- >>> >>> Best Regards, >>> >>> SZ >>> On Mon, Dec 5, 2011 at 16:36, Fastream Technologies >> > wrote: >>> Okay, let's do it one entry per URL. Now the TList recording and deleting afterwards in OnList does NOT work. Gives AV. What is the proper way? Can you help us with some consultancy? Please let me know privately: ga...@fastream.com. Best Regards, SZ On Mon, Dec 5, 2011 at 13:47, Arno Garrels wrote: > Fastream Technologies wrote: > > Let me elaborate the issue: In our caches, we may have duplicate > > URLs. > > Then TCacheTree doesn't fit. > As I wrote yesterday, the Key (in your case the URL) must be unique, > no way around, it is the primary key. > However there may exist multiple, different Keys/URLs with the same > TimeStamp since it is easily possible to add thousands of items > in less than 10 ms with Now() always returning the same value. > > -- > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > >>> >> > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Both of these do not work. Must I pass Now() while updating? I am just passing the old timestamp! Regards, SZ On Mon, Dec 5, 2011 at 16:51, Fastream Technologies wrote: > Ok, let's go step by step: How do I get the TCacheNode of the last > inserted one? First() or Last()? > SZ > On Mon, Dec 5, 2011 at 16:38, Fastream Technologies wrote: > >> FYI, this is the code: >> >>RAMFileCacheIndex->OnList = CacheTreeOnListForRAM; >> RAMFileCacheIndex->ListTree(); >> >> for(int i = RAMFileCacheIndexList->Count - 1; i >= 0; --i) >> >> deleteFileFromRAMCacheWRTIndex((RAMFileCache*)RAMFileCacheIndexList->Items[i], >> false); (basically deletes the data >> >> RAMFileCacheIndexList->Clear(); >> ... >> >> void __fastcall ProxyCache::CacheTreeOnListForRAM(TObject *Sender, const >> String Key, TDateTime TimeStamp, Pointer Data, int Len, TDateTime Expires, >> bool &Cancel) >> { >> RAMFileCacheIndexList->Add(Data); >> } >> >> //--- >> >> Best Regards, >> >> SZ >> On Mon, Dec 5, 2011 at 16:36, Fastream Technologies >> wrote: >> >>> Okay, let's do it one entry per URL. Now the TList recording and >>> deleting afterwards in OnList does NOT work. Gives AV. What is the proper >>> way? Can you help us with some consultancy? Please let me know privately: >>> ga...@fastream.com. >>> Best Regards, >>> >>> SZ >>> >>> On Mon, Dec 5, 2011 at 13:47, Arno Garrels wrote: >>> Fastream Technologies wrote: > Let me elaborate the issue: In our caches, we may have duplicate > URLs. Then TCacheTree doesn't fit. As I wrote yesterday, the Key (in your case the URL) must be unique, no way around, it is the primary key. However there may exist multiple, different Keys/URLs with the same TimeStamp since it is easily possible to add thousands of items in less than 10 ms with Now() always returning the same value. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be >>> >>> >> > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Ok, let's go step by step: How do I get the TCacheNode of the last inserted one? First() or Last()? SZ On Mon, Dec 5, 2011 at 16:38, Fastream Technologies wrote: > FYI, this is the code: > > RAMFileCacheIndex->OnList = CacheTreeOnListForRAM; > RAMFileCacheIndex->ListTree(); > > for(int i = RAMFileCacheIndexList->Count - 1; i >= 0; --i) > > deleteFileFromRAMCacheWRTIndex((RAMFileCache*)RAMFileCacheIndexList->Items[i], > false); (basically deletes the data > > RAMFileCacheIndexList->Clear(); > ... > > void __fastcall ProxyCache::CacheTreeOnListForRAM(TObject *Sender, const > String Key, TDateTime TimeStamp, Pointer Data, int Len, TDateTime Expires, > bool &Cancel) > { > RAMFileCacheIndexList->Add(Data); > } > > //--- > > Best Regards, > > SZ > On Mon, Dec 5, 2011 at 16:36, Fastream Technologies > wrote: > >> Okay, let's do it one entry per URL. Now the TList recording and deleting >> afterwards in OnList does NOT work. Gives AV. What is the proper way? Can >> you help us with some consultancy? Please let me know privately: >> ga...@fastream.com. >> Best Regards, >> >> SZ >> >> On Mon, Dec 5, 2011 at 13:47, Arno Garrels wrote: >> >>> Fastream Technologies wrote: >>> > Let me elaborate the issue: In our caches, we may have duplicate >>> > URLs. >>> >>> Then TCacheTree doesn't fit. >>> As I wrote yesterday, the Key (in your case the URL) must be unique, >>> no way around, it is the primary key. >>> However there may exist multiple, different Keys/URLs with the same >>> TimeStamp since it is easily possible to add thousands of items >>> in less than 10 ms with Now() always returning the same value. >>> >>> -- >>> Arno Garrels >>> -- >>> To unsubscribe or change your settings for TWSocket mailing list >>> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket >>> Visit our website at http://www.overbyte.be >>> >> >> > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
FYI, this is the code: RAMFileCacheIndex->OnList = CacheTreeOnListForRAM; RAMFileCacheIndex->ListTree(); for(int i = RAMFileCacheIndexList->Count - 1; i >= 0; --i) deleteFileFromRAMCacheWRTIndex((RAMFileCache*)RAMFileCacheIndexList->Items[i], false); (basically deletes the data RAMFileCacheIndexList->Clear(); ... void __fastcall ProxyCache::CacheTreeOnListForRAM(TObject *Sender, const String Key, TDateTime TimeStamp, Pointer Data, int Len, TDateTime Expires, bool &Cancel) { RAMFileCacheIndexList->Add(Data); } //--- Best Regards, SZ On Mon, Dec 5, 2011 at 16:36, Fastream Technologies wrote: > Okay, let's do it one entry per URL. Now the TList recording and deleting > afterwards in OnList does NOT work. Gives AV. What is the proper way? Can > you help us with some consultancy? Please let me know privately: > ga...@fastream.com. > Best Regards, > > SZ > > On Mon, Dec 5, 2011 at 13:47, Arno Garrels wrote: > >> Fastream Technologies wrote: >> > Let me elaborate the issue: In our caches, we may have duplicate >> > URLs. >> >> Then TCacheTree doesn't fit. >> As I wrote yesterday, the Key (in your case the URL) must be unique, >> no way around, it is the primary key. >> However there may exist multiple, different Keys/URLs with the same >> TimeStamp since it is easily possible to add thousands of items >> in less than 10 ms with Now() always returning the same value. >> >> -- >> Arno Garrels >> -- >> To unsubscribe or change your settings for TWSocket mailing list >> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket >> Visit our website at http://www.overbyte.be >> > > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Okay, let's do it one entry per URL. Now the TList recording and deleting afterwards in OnList does NOT work. Gives AV. What is the proper way? Can you help us with some consultancy? Please let me know privately: ga...@fastream.com. Best Regards, SZ On Mon, Dec 5, 2011 at 13:47, Arno Garrels wrote: > Fastream Technologies wrote: > > Let me elaborate the issue: In our caches, we may have duplicate > > URLs. > > Then TCacheTree doesn't fit. > As I wrote yesterday, the Key (in your case the URL) must be unique, > no way around, it is the primary key. > However there may exist multiple, different Keys/URLs with the same > TimeStamp since it is easily possible to add thousands of items > in less than 10 ms with Now() always returning the same value. > > -- > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > Let me elaborate the issue: In our caches, we may have duplicate > URLs. Then TCacheTree doesn't fit. As I wrote yesterday, the Key (in your case the URL) must be unique, no way around, it is the primary key. However there may exist multiple, different Keys/URLs with the same TimeStamp since it is easily possible to add thousands of items in less than 10 ms with Now() always returning the same value. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Ok but how will I update an existing duplicarte record so that it becomes Last()?? Best Regards, SZ On Mon, Dec 5, 2011 at 13:11, Arno Garrels wrote: > Fastream Technologies wrote: > > On Sun, Dec 4, 2011 at 11:05, Arno Garrels > > wrote: > > > >> - Original Message - > >> From: "Fastream Technologies" > >> To: "ICS support mailing" > >> Sent: Sunday, December 04, 2011 7:16 AM > >> Subject: Re: [twsocket] Converting a cache to AVL tree > >> > >> > >>> The component I tried to use is TCacheTree. It has a timeout > >>> argument for each added item. I do not want any timers or any > >>> timeouts yet liked the component. Is there a way to omit > >>> expiration. I will use my own code for it. > >> > >> TCacheTree doesn't use any timer, it just provides two TDateTime > >> fields. There are two indices, first is Key of type string, second > >> is TimeStamp of type TDateTime used to find oldest entries very > >> fast. It's two linked AVL trees. > >> > >> procedure Insert( > >>Key: String;// Unique key > >>Data : Pointer; // Pointer to data > >>Len: Integer; // Optionally data size > >>TimeStamp : TDateTime = MinDT; // Second key (dups are allowed > >> and handled) > >>Expires: TDateTime = MinDT; // What ever you like > >>UpdateTime : Boolean = True;// Shall the TDateTime fields be > >> updated? > >>UpdateData : Boolean = True); // Shall Data be updated? > >> > >> Use Insert() for both add and update an entry. > >> > >> Node : TCacheNode; > >> begin > >> Node := FCacheTree.FindKey(Key); > >> if Node <> nil then > >> begin > >>// Node.IdxRef.TimeStamp // i.e read the TimeStamp > >>// i.e update TimeStamp and Expires, don't update Data > >>FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); > >> end; > >> > >> Oldest() returns oldest entry. > >> Flush() removes all entries older or same DateTime as passed. > >> > >> Hope this helps. > >> > >> -- > >> Arno Garrels > >> > >> > >> > > > > Critical question: Node.IdxRef.TimeStamp = updatedDate; > > You can't assign a value, property TimeStamp is read-only. > > > Would this work? Because we may have duplicates... > > Use Insert() as described above to update the TimeStamp value. > Yes, TimeStamp duplicates are allowed. > > -- > Arno Garrels > > > > > > Regards, > > > > SZ > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > On Sun, Dec 4, 2011 at 11:05, Arno Garrels > wrote: > >> - Original Message - >> From: "Fastream Technologies" >> To: "ICS support mailing" >> Sent: Sunday, December 04, 2011 7:16 AM >> Subject: Re: [twsocket] Converting a cache to AVL tree >> >> >>> The component I tried to use is TCacheTree. It has a timeout >>> argument for each added item. I do not want any timers or any >>> timeouts yet liked the component. Is there a way to omit >>> expiration. I will use my own code for it. >> >> TCacheTree doesn't use any timer, it just provides two TDateTime >> fields. There are two indices, first is Key of type string, second >> is TimeStamp of type TDateTime used to find oldest entries very >> fast. It's two linked AVL trees. >> >> procedure Insert( >>Key: String;// Unique key >>Data : Pointer; // Pointer to data >>Len: Integer; // Optionally data size >>TimeStamp : TDateTime = MinDT; // Second key (dups are allowed >> and handled) >>Expires: TDateTime = MinDT; // What ever you like >>UpdateTime : Boolean = True;// Shall the TDateTime fields be >> updated? >>UpdateData : Boolean = True); // Shall Data be updated? >> >> Use Insert() for both add and update an entry. >> >> Node : TCacheNode; >> begin >> Node := FCacheTree.FindKey(Key); >> if Node <> nil then >> begin >>// Node.IdxRef.TimeStamp // i.e read the TimeStamp >>// i.e update TimeStamp and Expires, don't update Data >>FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); >> end; >> >> Oldest() returns oldest entry. >> Flush() removes all entries older or same DateTime as passed. >> >> Hope this helps. >> >> -- >> Arno Garrels >> >> >> > > Critical question: Node.IdxRef.TimeStamp = updatedDate; You can't assign a value, property TimeStamp is read-only. > Would this work? Because we may have duplicates... Use Insert() as described above to update the TimeStamp value. Yes, TimeStamp duplicates are allowed. -- Arno Garrels > > Regards, > > SZ -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Let me elaborate the issue: In our caches, we may have duplicate URLs. How would one update a timestamp with tcachenode pointer? Best Regards, SZ On Mon, Dec 5, 2011 at 12:47, Fastream Technologies wrote: > On Sun, Dec 4, 2011 at 11:05, Arno Garrels wrote: > >> - Original Message - >> From: "Fastream Technologies" >> To: "ICS support mailing" >> Sent: Sunday, December 04, 2011 7:16 AM >> Subject: Re: [twsocket] Converting a cache to AVL tree >> >> >> > The component I tried to use is TCacheTree. It has a timeout argument >> for >> > each added item. I do not want any timers or any timeouts yet liked the >> > component. Is there a way to omit expiration. I will use my own code >> for it. >> >> TCacheTree doesn't use any timer, it just provides two TDateTime fields. >> There are two indices, first is Key of type string, second is TimeStamp >> of type TDateTime used to find oldest entries very fast. It's two linked >> AVL trees. >> >> procedure Insert( >>Key: String;// Unique key >>Data : Pointer; // Pointer to data >>Len: Integer; // Optionally data size >>TimeStamp : TDateTime = MinDT; // Second key (dups are allowed and >> handled) >>Expires: TDateTime = MinDT; // What ever you like >>UpdateTime : Boolean = True;// Shall the TDateTime fields be >> updated? >>UpdateData : Boolean = True); // Shall Data be updated? >> >> Use Insert() for both add and update an entry. >> >> Node : TCacheNode; >> begin >> Node := FCacheTree.FindKey(Key); >> if Node <> nil then >> begin >>// Node.IdxRef.TimeStamp // i.e read the TimeStamp >>// i.e update TimeStamp and Expires, don't update Data >>FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); >> end; >> >> Oldest() returns oldest entry. >> Flush() removes all entries older or same DateTime as passed. >> >> Hope this helps. >> >> -- >> Arno Garrels >> >> >> > > Critical question: Node.IdxRef.TimeStamp = updatedDate; > > Would this work? Because we may have duplicates... > > Regards, > > SZ > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
On Sun, Dec 4, 2011 at 11:05, Arno Garrels wrote: > - Original Message - > From: "Fastream Technologies" > To: "ICS support mailing" > Sent: Sunday, December 04, 2011 7:16 AM > Subject: Re: [twsocket] Converting a cache to AVL tree > > > > The component I tried to use is TCacheTree. It has a timeout argument for > > each added item. I do not want any timers or any timeouts yet liked the > > component. Is there a way to omit expiration. I will use my own code for > it. > > TCacheTree doesn't use any timer, it just provides two TDateTime fields. > There are two indices, first is Key of type string, second is TimeStamp > of type TDateTime used to find oldest entries very fast. It's two linked > AVL trees. > > procedure Insert( >Key: String;// Unique key >Data : Pointer; // Pointer to data >Len: Integer; // Optionally data size >TimeStamp : TDateTime = MinDT; // Second key (dups are allowed and > handled) >Expires: TDateTime = MinDT; // What ever you like >UpdateTime : Boolean = True;// Shall the TDateTime fields be > updated? >UpdateData : Boolean = True); // Shall Data be updated? > > Use Insert() for both add and update an entry. > > Node : TCacheNode; > begin > Node := FCacheTree.FindKey(Key); > if Node <> nil then > begin >// Node.IdxRef.TimeStamp // i.e read the TimeStamp >// i.e update TimeStamp and Expires, don't update Data >FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); > end; > > Oldest() returns oldest entry. > Flush() removes all entries older or same DateTime as passed. > > Hope this helps. > > -- > Arno Garrels > > > Critical question: Node.IdxRef.TimeStamp = updatedDate; Would this work? Because we may have duplicates... Regards, SZ -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Arno Garrels wrote: > Arno Garrels wrote: >> Fastream Technologies wrote: >>> How about us to make a list of pointers in onlist and then remove? >> >> Yes, I'd just override DoListNode, something like (untested): > > Wait! It has to be tested, might not work, building a StringList > with the keys however will work. False alarm, it works with a node list :) -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Arno Garrels wrote: > Fastream Technologies wrote: >> How about us to make a list of pointers in onlist and then remove? > > Yes, I'd just override DoListNode, something like (untested): Wait! It has to be tested, might not work, building a StringList with the keys however will work. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > How about us to make a list of pointers in onlist and then remove? Yes, I'd just override DoListNode, something like (untested): TMyCache = class(TCacheTree) private FDeleteList: TList; FCondition: string; protected procedure DoListNode(Node: TAvlTreeNode; var Cancel: Boolean); override; public destructor Destroy; override; procedure RemoveSomeStuff(const ACondition: String); end; implementation { TMyCache } type TMyData = record SomeStr : string; end; PMyData = ^TMyData; procedure TMyCache.RemoveSomeStuff(const ACondition: String); var I: Integer; begin if not Assigned(FDeleteList) then FDeleteList := TList.Create; try FCondition := ACondition; ListTree; for I := 0 to FDeleteList.Count -1 do Remove(FDeleteList[I]); finally FDeleteList.Clear; FCondition := ''; end; end; destructor TMyCache.Destroy; begin FDeleteList.Free; inherited Destroy; end; procedure TMyCache.DoListNode(Node: TAvlTreeNode; var Cancel: Boolean); begin if (Node <> nil) and (FCondition <> '') then begin if (PMyData(TCacheNode(Node).Data)^.SomeStr = FCondition) then FDeleteList.Add(Node); end else inherited; end; > Best Regards, > > SZ > On Sun, Dec 4, 2011 at 15:24, Fastream Technologies > wrote: > >> Arno, >> >> The deletions occur once in a day/week or so, when the end admin user >> clicks a button in GUI. It is not a part of every second cache >> operation. What is the easiest/safest way to delete by iteration? >> >> a. Implement a new TCacheTree with IPv6 AVLPointerTree? >> b. A very slow workaround for the current class (speed is NOT an >> issue). Best Regards, >> >> SZ >> On Sun, Dec 4, 2011 at 14:31, Arno Garrels >> wrote: >> >>> Fastream Technologies wrote: Ok but how do I delete with respect to a data->property?? >>> >>> One needs one linked tree for each search key, if you >>> have to iterate over a tree in order to find something a list >>> would likely be faster. But if can live with slow deletions >>> maybe you can use TIcsAvlPointerTree rather than TAvlTree to write >>> a new TCacheTree. >>> We use regex and string comparison for this! If you can help me with it, I will appreciate. We can be sponsors for this feature. I think we can live with OnList way but really need to be able to delete with respect to data... >>> >>> Sounds like plenty of keys, I'm not sure whether this would be >>> faster with trees. >>> >>> -- >>> Arno Garrels >>> >>> >>> >>> -- >>> To unsubscribe or change your settings for TWSocket mailing list >>> please goto >>> http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our >>> website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
How about us to make a list of pointers in onlist and then remove? Best Regards, SZ On Sun, Dec 4, 2011 at 15:24, Fastream Technologies wrote: > Arno, > > The deletions occur once in a day/week or so, when the end admin user > clicks a button in GUI. It is not a part of every second cache operation. > What is the easiest/safest way to delete by iteration? > > a. Implement a new TCacheTree with IPv6 AVLPointerTree? > b. A very slow workaround for the current class (speed is NOT an issue). > Best Regards, > > SZ > On Sun, Dec 4, 2011 at 14:31, Arno Garrels wrote: > >> Fastream Technologies wrote: >> > Ok but how do I delete with respect to a data->property?? >> >> One needs one linked tree for each search key, if you >> have to iterate over a tree in order to find something a list >> would likely be faster. But if can live with slow deletions >> maybe you can use TIcsAvlPointerTree rather than TAvlTree to write >> a new TCacheTree. >> >> > We use >> > regex and string comparison for this! If you can help me with it, I >> > will appreciate. We can be sponsors for this feature. I think we can >> > live with OnList way but really need to be able to delete with >> > respect to data... >> >> Sounds like plenty of keys, I'm not sure whether this would be faster >> with trees. >> >> -- >> Arno Garrels >> >> >> >> -- >> To unsubscribe or change your settings for TWSocket mailing list >> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket >> Visit our website at http://www.overbyte.be >> > > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Arno, The deletions occur once in a day/week or so, when the end admin user clicks a button in GUI. It is not a part of every second cache operation. What is the easiest/safest way to delete by iteration? a. Implement a new TCacheTree with IPv6 AVLPointerTree? b. A very slow workaround for the current class (speed is NOT an issue). Best Regards, SZ On Sun, Dec 4, 2011 at 14:31, Arno Garrels wrote: > Fastream Technologies wrote: > > Ok but how do I delete with respect to a data->property?? > > One needs one linked tree for each search key, if you > have to iterate over a tree in order to find something a list > would likely be faster. But if can live with slow deletions > maybe you can use TIcsAvlPointerTree rather than TAvlTree to write > a new TCacheTree. > > > We use > > regex and string comparison for this! If you can help me with it, I > > will appreciate. We can be sponsors for this feature. I think we can > > live with OnList way but really need to be able to delete with > > respect to data... > > Sounds like plenty of keys, I'm not sure whether this would be faster > with trees. > > -- > Arno Garrels > > > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > Hello Arno, > Can one remove a node in onlist? No, it's not possible with this old class. The new TIcsAvlPointerTree in the IPv6 branch has an iterator and supports for - in loops as well as removing nodes while in a for - in loop. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > Ok but how do I delete with respect to a data->property?? One needs one linked tree for each search key, if you have to iterate over a tree in order to find something a list would likely be faster. But if can live with slow deletions maybe you can use TIcsAvlPointerTree rather than TAvlTree to write a new TCacheTree. > We use > regex and string comparison for this! If you can help me with it, I > will appreciate. We can be sponsors for this feature. I think we can > live with OnList way but really need to be able to delete with > respect to data... Sounds like plenty of keys, I'm not sure whether this would be faster with trees. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Ok but how do I delete with respect to a data->property?? We use regex and string comparison for this! If you can help me with it, I will appreciate. We can be sponsors for this feature. I think we can live with OnList way but really need to be able to delete with respect to data... Regards, SZ On Sun, Dec 4, 2011 at 13:22, Arno Garrels wrote: > Fastream Technologies wrote: > > On Sun, Dec 4, 2011 at 11:40, Arno Garrels > > wrote: > > > >> Traversing the tree is only possible with method ListTree > >> and assigning an OnList event handler. > >> > > > > Could you give an example to traversing for the firstly inserted n > > elements? > > Not possible. > Also iterating over a tree is much slower than over a list and should > be avoided if speed matters. > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > On Sun, Dec 4, 2011 at 11:40, Arno Garrels > wrote: > >> Traversing the tree is only possible with method ListTree >> and assigning an OnList event handler. >> > > Could you give an example to traversing for the firstly inserted n > elements? Not possible. Also iterating over a tree is much slower than over a list and should be avoided if speed matters. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Hello Arno, Can one remove a node in onlist? Regards, SubZ On Sun, Dec 4, 2011 at 13:16, Arno Garrels wrote: > Fastream Technologies wrote: > > Do you mean the tree self-destructs nodes and I will be notified of > > it to delete? > > You are notified before the class removes and frees a node, i.e method > Remove() triggers event OnFreeData and afterwards frees the node. The class > doesn't own Data but its nodes, so never call method Free of a node > returned > by a method. > However if Data points to some previously allocated memory you are > responsible to release it. > > > Or is it optional? > > Yes, more or less it is. If you, for instance, used Data to store > just an Integer value it's not required to free any memory. > > > Example: > > procedure TForm1.CacheFreeData(Sender: TObject; Data: Pointer; Len: > Integer); > begin >FreeMem(Data); > end; > > procedure TForm1.Button1Click(Sender: TObject); > var >Node: TCacheNode; >MyData: Pointer; > begin >FCache := TCacheTree.Create; >try >FCache.OnFreeData := CacheFreeData; >GetMem(MyData, 1024); >FCache.Insert('AKEY', MyData, 0, Now); >// either >Node := FCache.FindKey('AKEY'); >if Node <> nil then >FCache.Remove(Node); // Node no longer valid >// or >FCache.RemoveKey('AKEY'); >finally >FCache.Free; >end; > end; > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > Do you mean the tree self-destructs nodes and I will be notified of > it to delete? You are notified before the class removes and frees a node, i.e method Remove() triggers event OnFreeData and afterwards frees the node. The class doesn't own Data but its nodes, so never call method Free of a node returned by a method. However if Data points to some previously allocated memory you are responsible to release it. > Or is it optional? Yes, more or less it is. If you, for instance, used Data to store just an Integer value it's not required to free any memory. Example: procedure TForm1.CacheFreeData(Sender: TObject; Data: Pointer; Len: Integer); begin FreeMem(Data); end; procedure TForm1.Button1Click(Sender: TObject); var Node: TCacheNode; MyData: Pointer; begin FCache := TCacheTree.Create; try FCache.OnFreeData := CacheFreeData; GetMem(MyData, 1024); FCache.Insert('AKEY', MyData, 0, Now); // either Node := FCache.FindKey('AKEY'); if Node <> nil then FCache.Remove(Node); // Node no longer valid // or FCache.RemoveKey('AKEY'); finally FCache.Free; end; end; -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Okay, I now see your point, it is not async yet recursive. Regards, SZ On Sun, Dec 4, 2011 at 12:52, Fastream Technologies wrote: > I do not understand why it is async to traverse a list of nodes in RAM! It > ruins the program flow very much. Any solution? > Regards, > > SZ > > On Sun, Dec 4, 2011 at 12:36, Fastream Technologies wrote: > >> On Sun, Dec 4, 2011 at 11:40, Arno Garrels wrote: >> >>> Traversing the tree is only possible with method ListTree >>> and assigning an OnList event handler. >>> >> >> Could you give an example to traversing for the firstly inserted n >> elements? >> >> Regards, >> >> SZ >> > > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
I do not understand why it is async to traverse a list of nodes in RAM! It ruins the program flow very much. Any solution? Regards, SZ On Sun, Dec 4, 2011 at 12:36, Fastream Technologies wrote: > On Sun, Dec 4, 2011 at 11:40, Arno Garrels wrote: > >> Traversing the tree is only possible with method ListTree >> and assigning an OnList event handler. >> > > Could you give an example to traversing for the firstly inserted n > elements? > > Regards, > > SZ > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
On Sun, Dec 4, 2011 at 11:40, Arno Garrels wrote: > Traversing the tree is only possible with method ListTree > and assigning an OnList event handler. > Could you give an example to traversing for the firstly inserted n elements? Regards, SZ -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Do you mean the tree self-destructs nodes and I will be notified of it to delete? Or is it optional? Basically here is my destruction function: bool __fastcall ProxyCache::deleteFileFromRAMCacheWRTIndex(RAMFileCache *bufferFileCache, bool alreadyMarkedAsToDelete) { if(!bufferFileCache) return false; if(bufferFileCache->cacheTreeNode) { RAMFileCacheIndex->Remove(bufferFileCache->cacheTreeNode); bufferFileCache->cacheTreeNode = NULL; } cacheCurrentRAMSize -= bufferFileCache->getAndZeroSize(); // first time it subtracts and then returns 0 if(!bufferFileCache->getWriteLock() && !bufferFileCache->getIsReadLock()) { delete bufferFileCache; return true; } else { if(!alreadyMarkedAsToDelete) bufferFileCache->setDeleteFileASAP(); return false; } } //-- IOW, in our cache one URL can have just one entry in the tree but many sockets can be pending to delete. It has to wait until the very last socket connection to delete the actual object. Best Regards, SubZ On Sun, Dec 4, 2011 at 11:40, Arno Garrels wrote: > Fastream Technologies wrote: > > What about the events? Do I need to use them in TCacheTree? > > Thanks a lot, > > Most important is of course OnFreeData that triggers whenever > an entry is removed, so simply free Data there if required. > > Traversing the tree is only possible with method ListTree > and assigning an OnList event handler. > > -- > Arno Garrels > > > > > SZ > > On Sun, Dec 4, 2011 at 11:05, Arno Garrels > > wrote: > > > >> - Original Message - > >> From: "Fastream Technologies" > >> To: "ICS support mailing" > >> Sent: Sunday, December 04, 2011 7:16 AM > >> Subject: Re: [twsocket] Converting a cache to AVL tree > >> > >> > >>> The component I tried to use is TCacheTree. It has a timeout > >>> argument for each added item. I do not want any timers or any > >>> timeouts yet liked the component. Is there a way to omit > >>> expiration. I will use my own code for it. > >> > >> TCacheTree doesn't use any timer, it just provides two TDateTime > >> fields. There are two indices, first is Key of type string, second > >> is TimeStamp of type TDateTime used to find oldest entries very > >> fast. It's two linked AVL trees. > >> > >> procedure Insert( > >>Key: String;// Unique key > >>Data : Pointer; // Pointer to data > >>Len: Integer; // Optionally data size > >>TimeStamp : TDateTime = MinDT; // Second key (dups are allowed > >> and handled) > >>Expires: TDateTime = MinDT; // What ever you like > >>UpdateTime : Boolean = True;// Shall the TDateTime fields be > >> updated? > >>UpdateData : Boolean = True); // Shall Data be updated? > >> > >> Use Insert() for both add and update an entry. > >> > >> Node : TCacheNode; > >> begin > >> Node := FCacheTree.FindKey(Key); > >> if Node <> nil then > >> begin > >>// Node.IdxRef.TimeStamp // i.e read the TimeStamp > >>// i.e update TimeStamp and Expires, don't update Data > >>FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); > >> end; > >> > >> Oldest() returns oldest entry. > >> Flush() removes all entries older or same DateTime as passed. > >> > >> Hope this helps. > >> > >> -- > >> Arno Garrels > >> > >> > >>> Best Regards, > >>> > >>> SZ > >>> On Sat, Dec 3, 2011 at 18:54, Arno Garrels > >>> wrote: > >>> > >>>> Fastream Technologies wrote: > >>>>> Hello, > >>>>> > >>>>> I wonder if there is an easy way to do this? How does one achieve > >>>>> no timeout in ICS avl tree? > >>>> > >>>> Please be more specific, AFAIR there's no timeout in any ICS AVL > >>>> tree. BTW: Also have a look at the new TIcsAvlPointerTree and > >>>> TIcsAvlObjectTree in the IPv6 branch, included in > >>>> OverbyteIcsAvlTrees. > >>>> > >>>> -- > >>>> Arno Garrels > >>>> -- > >>>> To unsubscribe or change your settings for TWSocket mailing list > >>>> please goto > >>>> http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit > >>>> our website at http://www.overbyte.be > >>>> > >>> -- > >>> To unsubscribe or change your settings for TWSocket mailing list > >>> please goto > >>> http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our > >>> website at http://www.overbyte.be > >> -- > >> To unsubscribe or change your settings for TWSocket mailing list > >> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > >> Visit our website at http://www.overbyte.be > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > What about the events? Do I need to use them in TCacheTree? > Thanks a lot, Most important is of course OnFreeData that triggers whenever an entry is removed, so simply free Data there if required. Traversing the tree is only possible with method ListTree and assigning an OnList event handler. -- Arno Garrels > > SZ > On Sun, Dec 4, 2011 at 11:05, Arno Garrels > wrote: > >> - Original Message - >> From: "Fastream Technologies" >> To: "ICS support mailing" >> Sent: Sunday, December 04, 2011 7:16 AM >> Subject: Re: [twsocket] Converting a cache to AVL tree >> >> >>> The component I tried to use is TCacheTree. It has a timeout >>> argument for each added item. I do not want any timers or any >>> timeouts yet liked the component. Is there a way to omit >>> expiration. I will use my own code for it. >> >> TCacheTree doesn't use any timer, it just provides two TDateTime >> fields. There are two indices, first is Key of type string, second >> is TimeStamp of type TDateTime used to find oldest entries very >> fast. It's two linked AVL trees. >> >> procedure Insert( >>Key: String;// Unique key >>Data : Pointer; // Pointer to data >>Len: Integer; // Optionally data size >>TimeStamp : TDateTime = MinDT; // Second key (dups are allowed >> and handled) >>Expires: TDateTime = MinDT; // What ever you like >>UpdateTime : Boolean = True;// Shall the TDateTime fields be >> updated? >>UpdateData : Boolean = True); // Shall Data be updated? >> >> Use Insert() for both add and update an entry. >> >> Node : TCacheNode; >> begin >> Node := FCacheTree.FindKey(Key); >> if Node <> nil then >> begin >>// Node.IdxRef.TimeStamp // i.e read the TimeStamp >>// i.e update TimeStamp and Expires, don't update Data >>FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); >> end; >> >> Oldest() returns oldest entry. >> Flush() removes all entries older or same DateTime as passed. >> >> Hope this helps. >> >> -- >> Arno Garrels >> >> >>> Best Regards, >>> >>> SZ >>> On Sat, Dec 3, 2011 at 18:54, Arno Garrels >>> wrote: >>> >>>> Fastream Technologies wrote: >>>>> Hello, >>>>> >>>>> I wonder if there is an easy way to do this? How does one achieve >>>>> no timeout in ICS avl tree? >>>> >>>> Please be more specific, AFAIR there's no timeout in any ICS AVL >>>> tree. BTW: Also have a look at the new TIcsAvlPointerTree and >>>> TIcsAvlObjectTree in the IPv6 branch, included in >>>> OverbyteIcsAvlTrees. >>>> >>>> -- >>>> Arno Garrels >>>> -- >>>> To unsubscribe or change your settings for TWSocket mailing list >>>> please goto >>>> http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit >>>> our website at http://www.overbyte.be >>>> >>> -- >>> To unsubscribe or change your settings for TWSocket mailing list >>> please goto >>> http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our >>> website at http://www.overbyte.be >> -- >> To unsubscribe or change your settings for TWSocket mailing list >> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket >> Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
What about the events? Do I need to use them in TCacheTree? Thanks a lot, SZ On Sun, Dec 4, 2011 at 11:05, Arno Garrels wrote: > - Original Message - > From: "Fastream Technologies" > To: "ICS support mailing" > Sent: Sunday, December 04, 2011 7:16 AM > Subject: Re: [twsocket] Converting a cache to AVL tree > > > > The component I tried to use is TCacheTree. It has a timeout argument for > > each added item. I do not want any timers or any timeouts yet liked the > > component. Is there a way to omit expiration. I will use my own code for > it. > > TCacheTree doesn't use any timer, it just provides two TDateTime fields. > There are two indices, first is Key of type string, second is TimeStamp > of type TDateTime used to find oldest entries very fast. It's two linked > AVL trees. > > procedure Insert( >Key: String;// Unique key >Data : Pointer; // Pointer to data >Len: Integer; // Optionally data size >TimeStamp : TDateTime = MinDT; // Second key (dups are allowed and > handled) >Expires: TDateTime = MinDT; // What ever you like >UpdateTime : Boolean = True;// Shall the TDateTime fields be > updated? >UpdateData : Boolean = True); // Shall Data be updated? > > Use Insert() for both add and update an entry. > > Node : TCacheNode; > begin > Node := FCacheTree.FindKey(Key); > if Node <> nil then > begin >// Node.IdxRef.TimeStamp // i.e read the TimeStamp >// i.e update TimeStamp and Expires, don't update Data >FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); > end; > > Oldest() returns oldest entry. > Flush() removes all entries older or same DateTime as passed. > > Hope this helps. > > -- > Arno Garrels > > > > Best Regards, > > > > SZ > > On Sat, Dec 3, 2011 at 18:54, Arno Garrels wrote: > > > >> Fastream Technologies wrote: > >> > Hello, > >> > > >> > I wonder if there is an easy way to do this? How does one achieve no > >> > timeout in ICS avl tree? > >> > >> Please be more specific, AFAIR there's no timeout in any ICS AVL tree. > >> BTW: Also have a look at the new TIcsAvlPointerTree and > TIcsAvlObjectTree > >> in the IPv6 branch, included in OverbyteIcsAvlTrees. > >> > >> -- > >> Arno Garrels > >> -- > >> To unsubscribe or change your settings for TWSocket mailing list > >> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > >> Visit our website at http://www.overbyte.be > >> > > -- > > To unsubscribe or change your settings for TWSocket mailing list > > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > > Visit our website at http://www.overbyte.be > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
- Original Message - From: "Fastream Technologies" To: "ICS support mailing" Sent: Sunday, December 04, 2011 7:16 AM Subject: Re: [twsocket] Converting a cache to AVL tree > The component I tried to use is TCacheTree. It has a timeout argument for > each added item. I do not want any timers or any timeouts yet liked the > component. Is there a way to omit expiration. I will use my own code for it. TCacheTree doesn't use any timer, it just provides two TDateTime fields. There are two indices, first is Key of type string, second is TimeStamp of type TDateTime used to find oldest entries very fast. It's two linked AVL trees. procedure Insert( Key: String;// Unique key Data : Pointer; // Pointer to data Len: Integer; // Optionally data size TimeStamp : TDateTime = MinDT; // Second key (dups are allowed and handled) Expires: TDateTime = MinDT; // What ever you like UpdateTime : Boolean = True;// Shall the TDateTime fields be updated? UpdateData : Boolean = True); // Shall Data be updated? Use Insert() for both add and update an entry. Node : TCacheNode; begin Node := FCacheTree.FindKey(Key); if Node <> nil then begin // Node.IdxRef.TimeStamp // i.e read the TimeStamp // i.e update TimeStamp and Expires, don't update Data FCacheTree.Insert(Key, nil, 0, time1, time2, TRUE, FALSE); end; Oldest() returns oldest entry. Flush() removes all entries older or same DateTime as passed. Hope this helps. -- Arno Garrels > Best Regards, > > SZ > On Sat, Dec 3, 2011 at 18:54, Arno Garrels wrote: > >> Fastream Technologies wrote: >> > Hello, >> > >> > I wonder if there is an easy way to do this? How does one achieve no >> > timeout in ICS avl tree? >> >> Please be more specific, AFAIR there's no timeout in any ICS AVL tree. >> BTW: Also have a look at the new TIcsAvlPointerTree and TIcsAvlObjectTree >> in the IPv6 branch, included in OverbyteIcsAvlTrees. >> >> -- >> Arno Garrels >> -- >> To unsubscribe or change your settings for TWSocket mailing list >> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket >> Visit our website at http://www.overbyte.be >> > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
The component I tried to use is TCacheTree. It has a timeout argument for each added item. I do not want any timers or any timeouts yet liked the component. Is there a way to omit expiration. I will use my own code for it. Best Regards, SZ On Sat, Dec 3, 2011 at 18:54, Arno Garrels wrote: > Fastream Technologies wrote: > > Hello, > > > > I wonder if there is an easy way to do this? How does one achieve no > > timeout in ICS avl tree? > > Please be more specific, AFAIR there's no timeout in any ICS AVL tree. > BTW: Also have a look at the new TIcsAvlPointerTree and TIcsAvlObjectTree > in the IPv6 branch, included in OverbyteIcsAvlTrees. > > -- > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Converting a cache to AVL tree
Fastream Technologies wrote: > Hello, > > I wonder if there is an easy way to do this? How does one achieve no > timeout in ICS avl tree? Please be more specific, AFAIR there's no timeout in any ICS AVL tree. BTW: Also have a look at the new TIcsAvlPointerTree and TIcsAvlObjectTree in the IPv6 branch, included in OverbyteIcsAvlTrees. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be