-
Notifications
You must be signed in to change notification settings - Fork 0
list #4
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
base: master
Are you sure you want to change the base?
list #4
Conversation
6c5ee83 to
cf70c2b
Compare
cf70c2b to
d4dc1f6
Compare
| func (cache *lruCache) Clear() { | ||
| cache.mu.Lock() | ||
| defer cache.mu.Unlock() | ||
|
|
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.
Отличное решение по очистке кеша за О(1)!
| } | ||
|
|
||
| func (l *list) Remove(i *ListItem) { | ||
| l.len-- |
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.
Для того, чтобы это было возможно реализовать, стоит завязать проверку условий ( l.len > 1 и l.len == 1) для добавления элемента в список не на текущую длину списка l.len (текущее количество элементов в кеше), а на проверку наличия элементов l.firstNode и l.lastNode
| cache.mu.Lock() | ||
| defer cache.mu.Unlock() | ||
|
|
||
| var result interface{} |
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.
здесь можно немного упростить код и обойтись без введения дополнительной переменной result, просто вернув nil, false если !ok
|
Здравствуйте, София! 10 из 10 |
Домашнее задание №4 «LRU-кэш»
Чек-лист студента (Что это?)
go mod tidy..syncфайл. Зачем его удалять?Критерии оценки
выталкивания из кэша редко используемых элементов) - до 3 баллов
Зачёт от 7 баллов