Skip to content
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

Cleanup type assertions in the linkedHashmap #1341

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions utils/linkedhashmap/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ func (it *iterator[K, V]) Next() bool {
// It's important to ensure that [it.next] is not nil
// by not deleting elements that have not yet been iterated
// over from [it.lh]
it.key = it.next.Value.(keyValue[K, V]).key
it.value = it.next.Value.(keyValue[K, V]).value
kv := it.next.Value.(keyValue[K, V])
it.key = kv.key
it.value = kv.value
it.next = it.next.Next() // Next time, return next element
it.exhausted = it.next == nil
return true
Expand Down
9 changes: 6 additions & 3 deletions utils/linkedhashmap/linkedhashmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (lh *linkedHashmap[K, V]) put(key K, value V) {

func (lh *linkedHashmap[K, V]) get(key K) (V, bool) {
if e, ok := lh.entryMap[key]; ok {
return e.Value.(keyValue[K, V]).value, true
kv := e.Value.(keyValue[K, V])
return kv.value, true
}
return utils.Zero[V](), false
}
Expand All @@ -126,14 +127,16 @@ func (lh *linkedHashmap[K, V]) len() int {

func (lh *linkedHashmap[K, V]) oldest() (K, V, bool) {
if val := lh.entryList.Front(); val != nil {
return val.Value.(keyValue[K, V]).key, val.Value.(keyValue[K, V]).value, true
kv := val.Value.(keyValue[K, V])
return kv.key, kv.value, true
}
return utils.Zero[K](), utils.Zero[V](), false
}

func (lh *linkedHashmap[K, V]) newest() (K, V, bool) {
if val := lh.entryList.Back(); val != nil {
return val.Value.(keyValue[K, V]).key, val.Value.(keyValue[K, V]).value, true
kv := val.Value.(keyValue[K, V])
return kv.key, kv.value, true
}
return utils.Zero[K](), utils.Zero[V](), false
}
Expand Down