- creating a common containers interface for all data structures

pull/1/head
emirpasic 9 years ago
parent d6be7ca2e5
commit be9edcef3c

@ -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{}
}

@ -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{}
}

@ -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{}
}

@ -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{}
}

@ -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{}
}

@ -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 (

@ -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{}
}
Loading…
Cancel
Save