switch to go vendoring

This commit is contained in:
Michael Barz
2023-04-19 20:10:09 +02:00
parent 632fa05ef9
commit afc6ed1e41
8527 changed files with 3004916 additions and 2 deletions

5
vendor/github.com/cevaris/ordered_map/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,5 @@
*.test
*~
.idea
*.iml

19
vendor/github.com/cevaris/ordered_map/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,19 @@
---
language: go
go:
- tip
- 1.12
- 1.11
- 1.10
- 1.9
- 1.8
- 1.7
- 1.6
- 1.5
- 1.4
- 1.3
install:
- make
- make test

21
vendor/github.com/cevaris/ordered_map/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015-2016 Adam Cardenas
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

10
vendor/github.com/cevaris/ordered_map/Makefile generated vendored Normal file
View File

@@ -0,0 +1,10 @@
all: build install
build:
go build
install:
go install
test:
go test -v *.go

113
vendor/github.com/cevaris/ordered_map/README.md generated vendored Normal file
View File

@@ -0,0 +1,113 @@
# Ordered Map for golang
[![Build Status](https://travis-ci.org/cevaris/ordered_map.svg?branch=master)](https://travis-ci.org/cevaris/ordered_map)
**OrderedMap** is a Python port of OrderedDict implemented in golang. Golang's builtin `map` purposefully randomizes the iteration of stored key/values. **OrderedMap** struct preserves inserted key/value pairs; such that on iteration, key/value pairs are received in inserted (first in, first out) order.
## Features
- Full support Key/Value for all data types
- Exposes an Iterator that iterates in order of insertion
- Full Get/Set/Delete map interface
- Supports Golang v1.3 through v1.12
## Download and Install
`go get https://github.com/cevaris/ordered_map.git`
## Examples
### Create, Get, Set, Delete
```go
package main
import (
"fmt"
"github.com/cevaris/ordered_map"
)
func main() {
// Init new OrderedMap
om := ordered_map.NewOrderedMap()
// Set key
om.Set("a", 1)
om.Set("b", 2)
om.Set("c", 3)
om.Set("d", 4)
// Same interface as builtin map
if val, ok := om.Get("b"); ok == true {
// Found key "b"
fmt.Println(val)
}
// Delete a key
om.Delete("c")
// Failed Get lookup becase we deleted "c"
if _, ok := om.Get("c"); ok == false {
// Did not find key "c"
fmt.Println("c not found")
}
fmt.Println(om)
}
```
### Iterator
```go
n := 100
om := ordered_map.NewOrderedMap()
for i := 0; i < n; i++ {
// Insert data into OrderedMap
om.Set(i, fmt.Sprintf("%d", i * i))
}
// Iterate though values
// - Values iteration are in insert order
// - Returned in a key/value pair struct
iter := om.IterFunc()
for kv, ok := iter(); ok; kv, ok = iter() {
fmt.Println(kv, kv.Key, kv.Value)
}
```
### Custom Structs
```go
om := ordered_map.NewOrderedMap()
om.Set("one", &MyStruct{1, 1.1})
om.Set("two", &MyStruct{2, 2.2})
om.Set("three", &MyStruct{3, 3.3})
fmt.Println(om)
// Ouput: OrderedMap[one:&{1 1.1}, two:&{2 2.2}, three:&{3 3.3}, ]
```
## For Development
Git clone project
`git clone https://github.com/cevaris/ordered_map.git`
Build and install project
`make`
Run tests
`make test`

16
vendor/github.com/cevaris/ordered_map/key_pair.go generated vendored Normal file
View File

@@ -0,0 +1,16 @@
package ordered_map
import "fmt"
type KVPair struct {
Key interface{}
Value interface{}
}
func (k *KVPair) String() string {
return fmt.Sprintf("%v:%v", k.Key, k.Value)
}
func (kv1 *KVPair) Compare(kv2 *KVPair) bool {
return kv1.Key == kv2.Key && kv1.Value == kv2.Value
}

62
vendor/github.com/cevaris/ordered_map/node.go generated vendored Normal file
View File

@@ -0,0 +1,62 @@
package ordered_map
import (
"fmt"
"bytes"
)
type node struct {
Prev *node
Next *node
Value interface{}
}
func newRootNode() *node {
root := &node{}
root.Prev = root
root.Next = root
return root
}
func newNode(prev *node, next *node, key interface{}) *node {
return &node{Prev: prev, Next: next, Value: key}
}
func (n *node) Add(value string) {
root := n
last := root.Prev
last.Next = newNode(last, n, value)
root.Prev = last.Next
}
func (n *node) String() string {
var buffer bytes.Buffer
if n.Value == "" {
// Need to sentinel
var curr *node
root := n
curr = root.Next
for curr != root {
buffer.WriteString(fmt.Sprintf("%s, ", curr.Value))
curr = curr.Next
}
} else {
// Else, print pointer value
buffer.WriteString(fmt.Sprintf("%p, ", &n))
}
return fmt.Sprintf("LinkList[%v]", buffer.String())
}
func (n *node) IterFunc() func() (string, bool) {
var curr *node
root := n
curr = root.Next
return func() (string, bool) {
for curr != root {
tmp := curr.Value.(string)
curr = curr.Next
return tmp, true
}
return "", false
}
}

121
vendor/github.com/cevaris/ordered_map/ordered_map.go generated vendored Normal file
View File

@@ -0,0 +1,121 @@
package ordered_map
import (
"fmt"
)
type OrderedMap struct {
store map[interface{}]interface{}
mapper map[interface{}]*node
root *node
}
func NewOrderedMap() *OrderedMap {
om := &OrderedMap{
store: make(map[interface{}]interface{}),
mapper: make(map[interface{}]*node),
root: newRootNode(),
}
return om
}
func NewOrderedMapWithArgs(args []*KVPair) *OrderedMap {
om := NewOrderedMap()
om.update(args)
return om
}
func (om *OrderedMap) update(args []*KVPair) {
for _, pair := range args {
om.Set(pair.Key, pair.Value)
}
}
func (om *OrderedMap) Set(key interface{}, value interface{}) {
if _, ok := om.store[key]; ok == false {
root := om.root
last := root.Prev
last.Next = newNode(last, root, key)
root.Prev = last.Next
om.mapper[key] = last.Next
}
om.store[key] = value
}
func (om *OrderedMap) Get(key interface{}) (interface{}, bool) {
val, ok := om.store[key]
return val, ok
}
func (om *OrderedMap) Delete(key interface{}) {
_, ok := om.store[key]
if ok {
delete(om.store, key)
}
root, rootFound := om.mapper[key]
if rootFound {
prev := root.Prev
next := root.Next
prev.Next = next
next.Prev = prev
delete(om.mapper, key)
}
}
func (om *OrderedMap) String() string {
builder := make([]string, len(om.store))
var index int = 0
iter := om.IterFunc()
for kv, ok := iter(); ok; kv, ok = iter() {
val, _ := om.Get(kv.Key)
builder[index] = fmt.Sprintf("%v:%v, ", kv.Key, val)
index++
}
return fmt.Sprintf("OrderedMap%v", builder)
}
func (om *OrderedMap) Iter() <-chan *KVPair {
println("Iter() method is deprecated!. Use IterFunc() instead.")
return om.UnsafeIter()
}
/*
Beware, Iterator leaks goroutines if we do not fully traverse the map.
For most cases, `IterFunc()` should work as an iterator.
*/
func (om *OrderedMap) UnsafeIter() <-chan *KVPair {
keys := make(chan *KVPair)
go func() {
defer close(keys)
var curr *node
root := om.root
curr = root.Next
for curr != root {
v, _ := om.store[curr.Value]
keys <- &KVPair{curr.Value, v}
curr = curr.Next
}
}()
return keys
}
func (om *OrderedMap) IterFunc() func() (*KVPair, bool) {
var curr *node
root := om.root
curr = root.Next
return func() (*KVPair, bool) {
for curr != root {
tmp := curr
curr = curr.Next
v, _ := om.store[tmp.Value]
return &KVPair{tmp.Value, v}, true
}
return nil, false
}
}
func (om *OrderedMap) Len() int {
return len(om.store)
}