Clickable, Popup, and Toggle Lists

Is there a way in D to have a list that allows you to move around values? I create a cache, and I would like to save the log when the last access to the item, so when compressing the cache or just about overflow, I can delete items that have not been accessed after a while.

I would like to be able to push my back and pop from the front. Notice that I would like to appear in front, not from the back, as I want the oldest items to come out.

I want to be able to search if the item is really in the list. If such a function does not exist, I could alternatively implement it myself; it does not matter.

I would like to be able to switch items around. This allows me when accessing an item in the list, I can return it back to the back, where are the most recent items.

Is there such a function already in D, maybe a better approach to this?

+3
source share
3 answers

No, there is no such package D about which I know. Ideally, it should behave like JCache , but I'm afraid it will be too much to ask. :) JCache will be a great addition to the already excellent Java API.

Community

D will certainly benefit from something like that.

+2
source

I suggest you use SList (single linked list) or double linked list as the base for your cache wrapper.

. .

+2

, CS , , "". , , .

, 95% ( ) - , . , .

Bjarne Stroustroup http://bulldozer00.com/2012/02/09/vectors-and-lists/

, , CS , , - , . - ( ).

, ( ++ STL) . , , : " , . gazillion , . - ".

, , - .

, . , : " , , ". . - , - , - , , ( ).

D popFront, ~. , , canFind std.algorithm . , length, .

The caveat that can be pointed out in this approach is that it implicitly comes with a memory allocation strategy that may seem wasteful. But this is practically a good default, and you really need to measure the metric you care about (performance and / or memory) before switching to something else.

+2
source

All Articles