From 032e5ae2556d99a044a6b9261c96d8a85b73ddfa Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 31 Oct 2018 11:50:40 +0000 Subject: [PATCH] Core: LRUCache::GetLRUKey (thanks fermium) git-svn-id: svn://ultimatepp.org/upp/trunk@12436 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Other.h | 14 +++++++++++--- uppsrc/Core/src.tpp/LRUCache_en-us.tpp | 8 +++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/uppsrc/Core/Other.h b/uppsrc/Core/Other.h index da2edc04a..2390a69d6 100644 --- a/uppsrc/Core/Other.h +++ b/uppsrc/Core/Other.h @@ -376,9 +376,10 @@ public: template void AdjustSize(P getsize); - T& GetLRU(); - void DropLRU(); - void Shrink(int maxsize, int maxcount = 30000); + T& GetLRU(); + const K& GetLRUKey(); + void DropLRU(); + void Shrink(int maxsize, int maxcount = 30000); template int Remove(P predicate); template bool RemoveOne(P predicate); @@ -434,6 +435,13 @@ T& LRUCache::GetLRU() return *data[tail].data; } +template +const K& LRUCacheKeyRet::GetLRUKey() +{ + int tail = data[head].prev; + return key[tail].key; +} + template void LRUCache::DropLRU() { diff --git a/uppsrc/Core/src.tpp/LRUCache_en-us.tpp b/uppsrc/Core/src.tpp/LRUCache_en-us.tpp index 9ce0fa8f4..375f7f4cc 100644 --- a/uppsrc/Core/src.tpp/LRUCache_en-us.tpp +++ b/uppsrc/Core/src.tpp/LRUCache_en-us.tpp @@ -1,5 +1,4 @@ topic "LRUCache"; -[2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,2#27521748481378242620020725143825:desc] [0 $$3,0#96390100711032703541132217272105:end] @@ -9,6 +8,7 @@ topic "LRUCache"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] +[2 $$0,0#00000000000000000000000000000000:Default] [{_} [ {{10000@(113.42.0) [s0;%% [*@7;4 LRUCache]]}}&] [s1;@(0.0.255)3 &] @@ -75,6 +75,12 @@ parameter) to retrieve the size of individual data items.&] the cache (candidate for removal).&] [s3; &] [s4; &] +[s5;:Upp`:`:LRUCache`:`:GetLRUKey`(`): [@(0.0.255) const]_[*@4 K][@(0.0.255) `&]_[* GetLRUKey +]()&] +[s2;%% Returns the key of the least recently used data item in the +cache (candidate for removal).&] +[s3; &] +[s4; &] [s5;:LRUCache`:`:DropLRU`(`): [@(0.0.255) void]_[* DropLRU]()&] [s2;%% Removes the least recently used data item from the cache.&] [s3; &]