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 arno.garr...@gmx.de wrote: - Original Message - From: Fastream Technologies ga...@fastream.com To: ICS support mailing twsocket@elists.org 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 arno.garr...@gmx.de 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
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 arno.garr...@gmx.de wrote: - Original Message - From: Fastream Technologies ga...@fastream.com To: ICS support mailing twsocket@elists.org 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 arno.garr...@gmx.de 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
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 arno.garr...@gmx.de 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 arno.garr...@gmx.de wrote: - Original Message - From: Fastream Technologies ga...@fastream.com To: ICS support mailing twsocket@elists.org 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 arno.garr...@gmx.de 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
On Sun, Dec 4, 2011 at 11:40, Arno Garrels arno.garr...@gmx.de 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 ga...@fastream.comwrote: On Sun, Dec 4, 2011 at 11:40, Arno Garrels arno.garr...@gmx.de 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
Okay, I now see your point, it is not async yet recursive. Regards, SZ On Sun, Dec 4, 2011 at 12:52, Fastream Technologies ga...@fastream.comwrote: 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 ga...@fastream.comwrote: On Sun, Dec 4, 2011 at 11:40, Arno Garrels arno.garr...@gmx.de 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
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
Fastream Technologies wrote: On Sun, Dec 4, 2011 at 11:40, Arno Garrels arno.garr...@gmx.de 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
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 arno.garr...@gmx.de wrote: Fastream Technologies wrote: On Sun, Dec 4, 2011 at 11:40, Arno Garrels arno.garr...@gmx.de 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: 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
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 arno.garr...@gmx.de 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 ga...@fastream.comwrote: 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 arno.garr...@gmx.de 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: 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 ga...@fastream.comwrote: 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 arno.garr...@gmx.de 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 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