# package ring
`import "container/ring"`
ring实现了环形链表的操作。
## Index
* [type Ring](#Ring)
* [func New(n int) \*Ring](#New)
* [func (r \*Ring) Len() int](#Ring.Len)
* [func (r \*Ring) Next() \*Ring](#Ring.Next)
* [func (r \*Ring) Prev() \*Ring](#Ring.Prev)
* [func (r \*Ring) Move(n int) \*Ring](#Ring.Move)
* [func (r \*Ring) Link(s \*Ring) \*Ring](#Ring.Link)
* [func (r \*Ring) Unlink(n int) \*Ring](#Ring.Unlink)
* [func (r \*Ring) Do(f func(interface{}))](#Ring.Do)
## type [Ring](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L14 "View Source")
```
type Ring struct {
Value interface{} // 供调用者使用,本包不会操作该字段
// 包含隐藏或非导出字段
}
```
Ring类型代表环形链表的一个元素,同时也代表链表本身。环形链表没有头尾;指向环形链表任一元素的指针都可以作为整个环形链表看待。Ring零值是具有一个(Value字段为nil的)元素的链表。
### func [New](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L62 "View Source")
```
func New(n int) *Ring
```
New创建一个具有n个元素的环形链表。
### func (\*Ring) [Len](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L121 "View Source")
```
func (r *Ring) Len() int
```
Len返回环形链表中的元素个数,复杂度O(n)。
### func (\*Ring) [Next](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L26 "View Source")
```
func (r *Ring) Next() *Ring
```
返回后一个元素,r不能为空。
### func (\*Ring) [Prev](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L34 "View Source")
```
func (r *Ring) Prev() *Ring
```
返回前一个元素,r不能为空。
### func (\*Ring) [Move](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L44 "View Source")
```
func (r *Ring) Move(n int) *Ring
```
返回移动n个位置(n>=0向前移动,n<0向后移动)后的元素,r不能为空。
### func (\*Ring) [Link](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L93 "View Source")
```
func (r *Ring) Link(s *Ring) *Ring
```
Link连接r和s,并返回r原本的后继元素r.Next()。r不能为空。
如果r和s指向同一个环形链表,则会删除掉r和s之间的元素,删掉的元素构成一个子链表,返回指向该子链表的指针(r的原后继元素);如果没有删除元素,则仍然返回r的原后继元素,而不是nil。如果r和s指向不同的链表,将创建一个单独的链表,将s指向的链表插入r后面,返回s原最后一个元素后面的元素(即r的原后继元素)。
### func (\*Ring) [Unlink](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L111 "View Source")
```
func (r *Ring) Unlink(n int) *Ring
```
删除链表中n % r.Len()个元素,从r.Next()开始删除。如果n % r.Len() == 0,不修改r。返回删除的元素构成的链表,r不能为空。
### func (\*Ring) [Do](https://github.com/golang/go/blob/master/src/container/ring/ring.go#L134 "View Source")
```
func (r *Ring) Do(f func(interface{}))
```
对链表的每一个元素都执行f(正向顺序),注意如果f改变了\*r,Do的行为是未定义的。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe