Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(39)

Issue 130044: Add some basic functions for LRU cache.

Can't Edit
Can't Publish+Mail
Start Review
Created:
16 years, 3 months ago by cykoo1
Modified:
16 years ago
Reviewers:
ChrisM, Alasdair
CC:
google-concurrency-library_googlegroups.com
Visibility:
Public.

Patch Set 1 #

Total comments: 13

Patch Set 2 : Address responses #

Total comments: 2

Patch Set 3 : Update in reponse to Alasdair's comments #

Total comments: 18

Patch Set 4 : Responses to chris' comments #

Total comments: 9

Patch Set 5 : Responses to Chris' comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+346 lines, -1 line) Patch
M Makefile View 1 chunk +1 line, -1 line 0 comments Download
A include/lru_cache.h View 1 2 3 4 1 chunk +148 lines, -0 lines 0 comments Download
A src/lru_cache.cc View 1 chunk +1 line, -0 lines 0 comments Download
A testing/lru_test.cc View 1 2 3 4 1 chunk +196 lines, -0 lines 0 comments Download

Messages

Total messages: 9
cykoo1
16 years, 3 months ago (2009-10-08 01:33:07 UTC) #1
ChrisM
Looks pretty good in general, though I have a few questions. http://codereview.appspot.com/130044/diff/1/3 File include/lru_cache.h (right): ...
16 years, 3 months ago (2009-10-16 16:02:12 UTC) #2
cykoo1
Sorry for the late response. Here are the updates. http://codereview.appspot.com/130044/diff/1/3 File include/lru_cache.h (right): http://codereview.appspot.com/130044/diff/1/3#newcode2 Line ...
16 years, 2 months ago (2009-10-29 01:20:59 UTC) #3
Alasdair
http://codereview.appspot.com/130044/diff/3001/3003 File include/lru_cache.h (right): http://codereview.appspot.com/130044/diff/3001/3003#newcode126 Line 126: int max_size_; Should probably be size_t for max ...
16 years, 2 months ago (2009-10-30 18:58:05 UTC) #4
cykoo1
http://codereview.appspot.com/130044/diff/3001/3003 File include/lru_cache.h (right): http://codereview.appspot.com/130044/diff/3001/3003#newcode126 Line 126: int max_size_; On 2009/10/30 18:58:05, Alasdair wrote: > ...
16 years, 2 months ago (2009-11-02 18:54:21 UTC) #5
ChrisM
http://codereview.appspot.com/130044/diff/4003/3008 File include/lru_cache.h (right): http://codereview.appspot.com/130044/diff/4003/3008#newcode16 Line 16: // TODO: makes this class thread-safe and adds ...
16 years, 2 months ago (2009-11-05 19:29:54 UTC) #6
cykoo1
I've also run the test under thread sanitizer (http://code.google.com/p/google-concurrency-library/wiki/RaceDetectionTools). http://codereview.appspot.com/130044/diff/4003/3008 File include/lru_cache.h (right): http://codereview.appspot.com/130044/diff/4003/3008#newcode16 include/lru_cache.h:16: ...
16 years, 1 month ago (2009-12-04 01:27:56 UTC) #7
ChrisM
Sorry i was a little slow on getting to this. It's pretty good now, though. ...
16 years, 1 month ago (2009-12-10 16:41:03 UTC) #8
cykoo1
16 years ago (2009-12-17 02:06:46 UTC) #9
http://codereview.appspot.com/130044/diff/4003/3008
File include/lru_cache.h (right):

http://codereview.appspot.com/130044/diff/4003/3008#newcode63
include/lru_cache.h:63: erase(lru_list_head_.prev->key);
On 2009/12/10 16:41:04, ccmysen wrote:
> minor question, but do you think we should modify this so that you do
> while(size() > max_size_) {} so that if someone else inserts, we could clean
up
> for that thread? There is a concurrency issue there, but just thought I'd ask.

The current API only allows adding 1 element at a time. It's not clear to me why
we need a while loop().

http://codereview.appspot.com/130044/diff/4003/3008#newcode67
include/lru_cache.h:67: bool lookup(const key_type& k, value_type& v) {
On 2009/12/10 16:41:04, ccmysen wrote:
> is the expectation that these functions generally go uncommented? otherwise it
> might be nice to have a couple function level comments mentioning what is
being
> done.
done.

http://codereview.appspot.com/130044/diff/4003/3008#newcode81
include/lru_cache.h:81: bool erase(const key_type& k) {
On 2009/12/10 16:41:04, ccmysen wrote:
> so, often erase() is for iterators, do you think we should make it clear that
we
> erase keys?

I looked a bit over the c++0x standard draft (n2914.pdf). and notice that
erase() isn't only for iterators , e.g. in map, it has something like size_type
erase(const key_type& k)

http://codereview.appspot.com/130044/diff/9001/10002#newcode21
include/lru_cache.h:21: struct lru_list_element {
On 2009/12/10 16:41:04, ccmysen wrote:
> or better yet, can you use an existing doubly linked list for this with a
value
> with pair<Key, T>?

Actually I thought about that too (using stl implementation or put the linked
list into a separate class). The main reason is that the current implementations
assume quite a lot of knowledge about the implementation of the linked list.

For instance, an existing doubly linked list would identify an element via
iterator. But that doesn't quite fit here: the hash map will need to store
pointers to elements in the linked list - the position of an element would
change over time due to insert/erase etc.

http://codereview.appspot.com/130044/diff/9001/10002#newcode47
include/lru_cache.h:47: // Remove existing entry (if any).
On 2009/12/10 16:41:04, ccmysen wrote:
> can you explain somewhere why you need a recursive mutex for this code?

Because I would need to remove an old entry first. The cleanest way is to call
erase(). But it will end up in deadlock unless mutex is recursive.

http://codereview.appspot.com/130044/diff/9001/10004
File testing/lru_test.cc (right):

http://codereview.appspot.com/130044/diff/9001/10004#newcode62
testing/lru_test.cc:62: // Make sure that the cache still works after being
cleared.
On 2009/12/10 16:41:04, ccmysen wrote:
> const int kOffset = 5;
> 
> insert(kOffset + i*2, kOffset + i*2 + 1)?

Done.

http://codereview.appspot.com/130044/diff/9001/10004#newcode77
testing/lru_test.cc:77: // A small test for shared pointer.
On 2009/12/10 16:41:04, ccmysen wrote:
> small test that shared pointers work properly?

Done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b