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 <[email protected]> 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;
> > property Key: String read FKey;
> > property Data: Pointer read FData write FData; // could you
> > add this "write FData"?? Fastream
> > property Len: Integer read FLen;
> > property IdxRef: 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