diff --git a/containers/containers.go b/containers/containers.go new file mode 100644 index 0000000..fc348d2 --- /dev/null +++ b/containers/containers.go @@ -0,0 +1,36 @@ +/* +Copyright (c) 2015, Emir Pasic +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// All data structures must implement the container structure + +package containers + +type Interface interface { + Empty() bool + Size() int + Clear() + Values() []interface{} +} diff --git a/lists/lists.go b/lists/lists.go index e76c1ef..32e71f5 100644 --- a/lists/lists.go +++ b/lists/lists.go @@ -18,13 +18,17 @@ with this distribution for more information. package lists +import "github.com/emirpasic/gods/containers" + type Interface interface { Get(index int) (interface{}, bool) Remove(index int) Add(elements ...interface{}) Contains(elements ...interface{}) bool - Empty() bool - Size() int - Clear() - Values() []interface{} + + containers.Interface + // Empty() bool + // Size() int + // Clear() + // Values() []interface{} } diff --git a/maps/maps.go b/maps/maps.go index a37d100..eddcc20 100644 --- a/maps/maps.go +++ b/maps/maps.go @@ -26,13 +26,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package maps +import "github.com/emirpasic/gods/containers" + type Interface interface { Put(key interface{}, value interface{}) Get(key interface{}) (value interface{}, found bool) Remove(key interface{}) - Empty() bool - Size() int - Clear() Keys() []interface{} - Values() []interface{} + + containers.Interface + // Empty() bool + // Size() int + // Clear() + // Values() []interface{} } diff --git a/sets/sets.go b/sets/sets.go index 8cd4dd7..2a6e2dc 100644 --- a/sets/sets.go +++ b/sets/sets.go @@ -18,12 +18,16 @@ with this distribution for more information. package sets +import "github.com/emirpasic/gods/containers" + type Interface interface { Add(elements ...interface{}) Remove(elements ...interface{}) Contains(elements ...interface{}) bool - Empty() bool - Size() int - Clear() - Values() []interface{} + + containers.Interface + // Empty() bool + // Size() int + // Clear() + // Values() []interface{} } diff --git a/stacks/stacks.go b/stacks/stacks.go index cd5f816..fe9abbb 100644 --- a/stacks/stacks.go +++ b/stacks/stacks.go @@ -26,12 +26,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package stacks +import "github.com/emirpasic/gods/containers" + type Interface interface { Push(value interface{}) Pop() (value interface{}, ok bool) Peek() (value interface{}, ok bool) - Empty() bool - Size() int - Clear() - Values() []interface{} + + containers.Interface + // Empty() bool + // Size() int + // Clear() + // Values() []interface{} } diff --git a/trees/redblacktree/redblacktree.go b/trees/redblacktree/redblacktree.go index 5c36dca..42a8553 100644 --- a/trees/redblacktree/redblacktree.go +++ b/trees/redblacktree/redblacktree.go @@ -34,9 +34,14 @@ package redblacktree import ( "fmt" "github.com/emirpasic/gods/stacks/linkedliststack" + "github.com/emirpasic/gods/trees" "github.com/emirpasic/gods/utils" ) +func assertInterfaceImplementation() { + var _ trees.Interface = (*Tree)(nil) +} + type color bool const ( diff --git a/trees/trees.go b/trees/trees.go new file mode 100644 index 0000000..3714bee --- /dev/null +++ b/trees/trees.go @@ -0,0 +1,37 @@ +/* +Copyright (c) 2015, Emir Pasic +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package trees + +import "github.com/emirpasic/gods/containers" + +type Interface interface { + containers.Interface + // Empty() bool + // Size() int + // Clear() + // Values() []interface{} +}