From 4faed184c90122e05e70ea3755ead4f5b7009416 Mon Sep 17 00:00:00 2001 From: Thomas Meckel Date: Sun, 23 Jun 2019 15:32:29 +0200 Subject: [PATCH] Added github.com/golang-collections/collections to vendor directory --- .../golang-collections/collections/LICENSE | 20 +++++++++ .../collections/stack/stack.go | 44 +++++++++++++++++++ .../collections/stack/stack_test.go | 42 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 vendor/github.com/golang-collections/collections/LICENSE create mode 100644 vendor/github.com/golang-collections/collections/stack/stack.go create mode 100644 vendor/github.com/golang-collections/collections/stack/stack_test.go diff --git a/vendor/github.com/golang-collections/collections/LICENSE b/vendor/github.com/golang-collections/collections/LICENSE new file mode 100644 index 000000000..75a26aeb3 --- /dev/null +++ b/vendor/github.com/golang-collections/collections/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2012 Caleb Doxsey + +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. \ No newline at end of file diff --git a/vendor/github.com/golang-collections/collections/stack/stack.go b/vendor/github.com/golang-collections/collections/stack/stack.go new file mode 100644 index 000000000..04063dfab --- /dev/null +++ b/vendor/github.com/golang-collections/collections/stack/stack.go @@ -0,0 +1,44 @@ +package stack + +type ( + Stack struct { + top *node + length int + } + node struct { + value interface{} + prev *node + } +) +// Create a new stack +func New() *Stack { + return &Stack{nil,0} +} +// Return the number of items in the stack +func (this *Stack) Len() int { + return this.length +} +// View the top item on the stack +func (this *Stack) Peek() interface{} { + if this.length == 0 { + return nil + } + return this.top.value +} +// Pop the top item of the stack and return it +func (this *Stack) Pop() interface{} { + if this.length == 0 { + return nil + } + + n := this.top + this.top = n.prev + this.length-- + return n.value +} +// Push a value onto the top of the stack +func (this *Stack) Push(value interface{}) { + n := &node{value,this.top} + this.top = n + this.length++ +} \ No newline at end of file diff --git a/vendor/github.com/golang-collections/collections/stack/stack_test.go b/vendor/github.com/golang-collections/collections/stack/stack_test.go new file mode 100644 index 000000000..52c909475 --- /dev/null +++ b/vendor/github.com/golang-collections/collections/stack/stack_test.go @@ -0,0 +1,42 @@ +package stack + +import ( + "testing" +) + +func Test(t *testing.T) { + s := New() + + if s.Len() != 0 { + t.Errorf("Length of an empty stack should be 0") + } + + s.Push(1) + + if s.Len() != 1 { + t.Errorf("Length should be 0") + } + + if s.Peek().(int) != 1 { + t.Errorf("Top item on the stack should be 1") + } + + if s.Pop().(int) != 1 { + t.Errorf("Top item should have been 1") + } + + if s.Len() != 0 { + t.Errorf("Stack should be empty") + } + + s.Push(1) + s.Push(2) + + if s.Len() != 2 { + t.Errorf("Length should be 2") + } + + if s.Peek().(int) != 2 { + t.Errorf("Top of the stack should be 2") + } +} \ No newline at end of file