乐趣区

关于go:go源码阅读-containerring

一、介绍
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)
退出移动版