go源码阅读 container/ring

一、介绍
ring是一个首尾相连的list,源码位于 src/container/ring/ring.go
其中每一个元素的定义如下:

// A Ring is an element of a circular list, or ring.
// Rings do not have a beginning or end; a pointer to any ring element
// serves as reference to the entire ring. Empty rings are represented
// as nil Ring pointers. The zero value for a Ring is a one-element
// ring with a nil Value.
//
type Ring struct {
    next, prev *Ring
    Value      interface{} // for use by client; untouched by this library
}

通过New方法可以创建一个特定大小的ring,例如:

r := ring.New(5)

你可能感兴趣的:(go)