Documentation ¶
Index ¶
- type CompareFunc
- type SortMap
- func (sm *SortMap) Begin() (interface{}, bool)
- func (sm *SortMap) Delete(k interface{}) interface{}
- func (sm *SortMap) End() (interface{}, bool)
- func (sm *SortMap) Get(k interface{}) interface{}
- func (sm *SortMap) Len() int
- func (sm *SortMap) Less(i, j int) bool
- func (sm *SortMap) Next() (v interface{}, has bool)
- func (sm *SortMap) Set(k interface{}, v interface{})
- func (sm *SortMap) Swap(i, j int)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompareFunc ¶
type CompareFunc func(ka, va, kb, vb interface{}) bool
CompareFunc has 4 paramaters in two pair: `a(ka=>va)` and `b(kb=>vb)`.
type SortMap ¶
SortMap illustrates how to sort a map
Example ¶
package main import ( "fmt" "github.com/mikespook/sortmap" "sort" "sync" ) func main() { var wg sync.WaitGroup by := func(ka, va, kb, vb interface{}) bool { return ka.(int) < kb.(int) } sm := sortmap.New(by) for i := 0; i < 100; i++ { wg.Add(1) go func() { for i := 0; i < 10000; i++ { sm.Set(i, i) } wg.Done() }() } wg.Wait() sort.Sort(sm) for i := 0; i < 100; i++ { wg.Add(1) go func() { for a, ok := sm.Begin(); ok; a, ok = sm.Next() { fmt.Println(a, ok) } wg.Done() }() } wg.Wait() }
Output:
func (*SortMap) Begin ¶
Begin resets the position indicator and return the first data and true, or nil and false if not data has been added into the map
func (*SortMap) Delete ¶
func (sm *SortMap) Delete(k interface{}) interface{}
Delete removes the data with key `k` and returns it
func (*SortMap) End ¶
End sets the position indicator to the end of data and return it and true, or nil and false if not data has been added into the map
func (*SortMap) Get ¶
func (sm *SortMap) Get(k interface{}) interface{}
Get returns the data with key `k`
func (*SortMap) Less ¶
Less is part of sort.Interface. It is implemented by calling the "By" closure in the sorter.
func (*SortMap) Next ¶
Next returns the next data and true, or nil and false if it's the end of data
Click to show internal directories.
Click to hide internal directories.