
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
github.com/wk8/go-ordered-map
Same as regular maps, but also remembers the order in which keys were inserted, akin to Python's collections.OrderedDict
s.
It offers the following features:
break
the iteration, and in time linear to the number of keys iterated over rather than the total length of the ordered mapinterface{}
scontainer/list
go get -u github.com/wk8/go-ordered-map
Or use your favorite golang vendoring tool!
All go versions >= 1.13 are supported. There's no reason for older versions to not also work, but they're not part of the build matrix.
The full documentation is available on godoc.org.
package main
import (
"fmt"
"github.com/wk8/go-ordered-map"
)
func main() {
om := orderedmap.New()
om.Set("foo", "bar")
om.Set("bar", "baz")
om.Set("coucou", "toi")
fmt.Println(om.Get("foo")) // => bar, true
fmt.Println(om.Get("i dont exist")) // => <nil>, false
// iterating pairs from oldest to newest:
for pair := om.Oldest(); pair != nil; pair = pair.Next() {
fmt.Printf("%s => %s\n", pair.Key, pair.Value)
} // prints:
// foo => bar
// bar => baz
// coucou => toi
// iterating over the 2 newest pairs:
i := 0
for pair := om.Newest(); pair != nil; pair = pair.Prev() {
fmt.Printf("%s => %s\n", pair.Key, pair.Value)
i++
if i >= 2 {
break
}
} // prints:
// coucou => toi
// bar => baz
}
All of OrderedMap
's methods accept and return interface{}
s, so you can use any type of keys that regular map
s accept, as well pack/unpack arbitrary values, e.g.:
type myStruct struct {
payload string
}
func main() {
om := orderedmap.New()
om.Set(12, &myStruct{"foo"})
om.Set(1, &myStruct{"bar"})
value, present := om.Get(12)
if !present {
panic("should be there!")
}
fmt.Println(value.(*myStruct).payload) // => foo
for pair := om.Oldest(); pair != nil; pair = pair.Next() {
fmt.Printf("%d => %s\n", pair.Key, pair.Value.(*myStruct).payload)
} // prints:
// 12 => foo
// 1 => bar
}
There are several other ordered map golang implementations out there, but I believe that at the time of writing none of them offer the same functionality as this library; more specifically:
string
keys, its Delete
operations are linearDelete
operations are linearDelete
and Get
operations are linear, iterations trigger a linear memory allocationFAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.