Documentation
¶
Overview ¶
Package maporder provides a map that maintains the order of insertion.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Example ¶
package main
import (
"encoding/json"
"fmt"
"github.com/itcomusic/mapo"
)
func main() {
m := mapo.New()
m.Set("a", 1)
m.Set("b", 2)
m.Set("c", 3)
fmt.Println(m.Keys()) // [a, b, c]
value, ok := m.Get("a")
fmt.Println(value, ok) // 1, true
m.Delete("c")
b, err := json.Marshal(m)
if err != nil {
panic(err)
}
fmt.Println(string(b)) // {"a":1,"b":2}
var m2 mapo.Map
if err := json.Unmarshal(b, &m2); err != nil {
panic(err)
}
fmt.Println(m2.Keys()) // [a, b]
}
Output: [a b c] 1 true {"a":1,"b":2} [a b]
func NewWithSize ¶
NewWithSize creates a new Map with the given capacity.
func (*Map) MarshalJSON ¶
func (*Map) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.