github.com/min1324/cmap@v1.0.3-0.20220418125848-74e72bbe3be4/interface.go (about) 1 package cmap 2 3 type Interface interface { 4 // Load returns the value stored in the map for a key, or nil if no 5 // value is present. 6 // The ok result indicates whether value was found in the map. 7 Load(key interface{}) (value interface{}, ok bool) 8 9 // Store sets the value for a key. 10 Store(key, value interface{}) 11 12 // LoadOrStore returns the existing value for the key if present. 13 // Otherwise, it stores and returns the given value. 14 // The loaded result is true if the value was loaded, false if stored. 15 LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) 16 17 // Delete deletes the value for a key. 18 Delete(key interface{}) 19 20 // LoadAndDelete deletes the value for a key, returning the previous value if any. 21 // The loaded result reports whether the key was present. 22 LoadAndDelete(key interface{}) (value interface{}, loaded bool) 23 24 // Range calls f sequentially for each key and value present in the map. 25 // If f returns false, range stops the iteration. 26 Range(f func(key, value interface{}) bool) 27 28 // Count returns the number of elements within the map. 29 Count() int64 30 } 31 32 // New return an initialize map 33 func New() Interface { 34 return &Map{} 35 } 36 37 // NewFMap return an initialize fmap 38 func NewFMap() Interface { 39 return &FMap{} 40 } 41 42 // NewCMap return an initialize cmap 43 func NewCMap() Interface { 44 m := &CMap{} 45 n := m.getNode() 46 n.initBuckets() 47 return m 48 }