支持获取一个
This commit is contained in:
parent
1aa52e0821
commit
db86a646f4
|
@ -247,6 +247,18 @@ func (slf *Map[Key, Value]) Size() int {
|
|||
return len(slf.data)
|
||||
}
|
||||
|
||||
// GetOne 获取一个
|
||||
func (slf *Map[Key, Value]) GetOne() (value Value) {
|
||||
if !slf.atom {
|
||||
slf.lock.RLock()
|
||||
defer slf.lock.RUnlock()
|
||||
}
|
||||
for _, v := range slf.data {
|
||||
return v
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (slf *Map[Key, Value]) MarshalJSON() ([]byte, error) {
|
||||
m := slf.Map()
|
||||
return json.Marshal(m)
|
||||
|
|
|
@ -14,4 +14,5 @@ type MapReadonly[Key comparable, Value any] interface {
|
|||
Slice() []Value
|
||||
Map() map[Key]Value
|
||||
Size() int
|
||||
GetOne() (value Value)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue