-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.go
65 lines (60 loc) · 2.39 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gollections
// A Collection is a grouping of elements.
type Collection interface {
// Add appends new elements to the end of the collection.
Add(values ...interface{})
// Clear removes all elements from the collection.
Clear()
// Contains checks if the collection contains all specified values.
Contains(values ...interface{}) bool
// IsEmpty checks if the collection contains no elements.
IsEmpty() bool
// Remove removes all specified values from the collection.
Remove(values ...interface{})
// Size gets the number of elements in the collection.
Size() int
// SliceCopy copies all values in the collection to the supplied slice.
SliceCopy(ptrToSlice interface{}) error
// ToArray gets an array representation of the collection.
ToArray() []interface{}
}
// A List is an ordered collection that can be accessed by index.
type List interface {
Collection
// IndexOf gets the first occurance of the specified value or -1 if not found.
IndexOf(value interface{}) int
// Insert adds elements at the specified index. Can return index not found error.
Insert(index int, values ...interface{}) error
// Get retrieves the value of the element at the specified index.
Get(index int) (interface{}, error)
// RemoveAt removes the element at the specified index.
RemoveAt(index int) error
// Set overwrites the value of the element at the specified index.
Set(index int, value interface{}) error
}
// A Queue provides FIFO access to a collection.
type Queue interface {
Collection
// PeekFirst gets the value of the first element in the collection.
PeekFirst() (interface{}, error)
// PopFirst gets the value of the first element in the collection. The element is removed.
PopFirst() (interface{}, error)
}
// A Deque is a double ended queue.
type Deque interface {
Queue
// AddFirst adds new elements to the beginning of the collection.
AddFirst(values ...interface{})
// PeekLast gets the value of the last element in the collection.
PeekLast() (interface{}, error)
// PopLast gets the value of the last element in the collection. The element is removed.
PopLast() (interface{}, error)
}
// A Stack provides FILO/LIFO access to a collection.
type Stack interface {
Collection
// PeekLast gets the value of the last element in the collection.
PeekLast() (interface{}, error)
// PopLast gets the value of the last element in the collection. The element is removed.
PopLast() (interface{}, error)
}