-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hw04 lru cache #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://otus.ru/teacher-lk/homework/52091/6597/
Здравствуйте!
Хорошая работа. Не хватает одного тестика и есть вопросы по вашем комментариям, а так все ок. Рекомендовал бы внимательнее читать ТЗ к задачам.
Принято
9 / 10
|
||
middle := l.Back().Next // 20 | ||
middle := l.Back().Prev // 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Видно, что вы плохо читали ТЗ.
Там приведена структура ожидаемого списка
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Но погодите... Back()
вернет последний элемент, l.Back().Next
вернет nil
, но никак не средний. Или я что-то не так понял?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
все, увидел... Мой фолт :(
} | ||
|
||
// Just for debugging purpose | ||
func (l *list) display() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Рекомендовал бы в display отдавать io.Writer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
попробую, спасибо
Remove(i *listItem) | ||
MoveToFront(i *listItem) | ||
|
||
display() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Приватные методы в интерфейсе - редкий кейс
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
спасибо, учту
require.Equal(t, []interface{}{nil, false}, wrap(c.Get("ccc"))) | ||
}) | ||
|
||
t.Run("check cache capacity", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не хватает теста, где вы проверяете не просто размер очередь и её очистку через Clear(), но и проверяете перестановку элементов в очереди:
- добавили элементы
- дернули элементы несколько раз
- добавили новый, проверили, что из очереди удалился наименее используемый
} | ||
|
||
func (c *lruCache) Clear() { | ||
for key, item := range c.items { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно пересоздать items
и queue
аналогично конструктору. GC выполнит свою работу
return found | ||
} | ||
|
||
func (c *lruCache) Clear() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mux
потерялся?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
упс
c.queue.Remove(item) | ||
} | ||
c.items[key] = c.queue.PushFront(cacheItem{key: key, value: value}) | ||
if c.queue.Len() > c.capacity { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно вынести в отдельный приватный purge
метод
c.mux.Lock() | ||
defer c.mux.Unlock() | ||
item, found := c.items[key] | ||
// it's strange, that I cannot return c.items[key] directly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что странного?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну допустим в этом кейсе неактуально, но было бы удобно делать return c.items[key]
, вместо создания дополнительных переменных, но почему-то компилятор не дает такого делать
defer c.mux.Unlock() | ||
item, found := c.items[key] | ||
if found { | ||
// Looks like I cannot reassign value in a such way |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему так выглядит?
Можно зарессайнить значение + MoveToFront
?
… hw04_lru_cache # Conflicts: # .travis.yml # README.md # hw04_lru_cache/cache.go # hw04_lru_cache/cache_test.go # hw04_lru_cache/go.mod # hw04_lru_cache/go.sum # hw04_lru_cache/list.go # hw04_lru_cache/list_test.go # hw05_parallel_execution/README.md # hw05_parallel_execution/go.mod # hw05_parallel_execution/go.sum # hw05_parallel_execution/run_test.go # hw06_pipeline_execution/pipeline_test.go # hw07_file_copying/test.sh # hw08_envdir_tool/README.md # hw08_envdir_tool/test.sh # hw09_generator_of_validators/test.sh # hw11_telnet_client/test.sh
никаких изменений, случайно запушил несколько коммитов, подмерджил мастер |
Домашнее задание №4 «LRU-кэш»
Критерии оценки
выталкивания из кэша редко используемых элементов) - до 3 баллов
Зачёт от 7 баллов