func (iterator *Iterator) Begin() // 将迭代器重置为初始状态,然后调用Next获取第一个元素func (iterator *Iterator) End() // 将迭代器移过最后一个元素,然后调用Prev获取最后一个元素// 将迭代器移动到第一个元素,如果容器中有第一个元素则返回true。// 如果First()返回true,则可以通过index()和value()检索第一个元素的索引和值。修改迭代器的状态func (iterator *Iterator) First() bool// 将迭代器移动到最后元素,如果容器中有第一个元素则返回true。// 如果Last()返回true,则可以通过index()和value()检索第一个元素的索引和值。修改迭代器的状态func (iterator *Iterator) Last() boolfunc (iterator *Iterator) Next() boolfunc (iterator *Iterator) Prev() boolfunc (iterator *Iterator) Index() int func (iterator *Iterator) Value() interface{}
func New(values ...interface{}) *Listfunc (list *List) Add(values ...interface{})func (list *List) All(f func(index int, value interface{}) bool) boolfunc (list *List) Any(f func(index int, value interface{}) bool) boolfunc (list *List) Append(values ...interface{})func (list *List) Clear()func (list *List) Contains(values ...interface{}) boolfunc (list *List) Each(f func(index int, value interface{}))func (list *List) Empty() bool// 将容器中的每个元素传递给给定的函数,并返回函数为true或-1的第一个元素(索引,值)// 如果没有元素符合条件,则返回nilfunc (list *List) Find(f func(index int, value interface{}) bool) (index int, value interface{})func (list *List) FromJSON(data []byte) errorfunc (list *List) Get(index int) (interface{}, bool)func (list *List) IndexOf(value interface{}) intfunc (list *List) Insert(index int, values ...interface{})func (list *List) Iterator() Iterator// 为每个元素调用给定函数一次,并返回一个包含给定函数返回值的容器func (list *List) Map(f func(index int, value interface{}) interface{}) *List// 在首部添加元素func (list *List) Prepend(values ...interface{})func (list *List) Remove(index int)// 返回一个新容器,其中包含给定函数返回真值的所有元素func (list *List) Select(f func(index int, value interface{}) bool) *Listfunc (list *List) Set(index int, value interface{})func (list *List) Size() intfunc (list *List) Sort(comparator utils.Comparator)func (list *List) String() stringfunc (list *List) Swap(i, j int)func (list *List) ToJSON() ([]byte, error)func (list *List) Values() []interface{}
例子
package mainimport ( dll "github.com/emirpasic/gods/lists/doublylinkedlist" "github.com/emirpasic/gods/utils")// DoublyLinkedListExample to demonstrate basic usage of DoublyLinkedListfunc main() { list := dll.New() list.Add("a") // ["a"] list.Append("b") // ["a","b"] (same as Add()) list.Prepend("c") // ["c","a","b"] list.Sort(utils.StringComparator) // ["a","b","c"] _, _ = list.Get(0) // "a",true _, _ = list.Get(100) // nil,false _ = list.Contains("a", "b", "c") // true _ = list.Contains("a", "b", "c", "d") // false list.Remove(2) // ["a","b"] list.Remove(1) // ["a"] list.Remove(0) // [] list.Remove(0) // [] (ignored) _ = list.Empty() // true _ = list.Size() // 0 list.Add("a") // ["a"] list.Clear() // []}