-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(container/gmap): add generic list map feature #4520
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
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.
Pull Request Overview
This PR introduces a new generic list map implementation (ListKVMap[K, V]) and refactors the existing ListMap to use it as the underlying implementation. The main goal is to provide a type-safe, generic version of the ordered map while maintaining backward compatibility with the existing non-generic ListMap.
- Adds new generic
ListKVMap[K, V]type with full map operations - Refactors
ListMapto wrapListKVMap[any, any]with lazy initialization - Delegates most
ListMapmethods to the underlying generic implementation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| container/gmap/gmap_list_k_v_map.go | New file implementing the generic ListKVMap[K, V] type with type-safe operations for ordered key-value storage |
| container/gmap/gmap_list_map.go | Refactored to use ListKVMap[any, any] as the underlying implementation with lazy initialization and method delegation |
Comments suppressed due to low confidence (2)
container/gmap/gmap_list_map.go:319
- Direct access to
m.mu,m.data, andm.listbypasses the genericListKVMapimplementation after lazy initialization. This should usem.ListKVMap.UnmarshalValue(value)instead to maintain consistency with the new design.
m.mu.Lock()
defer m.mu.Unlock()
for k, v := range gconv.Map(value) {
if e, ok := m.data[k]; !ok {
m.data[k] = m.list.PushBack(&gListMapNode{k, v})
} else {
e.Value = &gListMapNode{k, v}
}
}
container/gmap/gmap_list_map.go:279
- The
Flip()method signature is inconsistent with the underlyingListKVMap.Flip()method, which returns an error. This method should returnerrorand propagate any errors from the conversion operations, or handle them appropriately. The current implementation silently ignores potential errors.
// Flip exchanges key-value of the map to value-key.
func (m *ListMap) Flip() {
data := m.Map()
m.Clear()
for key, value := range data {
m.Set(value, key)
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
fix(container/gmap): 修复 GetOrSetFuncLock 和 SetIfNotExistFuncLock 中的并发安全问题
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.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
container/gmap/gmap_list_map.go:320
- The
UnmarshalValuemethod is directly accessingm.dataandm.listfields which are now private fields of the embeddedListKVMap[any, any]type. This will cause a compilation error. The method should delegate tom.ListKVMap.UnmarshalValue(value)instead of manually accessing the internal fields.
m.mu.Lock()
defer m.mu.Unlock()
for k, v := range gconv.Map(value) {
if e, ok := m.data[k]; !ok {
m.data[k] = m.list.PushBack(&gListMapNode{k, v})
} else {
e.Value = &gListMapNode{k, v}
}
}
return
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…保线程安全 test(container/gmap): 更新测试用例以验证空映射的行为
add the generic list map: ListKVMap[K,V] and let ListMap base on it.